#P10739. [SEERC 2020] Disk Sort

[SEERC 2020] Disk Sort

Problem Description

You have n+1n + 1 rods. Initially, each rod from 11 to nn has 33 disks on it, and the number of possible colors does not exceed nn.

In each operation, you may choose a pair (ai,bi)(a_i, b_i), meaning moving the top disk of rod aia_i onto the top of rod bib_i (rod aia_i must have at least 11 disk, and rod bib_i can have at most 22 disks).

You need to construct a valid sequence of operations such that after all operations, the colors of the disks on each rod are all the same, and rod n+1n + 1 is empty.

Input Format

The first line contains an integer n (1n1000)n\ (1 \leq n \leq 1000), meaning there are nn rods.

The next 33 lines each contain nn integers ci,j (1ci,jn)c_{i,j}\ (1 \leq c_{i,j} \leq n), where ci,jc_{i,j} is the color of the ii-th disk from top to bottom on rod jj.

Output Format

The first line contains an integer k (1k6n)k\ (1 \leq k \leq 6n), meaning the number of operations.

Then follow kk lines, each containing a pair (ai,bi)(a_i, b_i), indicating the move operation.

4
2 3 1 4
2 1 1 4
2 3 3 4
8
3 5
3 5
2 3
2 5
2 3
5 2
5 2
5 2

2
1 2
1 2
1 2
0

Hint

Translated by ChatGPT 5