#include namespace { #pragma GCC diagnostic ignored "-Wunused-function" #include #pragma GCC diagnostic warning "-Wunused-function" using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; bool solve() { int n; cin >> n; int op[40][40]; rep(i, n) rep(j, n) cin >> op[i][j]; { bool ok = true; rep(i, n) rep(j, n) rep(k, n) ok &= op[op[i][j]][k] == op[i][op[j][k]]; if (!ok) return false; } rep(e, n) { bool ok = true; rep(g, n) ok &= g == op[g][e] && g == op[e][g]; if (!ok) continue; rep(g, n) { bool found = false; rep(h, n) { found |= op[h][g] == e && op[g][h] == e; } if (!found) { ok = false; break; } } if (ok) return true; } return false; } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << (solve() ? "Yes\n" : "No\n"); }