import Intcode code = list(map(int, open("input.txt", "r").read().strip().split(","))) + [0]*10000000 painted = [] x = 500 y = 500 board = [[0]*1001]*1001 index = 0 directions = [(0, 1), (1, 0), (0, -1), (-1, 0)] c = Intcode.Intcode_Computer(code, 0) while not c.halted: c.inputs.append(board[x][y]) for i in range(2): c.run() paint = c.outputs[-2] turn = c.outputs[-1] board[x][y] = paint if((x, y) not in painted): painted.append((x, y)) if(turn == 1): index += 1 if(turn == 0): index -= 1 if(index > 3): index = 0 if(index < 0): index = 3 x += directions[index][0] y += directions[index][1] print(len(painted))