CF BUDDY
← Problems·

1392E · Omkar and Duck

2100 · bitmasks, constructive algorithms, interactive

Problem: This is an interactive problem.

Omkar has just come across a duck! The duck is walking on a grid with nn rows and nn columns (2n252 \leq n \leq 25) so that the grid contains a total of n2n^2 cells. Let's denote by (x,y)(x, y) the cell in the xx-th row from the top and the yy-th column from the left. Right now, the duck is at the cell (1,1)(1, 1) (the cell in the top left corner) and would like to reach the cell (n,n)(n, n) (the cell in the bottom right corner) by moving either down 11 cell or to the right 11 cell each second.

Since Omkar thinks ducks are fun, he wants to play a game with you based on the movement of the duck. First, for each cell (x,y)(x, y) in the grid, you will tell Omkar a nonnegative integer ax,ya_{x,y} not exceeding 101610^{16}, and Omkar will then put ax,ya_{x,y} uninteresting problems in the cell (x,y)(x, y). After that, the duck will start their journey from (1,1)(1, 1) to (n,n)(n, n). For each cell (x,y)(x, y) that the duck crosses during their journey (including the cells (1,1)(1, 1) and (n,n)(n, n)), the duck will eat the ax,ya_{x,y} uninteresting problems in that cell. Once the duck has completed their journey, Omkar will measure their mass to determine the total number kk of uninteresting problems that the duck ate on their journey, and then tell you kk.

Your challenge, given kk, is to exactly reproduce the duck's path, i. e. to tell Omkar precisely which cells the duck crossed on their journey. To be sure of your mastery of this game, Omkar will have the duck complete qq different journeys (1q1031 \leq q \leq 10^3). Note that all journeys are independent: at the beginning of each journey, the cell (x,y)(x, y) will still contain ax,ya_{x,y} uninteresting tasks.

Note: The duck's three journeys are illustrated below.

1+2+3+2+10+3+2=231 + 2 + 3 + 2 + 10 + 3 + 2 = 23

1+4+9+0+7+3+2=261 + 4 + 9 + 0 + 7 + 3 + 2 = 26

1+2+3+6+10+3+2=271 + 2 + 3 + 6 + 10 + 3 + 2 = 27

Sample Cases

Case 1

Input

4




3
23







26







27

Output

1 2 3 6
4 6 2 10
9 0 7 3
2 8 8 2


1 1
1 2
1 3
2 3
2 4
3 4
4 4

1 1
2 1
3 1
3 2
3 3
3 4
4 4

1 1
1 2
1 3
1 4
2 4
3 4
4 4

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback