Problem: Problem

There are $ N $ Amidakuji with 3 vertical lines.
No matter which line you start from, the Amidakuji that ends at the starting line is considered a good Amidakuji.
You can select one or more Amidakuji and connect them vertically in any order.
Output "yes" if you can make a good Amidakuji, otherwise output "no".

There are $ w_i $ horizontal lines in the $ i $ th Amidakuji.
$ a_ {i, j} $ indicates whether the $ j $ th horizontal bar from the top of Amidakuji $ i $ extends from the central vertical line to the left or right.
If $ a_ {i, j} $ is 0, it means that it extends to the left, and if it is 1, it means that it extends to the right.

Constraints

The input satisfies the following conditions.

* $ 1 \ le N \ le 50 $
* $ 0 \ le w_i \ le 100 $
* $ a_ {i, j} $ is 0 or 1

Input

The input is given in the following format.


$ N $
$ w_1 $ $ a_ {1,1} $ $ a_ {1,2} $ ... $ a_ {1, w_1} $
$ w_2 $ $ a_ {2,1} $ $ a_ {2,2} $ ... $ a_ {2, w_2} $
...
$ w_N $ $ a_ {N, 1} $ $ a_ {N, 2} $ ... $ a_ {N, w_N} $


All inputs are given as integers.
$ N $ is given on the first line.
$ W_i $ and $ w_i $ $ a_ {i, j} $ are given on the following $ N $ line, separated by blanks.

Output

If you can make a good Amidakuji, it outputs "yes", otherwise it outputs "no".

Examples

Input

3
2 0 0
1 1
5 1 0 0 1 0


Output

yes


Input

2
1 1
1 0


Output

no

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;

using ei = tuple<int, int, int>;

ei pajie[] = {ei(0, 1, 2), ei(0, 2, 1), ei(1, 0, 2), ei(1, 2, 0), ei(2, 0, 1), ei(2, 1, 0), ei(0, 1, 2)};

ei latte(ei be, ei et) {
  int a[3], b[3];
  tie(a[0], a[1], a[2]) = be;
  tie(b[0], b[1], b[2]) = et;
  return ei(b[a[0]], b[a[1]], b[a[2]]);
}

int main() {
  int n;
  cin >> n;

  vector<ei> v;
  for (int i = 0; i < n; ++i) {
    int a = 0, b = 1, c = 2;

    int w;
    cin >> w;

    while (w--) {
      int f;
      cin >> f;

      if (f)
        swap(a, b);
      else
        swap(b, c);
    }

    v.push_back(ei(a, b, c));

    // cerr << "{" << a << ", " << b << ", " << c << "}" << endl;
  }

  map<ei, int> unzip;
  for (int i = 0; i < 6; ++i) {
    unzip[pajie[i]] = i;
  }

  int dp[50][7] = {};
  dp[0][6] = 1;

  // cerr << unzip[v[0]] << endl;

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 7; ++j) {
      if (dp[i][j]) {
        dp[i + 1][j] = 1;
        dp[i + 1][unzip[latte(pajie[j], v[i])]] = 1;
      }
    }
  }

  cout << (dp[n][0] ? "yes" : "no") << endl;
}