n = int(input()) if n == 1: print(1) exit() A = [[0]*n for _ in range(n)] for i in range(n): r = [] *a, = input().split() for j in range(n): A[j][i] = -20 if a[j] == "?" else int(a[j]) if a[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])