N = int(input()) L = [] for _ in range(N): L.append(list(map(int, input().split()))) check1 = 1 for i in range(N): for j in range(N): for k in range(N): if L[L[i][j]][k] != L[i][L[j][k]]: check1 = 0 break e = -1 check2 = -1 for i in range(N): check2 = 1 for j in range(N): if L[i][j] != j or L[j][i] != j: check2 = 0 break if check2 == 1: e = i break check3 = -1 for i in range(N): check3 = 0 for j in range(N): if L[i][j] == e == L[j][i]: check3 = 1 break if check3 == 0: break if check1 == check2 == check3 == 1: print("Yes") else: print("No")