#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i,begin,end) for(int i=(begin);i<(end);i++)
#define REP(i,n) FOR(i,0,n)

int N, u, v;

int main()
{
    constexpr array<lint, 502> p{7937,7907,7877,7841,7793,7753,7717,7687,7649,7607,7583,7559,7537,7507,7481,7451,7393,7333,7307,7247,7219,7193,7151,7109,7057,7019,6991,6967,6947,6899,6863,6829,6793,6763,6719,6691,6661,6619,6577,6553,6521,6469,6421,6373,6353,6323,6299,6269,6229,6203,6163,6131,6091,6067,6037,5987,5927,5881,5861,5843,5813,5783,5741,5701,5669,5651,5623,5569,5527,5503,5477,5441,5417,5393,5347,5303,5273,5231,5189,5153,5107,5081,5039,5009,4987,4957,4933,4903,4861,4801,4787,4733,4703,4663,4643,4603,4567,4523,4507,4463,4441,4397,4357,4327,4273,4253,4229,4201,4153,4127,4091,4051,4019,4001,3943,3919,3889,3853,3823,3793,3761,3719,3691,3659,3623,3593,3559,3539,3517,3469,3457,3407,3371,3343,3319,3299,3253,3217,3187,3163,3109,3067,3037,3001,2963,2927,2897,2857,2833,2797,2767,2731,2711,2689,2671,2647,2609,2557,2539,2477,2447,2417,2389,2371,2341,2309,2281,2251,2221,2179,2141,2113,2087,2063,2027,1999,1979,1933,1901,1873,1847,1801,1777,1741,1709,1669,1637,1613,1597,1567,1543,1499,1483,1453,1433,1409,1367,1319,1297,1279,1237,1217,1187,1153,1117,1093,1063,1039,1019,991,967,937,907,877,853,823,797,761,739,709,677,653,631,607,587,563,523,499,467,449,431,401,379,353,331,307,277,257,233,211,191,167,149,127,103,83,67,47,31,17,5,11,23,41,59,73,97,109,137,157,179,197,227,241,269,283,313,347,367,389,419,439,461,487,509,547,571,599,617,643,661,691,727,751,773,811,829,859,883,919,947,977,1009,1031,1051,1087,1103,1129,1171,1201,1229,1259,1289,1303,1327,1381,1427,1447,1471,1489,1523,1553,1579,1607,1621,1663,1697,1723,1753,1787,1823,1867,1879,1913,1951,1993,2011,2039,2081,2099,2131,2153,2207,2239,2269,2293,2333,2351,2381,2399,2437,2467,2521,2549,2591,2621,2659,2683,2699,2719,2749,2789,2803,2843,2879,2909,2953,2971,3019,3049,3083,3121,3169,3203,3229,3259,3307,3329,3359,3389,3433,3463,3499,3529,3547,3581,3613,3637,3673,3701,3733,3769,3803,3847,3877,3911,3929,3967,4007,4027,4073,4099,4133,4159,4217,4241,4261,4289,4339,4373,4421,4451,4483,4517,4549,4591,4637,4651,4679,4723,4759,4793,4817,4877,4919,4943,4969,4999,5021,5059,5099,5119,5171,5209,5237,5281,5323,5381,5407,5431,5449,5483,5519,5557,5581,5641,5657,5689,5717,5749,5801,5827,5851,5869,5903,5953,6011,6047,6079,6113,6143,6197,6217,6257,6277,6311,6337,6361,6389,6449,6481,6547,6569,6599,6653,6679,6703,6737,6781,6823,6841,6871,6911,6959,6977,7001,7039,7079,7127,7177,7211,7237,7283,7321,7351,7417,7459,7489,7523,7547,7573,7591,7639,7673,7699,7727,7759,7823,7867,7883,7927,7951};
    constexpr array<lint, 502> q{7949,7919,7879,7853,7817,7757,7723,7691,7669,7621,7589,7561,7541,7517,7487,7457,7411,7349,7309,7253,7229,7207,7159,7121,7069,7027,6997,6971,6949,6907,6869,6833,6803,6779,6733,6701,6673,6637,6581,6563,6529,6473,6427,6379,6359,6329,6301,6271,6247,6211,6173,6133,6101,6073,6043,6007,5939,5897,5867,5849,5821,5791,5743,5711,5683,5653,5639,5573,5531,5507,5479,5443,5419,5399,5351,5309,5279,5233,5197,5167,5113,5087,5051,5011,4993,4967,4937,4909,4871,4813,4789,4751,4721,4673,4649,4621,4583,4547,4513,4481,4447,4409,4363,4337,4283,4259,4231,4211,4157,4129,4093,4057,4021,4003,3947,3923,3907,3863,3833,3797,3767,3727,3697,3671,3631,3607,3571,3541,3527,3491,3461,3413,3373,3347,3323,3301,3257,3221,3191,3167,3119,3079,3041,3011,2969,2939,2903,2861,2837,2801,2777,2741,2713,2693,2677,2657,2617,2579,2543,2503,2459,2423,2393,2377,2347,2311,2287,2267,2237,2203,2143,2129,2089,2069,2029,2003,1987,1949,1907,1877,1861,1811,1783,1747,1721,1693,1657,1619,1601,1571,1549,1511,1487,1459,1439,1423,1373,1321,1301,1283,1249,1223,1193,1163,1123,1097,1069,1049,1021,997,971,941,911,881,857,827,809,769,743,719,683,659,641,613,593,569,541,503,479,457,433,409,383,359,337,311,281,263,239,223,193,173,151,131,107,89,71,53,37,19,7,13,29,43,61,79,101,113,139,163,181,199,229,251,271,293,317,349,373,397,421,443,463,491,521,557,577,601,619,647,673,701,733,757,787,821,839,863,887,929,953,983,1013,1033,1061,1091,1109,1151,1181,1213,1231,1277,1291,1307,1361,1399,1429,1451,1481,1493,1531,1559,1583,1609,1627,1667,1699,1733,1759,1789,1831,1871,1889,1931,1973,1997,2017,2053,2083,2111,2137,2161,2213,2243,2273,2297,2339,2357,2383,2411,2441,2473,2531,2551,2593,2633,2663,2687,2707,2729,2753,2791,2819,2851,2887,2917,2957,2999,3023,3061,3089,3137,3181,3209,3251,3271,3313,3331,3361,3391,3449,3467,3511,3533,3557,3583,3617,3643,3677,3709,3739,3779,3821,3851,3881,3917,3931,3989,4013,4049,4079,4111,4139,4177,4219,4243,4271,4297,4349,4391,4423,4457,4493,4519,4561,4597,4639,4657,4691,4729,4783,4799,4831,4889,4931,4951,4973,5003,5023,5077,5101,5147,5179,5227,5261,5297,5333,5387,5413,5437,5471,5501,5521,5563,5591,5647,5659,5693,5737,5779,5807,5839,5857,5879,5923,5981,6029,6053,6089,6121,6151,6199,6221,6263,6287,6317,6343,6367,6397,6451,6491,6551,6571,6607,6659,6689,6709,6761,6791,6827,6857,6883,6917,6961,6983,7013,7043,7103,7129,7187,7213,7243,7297,7331,7369,7433,7477,7499,7529,7549,7577,7603,7643,7681,7703,7741,7789,7829,7873,7901,7933,7963};

    cin >> N;
    REP(i,N) REP(j,N)
    {
        u = (i + j) / 2, v = (i + (500 - j)) / 2;
        cout << (((i + j) & 1) ? p[u + 1] * q[v + 1] : p[u] * p[u + 1] * q[v] * q[v + 1] + 3) << (j == N - 1 ? "\n" : " ");
    }
}


Measured memory_bytes: 2944