import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[][] a = new int[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { a[i][j] = sc.nextInt(); } } sc.close(); boolean[] ek = new boolean[n]; Arrays.fill(ek, true); for (int m = 0; m < n; m++) { for (int e = 0; e < n; e++) { if (a[m][e] == a[e][m] && a[m][e] == m) { } else { ek[e] = false; break; } } } for (int e = 0; e < n; e++) { if (ek[e]) { boolean flga = true; for (int m = 0; m < n; m++) { boolean flg = false; for (int i = 0; i < n; i++) { if (a[m][i] == a[i][m] && a[m][i] == e) { flg = true; break; } } if (!flg) { flga = false; break; } } if (flga) { label: for (int m0 = 0; m0 < n; m0++) { for (int m1 = 0; m1 < n; m1++) { for (int m2 = 0; m2 < n; m2++) { if (a[a[m0][m1]][m2] != a[m0][a[m1][m2]]) { flga = false; break label; } } } } if (flga) { System.out.println("Yes"); return; } } } } System.out.println("No"); } }