#%%
f = open("input_2.txt", "r")
# f = open("input.txt", "r")
lines = f.readlines()
print(lines)
f.close()


#%%
for line in lines:
    row = line.replace("\n", "")
    print(row)


# %%
data = []
for line in lines:
    row = line.replace("\n", "")
    data.append(list(row))
    print(row)

rows = len(data)
cols = len(data[0])
grid = [[0] * cols for i in range(rows)]


# %%


def is_safe(row, col, n_row, n_col, data):
    # print(row, col, "=>", n_row, n_col)
    # if 0 > n_row >= rows or 0 > n_col >= cols:
    if n_row < 0 or n_row >= rows:
        # print(f"{n_row} row OOB")
        return False
    if n_col < 0 or n_col >= cols:
        # print(f"{n_col} col OOB")
        return False

    curr = data[row][col]
    next = data[n_row][n_col]
    if curr == "S":
        curr = "a"
    if next == "E":
        next = "z"

    if ord(next) - ord(curr) > 1:
        # print(f"{n_row}, {n_col} TOO HIGH")
        return False

    return True


goal = (2, 5)
# goal = (20, 138)


def bfs(data, start):
    q = [[start]]
    seen = set([start])
    while q:
        print("Q:", q)
        path = q.pop(0)
        print("Path:", path)
        print("Q:", q)
        curr = path[-1]
        if curr == goal:
            print("DEST")
            return path
        row, col = curr
        for n_row, n_col in [
            (row, col + 1),
            (row, col - 1),
            (row + 1, col),
            (row - 1, col),
        ]:
            safe = is_safe(row, col, n_row, n_col, data)
            cache = (n_row, n_col) not in seen
            if safe and cache:
                q.append(path + [(n_row, n_col)])
                seen.add((n_row, n_col))


# %%
path = bfs(data, (0, 0))
print("= ", path)
print(len(path))


# %%
for i, row in enumerate(data):
    # print()
    for j, col in enumerate(row):
        # print(col, end ="")
        if col == "S" or col == "a":
            print(i, j, col)


