-99. Bingo

I'm a slow walker, but I never walk backwards.

題目來源:judgegirl from ntu prof. pangfeng Liu

Task Description

Write a program to play bingo. A bingo board has rows and columns. Each entry has a different number from to . The numbers from to will be randomly called. If a player has all the numbers in a row, a column, or a diagonal called he can declare bingo and win the game. Now given the bingo boards of players, determine who wins the bingo.

Input

The first line of the input has and . Each of the next lines has the numbers of the bingo board of the first player. The next line has the name of the second player, and the next lines have the numbers for the second player, and so on. The next line has numbers that are called in sequence during the bingo game.

Output

Print the indices of the winners of the game and by which number they won the game. If there are more than one winner, print the player indices one by one according to the order they appear in input.

Limits

  • positive is no more than .
  • is positive and no more than .
  • The length of a name is positive and no more than 64. The name consist of only letters.

Sample input

2 3
Alice
1 2 3
4 5 6
7 8 9
Blob
1 2 3
4 5 6
7 8 9
1 2 4 8 6 3 9 5 7

Sample output

3 Alice Blob

Submit

Login

Testdata Set

Download Testdata