# 単位元の列では0123---となる必要がある、行も同様 # 逆元があるのだから各行に単位元が存在する # 結合律が成り立つためには対角線でミラーの関係が必要 # 自信ないがそれでやってみるか N = int(input()) matrix = [] unit_test1 = False unit = -1 for i in range(N): temp = list(map(int, input().split())) matrix.append(temp) if temp == [a for a in range(N)]: unit_test1 = True unit = i unit_test2 = True for i in range(N): if matrix[i][unit] != i: unit_test2 = False inverse_test1 = True for i in range(N): if unit not in matrix[i]: inverse_test1 = False inverse_test2 = True for j in range(N): temp = set() for i in range(N): temp.add(matrix[i][j]) if unit not in temp: inverse_test2 = False transpose = [[0]*N for i in range(N)] for i in range(N): for j in range(N): transpose[i][j] = matrix[j][i] if transpose == matrix: transpose_test = True else: transpose_test = False ans = 'No' if unit_test1 == True and unit_test2 == True: if inverse_test1 == True and inverse_test2 == True: if transpose_test == True: ans = 'Yes' print(ans)