#include <iostream>
using namespace std;
void create(int** x, int k)
{
if (k == 1)
{
x[0][0] = 1;
x[0][1] = 2;
x[1][0] = 3;
x[1][1] = 1;
}
else
{
create(x, k - 1);
int from = 1 << (k - 1), n = 1 << k;
for (int i = from; i < n; i++)
for (int j = from; j < n; j++)
x[i][j] = x[i - from][j - from];
for (int i = 0; i < from; i++)
for (int j = 0; j < from; j++)
{
x[i + from][j] = x[i][j] + n;
x[i][j + from] = x[i][j] + n;
}
for (int i = 0; i < from; i++)
x[i + from][i]--;
}
}
int main()
{
int k, n = 1;
scanf("%d", &k);
n <<= k;
int** x = new int*[n];
for (int i = 0; i < n; i++)
x[i] = new int[n];
create(x, k);
for (int i = 0; i < n; i++)
{
printf("%d", x[i][0]);
for (int j = 1; j < n; j++)
printf(" %d", x[i][j]);
printf("\n");
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdm9pZCBjcmVhdGUoaW50KiogeCwgaW50IGspCnsKICBpZiAoayA9PSAxKQogIHsKICAgIHhbMF1bMF0gPSAxOwogICAgeFswXVsxXSA9IDI7CiAgICB4WzFdWzBdID0gMzsKICAgIHhbMV1bMV0gPSAxOwogIH0KICBlbHNlIAogIHsKICAgIGNyZWF0ZSh4LCBrIC0gMSk7CiAgICBpbnQgZnJvbSA9IDEgPDwgKGsgLSAxKSwgbiA9IDEgPDwgazsKICAgIGZvciAoaW50IGkgPSBmcm9tOyBpIDwgbjsgaSsrKQogICAgICBmb3IgKGludCBqID0gZnJvbTsgaiA8IG47IGorKykKICAgICAgICB4W2ldW2pdID0geFtpIC0gZnJvbV1baiAtIGZyb21dOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBmcm9tOyBpKyspCiAgICAgIGZvciAoaW50IGogPSAwOyBqIDwgZnJvbTsgaisrKQogICAgICB7CiAgICAgICAgeFtpICsgZnJvbV1bal0gPSB4W2ldW2pdICsgbjsKICAgICAgICB4W2ldW2ogKyBmcm9tXSA9IHhbaV1bal0gKyBuOwogICAgICB9CiAgICBmb3IgKGludCBpID0gMDsgaSA8IGZyb207IGkrKykKICAgICAgeFtpICsgZnJvbV1baV0tLTsKICB9Cn0KCmludCBtYWluKCkgCnsKICBpbnQgaywgbiA9IDE7CiAgc2NhbmYoIiVkIiwgJmspOwogIG4gPDw9IGs7CiAgaW50KiogeCA9IG5ldyBpbnQqW25dOwogIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKQogICAgeFtpXSA9IG5ldyBpbnRbbl07CiAgY3JlYXRlKHgsIGspOwogIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKQogIHsKICAgIHByaW50ZigiJWQiLCB4W2ldWzBdKTsKICAgIGZvciAoaW50IGogPSAxOyBqIDwgbjsgaisrKQogICAgICBwcmludGYoIiAlZCIsIHhbaV1bal0pOwogICAgcHJpbnRmKCJcbiIpOwogIH0KICByZXR1cm4gMDsKfQ==