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:
//あみだくじは「置換」で表せる。これは6通りしかないので、実質N ≦ 6。よって全部試せる。
//同じ「置換」を表すあみだくじを2つ以上使うケースは存在するか？　→ 存在するかもしれない…。    
//嘘解法？：同じあみだくじを4つ以上使うケースがないものとして考える。　→　書いてみよう
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

int n;
int w, a;
map<vector<int>, int> mp;
vector<vector<int>> ts;

bool dfs(int used, vector<int> perm) {
	int i, j;
	
	if (used > 0 && perm[0] == 0 && perm[1] == 1 && perm[2] == 2) return true;
	for (i = 0; i < ts.size(); i++) {
		if ((used >> i) & 1) continue;
		
		vector<int> nP;
		for (j = 0; j < 3; j++) {
			nP.push_back(ts[i][perm[j]]);
		}
		bool res = dfs(used + (1 << i), nP);
		if (res) return true;
	}
	return false;
}

int main() {
	int i, j;
	
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> w;
		int hoge[3] = {0, 1, 2};
		for (j = 0; j < w; j++) {
			cin >> a;
			swap(hoge[a], hoge[a + 1]);
		}
		
		vector<int> tikan;
		tikan.resize(3);
		for (j = 0; j < 3; j++) tikan[hoge[j]] = j;
		if (mp.find(tikan) == mp.end()) mp[tikan] = 0;
		mp[tikan]++;
	}
	
	for (map<vector<int>, int>::iterator it = mp.begin(); it != mp.end(); it++) {
		for (i = 0; i < min((it->second), 3); i++) {
			ts.push_back(it->first);
		}
	}
	
	//for (i = 0; i < ts.size(); i++) { for (j = 0; j < 3; j++) cout << ts[i][j] << " " ; cout << endl; }
	bool res = dfs(0, {0, 1, 2});
	if (res) cout << "yes" << endl;
	else cout << "no" << endl;
	return 0;
}