n = int(input()) if n == 1: exit(print(1)) a = [[0] * n for _ in range(n)] for i in range(n): k = list(input().split()) for j in range(n): a[j][i] = -20 if k[j] == "?" else int(k[j]) if k[j] == "?": x, y = j, i def check(a): def f(i, j): return sum(p * q for p, q in zip(a[i], a[j])) v = f(0, 0) for i in range(n): for j in range(n): if i != j and f(i, j): return 0 return 1 while not check(a): a[x][y] += 1 print(a[x][y])