#include #include #include #include #include #include #include #include #include #include #include using namespace std; using namespace atcoder; typedef long long ll; #define rep(i,n) for (int i = 0; i < int(n);i++) int main(){ int n; cin >> n; vector> a(n,vector(n)); for (int i = 0; i < n;i++){ for (int j = 0; j < n;j++){ cin >> a[i][j]; } } bool yes = true; for (int i = 0; i < n;i++){ for (int j = 0; j < n;j++){ for (int k = 0; k < n;k++){ if (a[a[i][j]][k] != a[i][a[j][k]]){ yes = false; break; } } } } int cnt = 0; int ee = 0; for (int i = 0; i < n;i++){ for (int e = 0; e < n;e++){ if (a[i][e] == i && a[e][i] == i){ cnt++; ee = e; } } } if (cnt != n){ yes = false; } cnt = 0; for (int i = 0; i < n;i++){ for (int j = 0; j < n;j++){ if (a[i][j] == ee && ee == a[j][i]){ cnt++; } } } if (cnt != n){ yes = false; } if (yes) cout << "Yes\n"; else cout << "No\n"; return 0; }