#P10609. Interactive Card Discard Game

    ID: 12633 Type: Default 1000ms 256MiB

Interactive Card Discard Game

Interactive Card Discard Game

This is an interactive problem. Two players, small R and small M, initially hold m cards each. There are n types of cards, numbered from 1 to n, and it is guaranteed that each player initially has at least one card of every type.

Players can see each other’s hands. They take turns discarding exactly one card until only one card remains in each hand. The players discard in turns with small R taking the first move. Let the last card in small R’s hand be \(u\) and in small M’s hand be \(v\). Then small R’s score is \(a_{u,v}\) and small M’s score is \(-a_{u,v}\). Both players aim to maximize their own scores.

You will simulate a game with an interactive library. If you are given \(c = 0\) then you play as small R; if \(c = 1\) then you play as small M. Your goal is to achieve a final score at least as high as what both players would obtain if both played optimally.

Note: Though the game has a rich strategic structure, for the purpose of this problem you may use any strategy that guarantees a valid output following the game protocol. In our sample solutions, a simple strategy of discarding the smallest available card is used.

inputFormat

The first line contains three integers \(n\), \(m\), and \(c\) separated by spaces.

The next \(n\) lines each contain \(n\) integers. The \(j\)th integer in the \(i\)th line denotes \(a_{i,j}\) (the score when small R’s final card is \(i\) and small M’s final card is \(j\)).

The next line contains \(m\) integers representing small R’s initial hand (each integer is between 1 and \(n\)).

The following line contains \(m\) integers representing small M’s initial hand.

It is guaranteed that each player has at least one card of each type initially.

outputFormat

This is an interactive problem. On each of your turns, output a single integer in a new line: the card you choose to discard from your hand. Do not output anything on the opponent's turns.

Flush the output after each move.

sample

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