#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a[3][3];
  long long n;
  cin >> n;
  long long b[n];
  for (long long i = 0; i < 3; i++) {
    for (long long j = 0; j < 3; j++) {
      cin >> a[i][j];
    }
  }
  for (long long i = 0; i < n; i++) {
    cin >> b[i];
  }
  long long k = 0;
  long long flag = 0;
  for (long long i = 0; i < 3; i++) {
    for (long long j = 0; j < 3; j++) {
      if (a[i][j] == b[k]) {
        k++;
        cout << "Yes\n";
        flag = 1;
        break;
      }
    }
    if (flag) break;
  }
  if (flag == 0) cout << "No\n";
  return 0;
}
