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;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cerr<<(#v)<<":";for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;
#define printVS(vs) cerr<<(#vs)<<":"<<endl;for(auto(s):(vs)){cerr<<(s)<< endl;}
#define printVV(vv) cerr<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;}
#define printP(p) cerr<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cerr<<(#vp)<<":"<<endl;for(auto(p):(vp)){cerr<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cerr << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cerr << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1ll << 60;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

vi f(vi a, vi b) {
  vi c(3);
  rep(i, 3) {
    c[b[i]] = a[i];
  }
  return c;
}

signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  int n;
  cin >> n;
  map<vi, int> mp;
  vvi perms = {
    {0, 1, 2},
    {0, 2, 1},
    {1, 0, 2},
    {1, 2, 0},
    {2, 0, 1},
    {2, 1, 0}
  };
  rep(i, n) {
    int w;
    cin >> w;
    vi perm(3);
    iota(all(perm), 0);
    rep(j, w) {
      int a;
      cin >> a;
      if (a == 0) {
        swap(perm[0], perm[1]);
      }
      else {
        swap(perm[1], perm[2]);
      }
    }
    mp[perm]++;
  }

  /*
  for (auto p : mp) {
    rep(i, 3) cerr << p.first[i] << " ";
    cerr << ": " << p.second << endl;
  }
  */

  if (mp[perms[0]] >= 1
    || mp[perms[1]] >= 2
    || mp[perms[2]] >= 2
    || mp[perms[3]] >= 3
    || mp[perms[4]] >= 3
    || mp[perms[5]] >= 2)
  {
    cout << "yes" << endl;
    return 0;
  }

  vvi list;
  rep(i, 6) {
    rep(j, mp[perms[i]]) {
      list.push_back(perms[i]);
    }
  }

  rep(state, 1 << list.size()) {
    // cerr << "state = " << state << endl;
    if (state == 0) continue;
    vvi chosen;
    rep(i, list.size()) {
      if ((state >> i) & 1) {
        chosen.push_back(list[i]);
      }
    }
    sort(all(chosen));
    do {
      // printVV(chosen);
      vi perm(3);
      iota(all(perm), 0);
      rep(i, chosen.size()) {
        perm = f(perm, chosen[i]);
      }
      if (perm == perms[0]) {
        cout << "yes" << endl;
        return 0;
      }
    } while (next_permutation(all(chosen)));
  }

  cout << "no" << endl;

}