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<iostream>
#include<vector>
using namespace std;

int arr[6][3] = {
    {0, 1, 2}, 
    {0, 2, 1},
    {1, 0, 2},
    {1, 2, 0},
    {2, 0, 1},
    {2, 1, 0}
};

vector<int> w(6, 0);
bool valid = false;

void dfs(vector<int> v){
    if(v[0] == 0 && v[1] == 1 && v[2] == 2){
        valid = true;
        return;
    }
    for(int i = 0; i < 6; i++){
        if(w[i] == 0)   continue;
        w[i]--;
        vector<int> next(3);
        for(int j = 0; j < 3; j++)  next[j] = v[arr[i][j]];
        dfs(next);
        w[i]++;
    }
}

int main(){
    int n;
    cin >> n;
    while(n-- > 0){
        vector<int> v({0, 1, 2});
        int q;  cin >> q;
        while(q-- > 0){
            int a;  cin >> a;
            if(a == 0)  swap(v[0], v[1]);
            if(a == 1)  swap(v[1], v[2]);
        }
        for(int i = 0; i < 6; i++){
            bool valid = true;
            for(int j = 0; j < 3; j++){
                valid &= arr[i][j]==v[j];
            }
            if(valid)   w[i]++;
        }
    }
    if(w[0] >= 1 || w[1] >= 2 || w[2] >= 2 || w[3] >= 3 || w[4] >= 3 || w[5] >= 2){
        valid = true;
    }else{
        for(int i = 0; i < 6; i++){
            if(w[i] == 0)   continue;
            vector<int> next(3);
            for(int j = 0; j < 3; j++)  next[j] = arr[i][j];
            w[i]--;
            dfs(next);
            w[i]++;
        }
    }
    cout << (valid ? "yes" : "no") << endl;
    return 0;
}