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;

int main(){
  int n;
  cin>>n;

  vector<int> ty(6,0);
  for(int i=0;i<n;i++){
    int w;
    cin>>w;
    int a=1;
    int b=2;
    int c=3;

    for(int j=0;j<w;j++){
      int t;
      cin>>t;
      if(t==0){
        int tmp=a;
        a=b;
        b=tmp;
      }else{
        int tmp=b;
        b=c;
        c=tmp;
      }
    }
    if(a==1&&b==2)ty[0]++;
    if(a==2&&b==1)ty[1]++;
    if(a==1&&b==3)ty[2]++;
    if(a==3&&b==2)ty[3]++;
    if(a==2&&b==3)ty[4]++;
    if(a==3&&b==1)ty[5]++;
  }

  //for(int i=0;i<6;i++)cout<<ty[i]<<endl;


  if(ty[0]!=0){
    cout<<"yes"<<endl;
    return 0;
  }

  if(ty[1]>1||ty[2]>1||ty[3]>1){
    cout<<"yes"<<endl;
    return 0;
  }

  if(ty[4]>2||ty[5]>2){
    cout<<"yes"<<endl;
    return 0;
  }

  if(ty[4]==1&&ty[5]==1){
    cout<<"yes"<<endl;
    return 0;
  }

  vector<int> np;
  for(int i=1;i<6;i++){
    for(int j=0;j<ty[i];j++)np.push_back(i);
  }
  //for(int i=0;i<np.size();i++)cout<<np[i];

  do{
    int a=1;
    int b=2;
    int c=3;
    int tmp;
    for(int i=0;i<np.size();i++){
      if(np[i]==1){
        tmp=a;
        a=b;
        b=tmp;
      }

      if(np[i]==2){
        tmp=b;
        b=c;
        c=tmp;
      }

      if(np[i]==3){
        tmp=a;
        a=c;
        c=tmp;
      }

      if(np[i]==4){
        tmp=a;
        a=b;
        b=c;
        c=tmp;
      }

      if(np[i]==5){
        tmp=a;
        a=c;
        c=b;
        b=tmp;
      }
      if(a==1&&b==2){
        //for(int i=0;i<np.size();i++)cout<<np[i];
        cout<<"yes"<<endl;
        return 0;
      }
    }
  }while(next_permutation(np.begin(),np.end()));


  cout<<"no"<<endl;

}