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;

vector<vector<int>> ord;
int nxt[6][6];

void init(){
	{
		vector<int> a = { 0,1,2 };
		do{
			ord.push_back(a);
		} while(next_permutation(a.begin(), a.end()));
	}
	for(int i = 0; i < 6; i++){
		for(int j = 0; j < 6; j++){
			vector<int> v1 = ord[i], v2 = ord[j];
			vector<int> res(3);
			for(int k = 0; k < 3; k++){
				res[k] = v2[v1[k]];
			}
			nxt[i][j] = find(ord.begin(), ord.end(), res) - ord.begin();
		}
	}
}

bool dp[110][6][2];
int id[100];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	init();

	int N;
	cin >> N;
	for(int i = 0; i < N; i++){
		int w;
		cin >> w;
		vector<int> v = { 0,1,2 };
		while(w--){
			int a;
			cin >> a;
			if(a == 0) swap(v[0], v[1]);
			else swap(v[1], v[2]);
		}
		id[i] = find(ord.begin(), ord.end(), v) - ord.begin();
	}

	dp[0][0][0] = 1;
	for(int i = 0; i < N; i++){
		for(int j = 0; j < 6; j++){
			for(int k = 0; k < 2; k++){
				if(!dp[i][j][k]) continue;
				dp[i + 1][j][k] = 1;
				int to = nxt[j][id[i]];
				dp[i + 1][to][1] = 1;
			}
		}
	}

	if(dp[N][0][1]) cout << "yes" << endl;
	else cout << "no" << endl;
}