#include using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) int main() { int N; cin >> N; vector> a(N, vector(N)); rep(i, N) rep(j, N) cin >> a[i][j]; int e = -1; rep(i, N) { bool ye = true; rep(j, N) { if (a[i][j] == j && a[j][i] == j) continue; ye = false; } if (ye) e = i; } if (e == -1) { cout << "No" << endl; return 0; } bool ok = true; rep(i, N) { bool ye = false; rep(j, N) if (a[i][j] == e && a[j][i] == e) ye = true; if (!ye) ok = false; } rep(i, N) rep(j, N) rep(k, N) if (a[a[i][j]][k] != a[i][a[j][k]]) ok = false; if (ok) cout << "Yes" << endl; else cout << "No" << endl; return 0; }