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 "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> N;
	vector<int>v(N);
	vector<int>num(6);
	for (int i = 0; i < N; i++) {
		cin >> M;
		vector<int>box(3);
		for (int k = 0; k < 3; k++) {
			box[k] = k;
		}
		for (int k = 0; k < M; k++) {
			cin >> K;
			if (K) {
				swap(box[1], box[2]);
			}
			else {
				swap(box[0], box[1]);
			}
		}
		if (box[0] == 0 && box[1] == 1) {
			num[0]++;
		}
		else if (box[0] == 0 && box[1] == 2) {
			num[1]++;
		}
		else if(box[0] == 1 && box[1] == 0) {
			num[2]++;
		}
		else if (box[0] == 1 && box[1] == 2) {
			num[3]++;
		}
		else if (box[0] == 2 && box[1] == 0) {
			num[4]++;
		}
		else if (box[0] == 2 && box[1] == 1) {
			num[5]++;
		}
	}
	if (num[0]) {
		cout << "yes\n";
		return 0;
	}
	for (int i = 0; i < 6; i++) {
		for (int j = 0; j < 6; j++) {
			for (int k = 0; k < 6; k++) {
				for (int l = 0; l < 6; l++) {
					for (int m = 0; m < 6; m++) {
						for (int n = 0; n < 6; n++) {
							if (!i && !j && !k && !L && !m && !n) {
								continue;
							}
							vector<int>used(6);
							used[i]++;
							used[j]++;
							used[k]++;
							used[l]++;
							used[m]++;
							used[n]++;
							bool flag = true;
							for (int loop = 1; loop < 6; loop++) {
								if (used[loop] > num[loop]) {
									flag = false;
									continue;
								}
							}
							if (!flag) {
								continue;
							}
							vector<int>box(3);
							for (int k = 0; k < 3; k++) {
								box[k] = k;
							}
							if (i == 1) {
								swap(box[1], box[2]);
							}
							if (i == 2) {
								swap(box[1], box[0]);
							}
							if (i == 3) {
								swap(box[1], box[0]);
								swap(box[1], box[2]);
							}
							if (i == 4) {
								swap(box[0], box[1]);
								swap(box[0], box[2]);
							}
							if (i == 5) {
								swap(box[0], box[2]);
							}
							if (j == 1) {
								swap(box[1], box[2]);
							}
							if (j == 2) {
								swap(box[1], box[0]);
							}
							if (j == 3) {
								swap(box[1], box[0]);
								swap(box[1], box[2]);
							}
							if (j == 4) {
								swap(box[0], box[1]);
								swap(box[0], box[2]);
							}
							if (j == 5) {
								swap(box[0], box[2]);
							}
							if (k == 1) {
								swap(box[1], box[2]);
							}
							if (k == 2) {
								swap(box[1], box[0]);
							}
							if (k == 3) {
								swap(box[1], box[0]);
								swap(box[1], box[2]);
							}
							if (k == 4) {
								swap(box[0], box[1]);
								swap(box[0], box[2]);
							}
							if (k == 5) {
								swap(box[0], box[2]);
							}
							if (l == 1) {
								swap(box[1], box[2]);
							}
							if (l == 2) {
								swap(box[1], box[0]);
							}
							if (l == 3) {
								swap(box[1], box[0]);
								swap(box[1], box[2]);
							}
							if (l == 4) {
								swap(box[0], box[1]);
								swap(box[0], box[2]);
							}
							if (l == 5) {
								swap(box[0], box[2]);
							}
							if (m == 1) {
								swap(box[1], box[2]);
							}
							if (m == 2) {
								swap(box[1], box[0]);
							}
							if (m == 3) {
								swap(box[1], box[0]);
								swap(box[1], box[2]);
							}
							if (m == 4) {
								swap(box[0], box[1]);
								swap(box[0], box[2]);
							}
							if (m == 5) {
								swap(box[0], box[2]);
							}
							if (n == 1) {
								swap(box[1], box[2]);
							}
							if (n == 2) {
								swap(box[1], box[0]);
							}
							if (n == 3) {
								swap(box[1], box[0]);
								swap(box[1], box[2]);
							}
							if (n == 4) {
								swap(box[0], box[1]);
								swap(box[0], box[2]);
							}
							if (n == 5) {
								swap(box[0], box[2]);
							}
							if (box[0] == 0 && box[1] == 1) {
								cout << "yes\n";
								return 0;
							}
						}
					}
				}
			}
		}
	}
	cout << "no\n";
	return 0;
}