N = int(input()) A = [list(map(int, input().split())) for _ in range(N)] for i in range(N): for j in range(N): for k in range(N): if A[A[i][j]][k] != A[i][A[j][k]]: exit(print("No")) for i in range(N): if all(A[i][j] == A[j][i] == j for j in range(N)) and all(any(A[j][k] == A[k][j] == i for k in range(N)) for j in range(N)): exit(print("Yes")) print("No")