#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include constexpr int MOD{1'000'000'007}; constexpr int MOD2{998'244'353}; constexpr int INF{1'000'000'000}; //1e9 constexpr int NIL{-1}; constexpr long long LINF{1'000'000'000'000'000'000}; // 1e18 constexpr long double EPS{1E-10L}; using namespace std::literals; template bool chmax(T &a, const S &b){ if(a < b){a = b; return true;} return false; } template bool chmin(T &a, const S &b){ if(b < a){a = b; return true;} return false; } template bool inside(T x, T lx, T rx){ //semi-open return (std::ranges::clamp(x, lx, rx-1) == x); } template bool inside(T x, T y, T lx, T rx, T ly, T ry){ return inside(x, lx, rx) && inside(y, ly, ry); } template void print_vec(std::vector &v, std::string sep = " "s, std::string end = "\n"s){ std::ranges::copy(v | std::views::reverse | std::views::drop(1) | std::views::reverse, std::ostream_iterator(std::cout, sep.c_str())); if(!v.empty()) std::cout << v.back(); std::cout << end; } int main(){ std::cout << ([](){ int N; std::cin >> N; std::vector A(N, std::vector(N)); auto At{A}; for(int i{0}; i < N; ++i) for(int j{0}; j < N; ++j){ std::cin >> A[i][j]; At[j][i] = A[i][j]; } 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]]) return false; std::vector B(N); std::iota(std::ranges::begin(B), std::ranges::end(B), 0); int e_grp{NIL}; for(int i{0}; i < N && e_grp == NIL; ++i) if(A[i] == B && At[i] == B) e_grp = i; if(e_grp == NIL) return false; for(int i{0}; i < N; ++i){ int i_rev{NIL}; for(int j{0}; j < N && i_rev == NIL; ++j) if(A[i][j] == e_grp && A[j][i] == e_grp) i_rev = j; if(i_rev == NIL) return false; } return true; }() ? "Yes" : "No") << std::endl; return 0; }