Problem: At the foot of Liyushan Mountain, n tents will be carefully arranged to provide accommodation for those who are willing to experience the joy of approaching nature, the tranquility of the night, and the bright starry sky.

The i-th tent is located at the point of (x_i, y_i) and has a weight of w_i. A tent is important if and only if both x_i and y_i are even. You need to remove some tents such that for each remaining important tent (x, y), there do not exist 3 other tents (x'_1, y'_1), (x'_2, y'_2) and (x'_3, y'_3) such that both conditions are true: 

  1. |x'_j-x|, |y'_j - y|≤ 1 for all j ∈ \{1, 2, 3\}, and 
  2. these four tents form a parallelogram (or a rectangle) and one of its sides is parallel to the x-axis. 



Please maximize the sum of the weights of the tents that are not removed. Print the maximum value.

Input

The first line contains a single integer n (1≤ n≤ 1 000), representing the number of tents.

Each of the next n lines contains three integers x_i, y_i and w_i (-10^9≤ x_i,y_i ≤ 10^9, 1≤ w_i≤ 10^9), representing the coordinate of the i-th tent and its weight. No two tents are located at the same point.

Output

A single integer — the maximum sum of the weights of the remaining tents.

Examples

Input


5
0 0 4
0 1 5
1 0 3
1 1 1
-1 1 2


Output


12


Input


32
2 2 1
2 3 1
3 2 1
3 3 1
2 6 1
2 5 1
3 6 1
3 5 1
2 8 1
2 9 1
1 8 1
1 9 1
2 12 1
2 11 1
1 12 1
1 11 1
6 2 1
7 2 1
6 3 1
5 3 1
6 6 1
7 6 1
5 5 1
6 5 1
6 8 1
5 8 1
6 9 1
7 9 1
6 12 1
5 12 1
6 11 1
7 11 1


Output


24

Note

Here is an illustration of the second example. Black triangles indicate the important tents. This example also indicates all 8 forbidden patterns.

<image>

Solution (in CPP):

Solution:
#include<bits/stdc++.h>
using namespace std;
#define Re register int
typedef long long ll;

const int N = 1005, M = 10005;
const ll Inf = 1e15;
struct info
{
	int x, y, z, t;
}a[N];
int n, t, cnt = 1, l, r, hea[N << 1], h[N << 1], q[N << 1], d[N << 1], nxt[M], to[M];
ll ans, wi[M];

inline int read()
{
	char c = getchar();
	int ans = 0;
	bool f = 1;
	while (c < 48 || c > 57)
	{
		if (c == '-') f = 0;
		c = getchar();
	}
	while (c >= 48 && c <= 57) ans = (ans << 3) + (ans << 1) + (c ^ 48), c = getchar();
	return f ? ans : -ans;
}

inline void add(int x, int y, ll z)
{
	nxt[++cnt] = hea[x], to[cnt] = y, wi[cnt] = z, hea[x] = cnt;
	nxt[++cnt] = hea[y], to[cnt] = x, hea[y] = cnt;
}

inline ll min(ll x, ll y)
{
	return x < y ? x : y;
}

inline bool bfs()
{
	for (Re i = 0; i <= t; ++i) d[i] = 0, h[i] = hea[i];
	d[q[l = r = 0] = 0] = 1;
	while (l <= r)
	{
		int x = q[l++];
		for (Re i = hea[x]; i; i = nxt[i])
		{
			int u = to[i];
			if (!wi[i] || d[u]) continue;
			d[q[++r] = u] = d[x] + 1;
			if (u == t) return 1;
		}
	}
	return 0;
}

inline ll dinic(int x, ll flow)
{
	if (x == t) return flow;
	ll res = flow;
	for (Re &i = h[x]; i; i = nxt[i])
	{
		int u = to[i];
		if (!wi[i] || d[u] ^ d[x] + 1) continue;
		ll v = dinic(u, min(res, wi[i]));
		if (v)
		{
			wi[i] -= v, wi[i ^ 1] += v, res -= v;
			if (!res) break;
		}
	}
	return flow - res;
}

int main()
{
	n = read(), t = n << 1 | 1;
	for (Re i = 1; i <= n; ++i) a[i].x = read(), a[i].y = read(), a[i].z = read(), ans += a[i].z, a[i].t = (a[i].x & 1) << 1 | (a[i].y & 1);
	for (Re i = 1; i <= n; ++i)
	{
		add(i, i + n, a[i].z);
		if (a[i].t == 2) add(0, i, Inf);
		if (a[i].t == 3) add(i + n, t, Inf);
		for (Re j = 1; j <= n; ++j)
			if (abs(a[i].x - a[j].x) + abs(a[i].y - a[j].y) == 1)
				if ((a[i].t == 2 && !a[j].t) || (!a[i].t && a[j].t == 1) || (a[i].t == 1 && a[j].t == 3)) add(i + n, j, Inf);
	}
	ll fl;
	while (bfs())
		while (fl = dinic(0, ans)) ans -= fl;
	printf("%lld", ans);
	return 0;
}