toplista | 프로그래밍의 벗 PivotOJ
PivotOJ

toplista

시간 제한: 1000ms메모리 제한: 128MB출처: CHC 2006 Regional Competition - JuniorsBOJ 3156

문제

At the end of the year, a popular radio station publishes a list of songs, ranked by listeners' votes throughout the year. 

The station keeps the list confidential for a while, and organizes a guessing competition for the listeners. They announce certain hints about the placement of some songs and ask the listeners to deduce the exact positions of as many songs as possible. 

For example, consider the following two statements: 

  • The song "Ti Da Bu Di Bu Da" is one of the top three songs. 
  • Songs "Treba mi nešto jače od sna" and "Ja se konja bojim" are among the top two songs. 

They don't reveal anything directly, but one can still deduce that the song "Ti Da Bu Di Bu Da" comes in third on the list. 

Write a program that, given a number of statements, outputs all songs whose exact position on the list can be deduced. 

입력

The first line of input contains an integer N, 1 ≤ N ≤ 500, the number of statements. 

Each of the following N lines contains a statement of the form "A od B song1 song2 ... songA", 1 ≤ A ≤ B ≤ 100, meaning that the songs "song1", ..., "songA" are among the top B songs on the list. 

Each song name is a string, consisting of at most 20 lowercase letters of English alphabet ('a'-'z'). The total number of different songs across all statements will be at most 500. 

Note: the statements will not contradict each other and there will be at least one song whose exact position can be deduced. 

출력

Output all songs whose position on the list can be deduced. The result should be printed in the form "position song", sorted in ascending order by position, each song on its own line. 

예제

예제 1

입력
2
1 od 3 tidabu
2 od 2 trebami jasekonja
출력
3 tidabu

예제 2

입력
3
2 od 2 pjesma1 pjesma2
3 od 4 pjesma1 pjesma3 pjesma4
1 od 3 pjesma4
출력
3 pjesma4
4 pjesma3

예제 3

입력
4
1 od 4 jedan
2 od 3 dva tri
1 od 1 cetiri
1 od 4 dva
출력
1 cetiri
4 jedan
코드를 제출하려면 로그인하세요.