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 for i in range(N): check2 = 1 for j in range(N): if L[i][j] != j: check2 = 0 break if check2 == 1: e = i break for i in range(N): check3 = 0 for j in range(N): if L[i][j] == e: check3 = 1 break if check3 == 0: break if check1 == check2 == check3 == 1 or N ==0: print("Yes") else: print("No")