#include <bits/stdc++.h>

#ifndef This_is_Kunteynir
#define dbg(...)
#endif

#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi")

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define len(x) ((int)x.size())

using namespace std;
using ll = long long;
using ld = long double;
using i128 = __int128;

mt19937 rnd(time(0));

ld rd() {
    return ld(rnd() % (int)1e5) / 1e5;
}

int n;

bool check(vector<vector<int>> &a) {
    unordered_set<ll> se;
    for (int i = 0; i < n; ++i) {
        ll now = 0;
        for (int j = 0; j < n; ++j) {
            now += a[i][j];
        }
        se.insert(now);
    }
    for (int j = 0; j < n; ++j) {
        ll now = 0;
        for (int i = 0; i < n; ++i) {
            now += a[i][j];
        }
        se.insert(now);
    }
    ll now = 0;
    for (int i = 0; i < n; ++i) {
        now += a[i][i];
    }
    se.insert(now);
    now = 0;
    for (int i = 0; i < n; ++i) {
        now += a[i][n - i - 1];
    }
    se.insert(now);
    return len(se) == 2 * n + 2;
}

void solve() {
    cin >> n;
    if (n < 3) {
        cout << "No";
        return;
    }
    vector<vector<int>> a(n, vector<int> (n));
    vector<vector<int>> vis(n, vector<int> (n));
    int i = 0, j = 0, ls = 1, t = 0;
    while (ls <= n * n) {
        if (t == 0) {
            while (i < n && !vis[i][j]) {
                vis[i][j] = 1;
                a[i][j] = ls++;
                ++i;
            }
            --i;
            ++j;
        } else if (t == 1) {
            while (j < n && !vis[i][j]) {
                vis[i][j] = 1;
                a[i][j] = ls++;
                ++j;
            }
            --j;
            --i;
        } else if (t == 2) {
            while (i >= 0 && !vis[i][j]) {
                vis[i][j] = 1;
                a[i][j] = ls++;
                --i;
            }
            ++i;
            --j;
        } else {
            while (j >= 0 && !vis[i][j]) {
                vis[i][j] = 1;
                a[i][j] = ls++;
                --j;
            }
            ++j;
            ++i;
        }
        t = (t + 1) % 4;
    }
//    for (auto &v : a) {
//            for (auto h : v) cout << h << ' ';
//            cout << '\n';
//        }
    if (check(a)) {
        cout << "Yes\n";
        for (auto &v : a) {
            for (auto h : v) cout << h << ' ';
            cout << '\n';
        }
        return;
    }
    for (int tt = 0; tt < 50; ++tt) {
        int i1 = rnd() % n, j1 = rnd() % n;
        int i2 = rnd() % n, j2 = rnd() % n;
        swap(a[i1][j1], a[i2][j2]);
        if (check(a)) {
            cout << "Yes\n";
            for (auto &v : a) {
                for (auto h : v) cout << h << ' ';
                cout << '\n';
            }
            return;
        }
    }
    cout << "No";
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int _ = 1;
//    cin >> _;
    while (_--) {
        solve();
        cout << '\n';
    }
}
