#include<bits/stdc++.h>
 
using namespace std;
 
const long long MaxN = 5e2 + 17;
long long arr[MaxN][MaxN];
long long prime[4 * MaxN];
long long second_matrix[MaxN][MaxN];
int x[] = {-1, 1, 0, 0};
int y[] = {0, 0, -1, 1};
int n = 502;
map<long long, bool> mp;
 
long long lcm(long long a, long long b)
{
    return (a / __gcd(a, b)) * b;
}
 
void erich()
{
    const int MaxS = 2e4 + 17;
    bool isPrime[MaxS];
 
    for(int i = 2; i < MaxS; ++i)
        isPrime[i] = 1;
 
    int next = 1;
 
    for(int i = 2; i < MaxS; ++i)
    {
        if(isPrime[i])
        {
            prime[next++] = i;
 
            for(int j = i + i; j < MaxS; j += i)
                isPrime[j] = 0;
 
        }
    }
}
 
void fill_sec()
{
    for(int i = n - !(n % 2), j = 1; i >= 1; i -= 2, ++j)
    {
        int x = i;
        int y = 1;
 
        while(x <= n && y <= n)
        {
            second_matrix[x][y] = prime[n + j];
            ++x;
            ++y;
        }
    }
 
    for(int i = 3, j = 1; i <= n; i += 2, ++j)
    {
        int x = 1;
        int y = i;
 
        while(x <= n && y <= n)
        {
            second_matrix[x][y] = prime[n + n / 2 +  n % 2 + j];
            ++x;
            ++y;
        }
    }
}
 
void fill_matrix()
{
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= n; ++j)
            if(!((i + j) & 1))
                arr[i][j] = prime[(i + j) / 2] * second_matrix[i][j];
 
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= n; ++j)
            if((i + j) & 1)
            {
                arr[i][j] = 1;
 
                for(int k = 0; k < 4; ++k)
                {
                    int xx = i + x[k];
                    int yy = j + y[k];
 
                    if(xx >= 1 && xx <= n && yy >= 1 && yy <= n)
                        arr[i][j] = lcm(arr[i][j], arr[xx][yy]);
                }
 
                ++arr[i][j];
            }
 
}
bool check(long long a, long long b)
{
    if((max(a, b) % min(a, b)) != 1)
    {
        cout << a << ' ' << b << ' ' << (max(a, b) % min(a, b)) <<  '\n';
        exit(0);
    }
 
    return (max(a, b) % min(a, b)) == 1;
}
bool check()
{
    for(int i = 1; i <= n; ++i)
    {
        for(int j = 1; j <= n; ++j)
        {
            assert(arr[i][j] <= 1e15);
 
            for(int k = 0; k < 4; ++k)
            {
                int xx = i + x[k];
                int yy = j + y[k];
 
                if(xx >= 1 && xx <= n && yy >= 1 && yy <= n)
                    assert(check(arr[i][j], arr[xx][yy]));
 
            }
        }
    }
 
    return true;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
    erich();
    fill_sec();
    fill_matrix();
 
   /* for(int i = 1; i <= n; ++i)
    {
        for(int j = 1; j <= n; ++j)
        {
            if(!((i + j) & 1))
                cout << prime[(i + j) / 2] << ' ';
            else
                cout << 0 << ' ';
        }
 
        cout << '\n';
    }
 
    cout << '\n';
 
     for(int i = 1; i <= n; ++i)
    {
        for(int j = 1; j <= n; ++j)
            cout << second_matrix[i][j] << ' ';
        cout << '\n';
    }*/
 
    check();
 
    int m;
    cin >> m;
 
 
 
    for(int i = 1; i <= m; ++i)
    {
        for(int j = 1; j <= m; ++j)
            cout << arr[i][j] << ' ';
        cout << '\n';
    }
 
 
 
}

Measured memory_bytes: 7296