#include <bits/stdc++.h>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<vector<int>> a(n, vector<int>(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> a[i][j];
        }
    }
    bool ok = 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]]) {
                    ok = false;
                }
            }
        }
    }
    bool ok2 = false;
    int e = -1;
    for (int i = 0; i < n; i++) {
        bool cur = true;
        for (int j = 0; j < n; j++) {
            if (a[i][j] != j || a[i][j] != a[j][i]) {
                cur = false;
            }
        }
        if (cur) {
            e = i;
            ok2 = true;
        }
    }
    if (!ok || !ok2) {
        cout << "No" << '\n';
        return 0;
    }
    for (int i = 0; i < n; i++) {
        bool cur = false;
        for (int j = 0; j < n; j++) {
            if (a[i][j] == e && a[j][i] == e) {
                cur = true;
            }
        }
        if (!cur) {
            cout << "No" << '\n';
            return 0;
        }
    }
    cout << "Yes" << '\n';
}