import sys L = list(map(lambda s: [-999]+list(map(int, s))+[-999] ,sys.stdin.read().splitlines())) L = [[-999]*12] + L + [[-999]*12] def printgrid(): for row in L[1:-1]: print("".join(map(str,row[1:-1]))) printgrid() N = [] for s in range(1000): D = set() print("step",s+1) for x in range(1,11): for y in range(1,11): L[x][y] += 1 flash = True while flash: flash = False for x in range(1,11): for y in range(1,11): curr = L[x][y] if curr > 9: flash = True for (i,j) in [(0,1),(1,0),(-1,0),(0,-1),(1,1),(1,-1),(-1,1),(-1,-1)]: L[x+i][y+j] += 1 if (x+i,y+j) not in D else 0 #N+=1 L[x][y] = 0 D.add((x,y)) # can't increase its energy for the rest of the turn if len(D) == 100: print(s) N.append(s) printgrid() print(N[0]+1)