#include using namespace std; using ll = long long; int main() { ll n; cin >> n; vector result(n, vector(n)); for (ll i = 0; i < n; ++i) { for (ll j = 0; j < n; ++j) cin >> result[i][j]; } // 結合律 bool is_associative = true; for (ll i = 0; i < n; ++i) { for (ll j = 0; j < n; ++j) { for (ll k = 0; k < n; ++k) { // (i@j) @ k = i @ (j@k) if (result[result[i][j]][k] != result[i][result[j][k]]) { is_associative = false; } } } } if (not is_associative) { cout << "No" << endl; return 0; } // 単位律 bool exist_unit = false; ll unit = -1; for (ll e = 0; e < n; e++) { bool e_is_unit = true; for (ll x = 0; x < n; x++) { if (result[e][x] != x or result[x][e] != x) { e_is_unit = false; } } if (e_is_unit) { exist_unit = true; unit = e; } } if (not exist_unit) { cout << "No" << endl; return 0; } // cout << unit << endl; // 逆元 // 任意の i に対して <-> すべての i に対して, for (ll i = 0; i < n; ++i) { // i @ j = e and j @ i = e を満たす j が存在する. bool exist_inverse = false; for (ll j = 0; j < n; ++j) { if (result[i][j] == unit and result[j][i] == unit) { exist_inverse = true; } } if (not exist_inverse) { cout << "No" << endl; exit(0); } } cout << "Yes" << endl; return 0; }