<|instruction|>
Solve the below problem. The solution should start with an abridged problem statement. Then key observations. Then full solution based on the observations. Then C++ and Python implementations with comments.

109. Magic of David Copperfield II

time limit per test: 0.25 sec.
memory limit per test: 4096 KB


The well-known magician David Copperfield loves lo show the following trick: a square with N rows and N columns of different pictures appears on a TV screen, Let us number all the pictures in the following order:


1	2	...	N
...	...	...	...
N*(N-1)+1	N*(N-1)+2	...	N*N

Each member of the audience is asked to put a finger on the upper left picture (i.e., picture number one) and The Magic begins: the magician tells the audience to move the finger K1 times through the pictures (each move is a shift of the finger to the adjacent picture up, down, left or right provided that there is a picture to move to), then with a slight movement of his hand he removes some of the pictures with an exclamation "You are not there!", and ... it is true - your finger is not pointing to any of the pictures removed. Then again, he tells the audience to make K2 moves, and so on. At the end he removes all the pictures but one and smiling triumphantly declares, "I've caught you" (applause).

Just now, David is trying to repeat this trick. Unfortunately, he had-a hard day before, and you know how hard to conjure with a headache. You have to write a program that will help David to make his trick.

Input

The input file contains a single integer number N (1<N<101).


Output

Your program should write the following lines with numbers to the output file:
K1 X1,1 X1,2 ... X1,m1
K2 X2,1 X2,2 ... X2,m2
...
Ke Xe,1 Xe,2 ... Xe,me
where Ki is a number of moves the audience should make on the i-th turn (N<=Ki<300). All Ki, should be different (i.e. Ki<>Kj when i<>j). Xi,1 Xi,2 ... Xi,mi are the numbers of the pictures David should remove after the audience will make Ki moves (the number of the pictures removed is arbitrary, but each picture should be listed only once, and at least one picture should be removed on each turn).
A description of the every next turn should begin with a new line. All numbers on each line should be separated by one or more spaces. After e iterations, all pictures except one should be removed.


Sample Input

3
Sample Output

3 1 3 7 9
5 2 4 6 8

<|response|>
1. Abridged Problem Statement  
We have an N×N grid of distinct pictures numbered 1…N² in row-major order. A pointer starts at cell 1. We must plan a sequence of turns. On turn i:  
  • Pick a distinct Ki (N ≤ Ki < 300).  
  • Tell the audience to move the pointer exactly Ki steps (up/down/left/right).  
  • Remove at least one remaining picture that the pointer cannot be on after Ki moves.  

After e turns, exactly one picture must remain. Output each turn as a line:  
Ki Xi,1 Xi,2 … Xi,mi  

2. Key Observations  
1. Manhattan-distance reachability: from a start cell, the set of cells reachable in exactly K moves is  
 {cell c | d(start,c) ≤ K and (K–d(start,c)) even},  
 where d is Manhattan distance.  
2. Parity constraint: reachable cells in K moves share parity = (d(start,c) mod 2) ≡ (K mod 2).  
3. Anti-diagonals (constant i+j) group cells by distance from (0,0).  
4. By choosing K and exploiting parity, we can guarantee a whole group is unreachable and safely remove it.  

3. Full Solution Approach  
We index cells by (i,j) with 0≤i,j<N. Cell ID = i*N + j + 1. The pointer starts at (0,0). Let sum = i+j.

Step 1 (remove “too far” cells):  
- Choose K1 = N.  
- Any cell with sum > N has d=(i+j)>N, so it cannot be reached in ≤N moves ⇒ unreachable in exactly N moves.  
- Remove all cells with sum>N in one turn.  

After that, remaining cells satisfy sum ≤ N. Moreover, since N and d share parity for reachable cells, all surviving cells have parity = N mod 2.

Step 2 (remove one anti-diagonal per turn):  
- We will eliminate diagonals with sum = N, N–1, …, 1, one per turn.  
- For each target sum = d (from N down to 1), pick an odd Ki > N (all distinct). Because d ≡ N mod 2 exactly when parity(d)=parity(N), those diagonal cells have the same parity as the remaining region⇒unreachable in an odd number of steps ⇒ safe to remove the entire diagonal.  
- Choose the smallest odd K ≥ N+1, then increase by 2 each time to keep them distinct and <300.

After these N+1 turns, only the cell (0,0) with sum=0 remains.

4. C++ Implementation with Detailed Comments  
```cpp
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;

    // We'll collect each turn as a vector<int>: [K, removed_ids...]
    vector<vector<int>> turns;

    // ----- Turn 1: K = N, remove all cells with i+j > N -----
    turns.emplace_back();
    turns.back().push_back(N);
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (i + j > N) {
                int id = i * N + j + 1;
                turns.back().push_back(id);
            }
        }
    }

    // ----- Next N turns: remove diagonals sum = N, N-1, ..., 1 -----
    // Start with the smallest odd K >= N+1
    int K = N + 1;
    if (K % 2 == 0) K++;

    // For each diagonal index step = 0..N-1, target sum = N - step
    for (int step = 0; step < N; step++) {
        int targetSum = N - step;
        turns.emplace_back();
        turns.back().push_back(K);

        // Walk all (i,j) with i+j = targetSum
        // On the first diagonal (sum = N), skip (0,N) which is out of bounds
        int i = (step == 0 ? 1 : 0);
        int j = targetSum - i;
        while (i < N && j >= 0) {
            // Only valid grid cells appear in this loop
            int id = i * N + j + 1;
            turns.back().push_back(id);
            i++; 
            j--;
        }
        K += 2;  // next odd
    }

    // Output all turns
    for (auto &line : turns) {
        for (int x : line) {
            cout << x << ' ';
        }
        cout << '\n';
    }

    return 0;
}
```

5. Python Implementation with Detailed Comments  
```python
def magic_trick(N):
    turns = []

    # Turn 1: K = N, remove all cells with i+j > N
    line1 = [N]
    for i in range(N):
        for j in range(N):
            if i + j > N:
                cell_id = i * N + j + 1
                line1.append(cell_id)
    turns.append(line1)

    # Next N turns: remove diagonals sum = N, N-1, ..., 1
    K = N + 1
    if K % 2 == 0:
        K += 1

    for step in range(N):
        target_sum = N - step
        current = [K]

        # For sum=target_sum, iterate (i,j). Skip invalid (0,N) when step=0
        i = 1 if step == 0 else 0
        j = target_sum - i
        while i < N and j >= 0:
            cell_id = i * N + j + 1
            current.append(cell_id)
            i += 1
            j -= 1

        turns.append(current)
        K += 2  # next odd

    return turns

def main():
    import sys
    data = sys.stdin.read().strip().split()
    N = int(data[0])
    for line in magic_trick(N):
        print(' '.join(map(str, line)))

if __name__ == "__main__":
    main()
```

Explanation Recap  
- **Turn 1 (K=N):** removes all cells too far (i+j > N).  
- **Turns 2…N+1 (K odd >N):** each odd K flips parity from the current reachable region, so any diagonal whose cells share the old parity become unreachable and can be removed together.  
- After these steps, only the starting cell remains.