import os if (os.path.isfile("./input")): input = open("./input", "r").read() else: input = "..@@.@@@@.\n@@@.@.@.@@\n@@@@@.@.@@\n@.@@@@..@.\n@@.@@@@.@@\n.@@@@@@@.@\n.@.@.@.@@@\n@.@@@.@@@@\n.@@@@@@@@.\n@.@.@@@.@." map = input.split('\n') if (map[-1] == ""): map.pop() for i in range(len(map)): map[i] = list("." + map[i] + ".") map.append(list("." * len(map[0]))) map.insert(0, list("." * len(map[0]))) r = 0 lastr = -1 while (r != lastr): lastr = r; nmap = map; for y in range(len(map)): for x in range(len(map[y])): if map[y][x] == "@": c = 0 if (map[y+1][x+1] == "@"): c += 1 if (map[y+1][x] == "@"): c += 1 if (map[y+1][x-1] == "@"): c += 1 if (map[y][x+1] == "@"): c += 1 if (map[y][x-1] == "@"): c += 1 if (map[y-1][x+1] == "@"): c += 1 if (map[y-1][x] == "@"): c += 1 if (map[y-1][x-1] == "@"): c += 1 if (c < 4): r += 1 nmap[y][x] = "." map = nmap; print(r)