Page not loading? Try clicking here.
Placeholder

#1031

Bingo 1s 32MB

Problems

The Bingo game works as follows:

  1. A bingo board consists of 25 cells, each containing a unique number from 1 to 25.

  2. The host calls out numbers one by one. If a called number is on the board, it is marked off.

    • For example, if the numbers 5, 10, 7 are called, these three numbers are removed from the board.

  3. Whenever a row, column, or diagonal has all 5 numbers marked, a line is drawn.

  4. The first player to have 3 or more completed lines shouts "Bingo" and wins.


Task

Given Chulsoo’s bingo board and the order of numbers called by the host, determine after how many calls Chulsoo shouts "Bingo".


Input

The first 5 lines: the numbers on Chulsoo’s bingo board, from top row to bottom row, 5 numbers per line.

The next 5 lines: the numbers called by the host, in order, 5 numbers per line.

All numbers from 1 to 25 appear exactly once in both the board and the called numbers.


Output

Print a single integer: the count of calls after which Chulsoo shouts "Bingo".


Example

11 12 2 24 10

16 1 13 3 25
6 20 5 21 17
19 4 8 14 9
22 15 7 23 18
5 10 7 16 2
4 22 8 17 13
3 18 1 6 25
12 19 23 14 21
11 24 9 20 15
15


Source

KOI 본선 2006 초3/중2

You must sign in to write code.