n = int(input()) F = [list(map(int, input().split())) for _ in range(n)] for i in range(n): for j in range(n): for k in range(n): ij = F[i][j] ijk1 = F[ij][k] jk = F[j][k] ijk2 = F[i][jk] if ijk1 != ijk2: print("No") exit() E = [] for i in range(n): exist_e = True for j in range(n): if F[i][j] != j: exist_e = False break if exist_e: E.append(i) if len(E) != 1: print("No") exit() Invs = [[] for _ in range(n)] for i in range(n): for j in range(n): if F[i][j] in E: if j not in Invs[i]: Invs[i].append(j) if i not in Invs[j]: Invs[j].append(i) if len(Invs[i]) == 0: print("No") exit() for i in range(n): for j in Invs[i]: if i not in Invs[j]: print("No") exit() if len(Invs[i]) != len(Invs[j]): print("No") exit() print("Yes")