문제
Farmer John has gifts labeled for his cows, also labeled (). Each cow has a wishlist, which is a permutation of all gifts such that the cow prefers gifts that appear earlier in the list over gifts that appear later in the list.
FJ was lazy and just assigned gift to cow for all . Now, the cows have gathered amongst themselves and decided to reassign the gifts such that after reassignment, every cow ends up with the same gift as she did originally, or a gift that she prefers over the one she was originally assigned.
For each from to , compute the most preferred gift cow could hope to receive after reassignment.
입력
The first line contains . The next lines each contain the preference list of a cow. It is guaranteed that each line forms a permutation of .
출력
Please output lines, the -th of which contains the most preferred gift cow could hope to receive after reassignment.
예제 입력 1
4
1 2 3 4
1 3 2 4
1 2 3 4
1 2 3 4
예제 출력 1
1
3
2
4
점수
Test cases 2-3 satisfy .Test cases 4-11 satisfy no additional constraints.
코드를 제출하려면 로그인이 필요합니다.
로그인