#K93362. Puzzle Assignment Problem
Puzzle Assignment Problem
Puzzle Assignment Problem
You are given three sequences of integers. The first sequence represents the preferred themes of participants, where the i-th participant prefers the theme denoted by pi. The second and third sequences represent the two candidate themes (first and second, respectively) for each puzzle.
For each puzzle, assign it to a participant as follows:
- If there exists a participant whose preferred theme matches the puzzle's first theme, assign the puzzle to the participant with the smallest index among those.
- If not, and a participant's preferred theme matches the puzzle's second theme, assign it to the participant with the smallest index among those.
- If neither theme is matched, assign the puzzle to participant number 1 (by default).
It is guaranteed by the problem constraints that in actual test cases there will be at least one match. However, the default case is provided for completeness.
The mathematical description can be summarized as follows:
For each puzzle j, let Fj and Sj be its first and second themes, respectively. Let i be the smallest index such that pi = Fj or, if none exists, such that pi = Sj (or default to 1 if both fail). Output the list of these indices for all puzzles.
inputFormat
The input is read from standard input (stdin) and consists of three lines:
- The first line contains space-separated integers representing the preferred themes of the participants.
- The second line contains space-separated integers representing the first candidate themes for the puzzles.
- The third line contains space-separated integers representing the second candidate themes for the puzzles.
outputFormat
Output a single line to standard output (stdout) containing space-separated integers. Each integer is the index (1-indexed) of the participant assigned to the corresponding puzzle, in order.
## sample1
1
2
1