Problem:
Score : 200 points

Problem Statement

We have a bingo card with a 3\times3 grid. The square at the i-th row from the top and the j-th column from the left contains the number A_{i, j}.

The MC will choose N numbers, b_1, b_2, \cdots, b_N. If our bingo sheet contains some of those numbers, we will mark them on our sheet.

Determine whether we will have a bingo when the N numbers are chosen, that is, the sheet will contain three marked numbers in a row, column, or diagonal.

Constraints

All values in input are integers.

1 \leq A_{i, j} \leq 100

A_{i_1, j_1} \neq A_{i_2, j_2} ((i_1, j_1) \neq (i_2, j_2))

1 \leq N \leq 10

1 \leq b_i \leq 100

b_i \neq b_j (i \neq j)

Input

Input is given from Standard Input in the following format:

A_{1, 1} A_{1, 2} A_{1, 3}
A_{2, 1} A_{2, 2} A_{2, 3}
A_{3, 1} A_{3, 2} A_{3, 3}
N
b_1
\vdots
b_N

Output

If we will have a bingo, print Yes; otherwise, print No.

Sample Input 1

84 97 66
79 89 11
61 59 7
7
89
7
87
79
24
84
30

Sample Output 1

Yes

We will mark A_{1, 1}, A_{2, 1}, A_{2, 2}, A_{3, 3}, and complete the diagonal from the top-left to the bottom-right.

Sample Input 2

41 7 46
26 89 2
78 92 8
5
6
45
16
57
17

Sample Output 2

No

We will mark nothing.

Sample Input 3

60 88 34
92 41 43
65 73 48
10
60
43
88
11
48
73
65
41
92
34

Sample Output 3

Yes

We will mark all the squares.

Solution in C# (Mono 4.6.2.0) (judge verdict: Accepted)

/*********************************************
* 20.05.11 AtCoder Beginner Contest 157. A, B, C
* 
*
*********************************************/
/*********************************************
::test input::
*********************************************/

namespace TempName{
    using System;
    using System.Linq;
    using System.Collections.Generic;
    using System.Reflection;
    using static System.Console;
    using static IOmacro.CSharpInput; 
    using static IOmacro.CppInput;
    using static IOmacro.CConst;

    public class CRun{
        public readonly char problem_num = 'B';
        
        public void solve_1() {
            // A - Duplex Printing 
            // N페이지의 문서 양면인쇄. 최소 페이지수?
            
            int query_num = _int;
            int page = query_num / 2;
            int amari = query_num % 2;
            
            var ans = page + amari;
            WriteLine(ans);
            
        }

        public void solve_2() {
            // B - Bingo 
            // 3x3사이즈 빙고. 
            // N개의 수 선택. 빙고내에 그 수가 있는경우 낙인.
            // 그시점에서 빙고가 되있는지 판정.
            
            const int h = 3;
            const int w = 3;
            var bingo = new int[h,w];
            for (int iy = 0; iy < h; iy++) {
                for (int ix = 0; ix < w; ix++) {
                    bingo[iy,ix] = cin;
                }
            }
            var bingo_chk = new bool[h,w];
            Array.Clear(bingo_chk, 0, bingo_chk.Length);
            
            int qry_num = _int;
            while (qry_num-- > 0) {
                int qry = _int;
                for (int iy = 0; iy < h; iy++) {
                    for (int ix = 0; ix < w; ix++) {
                        if (bingo[iy,ix] == qry) {
                            bingo_chk[iy,ix] = true;
                        }
                    }
                }
            }
            
            if (bingo_chk[0,0]&&bingo_chk[0,1]&&bingo_chk[0,2] ||
            bingo_chk[1,0]&&bingo_chk[1,1]&&bingo_chk[1,2] ||
            bingo_chk[2,0]&&bingo_chk[2,1]&&bingo_chk[2,2] ||
            bingo_chk[0,0]&&bingo_chk[1,0]&&bingo_chk[2,0] ||
            bingo_chk[0,1]&&bingo_chk[1,1]&&bingo_chk[2,1] ||
            bingo_chk[0,2]&&bingo_chk[1,2]&&bingo_chk[2,2] ||
            bingo_chk[0,0]&&bingo_chk[1,1]&&bingo_chk[2,2] ||
            bingo_chk[0,2]&&bingo_chk[1,1]&&bingo_chk[2,0]) {
                WriteLine("Yes");
            }
            else {
                WriteLine("No");
            }
        }

        public void solve_3() {
            
        }
    }
    
    class Program { 
        static void Main() { 
            var run = new CRun();
            if (run.problem_num == 'A') run.solve_1(); 
            if (run.problem_num == 'B') run.solve_2(); 
            if (run.problem_num == 'C') run.solve_3();
        } 
    }
}

namespace IOmacro {
    //20.05.10. 수정
    
    using System; 
    using System.Linq; 
    using System.IO;
    using System.Collections.Generic;
    
    public class CSharpInput {
        public static StreamWriter _writer = new StreamWriter(Console.OpenStandardOutput());
        public const char separator = ' ';
        public static string _string{get{return Console.ReadLine();}}
        public static string[] _stringa{get{return (Console.ReadLine().Split(separator));}}
        public static int _int{get{return int.Parse(Console.ReadLine());}}
        public static int[] _inta{get{return Console.ReadLine().Split(separator).Select(int.Parse).ToArray();}}
        public static long _long{get{return long.Parse(Console.ReadLine());}}
        public static long[] _longa{get{return Console.ReadLine().Split(separator).Select(long.Parse).ToArray();}}    
        public static double _double{get{return double.Parse(Console.ReadLine());}}
        public static double[] _doublea{get{return Console.ReadLine().Split(separator).Select(double.Parse).ToArray();}}    
    }
    
    public class CConst {
        public static readonly int MINI = int.MaxValue;
        public static readonly long INF = Int64.MaxValue;
    }
    
    public class CppInput {
        public static CppInput cin => new CppInput();
        public const char separator = ' ';
        private static readonly Queue<string> _input = new Queue<string>();
        private CppInput(){}
        public static implicit operator string(CppInput _) {
            if (_input.Count == 0) Console.ReadLine().Split(separator).foreachExtension(x => _input.Enqueue(x));
            return _input.Dequeue();
        }
        public static implicit operator int(CppInput _){
            if (_input.Count == 0) Console.ReadLine().Split(separator).foreachExtension(x => _input.Enqueue(x));
            return int.Parse(_input.Dequeue());
        }
        public static implicit operator long(CppInput _){
            if (_input.Count == 0) Console.ReadLine().Split(separator).foreachExtension(x => _input.Enqueue(x));
            return long.Parse(_input.Dequeue());
        }
        public static implicit operator double(CppInput _){
            if (_input.Count == 0) Console.ReadLine().Split(separator).foreachExtension(x => _input.Enqueue(x));
            return double.Parse(_input.Dequeue());
        }
    }
    
    public static class EnumerableExtension {
        public delegate void Function<in T>(T val);
        public static void foreachExtension<T>(this IEnumerable<T> enumerable, Function<T> function) {
            foreach (var x in enumerable) function(x);
        }
    }
}