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;

map< vector< int >, int > beet_aizu;
set< vector< int > > used;

bool uku(vector< int > beet, bool f) {
  if(f && beet[0] == 0 && beet[1] == 1 && beet[2] == 2) {
    return true;
  }
  for(auto &s : beet_aizu) {
    if(s.second > 0) {
      vector< int > tree_one(3);
      tree_one[0] = beet[s.first[0]];
      tree_one[1] = beet[s.first[1]];
      tree_one[2] = beet[s.first[2]];
      s.second--;
      if(uku(tree_one, true)) return true;
      s.second++;
    }
  }
  return false;
}

int main() {
  int N;

  cin >> N;
  for(int i = 0; i < N; i++) {
    int W;
    cin >> W;
    vector< int > vv{0, 1, 2};
    for(int j = 0; j < W; j++) {
      int x;
      cin >> x;
      if(x == 0) swap(vv[0], vv[1]);
      else swap(vv[1], vv[2]);
    }
    beet_aizu[vv]++;
  }
  vector< int > oio{0, 1, 2};
  if(uku(oio, false)) cout << "yes" << endl;
  else cout << "no" << endl;
}