cho.sh
NotesCho Mini
Loading...

Bingo

Time limit

1s

Memory limit

128 MB

Problem

Bingo is played on a 5 x 5 board. The numbers from 1 through 25 are written on the board, one number per cell.

A caller then announces numbers one by one, and Cheolsu marks the matching cell on his board. For instance, after 5, 10, and 7 are called, those three cells are marked.

When all five cells in the same row, column, or diagonal are marked, that line is complete.

As soon as three or more lines are complete, Cheolsu calls "Bingo".

Given Cheolsu's board and the order in which the caller announces the numbers, determine after which called number Cheolsu first calls "Bingo".

Input

The first through fifth lines contain Cheolsu's bingo board, from top row to bottom row. Each line contains five integers separated by spaces.

The sixth through tenth lines contain the numbers announced by the caller, in order, in the same format.

The board numbers are exactly the integers from 1 through 25, each used once. The called numbers are also exactly the integers from 1 through 25, each used once.

Output

Print one integer: the number of calls made when Cheolsu first calls "Bingo".