#include <bits/stdc++.h>
using namespace std;

using ll = long long;

bool isPerfectSquare(ll x) {
    if (x < 0) return false;
    ll r = sqrt((long double)x);
    while (r * r < x) ++r;
    while (r * r > x) --r;
    return r * r == x;
}

bool isPrime(ll x) {
    if (x < 2) return false;
    if (x % 2 == 0) return x == 2;
    for (ll i = 3; i * i <= x; i += 2) {
        if (x % i == 0) return false;
    }
    return true;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;

    vector<vector<int>> a(N + 1, vector<int>(N + 1));
    vector<ll> row(N + 1, 0), col(N + 1, 0);

    for (int i = 1; i <= N; ++i) {
        for (int j = 1; j <= N; ++j) {
            cin >> a[i][j];
            row[i] += a[i][j];
            col[j] += a[i][j];
        }
    }

    ll diag1 = 0, diag2 = 0;
    for (int i = 1; i <= N; ++i) {
        diag1 += a[i][i];
        diag2 += a[i][N - i + 1];
    }

    bool ok = true;

    // Điều kiện 1
    if (row[1] != row[N]) ok = false;
    if (!isPerfectSquare((row[1] + row[N]) * 2LL)) ok = false;

    // Điều kiện 2
    if (col[1] == col[N]) ok = false;
    if (!isPrime(col[1] + col[N])) ok = false;

    if (N % 2 == 0) {
        int mid = N / 2;
        if (!isPerfectSquare(row[mid] * col[mid])) ok = false;
        if (diag1 == diag2) ok = false;
    } else {
        int mid = (N + 1) / 2;
        if (!isPrime(row[mid] + col[mid])) ok = false;
        if (diag1 != diag2) ok = false;
    }

    cout << (ok ? "Yes" : "No") << '\n';

    return 0;
}