# %%
a = [
    (0, 0),
    (0, 8),
    (0, 9),
    (0, 12),
    (0, 13),
    (0, 18),
    (0, 19),
    (0, 20),
    (0, 21),
    (0, 22),
    (0, 28),
    (0, 29),
    (0, 30),
    (0, 31),
    (0, 64),
    (0, 65),
    (0, 66),
    (0, 67),
    (0, 68),
    (0, 69),
    (0, 70),
    (0, 71),
    (0, 72),
    (0, 73),
    (0, 74),
    (0, 75),
    (0, 76),
    (0, 77),
    (0, 78),
    (0, 79),
    (0, 80),
    (0, 81),
    (0, 82),
    (0, 99),
    (0, 100),
    (0, 101),
    (0, 114),
    (0, 115),
    (0, 157),
    (0, 158),
    (0, 159),
    (0, 160),
    (1, 0),
    (1, 2),
    (1, 3),
    (1, 4),
    (1, 5),
    (1, 8),
    (1, 9),
    (1, 10),
    (1, 11),
    (1, 12),
    (1, 17),
    (1, 18),
    (1, 19),
    (1, 20),
    (1, 21),
    (1, 28),
    (1, 29),
    (1, 30),
    (1, 31),
    (1, 52),
    (1, 53),
    (1, 54),
    (1, 66),
    (1, 67),
    (1, 68),
    (1, 69),
    (1, 70),
    (1, 71),
    (1, 72),
    (1, 73),
    (1, 74),
    (1, 75),
    (1, 76),
    (1, 77),
    (1, 78),
    (1, 79),
    (1, 80),
    (1, 81),
    (1, 82),
    (1, 83),
    (1, 100),
    (1, 101),
    (1, 102),
    (1, 103),
    (1, 110),
    (1, 111),
    (1, 112),
    (1, 114),
    (1, 115),
    (1, 156),
    (1, 157),
    (1, 158),
    (1, 159),
    (1, 160),
    (2, 0),
    (2, 2),
    (2, 3),
    (2, 4),
    (2, 8),
    (2, 9),
    (2, 10),
    (2, 11),
    (2, 12),
    (2, 13),
    (2, 14),
    (2, 15),
    (2, 17),
    (2, 18),
    (2, 19),
    (2, 20),
    (2, 21),
    (2, 22),
    (2, 28),
    (2, 29),
    (2, 30),
    (2, 31),
    (2, 52),
    (2, 53),
    (2, 54),
    (2, 55),
    (2, 56),
    (2, 66),
    (2, 67),
    (2, 68),
    (2, 69),
    (2, 70),
    (2, 71),
    (2, 72),
    (2, 73),
    (2, 74),
    (2, 75),
    (2, 76),
    (2, 77),
    (2, 78),
    (2, 79),
    (2, 80),
    (2, 81),
    (2, 82),
    (2, 92),
    (2, 93),
    (2, 98),
    (2, 99),
    (2, 100),
    (2, 101),
    (2, 102),
    (2, 103),
    (2, 111),
    (2, 112),
    (2, 113),
    (2, 114),
    (2, 115),
    (2, 120),
    (2, 121),
    (2, 136),
    (2, 156),
    (2, 157),
    (2, 158),
    (2, 159),
    (2, 160),
    (3, 0),
    (3, 2),
    (3, 3),
    (3, 4),
    (3, 10),
    (3, 11),
    (3, 12),
    (3, 13),
    (3, 14),
    (3, 19),
    (3, 20),
    (3, 21),
    (3, 22),
    (3, 29),
    (3, 30),
    (3, 31),
    (3, 51),
    (3, 52),
    (3, 53),
    (3, 54),
    (3, 55),
    (3, 66),
    (3, 67),
    (3, 68),
    (3, 69),
    (3, 70),
    (3, 71),
    (3, 73),
    (3, 75),
    (3, 76),
    (3, 77),
    (3, 78),
    (3, 79),
    (3, 80),
    (3, 92),
    (3, 93),
    (3, 98),
    (3, 99),
    (3, 100),
    (3, 101),
    (3, 102),
    (3, 112),
    (3, 113),
    (3, 114),
    (3, 115),
    (3, 116),
    (3, 117),
    (3, 120),
    (3, 121),
    (3, 122),
    (3, 123),
    (3, 124),
    (3, 125),
    (3, 136),
    (3, 137),
    (3, 138),
    (3, 143),
    (3, 155),
    (3, 156),
    (3, 157),
    (3, 158),
    (3, 159),
    (3, 160),
    (4, 0),
    (4, 2),
    (4, 3),
    (4, 9),
    (4, 10),
    (4, 11),
    (4, 12),
    (4, 13),
    (4, 18),
    (4, 19),
    (4, 35),
    (4, 36),
    (4, 37),
    (4, 38),
    (4, 39),
    (4, 51),
    (4, 52),
    (4, 53),
    (4, 54),
    (4, 55),
    (4, 65),
    (4, 66),
    (4, 67),
    (4, 68),
    (4, 69),
    (4, 70),
    (4, 71),
    (4, 72),
    (4, 75),
    (4, 76),
    (4, 77),
    (4, 78),
    (4, 79),
    (4, 80),
    (4, 81),
    (4, 89),
    (4, 90),
    (4, 91),
    (4, 92),
    (4, 93),
    (4, 94),
    (4, 95),
    (4, 96),
    (4, 99),
    (4, 100),
    (4, 101),
    (4, 102),
    (4, 103),
    (4, 111),
    (4, 112),
    (4, 113),
    (4, 114),
    (4, 115),
    (4, 116),
    (4, 117),
    (4, 120),
    (4, 121),
    (4, 122),
    (4, 123),
    (4, 124),
    (4, 136),
    (4, 137),
    (4, 138),
    (4, 142),
    (4, 143),
    (4, 144),
    (4, 159),
    (4, 160),
    (5, 0),
    (5, 2),
    (5, 3),
    (5, 4),
    (5, 8),
    (5, 9),
    (5, 10),
    (5, 12),
    (5, 13),
    (5, 35),
    (5, 36),
    (5, 37),
    (5, 38),
    (5, 39),
    (5, 52),
    (5, 53),
    (5, 54),
    (5, 55),
    (5, 56),
    (5, 64),
    (5, 65),
    (5, 66),
    (5, 67),
    (5, 68),
    (5, 69),
    (5, 70),
    (5, 71),
    (5, 72),
    (5, 75),
    (5, 76),
    (5, 79),
    (5, 80),
    (5, 81),
    (5, 89),
    (5, 90),
    (5, 91),
    (5, 92),
    (5, 93),
    (5, 94),
    (5, 95),
    (5, 96),
    (5, 99),
    (5, 100),
    (5, 110),
    (5, 111),
    (5, 112),
    (5, 113),
    (5, 114),
    (5, 115),
    (5, 118),
    (5, 119),
    (5, 120),
    (5, 121),
    (5, 122),
    (5, 123),
    (5, 136),
    (5, 137),
    (5, 138),
    (5, 139),
    (5, 141),
    (5, 142),
    (5, 143),
    (5, 144),
    (5, 159),
    (5, 160),
    (6, 0),
    (6, 2),
    (6, 3),
    (6, 4),
    (6, 12),
    (6, 13),
    (6, 34),
    (6, 35),
    (6, 36),
    (6, 37),
    (6, 38),
    (6, 39),
    (6, 52),
    (6, 53),
    (6, 60),
    (6, 61),
    (6, 65),
    (6, 66),
    (6, 67),
    (6, 70),
    (6, 71),
    (6, 72),
    (6, 73),
    (6, 80),
    (6, 81),
    (6, 91),
    (6, 92),
    (6, 93),
    (6, 94),
    (6, 110),
    (6, 111),
    (6, 113),
    (6, 114),
    (6, 115),
    (6, 118),
    (6, 119),
    (6, 120),
    (6, 121),
    (6, 122),
    (6, 123),
    (6, 124),
    (6, 137),
    (7, 0),
    (7, 3),
    (7, 4),
    (7, 34),
    (7, 35),
    (7, 36),
    (7, 37),
    (7, 38),
    (7, 39),
    (7, 60),
    (7, 61),
    (7, 62),
    (7, 63),
    (7, 70),
    (7, 71),
    (7, 72),
    (7, 73),
    (7, 88),
    (7, 89),
    (7, 91),
    (7, 92),
    (7, 93),
    (7, 94),
    (7, 95),
    (7, 114),
    (7, 115),
    (7, 120),
    (7, 121),
    (7, 122),
    (7, 123),
    (7, 124),
    (7, 125),
    (7, 151),
    (7, 152),
    (7, 153),
    (8, 0),
    (8, 34),
    (8, 35),
    (8, 36),
    (8, 37),
    (8, 38),
    (8, 39),
    (8, 42),
    (8, 43),
    (8, 58),
    (8, 59),
    (8, 60),
    (8, 61),
    (8, 62),
    (8, 63),
    (8, 71),
    (8, 72),
    (8, 73),
    (8, 85),
    (8, 86),
    (8, 88),
    (8, 89),
    (8, 90),
    (8, 91),
    (8, 92),
    (8, 93),
    (8, 94),
    (8, 95),
    (8, 120),
    (8, 121),
    (8, 124),
    (8, 125),
    (8, 134),
    (8, 151),
    (8, 152),
    (8, 153),
    (8, 155),
    (9, 0),
    (9, 25),
    (9, 26),
    (9, 27),
    (9, 35),
    (9, 36),
    (9, 37),
    (9, 39),
    (9, 41),
    (9, 42),
    (9, 43),
    (9, 59),
    (9, 60),
    (9, 61),
    (9, 62),
    (9, 67),
    (9, 68),
    (9, 85),
    (9, 86),
    (9, 87),
    (9, 88),
    (9, 89),
    (9, 90),
    (9, 91),
    (9, 95),
    (9, 120),
    (9, 121),
    (9, 133),
    (9, 149),
    (9, 150),
    (9, 151),
    (9, 152),
    (9, 153),
    (9, 154),
    (9, 155),
    (9, 156),
    (10, 0),
    (10, 24),
    (10, 25),
    (10, 26),
    (10, 27),
    (10, 38),
    (10, 39),
    (10, 40),
    (10, 41),
    (10, 42),
    (10, 59),
    (10, 60),
    (10, 61),
    (10, 62),
    (10, 63),
    (10, 67),
    (10, 68),
    (10, 69),
    (10, 70),
    (10, 71),
    (10, 86),
    (10, 87),
    (10, 88),
    (10, 89),
    (10, 90),
    (10, 91),
    (10, 149),
    (10, 150),
    (10, 151),
    (10, 152),
    (10, 153),
    (10, 154),
    (10, 155),
    (10, 156),
    (11, 0),
    (11, 24),
    (11, 25),
    (11, 26),
    (11, 27),
    (11, 38),
    (11, 39),
    (11, 40),
    (11, 41),
    (11, 42),
    (11, 43),
    (11, 44),
    (11, 45),
    (11, 59),
    (11, 60),
    (11, 62),
    (11, 63),
    (11, 66),
    (11, 67),
    (11, 68),
    (11, 69),
    (11, 70),
    (11, 78),
    (11, 79),
    (11, 80),
    (11, 84),
    (11, 85),
    (11, 86),
    (11, 87),
    (11, 88),
    (11, 89),
    (11, 90),
    (11, 91),
    (11, 150),
    (11, 151),
    (11, 152),
    (11, 153),
    (11, 154),
    (11, 155),
    (12, 0),
    (12, 11),
    (12, 12),
    (12, 25),
    (12, 26),
    (12, 27),
    (12, 40),
    (12, 41),
    (12, 42),
    (12, 43),
    (12, 44),
    (12, 66),
    (12, 67),
    (12, 68),
    (12, 69),
    (12, 70),
    (12, 77),
    (12, 78),
    (12, 79),
    (12, 80),
    (12, 84),
    (12, 85),
    (12, 86),
    (12, 87),
    (12, 88),
    (12, 90),
    (12, 91),
    (12, 105),
    (12, 106),
    (12, 108),
    (12, 109),
    (12, 151),
    (12, 152),
    (12, 153),
    (12, 154),
    (12, 155),
    (13, 0),
    (13, 11),
    (13, 12),
    (13, 13),
    (13, 39),
    (13, 40),
    (13, 41),
    (13, 42),
    (13, 43),
    (13, 67),
    (13, 68),
    (13, 69),
    (13, 70),
    (13, 71),
    (13, 77),
    (13, 78),
    (13, 79),
    (13, 80),
    (13, 87),
    (13, 88),
    (13, 105),
    (13, 106),
    (13, 107),
    (13, 108),
    (13, 109),
    (13, 150),
    (13, 151),
    (13, 152),
    (13, 153),
    (13, 154),
    (13, 155),
    (14, 0),
    (14, 8),
    (14, 9),
    (14, 10),
    (14, 11),
    (14, 12),
    (14, 13),
    (14, 14),
    (14, 15),
    (14, 19),
    (14, 20),
    (14, 39),
    (14, 40),
    (14, 42),
    (14, 43),
    (14, 46),
    (14, 47),
    (14, 49),
    (14, 50),
    (14, 67),
    (14, 68),
    (14, 78),
    (14, 79),
    (14, 80),
    (14, 87),
    (14, 88),
    (14, 104),
    (14, 105),
    (14, 106),
    (14, 107),
    (14, 108),
    (14, 152),
    (15, 0),
    (15, 8),
    (15, 9),
    (15, 10),
    (15, 11),
    (15, 12),
    (15, 13),
    (15, 14),
    (15, 15),
    (15, 17),
    (15, 19),
    (15, 20),
    (15, 21),
    (15, 22),
    (15, 42),
    (15, 43),
    (15, 46),
    (15, 47),
    (15, 48),
    (15, 49),
    (15, 50),
    (15, 104),
    (15, 105),
    (15, 106),
    (15, 107),
    (15, 108),
    (15, 109),
    (15, 117),
    (15, 118),
    (16, 0),
    (16, 9),
    (16, 10),
    (16, 11),
    (16, 12),
    (16, 13),
    (16, 14),
    (16, 17),
    (16, 18),
    (16, 19),
    (16, 20),
    (16, 21),
    (16, 22),
    (16, 33),
    (16, 34),
    (16, 45),
    (16, 46),
    (16, 47),
    (16, 48),
    (16, 49),
    (16, 74),
    (16, 75),
    (16, 76),
    (16, 106),
    (16, 107),
    (16, 108),
    (16, 109),
    (16, 112),
    (16, 113),
    (16, 116),
    (16, 117),
    (16, 118),
    (16, 122),
    (16, 123),
    (16, 124),
    (17, 0),
    (17, 9),
    (17, 10),
    (17, 11),
    (17, 12),
    (17, 13),
    (17, 14),
    (17, 18),
    (17, 19),
    (17, 20),
    (17, 21),
    (17, 31),
    (17, 32),
    (17, 33),
    (17, 34),
    (17, 35),
    (17, 36),
    (17, 45),
    (17, 46),
    (17, 47),
    (17, 48),
    (17, 49),
    (17, 50),
    (17, 74),
    (17, 75),
    (17, 76),
    (17, 106),
    (17, 112),
    (17, 113),
    (17, 114),
    (17, 115),
    (17, 116),
    (17, 117),
    (17, 118),
    (17, 120),
    (17, 121),
    (17, 122),
    (17, 123),
    (17, 124),
    (18, 0),
    (18, 9),
    (18, 10),
    (18, 11),
    (18, 12),
    (18, 13),
    (18, 14),
    (18, 18),
    (18, 19),
    (18, 20),
    (18, 21),
    (18, 31),
    (18, 32),
    (18, 33),
    (18, 34),
    (18, 35),
    (18, 36),
    (18, 42),
    (18, 43),
    (18, 44),
    (18, 45),
    (18, 46),
    (18, 47),
    (18, 48),
    (18, 49),
    (18, 50),
    (18, 71),
    (18, 72),
    (18, 73),
    (18, 74),
    (18, 75),
    (18, 76),
    (18, 77),
    (18, 78),
    (18, 100),
    (18, 101),
    (18, 102),
    (18, 109),
    (18, 110),
    (18, 112),
    (18, 113),
    (18, 114),
    (18, 115),
    (18, 116),
    (18, 117),
    (18, 120),
    (18, 121),
    (18, 122),
    (18, 123),
    (18, 124),
    (19, 0),
    (19, 9),
    (19, 10),
    (19, 13),
    (19, 14),
    (19, 18),
    (19, 19),
    (19, 21),
    (19, 24),
    (19, 25),
    (19, 26),
    (19, 27),
    (19, 32),
    (19, 33),
    (19, 34),
    (19, 35),
    (19, 36),
    (19, 42),
    (19, 43),
    (19, 44),
    (19, 45),
    (19, 46),
    (19, 47),
    (19, 48),
    (19, 49),
    (19, 50),
    (19, 71),
    (19, 72),
    (19, 73),
    (19, 74),
    (19, 75),
    (19, 76),
    (19, 77),
    (19, 78),
    (19, 100),
    (19, 101),
    (19, 102),
    (19, 104),
    (19, 105),
    (19, 106),
    (19, 107),
    (19, 108),
    (19, 109),
    (19, 110),
    (19, 113),
    (19, 114),
    (19, 115),
    (19, 116),
    (19, 117),
    (19, 118),
    (19, 119),
    (19, 120),
    (19, 121),
    (19, 122),
    (19, 123),
    (19, 124),
    (19, 125),
    (20, 0),
    (20, 24),
    (20, 25),
    (20, 26),
    (20, 27),
    (20, 31),
    (20, 32),
    (20, 33),
    (20, 34),
    (20, 35),
    (20, 43),
    (20, 44),
    (20, 45),
    (20, 46),
    (20, 47),
    (20, 48),
    (20, 49),
    (20, 50),
    (20, 51),
    (20, 53),
    (20, 54),
    (20, 55),
    (20, 64),
    (20, 65),
    (20, 73),
    (20, 74),
    (20, 75),
    (20, 76),
    (20, 77),
    (20, 86),
    (20, 87),
    (20, 88),
    (20, 89),
    (20, 90),
    (20, 100),
    (20, 101),
    (20, 102),
    (20, 103),
    (20, 104),
    (20, 105),
    (20, 106),
    (20, 107),
    (20, 108),
    (20, 109),
    (20, 110),
    (20, 111),
    (20, 112),
    (20, 113),
    (20, 114),
    (20, 115),
    (20, 116),
    (20, 117),
    (20, 118),
    (20, 119),
    (20, 120),
    (20, 121),
    (20, 122),
    (20, 123),
    (20, 124),
    (21, 0),
    (21, 24),
    (21, 25),
    (21, 26),
    (21, 27),
    (21, 31),
    (21, 32),
    (21, 33),
    (21, 34),
    (21, 35),
    (21, 43),
    (21, 44),
    (21, 45),
    (21, 46),
    (21, 47),
    (21, 48),
    (21, 49),
    (21, 50),
    (21, 53),
    (21, 54),
    (21, 55),
    (21, 64),
    (21, 65),
    (21, 66),
    (21, 68),
    (21, 69),
    (21, 72),
    (21, 73),
    (21, 74),
    (21, 75),
    (21, 76),
    (21, 77),
    (21, 86),
    (21, 87),
    (21, 88),
    (21, 89),
    (21, 90),
    (21, 98),
    (21, 99),
    (21, 100),
    (21, 101),
    (21, 102),
    (21, 103),
    (21, 104),
    (21, 105),
    (21, 106),
    (21, 107),
    (21, 108),
    (21, 109),
    (21, 110),
    (21, 111),
    (21, 112),
    (21, 113),
    (21, 114),
    (21, 115),
    (21, 116),
    (21, 117),
    (21, 118),
    (21, 119),
    (21, 120),
    (21, 121),
    (21, 122),
    (21, 123),
    (21, 124),
    (22, 0),
    (22, 5),
    (22, 6),
    (22, 7),
    (22, 24),
    (22, 25),
    (22, 26),
    (22, 43),
    (22, 44),
    (22, 45),
    (22, 46),
    (22, 47),
    (22, 48),
    (22, 49),
    (22, 50),
    (22, 51),
    (22, 52),
    (22, 53),
    (22, 54),
    (22, 55),
    (22, 64),
    (22, 65),
    (22, 66),
    (22, 67),
    (22, 68),
    (22, 69),
    (22, 72),
    (22, 73),
    (22, 74),
    (22, 75),
    (22, 76),
    (22, 77),
    (22, 85),
    (22, 86),
    (22, 87),
    (22, 88),
    (22, 89),
    (22, 90),
    (22, 94),
    (22, 95),
    (22, 96),
    (22, 99),
    (22, 100),
    (22, 101),
    (22, 102),
    (22, 103),
    (22, 106),
    (22, 107),
    (22, 108),
    (22, 109),
    (22, 110),
    (22, 111),
    (22, 112),
    (22, 113),
    (22, 114),
    (22, 115),
    (22, 116),
    (22, 117),
    (23, 0),
    (23, 3),
    (23, 4),
    (23, 5),
    (23, 6),
    (23, 7),
    (23, 42),
    (23, 43),
    (23, 44),
    (23, 45),
    (23, 46),
    (23, 47),
    (23, 48),
    (23, 49),
    (23, 50),
    (23, 51),
    (23, 52),
    (23, 53),
    (23, 54),
    (23, 62),
    (23, 63),
    (23, 64),
    (23, 65),
    (23, 66),
    (23, 67),
    (23, 68),
    (23, 72),
    (23, 75),
    (23, 76),
    (23, 77),
    (23, 85),
    (23, 86),
    (23, 87),
    (23, 88),
    (23, 89),
    (23, 90),
    (23, 94),
    (23, 95),
    (23, 96),
    (23, 100),
    (23, 101),
    (23, 102),
    (23, 103),
    (23, 104),
    (23, 105),
    (23, 106),
    (23, 107),
    (23, 108),
    (23, 109),
    (23, 110),
    (23, 115),
    (23, 116),
    (23, 117),
    (23, 121),
    (23, 122),
    (23, 123),
    (23, 124),
    (23, 125),
    (24, 0),
    (24, 3),
    (24, 4),
    (24, 5),
    (24, 6),
    (24, 7),
    (24, 8),
    (24, 43),
    (24, 44),
    (24, 47),
    (24, 48),
    (24, 49),
    (24, 50),
    (24, 51),
    (24, 52),
    (24, 53),
    (24, 54),
    (24, 55),
    (24, 56),
    (24, 57),
    (24, 62),
    (24, 63),
    (24, 64),
    (24, 65),
    (24, 66),
    (24, 67),
    (24, 68),
    (24, 86),
    (24, 87),
    (24, 88),
    (24, 89),
    (24, 90),
    (24, 94),
    (24, 95),
    (24, 96),
    (24, 98),
    (24, 99),
    (24, 100),
    (24, 101),
    (24, 103),
    (24, 104),
    (24, 105),
    (24, 106),
    (24, 107),
    (24, 108),
    (24, 109),
    (24, 110),
    (24, 115),
    (24, 116),
    (24, 117),
    (24, 121),
    (24, 122),
    (24, 123),
    (24, 124),
    (24, 125),
    (25, 0),
    (25, 3),
    (25, 4),
    (25, 5),
    (25, 6),
    (25, 7),
    (25, 8),
    (25, 16),
    (25, 17),
    (25, 19),
    (25, 20),
    (25, 47),
    (25, 48),
    (25, 49),
    (25, 50),
    (25, 51),
    (25, 52),
    (25, 53),
    (25, 54),
    (25, 55),
    (25, 56),
    (25, 57),
    (25, 64),
    (25, 65),
    (25, 66),
    (25, 67),
    (25, 68),
    (25, 86),
    (25, 87),
    (25, 88),
    (25, 91),
    (25, 92),
    (25, 93),
    (25, 94),
    (25, 95),
    (25, 96),
    (25, 97),
    (25, 98),
    (25, 99),
    (25, 100),
    (25, 101),
    (25, 109),
    (25, 110),
    (25, 120),
    (25, 121),
    (25, 122),
    (25, 123),
    (25, 124),
    (25, 125),
    (26, 0),
    (26, 3),
    (26, 4),
    (26, 5),
    (26, 6),
    (26, 7),
    (26, 16),
    (26, 17),
    (26, 18),
    (26, 19),
    (26, 20),
    (26, 49),
    (26, 50),
    (26, 51),
    (26, 52),
    (26, 53),
    (26, 54),
    (26, 55),
    (26, 56),
    (26, 64),
    (26, 65),
    (26, 67),
    (26, 68),
    (26, 69),
    (26, 91),
    (26, 92),
    (26, 93),
    (26, 94),
    (26, 95),
    (26, 96),
    (26, 97),
    (26, 98),
    (26, 99),
    (26, 120),
    (26, 121),
    (26, 122),
    (26, 123),
    (26, 124),
    (26, 125),
    (27, 0),
    (27, 3),
    (27, 4),
    (27, 5),
    (27, 6),
    (27, 7),
    (27, 15),
    (27, 16),
    (27, 17),
    (27, 18),
    (27, 19),
    (27, 48),
    (27, 49),
    (27, 50),
    (27, 51),
    (27, 52),
    (27, 53),
    (27, 54),
    (27, 64),
    (27, 65),
    (27, 92),
    (27, 93),
    (27, 94),
    (27, 95),
    (27, 96),
    (27, 97),
    (27, 98),
    (27, 110),
    (27, 111),
    (27, 112),
    (27, 121),
    (27, 122),
    (27, 123),
    (27, 124),
    (27, 125),
    (27, 153),
    (27, 154),
    (28, 0),
    (28, 15),
    (28, 16),
    (28, 17),
    (28, 18),
    (28, 19),
    (28, 20),
    (28, 41),
    (28, 42),
    (28, 52),
    (28, 53),
    (28, 54),
    (28, 93),
    (28, 94),
    (28, 95),
    (28, 96),
    (28, 97),
    (28, 98),
    (28, 111),
    (28, 112),
    (28, 113),
    (28, 114),
    (28, 121),
    (28, 122),
    (28, 123),
    (28, 153),
    (28, 154),
    (29, 0),
    (29, 17),
    (29, 18),
    (29, 19),
    (29, 20),
    (29, 40),
    (29, 41),
    (29, 42),
    (29, 43),
    (29, 51),
    (29, 53),
    (29, 54),
    (29, 55),
    (29, 93),
    (29, 94),
    (29, 95),
    (29, 96),
    (29, 97),
    (29, 98),
    (29, 99),
    (29, 109),
    (29, 110),
    (29, 111),
    (29, 112),
    (29, 113),
    (29, 114),
    (29, 152),
    (29, 153),
    (29, 154),
    (29, 155),
    (29, 156),
    (30, 0),
    (30, 17),
    (30, 40),
    (30, 41),
    (30, 42),
    (30, 43),
    (30, 51),
    (30, 52),
    (30, 53),
    (30, 54),
    (30, 55),
    (30, 93),
    (30, 94),
    (30, 95),
    (30, 97),
    (30, 98),
    (30, 99),
    (30, 109),
    (30, 110),
    (30, 111),
    (30, 112),
    (30, 113),
    (30, 152),
    (30, 153),
    (30, 154),
    (30, 155),
    (30, 156),
    (31, 0),
    (31, 40),
    (31, 41),
    (31, 42),
    (31, 43),
    (31, 52),
    (31, 53),
    (31, 54),
    (31, 55),
    (31, 56),
    (31, 82),
    (31, 83),
    (31, 84),
    (31, 93),
    (31, 94),
    (31, 110),
    (31, 111),
    (31, 112),
    (31, 113),
    (31, 114),
    (31, 152),
    (31, 153),
    (31, 154),
    (31, 155),
    (31, 156),
    (32, 0),
    (32, 51),
    (32, 52),
    (32, 53),
    (32, 54),
    (32, 55),
    (32, 56),
    (32, 74),
    (32, 75),
    (32, 76),
    (32, 77),
    (32, 78),
    (32, 81),
    (32, 82),
    (32, 83),
    (32, 84),
    (32, 110),
    (32, 111),
    (32, 151),
    (32, 152),
    (32, 153),
    (32, 154),
    (33, 0),
    (33, 9),
    (33, 10),
    (33, 11),
    (33, 20),
    (33, 51),
    (33, 52),
    (33, 53),
    (33, 54),
    (33, 67),
    (33, 68),
    (33, 69),
    (33, 74),
    (33, 75),
    (33, 76),
    (33, 77),
    (33, 78),
    (33, 81),
    (33, 82),
    (33, 83),
    (33, 84),
    (33, 151),
    (33, 152),
    (33, 153),
    (33, 154),
    (33, 155),
    (34, 0),
    (34, 5),
    (34, 6),
    (34, 9),
    (34, 10),
    (34, 11),
    (34, 17),
    (34, 18),
    (34, 19),
    (34, 20),
    (34, 26),
    (34, 27),
    (34, 53),
    (34, 54),
    (34, 55),
    (34, 67),
    (34, 68),
    (34, 69),
    (34, 73),
    (34, 74),
    (34, 75),
    (34, 76),
    (34, 77),
    (34, 78),
    (34, 82),
    (34, 83),
    (34, 84),
    (34, 153),
    (34, 154),
    (35, 0),
    (35, 5),
    (35, 6),
    (35, 7),
    (35, 8),
    (35, 9),
    (35, 10),
    (35, 11),
    (35, 17),
    (35, 18),
    (35, 19),
    (35, 20),
    (35, 21),
    (35, 22),
    (35, 25),
    (35, 26),
    (35, 27),
    (35, 55),
    (35, 67),
    (35, 68),
    (35, 69),
    (35, 70),
    (35, 73),
    (35, 74),
    (35, 75),
    (35, 76),
    (35, 77),
    (35, 78),
    (35, 105),
    (35, 106),
    (35, 116),
    (35, 117),
    (35, 118),
    (35, 133),
    (35, 134),
    (35, 135),
    (35, 136),
    (35, 137),
    (35, 138),
    (36, 0),
    (36, 5),
    (36, 6),
    (36, 7),
    (36, 8),
    (36, 9),
    (36, 10),
    (36, 18),
    (36, 19),
    (36, 20),
    (36, 21),
    (36, 25),
    (36, 26),
    (36, 27),
    (36, 29),
    (36, 30),
    (36, 31),
    (36, 36),
    (36, 37),
    (36, 38),
    (36, 39),
    (36, 49),
    (36, 50),
    (36, 51),
    (36, 53),
    (36, 54),
    (36, 55),
    (36, 62),
    (36, 63),
    (36, 67),
    (36, 68),
    (36, 69),
    (36, 70),
    (36, 72),
    (36, 73),
    (36, 74),
    (36, 75),
    (36, 76),
    (36, 77),
    (36, 78),
    (36, 104),
    (36, 105),
    (36, 106),
    (36, 115),
    (36, 116),
    (36, 117),
    (36, 118),
    (36, 138),
    (36, 139),
    (36, 140),
    (36, 141),
    (37, 0),
    (37, 6),
    (37, 7),
    (37, 8),
    (37, 9),
    (37, 10),
    (37, 11),
    (37, 12),
    (37, 13),
    (37, 17),
    (37, 18),
    (37, 19),
    (37, 20),
    (37, 21),
    (37, 22),
    (37, 23),
    (37, 24),
    (37, 25),
    (37, 26),
    (37, 27),
    (37, 28),
    (37, 29),
    (37, 30),
    (37, 31),
    (37, 36),
    (37, 37),
    (37, 38),
    (37, 39),
    (37, 49),
    (37, 50),
    (37, 51),
    (37, 52),
    (37, 53),
    (37, 54),
    (37, 55),
    (37, 61),
    (37, 62),
    (37, 63),
    (37, 67),
    (37, 68),
    (37, 69),
    (37, 70),
    (37, 71),
    (37, 72),
    (37, 73),
    (37, 74),
    (37, 75),
    (37, 76),
    (37, 100),
    (37, 101),
    (37, 102),
    (37, 104),
    (37, 105),
    (37, 106),
    (37, 115),
    (37, 116),
    (37, 117),
    (37, 118),
    (37, 139),
    (37, 140),
    (37, 141),
    (37, 156),
    (37, 157),
    (37, 158),
    (37, 160),
    (38, 0),
    (38, 5),
    (38, 6),
    (38, 7),
    (38, 8),
    (38, 9),
    (38, 10),
    (38, 11),
    (38, 12),
    (38, 13),
    (38, 17),
    (38, 18),
    (38, 20),
    (38, 21),
    (38, 22),
    (38, 23),
    (38, 24),
    (38, 25),
    (38, 26),
    (38, 27),
    (38, 28),
    (38, 29),
    (38, 30),
    (38, 36),
    (38, 37),
    (38, 38),
    (38, 39),
    (38, 50),
    (38, 51),
    (38, 52),
    (38, 53),
    (38, 54),
    (38, 55),
    (38, 57),
    (38, 58),
    (38, 59),
    (38, 61),
    (38, 62),
    (38, 63),
    (38, 65),
    (38, 66),
    (38, 67),
    (38, 68),
    (38, 69),
    (38, 70),
    (38, 71),
    (38, 72),
    (38, 73),
    (38, 74),
    (38, 90),
    (38, 91),
    (38, 92),
    (38, 100),
    (38, 101),
    (38, 102),
    (38, 103),
    (38, 104),
    (38, 105),
    (38, 106),
    (38, 107),
    (38, 108),
    (38, 109),
    (38, 116),
    (38, 117),
    (38, 118),
    (38, 139),
    (38, 140),
    (38, 156),
    (38, 157),
    (38, 158),
    (38, 159),
    (38, 160),
    (39, 0),
    (39, 5),
    (39, 6),
    (39, 7),
    (39, 8),
    (39, 9),
    (39, 10),
    (39, 11),
    (39, 12),
    (39, 24),
    (39, 25),
    (39, 26),
    (39, 27),
    (39, 28),
    (39, 29),
    (39, 37),
    (39, 38),
    (39, 50),
    (39, 51),
    (39, 52),
    (39, 53),
    (39, 54),
    (39, 55),
    (39, 56),
    (39, 57),
    (39, 58),
    (39, 59),
    (39, 60),
    (39, 61),
    (39, 62),
    (39, 63),
    (39, 64),
    (39, 65),
    (39, 66),
    (39, 67),
    (39, 68),
    (39, 69),
    (39, 70),
    (39, 71),
    (39, 72),
    (39, 73),
    (39, 90),
    (39, 91),
    (39, 92),
    (39, 93),
    (39, 101),
    (39, 102),
    (39, 103),
    (39, 104),
    (39, 105),
    (39, 106),
    (39, 107),
    (39, 108),
    (39, 109),
    (39, 139),
    (39, 140),
    (39, 141),
    (39, 157),
    (39, 158),
    (39, 159),
    (39, 160),
    (40, 0),
    (40, 4),
    (40, 5),
    (40, 6),
    (40, 7),
    (40, 8),
    (40, 9),
    (40, 10),
    (40, 24),
    (40, 25),
    (40, 26),
    (40, 27),
    (40, 28),
    (40, 29),
    (40, 30),
    (40, 48),
    (40, 49),
    (40, 50),
    (40, 51),
    (40, 52),
    (40, 53),
    (40, 54),
    (40, 55),
    (40, 56),
    (40, 57),
    (40, 58),
    (40, 59),
    (40, 60),
    (40, 61),
    (40, 62),
    (40, 63),
    (40, 64),
    (40, 65),
    (40, 66),
    (40, 67),
    (40, 68),
    (40, 69),
    (40, 70),
    (40, 71),
    (40, 72),
    (40, 73),
    (40, 74),
    (40, 90),
    (40, 91),
    (40, 92),
    (40, 93),
    (40, 101),
    (40, 102),
    (40, 103),
    (40, 104),
    (40, 105),
    (40, 106),
    (40, 107),
    (40, 108),
    (40, 156),
    (40, 157),
    (40, 158),
    (40, 159),
    (40, 160),
]

p = []
for start in a:
    # print(start)
    tmp = bfs(data, start)
    if tmp:
        p.append(len(tmp))

print(min(p))

# %%
