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:
// header {{{
#include <bits/stdc++.h>
using namespace std;

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int n;cin >> n;
    vector<int> f(n);
    map<string, int> mp;
    mp["123"] = 0; // id
    mp["132"] = 1; // swap
    mp["213"] = 2; // swap
    mp["231"] = 3; // <<
    mp["312"] = 4; // >>
    mp["321"] = 5; // swap

    vector<int> cnt(6, 0);

    inc(i, 0, n){
        int w;cin >> w;
        string s = "123";
        inc(j, 0, w){
            int a;cin >> a;
            if(a == 0) swap(s[0], s[1]);
            if(a == 1) swap(s[1], s[2]);
        }
        f[i] = mp[s];
        cnt[f[i]]++;
    }

    string ans = "no";

    if(cnt[0] >= 1) ans = "yes"; // id
    if(cnt[1] >= 2) ans = "yes"; // swap
    if(cnt[2] >= 2) ans = "yes"; // swap
    if(cnt[5] >= 2) ans = "yes"; // swap
    if(cnt[3] >= 3) ans = "yes"; // <<3
    if(cnt[4] >= 3) ans = "yes"; // >>3
    if(cnt[3] >= 1 && cnt[4] >= 1) ans = "yes"; // << >>
    if(cnt[1]+cnt[2]+cnt[5] >= 2 && cnt[3]+cnt[4] >= 1) ans = "yes";

    cout << ans << endl;

    return 0;
}