n = int(input()) op = [list(map(int, input().split()))for _ in range(n)] ok = True e = -1 inv = True for i in range(n): for j in range(n): for k in range(n): ok &= op[i][op[j][k]] == op[op[i][j]][k] if not ok: print("No") exit() for i in range(n): eok = True for j in range(n): eok &= op[i][j] == op[j][i] == j if eok: e = i if e == -1: print("No") exit() for i in range(n): ex = False for j in range(n): ex |= op[i][j] == e inv &= ex if inv: print('Yes') else: print('No')