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 ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using vi = vector<int>;

vi in(){
    int w;
    cin >>w;

    vi p(3);
    iota(all(p),0);

    rep(i,w){
        int a;
        cin >>a;
        swap(p[a],p[a+1]);
    }

    return p;
}

bool solve(){
    vi p(3);
    iota(all(p),0);

    vector<vi> v;
    map<vi,int> m;
    do{
        m[p] = v.size();
        v.pb(p);
    }while(next_permutation(all(p)));

    int n;
    cin >>n;

    int ct[6]={};
    int loop[6]={1,2,2,3,3,2};
    rep(i,n){
        vi amida = in();
        ++ct[m[amida]];
    }

    rep(i,6){
        if(ct[i]>=loop[i]) return true;
    }

    vi x;
    rep(i,6)rep(j,ct[i]) x.pb(i);
    int X = x.size();

    vi E(3);
    iota(all(E),0);

    do{
        vi t(3);
        iota(all(t),0);

        rep(i,X){
            vi nt(3);
            vi f = v[x[i]];
            rep(j,3) nt[j] = t[f[j]];
            t = nt;
            if(t==E) return true;
        }
    }while(next_permutation(all(x)));

    return false;
}

int main(){
    cout << (solve()?"yes":"no") << endl;
    return 0;
}