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;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

vector<int> getperm(){
    int w;
    cin>>w;
    vector<int> ret = vector<int>{0,1,2};
    
    rep(i,w){
        int p;
        cin>>p;
        if(p==0)swap(ret[0],ret[1]);
        else    swap(ret[1],ret[2]);
    }
    
    return ret;
}

vector<int> f(vector<int> origin, vector<int> comb){
    vector<int> ret(3);
    rep(i,3){
        ret[i] = origin[comb[i]];
    }
    
    return ret;
}

int main(){
    int n;
    cin>>n;
    vector<vector<int>> v;
    map<vector<int>,int> mp;
    rep(i,n){
        vector<int> t = getperm();
        if(mp[t]<2){
            if(mp[t]==0 or t==vector<int>{2,0,1} or t==vector<int>{1,2,0}){
                v.pb(t);
            }}
        mp[t]++;
    }
    
    
    assert(v.size()<=8);
    
    if(mp[vector<int>{2,0,1}]>=3 or
       mp[vector<int>{1,2,0}]>=3 or
       mp[vector<int>{2,1,0}]>=2 or
       mp[vector<int>{1,0,2}]>=2 or
       mp[vector<int>{0,1,2}]>=2 or
       mp[vector<int>{0,2,1}]>=2){
        cout<<"yes"<<endl;
        return 0;
    }
    
    sort(all(v));
    
    do{
        vector<int> t = v[0];
        if(t==vector<int>{0,1,2}){
            cout<<"yes"<<endl;
            return 0;
        }
        for(int i=1;i<v.size();i++){
            t = f(t,v[i]);
            if(t==vector<int>{0,1,2}){
                cout<<"yes"<<endl;
                return 0;
            }
        }
    }while(next_permutation(all(v)));
    
    cout<<"no"<<endl;
}