print('day11')


def find(text):
    a = []
    rows = text.split('\n');
    for row in rows:
        ar = []
        for ch in row:
            ar.append(ch);
        a.append(ar)
    # print('a:', a)
    lr = len(a)
    lc = len(a[0])

    def countSeats(sa):
        cc = 0
        for x in range(0, lr):
            for y in range(0, lc):
                if sa[x][y] == '#':
                    cc += 1
        return cc

    def step(sArray):
        print('sArray:', sArray)
        newArray = []
        hasChange = False
        for x in range(0, lr):
            newRow = []
            for y in range(0, lc):
                c = 0;
                for idx in range(-1, 2):
                    for idy in range(-1, 2):
                        if idx == 0 and idy == 0:
                            continue;
                        x1 = x
                        y1 = y
                        dx = idx
                        dy = idy
                        while True:
                            x1 += dx
                            y1 += dy
                            if (x1 < 0 or x1 >= lr) or (y1 < 0 or y1 >= lc) or sArray[x1][y1] == 'L':
                                break
                            if sArray[x1][y1] == '.':
                                continue
                            if sArray[x1][y1] == '#':
                                c += 1
                                break;
                        # if sArray[x1][y1] == '#':
                        #     c += 1
                nsv = sArray[x][y]
                if sArray[x][y] == 'L' and c == 0:
                    hasChange = True
                    nsv = '#'
                elif sArray[x][y] == '#' and c >= 5:
                    hasChange = True
                    nsv = 'L'
                newRow.append(nsv)
            newArray.append(newRow)
        return newArray, hasChange

    hasChange = True
    co = 0
    sArray = a
    while hasChange:
        co += 1
        print("co: ", co)
        sArray, hasChange = step(sArray)
    print('sArray:', sArray)
    return countSeats(sArray)


a = """L.LL.LL.LL
LLLLLLL.LL
L.L.L..L..
LLLL.LL.LL
L.LL.LL.LL
L.LLLLL.LL
..L.L.....
LLLLLLLLLL
L.LLLLLL.L
L.LLLLL.LL"""
b = """LLLLL.LLLLLLLLLLLLLLLLL.LLLLLL.LLLLL.L.LLLLLL.LLLLLL.LLL.LLLLLLLL.LLLLL.L.LLLLLLLLLLLLLLLL.LLLLLLL
LLLLL.LLLLLLLLLLL.LLLLLLLLLLLLLLLLLL.LLLLLLLLL.LLLLL.LLL.LLLLLLLLLLLLL.L.LLLLLLLLLL.LLLLLL.LLLLLLL
LL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