#573
Unrated
Redistributing Gifts
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Farmer John has NN gifts labeled 1N1\ldots N for his NN cows, also labeled 1N1\ldots N (1N5001\le N\le 500). Each cow has a wishlist, which is a permutation of all NN 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 ii to cow ii for all ii. 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 ii from 11 to NN, compute the most preferred gift cow ii could hope to receive after reassignment.

입력

The first line contains NN. The next NN lines each contain the preference list of a cow. It is guaranteed that each line forms a permutation of 1N1\dots N.

출력

Please output NN lines, the ii-th of which contains the most preferred gift cow ii 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 N8N\le 8.Test cases 4-11 satisfy no additional constraints.

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.