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LLLLLLLL.LLLLLL.LLLLLL..LLLLLLLLLLLLLLLL.LLLLLLL.LLLLLLLL.LLLLL.LLLLLLLL
LLLLLL..LL.L.L..LL.LL....LL..LL.LLL...L..LL...L..L....L......L.L..LLL.L....LLLL.LL....LL.LL.....L.L
LLLLLL.LLLLLLLL.LLLLLLLLL.LLLLLLLLL.LLLLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLL.LLLLLLLLL.LLLLLLLL
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLLL.LLLLLL.LLLLLLLLLLLLLLL.LLLLL.LL.LLLLLLL.LLLLLLLL.LLLLL.LLLLLLLL
LLLLLLLLLL.LLLL.LLLLLLLLL.LLLLLLLLL.LLLLLL.LLLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLLLLL.LLLLL.LLLLLLLL
LLLLLLLLLL.LLLL.LLLLLLLLL.LLLLLLLLL.LLLLLL.LLLLLL.LLLLLLLLLLLLL.LLL.LLLLLL..LLLLLLLL.LLLLL.LLLLLLLL
LLLLLLLLLL.LLLL.LLL.LLLLL.LLLLLLLLL.LLLLLL.LLLLLL.LLLLLLLL.LL.LLLLL.LLLLLLLLLL.LLLLLLLLL.L.LLLLLLLL
.LLLLL.LLL.LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLL.LLLLLLLLLLLLLL.LLLLLLLL"""


def is_empty_rules_not_adjacent(input, positions):
    all_empty = True
    for (row, col) in positions:
        if row >= 0 and col >= 0 and row < len(input) and col < len(input[0]):
            if input[row][col] == "#":
                all_empty = False
    return all_empty


def seat_to_empty_if_all(input, positions):
    occupied = 0
    for (row, col) in positions:
        if row >= 0 and col >= 0 and row < len(input) and col < len(input[0]):
            if input[row][col] == "#":
                occupied += 1
    return occupied >= 5


def change_seat(seat):
    return "L" if seat == "#" else "#"


def calculate_position(index_row, index_col, input):
    return [(index_row, index_col + 1),
            (index_row, index_col - 1),
            (index_row - 1, index_col),
            (index_row + 1, index_col),
            (index_row + 1, index_col - 1),
            (index_row + 1, index_col + 1),
            (index_row - 1, index_col + 1),
            (index_row - 1, index_col - 1)]


def calculate_position_2(index_row, index_col, input):
    result = []
    added_1_col = 1
    for i in range(1, len(input[0])):
        if index_col + i < len(input[0]) and not input[index_row][index_col + i] == ".":
            added_1_col = i
            break
    result.append((index_row, index_col + added_1_col))

    remove_2_col = 1
    for i in range(1, len(input[0])):
        if index_col - i >= 0 and not input[index_row][index_col - i] == ".":
            remove_2_col = i
            break
    result.append((index_row, index_col - remove_2_col))

    add_3_row = 1
    for i in range(1, len(input)):
        if index_row + i < len(input) and not input[index_row + i][index_col] == ".":
            add_3_row = i
            break
    result.append((index_row + add_3_row, index_col))

    remove_4_row = 1
    for i in range(1, len(input)):
        if index_row - i >= 0 and not input[index_row - i][index_col] == ".":
            remove_4_row = i
            break
    result.append((index_row - remove_4_row, index_col))

    add_5_row = 1
    add_5_col = 1
    for i in range(1, len(input)):
        if index_row + i < len(input) and index_col + i < len(input[0]) and not input[index_row + i][
                                                                                    index_col + i] == ".":
            add_5_row = i
            add_5_col = i
            break
    result.append((index_row + add_5_row, index_col + add_5_col))

    add_6_row = 1
    remove_6_col = 1
    for i in range(1, len(input)):
        if index_row + i < len(input) and index_col - i >= 0 and not input[index_row + i][
                                                                         index_col - i] == ".":
            add_6_row = i
            remove_6_col = i
            break
    result.append((index_row + add_6_row, index_col - remove_6_col))

    remove_7_row = 1
    add_7_col = 1
    for i in range(1, len(input)):
        if index_row - i >= 0 and index_col + i < len(input[0]) and not input[index_row - i][
                                                                            index_col + i] == ".":
            remove_7_row = i
            add_7_col = i
            break
    result.append((index_row - remove_7_row, index_col + add_7_col))

    remove_8_row = 1
    remove_8_col = 1
    for i in range(1, len(input)):
        if index_row - i >= 0 and index_col - i >= 0 and not input[index_row - i][
                                                                 index_col - i] == ".":
            remove_8_row = i
            remove_8_col = i
            break
    result.append((index_row - remove_8_row, index_col - remove_8_col))
    return result


def apply_rules(input, index_row, index_col, rules, position_func):
    eight_positions = position_func(index_row, index_col, input)
    seat = input[index_row][index_col]
    changed = False
    for rule in rules[seat]:
        if rule(input, eight_positions):
            changed = True
    return change_seat(seat) if changed else seat


def change_round(input, position_func):
    result = [input]
    while True:
        new_input = []
        for row in range(0, len(result[-1])):
            new_row = ""
            for col in range(0, len(result[-1][row])):
                new_row += apply_rules(result[-1], row, col, {
                    "L": [is_empty_rules_not_adjacent],
                    "#": [seat_to_empty_if_all],
                    ".": []
                }, position_func)
            new_input.append(new_row)
        result.append(new_input)
        if result[-1] == result[-2]:
            break
    total = 0
    for i in result[-1]:
        total += i.count("#")
    print(total)


if __name__ == '__main__':
    input = INPUT.split("\n")
    # change_round(input, calculate_position)
    change_round(input, calculate_position_2)