import sys I = sys.stdin.read().splitlines() G = [list(l) for l in I] R = len(G) C = len(G[0]) def rotate(G, F): for r in range(R): for c in range(C): F[c][R-1-r] = G[r][c] def tilt(G): for x in range(C): for y in range(R): if G[y][x] == "O": for j in range(y-1,0-1,-1): if G[j][x] == '.': G[j][x] = "O" G[j+1][x] = "." else: break score = lambda: sum((R-y)*row.count('O') for y,row in enumerate(G)) cache = {} F = [['?' for _ in range(C)] for _ in range(R)] # pre-allocate saves 10% time (no GC) target = 1_000_000_000 t = 0 while t