P10609 Eliminate Interference
Background
Unbeknownst to Renko, Merry had secretly gone on an adventure weeks ago and had not returned. Upon learning this, Renko was filled with regret.
To find the missing Merry, Renko searched for clues at Merry's house but found nothing.
"What should I do? If only I could eliminate the interference and find useful clues. Maybe I should think from Merry's perspective!"
Description
**This is an interactive problem.**
To analyze from both perspectives, Renko imagines a game between Little R and Little M, with the following rules:
Both Little R and Little M initially have $m$ cards, categorized into $n$ types numbered $1$ to $n$. **Each type has at least one card initially for both players.** They can see each other's cards.
They take turns discarding cards, **with Little R going first**. Each turn, they discard exactly one card. When both are left with one card each—suppose Little R's card is $u$ and Little M's is $v$—Little R's score is $a_{u,v}$, and Little M's score is $-a_{u,v}$. Both aim to maximize their own scores.
You will simulate a game with the interactor. If $c=0$, you play as Little R; if $c=1$, you play as Little M. Your score must meet or exceed the optimal score when both play optimally.
Input Format
- The first line contains three integers $n$, $m$, $c$, as described.
- The next $n$ lines each contain $n$ integers, representing matrix $a$. The $i$-th row and $j$-th column is $a_{i,j}$.
- The next two lines each contain $n$ integers:
- The first line: $R_i$ denotes Little R's initial count of type $i$ cards.
- The second line: $M_i$ denotes Little M's initial count of type $i$ cards.
It is guaranteed that $\sum R_i = \sum M_i = m$.
**Interaction Process**:
1. If it is the opponent's turn (interactor's move), read an integer $x$, indicating they discarded a type $x$ card.
2. If it is your turn, output an integer $y$, indicating you discard a type $y$ card.
3. If the game ends (both have one card left) and your score is suboptimal/your move is invalid, read `-1` and exit.
4. If the game ends and your score is optimal, read `0` and exit.
**Note: After each output, flush the buffer. Common methods include**:
- C++: `fflush(stdout)` or `cout.flush()`.
- C: `fflush(stdout)`.
- Java: `System.out.flush()`.
- Python: `stdout.flush()`.
- Pascal: `flush(output)`.
- Others: Refer to documentation.
Output Format
Follow the interaction rules described above.
Explanation/Hint
### Explanation
#### Sample #1
You play as Little R (first to act). If you discard a type $1$ card and the opponent discards type $2$, your score is $1$, which is optimal.
This sample satisfies **Special Properties B and C**.
#### Sample #2
As Little R, the optimal score is $3$.
This sample satisfies **Special Property A**.
#### Sample #3
You play as Little M (second to act). The optimal score for Little M is $1$.
### Constraints
**Bundled testing is used.**
$$
\def\arraystretch{1.5}
\begin{array}{|c|c|c|c|c|c|}\hline
\textbf{Subtask} & \textbf{Points} & \bm{n \leq} & \bm{m \leq} & \textbf{Special Property} & \textbf{Subtask Dependencies} \cr\hline
1 & 20 & 5 & 5 & - & - \cr\hline
2 & 15 & 10^3 & 10^4 & \mathbf{A} & - \cr\hline
3 & 20 & 10^3 & 10^4 & \mathbf{B} & - \cr\hline
4 & 20 & 10^3 & 10^3 & \mathbf{C} & - \cr\hline
5 & 25 & 10^3 & 10^4 & - & 1,2,3,4 \cr\hline
\end{array}
$$
**Special Properties**:
- **A**: $a_{i,j} = i + j$.
- **B**: $a$ contains only $0$ and $1$.
- **C**: Each player initially has exactly one card per type.
For all data:
$1 \leq n \leq 10^3$, $1 \leq m \leq 10^4$, $|a_{i,j}| \leq 10^8$, $1 \leq R_i, M_i \leq m$, $\sum R_i = \sum M_i = m$. The interactor's moves are guaranteed valid.
---
Translated by DeepSeek R1