n = int(input()) if n == 0: print("No") exit() op = [] for _ in range(n): row = list(map(int, input().split())) op.append(row) # Check associativity associative = True for a in range(n): for b in range(n): for c in range(n): left = op[op[a][b]][c] right = op[a][op[b][c]] if left != right: associative = False break if not associative: break if not associative: break if not associative: print("No") exit() # Find identity element identity = -1 for e in range(n): valid = True for x in range(n): if op[e][x] != x or op[x][e] != x: valid = False break if valid: identity = e break if identity == -1: print("No") exit() # Check inverse elements has_inverses = True for x in range(n): found = False for y in range(n): if op[x][y] == identity and op[y][x] == identity: found = True break if not found: has_inverses = False break print("Yes" if has_inverses else "No")