#include using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #else #define Debug(...) void(0) #endif #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; int main() { int n; cin >> n; vector a(n, vector(n)); rep(i, n) rep(j, n) cin >> a[i][j]; bool ok = true; rep(i, n) rep(j, n) rep(k, n) if (a[a[i][j]][k] != a[i][a[j][k]]) ok = false; bool exi = false; rep(e, n) { bool tmp = true; rep(i, n) if (a[i][e] != i || a[e][i] != i) tmp = false; rep(i, n) { bool exis = false; rep(j, n) if (a[i][j] == e && a[j][i] == e) exis = true; if (!exis) tmp = false; } if (tmp) exi = true; } cout << (ok && exi ? "Yes" : "No") << endl; return 0; }