{"raw_statement":[{"iden":"problem statement","content":"There are $N \\times M$ stones on a number line, with $M$ colors labeled $1$ through $M$, and $N$ stones of each color. Here, $N$ is an **even number**, and $M$ is an **odd number**. Among the stones of color $i$, the $j$\\-th stone from the left $(1 ≤ i ≤ M,\\ 1 ≤ j ≤ N)$ is initially placed at the coordinate $(j-1) \\times M + i$. Stones of the same color are indistinguishable.\nYou can perform the following operation up to $(N+1) \\times M$ times:\n\n> Pick two adjacent stones and move them, in the same order, to any unoccupied adjacent positions.  \n> Specifically:\n> \n> 1.  Choose an integer $x$ such that $-10^9 \\leq x \\leq 10^9-1$ and there are stones at both coordinates $x$ and $x+1$. Let the stone at $x$ be $A$ and the stone at $x+1$ be $B$. Remove $A$ and $B$ from the number line.\n> 2.  Choose an integer $y$ such that $-10^9 \\leq y \\leq 10^9-1$ and there are no stones at both coordinates $y$ and $y+1$. Place $A$ at $y$ and $B$ at $y+1$.\n\nYour goal is to rearrange the stones to satisfy the following two conditions:\n\n*   All stones are part of a single contiguous block. That is, there exists an integer $n$ such that for all integers $x$ satisfying $n \\leq x \\leq n + NM - 1$, there is exactly one stone at coordinate $x$.\n*   Additionally, the stones are sorted by color in ascending order. Specifically, among the stones of color $i$, the $j$\\-th stone from the left $(1 ≤ i ≤ M,\\ 1 ≤ j ≤ N)$ is at coordinate $n + (i-1) \\times N + (j-1)$.\n\nUnder the constraints of this problem, it can be shown that the goal is always achievable. Output one valid sequence of operations to achieve the goal. You do not need to minimize the number of operations."},{"iden":"constraints","content":"*   $2 \\leq N \\leq 1000$\n*   $3 \\leq M \\leq 999$\n*   $N$ is even\n*   $M$ is odd"},{"iden":"input","content":"The input is given in the following format:\n\n$N$ $M$"},{"iden":"sample input 1","content":"4 3"},{"iden":"sample output 1","content":"13\n3 13\n10 3\n12 10\n6 12\n4 6\n1 4\n13 14\n14 14\n14 999999999\n999999999 -1000000000\n9 13\n5 9\n-1000000000 5\n\nInitially, the stones are placed as follows (`.` indicates an unoccupied position). The coordinate of the leftmost `.` is $0$, and the coordinate of the rightmost `.` is $15$.\n\n.123123123123...\n\nAfter the first three operations, the stone arrangement changes as follows:\n\n.123123123123...\n↓\n.12..2312312331.\n↓\n.121223123..331.\n↓\n.12122312333..1.\n\nFinally, the stones are rearranged as follows:\n\n...111122223333.\n\nThis arrangement satisfies the conditions of being a single contiguous block and sorted by color. Additionally, the number of operations is at most $(N + 1) \\times M = 15$, so this output is valid."}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}