n = int(input()) a = [list(map(int, input().split())) for _ in range(n)] for i in range(n): for j in range(n): if a[i][j] != a[j][i]: print("No") exit() for i in range(n-1): if a[i][i] != a[i+1][i+1]: print("No") exit() for i in range(n): for j in range(n): for k in range(n): if a[i][a[j][k]] != a[a[i][j]][k]: print("No") exit() print("Yes")