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>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

map<vi,int> mp;

bool dfs(vi nw,int* cnt,int pos,bool flag)
{
    if(pos == 6){
        return flag && (nw == vi{0,1,2});
    }
    rep(i,cnt[pos]+1){
        if(dfs(nw,cnt,pos+1,(flag|(i >= 1)))){
            return true;
        }
        if(i == cnt[pos]){
            break;
        }
        if(pos == 1){
            swap(nw[1],nw[2]);
        }else if(pos == 2){
            swap(nw[0],nw[1]);
        }else if(pos == 3){
            swap(nw[0],nw[2]);
        }else if(pos == 4){
            swap(nw[0],nw[1]);
            swap(nw[1],nw[2]);
        }else{
            swap(nw[0],nw[2]);
            swap(nw[1],nw[2]);
        }
    }
    return false;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    mp[vi{0,1,2}] = 0,mp[vi{0,2,1}] = 1,mp[vi{1,0,2}] = 2;
    mp[vi{2,1,0}] = 3,mp[vi{1,2,0}] = 4,mp[vi{2,0,1}] = 5;
    int cnt[6] = {};
    rep(i,n){
        vi st = {0,1,2};
        int a;
        cin >> a;
        rep(j,a){
            int c;
            cin >> c;
            if(c){
                swap(st[1],st[2]);
            }else{
                swap(st[0],st[1]);
            }
        }
        cnt[mp[st]]++;
    }
    if(cnt[0] >= 1){
        cout << "yes\n";
        return 0;
    }
    if(cnt[1] >= 2 || cnt[2] >= 2 || cnt[3] >= 2){
        cout << "yes\n";
        return 0;
    }
    if(cnt[4] >= 3 || cnt[5] >= 3){
        cout << "yes\n";
        return 0;
    }
    if(dfs(vi{0,1,2},cnt,0,false)){
        cout << "yes\n";
    }else{
        cout << "no\n";
    }
    return 0;
}