## 示例代码

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

#define max_n 3000
#define max_round 50

int n;
bool X[max_round + 1][max_n + 1], Y[max_round + 1][max_n + 1];

int solve(int n, int low, int round) {
/**
* n: size of matrix
* low: the index of first row in this matrix
*      according to the original matrix
* round: number of round
*/
// Special case for n<=4
if (n == 1) {
return round;
} else if (n == 2) {
round += 1;
X[round][low] = Y[round][low + 1] = true;
return round;
} else if (n == 3) {
round += 1;
X[round][low] = Y[round][low + 1] = Y[round][low + 2] = true;
round += 1;
X[round][low + 1] = Y[round][low + 2] = true;
round += 1;
X[round][low + 2] = Y[round][low] = true;
return round;
} else if (n == 4) {
round += 1;
X[round][low + 2] = X[round][low + 3] = Y[round][low] = true;
round += 1;
X[round][low] = X[round][low + 3] = Y[round][low + 1] = true;
round += 1;
X[round][low] = X[round][low + 1] = Y[round][low + 2] =
Y[round][low + 3] = true;
round += 1;
X[round][low + 2] = Y[round][low + 3] = true;
return round;
}
// 4 rounds for up_right and down_left
int up_n, down_n, down_low;
up_n = (n - 1) / 2;
down_n = n - up_n - 1;
down_low = low + up_n + 1;
// round 1
round += 1;
for (int d = 0; d < down_n; ++d) X[round][down_low + d] = true;
for (int d = 0; d < up_n; ++d) Y[round][low + d] = true;
// round 2
round += 1;
for (int d = 0; d < up_n; ++d) X[round][low + d] = true;
for (int d = 0; d < down_n; ++d) Y[round][down_low + d] = true;
// round 3
round += 1;
X[round][low + up_n] = true;
for (int d = 0; d < n; ++d) {
if (d != up_n and d != up_n - 1) Y[round][low + d] = true;
}
// round 4
round += 1;
Y[round][low + up_n] = true;
for (int d = 0; d < n; ++d) {
if (d != up_n and d != up_n + 1) X[round][low + d] = true;
}
// solve up_left and down_right
int up_round = solve(up_n, low, round);
int down_round = solve(down_n, down_low, round);
return max(up_round, down_round);
}

void output_round(bool* X) {
bool is_first = true;
for (int j = 1; j <= n; ++j) {
if (X[j]) {
if (is_first) {
printf("%d", j);
is_first = false;
} else {
printf(" %d", j);
}
}
}
printf("\n");
}

int main() {
// Input
scanf("%d", &n);

// Solve by Divide & Conquer
int round = solve(n, 1, 0);

// Output
// printf("%d\n", round);
for (int i = 1; i <= round; ++i) {
output_round(X[i]);
output_round(Y[i]);
}

return 0;
}