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)

using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        // 最小公倍数
        public static long Lcm(long a, long b)
        {
            return a * b / Gcd(a, b);
        }

        // ユークリッドの互除法 
        public static long Gcd(long a, long b)
        {
            if (a < b)
                // 引数を入替えて自分を呼び出す
                return Gcd(b, a);
            while (b != 0)
            {
                var remainder = a % b;
                a = b;
                b = remainder;
            }
            return a;
        }

        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
            Console.ReadLine();
        }

        public void Solve(ConsoleInput cin)
        {
            int[] a1 = cin.ReadIntArray(3);
            int[] a2 = cin.ReadIntArray(3);
            int[] a3 = cin.ReadIntArray(3);
            bool[,] nuketa = new bool[3, 3];
            int n = cin.ReadInt;
            int[] b = cin.ReadIntArray(n);
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    if (a1[j] == b[i])
                    {
                        nuketa[0, j] = true;
                    }
                }
                for (int j = 0; j < 3; j++)
                {
                    if (a2[j] == b[i])
                    {
                        nuketa[1, j] = true;
                    }
                }
                for (int j = 0; j < 3; j++)
                {
                    if (a3[j] == b[i])
                    {
                        nuketa[2, j] = true;
                    }
                }
            }

            if(nuketa[0, 0] && nuketa[1, 0] && nuketa[2, 0])
            {
                Console.WriteLine("Yes");
                Console.ReadLine();

                return;
            }            
            if(nuketa[0, 1] && nuketa[1, 1] && nuketa[2, 1])
            {
                Console.WriteLine("Yes");
                Console.ReadLine();

                return;

            }
            if (nuketa[0, 2] && nuketa[1, 2] && nuketa[2, 2])
            {
                Console.WriteLine("Yes");
                Console.ReadLine();

                return;

            }
            if (nuketa[0, 0] && nuketa[0, 1] && nuketa[0, 2])
            {
                Console.WriteLine("Yes");
                Console.ReadLine();

                return;

            }
            if (nuketa[1, 0] && nuketa[1, 1] && nuketa[1, 2])
            {
                Console.WriteLine("Yes");
                Console.ReadLine();

                return;

            }
            if (nuketa[2, 0] && nuketa[2, 1] && nuketa[2, 2])
            {
                Console.WriteLine("Yes");
                Console.ReadLine();

                return;

            }
            if (nuketa[0, 0] && nuketa[1, 1] && nuketa[2, 2])
            {
                Console.WriteLine("Yes");
                Console.ReadLine();

                return;

            }
            if (nuketa[0, 2] && nuketa[1, 1] && nuketa[2, 0])
            {
                Console.WriteLine("Yes");
                Console.ReadLine();

                return;

            }
            Console.WriteLine("No");
            Console.ReadLine();

        }
    }
    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }

    public class Util
    {
        //nCrを計算したいときに使用
        public static ModInt Comb(int n, int r)
        {
            ModInt res = 1;
            for (int i = 1; i <= r; i++)
            {
                res *= n;
                res /= i;
                n--;
            }
            return res;
        }

        //n^mを計算
        public static ModInt Power(ModInt n, long m)
        {
            ModInt pow = n;
            ModInt res = 1;
            while (m > 0)
            {
                if ((m & 1) == 1) res *= pow;
                pow *= pow;
                m >>= 1;
            }
            return res;
        }
    }


    public struct ModInt
    {
        public const int Mod = 1000000007;
        const long POSITIVIZER = ((long)Mod) << 31;
        long Data;
        public ModInt(long data) { if ((Data = data % Mod) < 0) Data += Mod; }
        public static implicit operator long(ModInt modInt) => modInt.Data;
        public static implicit operator ModInt(long val) => new ModInt(val);
        public static ModInt operator -(ModInt a, int b) => new ModInt() { Data = (a.Data - b + POSITIVIZER) % Mod };
        public static ModInt operator -(ModInt a, ModInt b) { long res = a.Data - b.Data; return new ModInt() { Data = res < 0 ? res + Mod : res }; }
        public static ModInt operator *(ModInt a, int b) => new ModInt(a.Data * b);
        public static ModInt operator *(ModInt a, ModInt b) => new ModInt() { Data = a.Data * b.Data % Mod };
        public static ModInt operator /(ModInt a, ModInt b) => new ModInt() { Data = a.Data * GetInverse(b) % Mod };
        public override int GetHashCode() => (int)Data;
        static long GetInverse(long a)
        {
            long div, p = Mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
            while (true)
            {
                if (p == 1) return x2 + Mod; div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p;
                if (a == 1) return x1 + Mod; div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a;
            }
        }
    }
}