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:

#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t N;

//123:0(1個未満)
//132:1(二個未満)
//213:2(二個未満)
//321:3(二個未満)
//231:4
//312:5
std::array<int, 3> get_type(int id)
{
	switch (id)
	{
	case 0:
		return {1,2,3};
	case 1:
		return { 1,3,2 };
	case 2:
		return { 2,1,3 };
	case 3:
		return { 3,2,1 };
	case 4:
		return { 2,3,1 };
	case 5:
		return { 3,1,2 };
	default:
		break;
	}
}
int get_id(std::array<int, 3> res)
{
	if (res[0] == 1) {
		if (res[1] == 2) {
			return 0;
		}
		else {
			return 1;
		}
	}
	else if (res[0] == 2) {
		if (res[1] == 1) {
			return 2;
		}
		else {
			return 4;
		}
	}
	else  {
		if (res[1] == 1) {
			return 5;
		}
		else {
			return 3;
		}
	}
}

int amida_num[6];

bool func(std::array<int, 3> v)
{
	for (int32_t i = 0; i < 6; i++)
	{
		if (amida_num[i] > 0)
		{
			--amida_num[i];
			auto sw = get_type(i);

			std::array<int, 3> next;
			next[0] = v[sw[0] - 1];
			next[1] = v[sw[1] - 1];
			next[2] = v[sw[2] - 1];
			if (get_id(next) == 0) { return true; }
			if (func(next)) {
				return true;
			}
			++amida_num[i];
		}
	}
	return false;
}


int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N;
	for (int32_t i = 0; i < N; i++)
	{
		int32_t w;
		in >> w;
		std::array<int, 3> res{ 1,2,3 };
		while(w--)
		{
			int t;
			in >> t;
			if (t == 1) {
				std::swap(res[1], res[2]);
			}
			else {
				std::swap(res[1], res[0]);
			}
		}
		amida_num[get_id(res)]++;
	}
	if (amida_num[0] >= 1) { out << "yes" << endl; return 0; }
	if (amida_num[1] >= 2) { out << "yes" << endl; return 0; }
	if (amida_num[2] >= 2) { out << "yes" << endl; return 0; }
	if (amida_num[3] >= 2) { out << "yes" << endl; return 0; }
	if (amida_num[4] >= 3) { out << "yes" << endl; return 0; }
	if (amida_num[5] >= 3) { out << "yes" << endl; return 0; }

	if (func({ 1,2,3 })) {
		out << "yes" << endl;
	}
	else {
		out << "no" << endl;
	}

	return 0;
}
#endif