题目描述
Problem Description
The Tanabata Festival, due to the legend of the Cowherd and the Weaver Girl, has been labeled as a "Valentine's Day."
This year, TYVJ is hosting an offline Tanabata Festival.
Vani successfully invited cl to spend the Tanabata Festival with him, and they decided to visit the TYVJ Tanabata Festival.
The TYVJ Tanabata Festival resembles the summer festivals in the 11th district.
The festival venue is a rectangular area consisting of $N$ rows and $M$ columns, totaling $N \times M$ stalls.
Although there are many types of stalls, cl is only interested in a few, such as takoyaki, apple candy, cotton candy, shooting booths, etc.
Vani contacted the festival organizer zhq in advance, hoping to arrange the stalls appropriately so that the number of stalls cl is interested in is the same in each row and each column.
However, zhq told Vani that the stalls have already been randomly arranged. The only way to meet cl's requirements is to swap two adjacent stalls.
Two stalls are adjacent if and only if they are in the same row or column and in adjacent positions.
Due to the successful space-time distortion by the TYVJ development team led by zhq, the first and last positions in each row or column are also considered adjacent.
Now, Vani wants to know how many of his requirements can be met at most.
Under this premise, what is the minimum number of swaps required.
Input Format
The first line contains three integers $N$, $M$, and $T$, where $T$ represents the number of stalls cl is interested in.
The next $T$ lines each contain two integers $x$ and $y$, indicating that cl is interested in the stall located at the $x$-th row and $y$-th column.
Output Format
First, output a string.
If both of Vani's requirements can be met, output both;
If only the number of interested stalls in each row can be made the same, output row;
If only the number of interested stalls in each column can be made the same, output column;
If neither can be met, output impossible.
If the output string is not impossible, then output the minimum number of swaps, separated from the string by a space.
Sample Input and Output
Sample Input #1
2 3 4
1 3
2 1
2 2
2 3
Sample Output #1
row 1
Sample Input #2
3 3 3
1 3
2 2
2 3
Sample Output #2
both 2
Notes/Hints
For $30\%$ of the data, $N, M \le 100$.
For $70\%$ of the data, $N, M \le 1000$.
For $100\%$ of the data, $1 \le N, M \le 100000$, $0 \le T \le \min(N \times M, 100000)$, $1 \le x \le N$, $1 \le y \le M$.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分