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;
using LL = long long;
#define fi first
#define se second
int label(int x, int y) {
	x &= 1, y &= 1;
	if (x && y) return 3;
	if (!x && y) return 2;
	if (x && !y) return 0;
	return 1;
}
const LL INF = 1e15;
const int MAX_N = 2e3 + 5, dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
struct Graph { int to, next; LL cap; } e[MAX_N * 100];
int fir[MAX_N], e_cnt;
void clearGraph() { memset(fir, -1, sizeof(fir)); e_cnt = 0; }
void Add_Edge(int u, int v, LL c) {
	e[e_cnt] = (Graph){v, fir[u], c}, fir[u] = e_cnt++;
	e[e_cnt] = (Graph){u, fir[v], 0}, fir[v] = e_cnt++;
}
int S, T, iter[MAX_N], level[MAX_N];
bool bfs() {
	queue<int> que;
	for (int i = 0; i <= T; i++) iter[i] = fir[i], level[i] = -1;
	level[S] = 0, que.push(S);
	while (!que.empty()) {
		int x = que.front(); que.pop();
		for (int i = fir[x]; ~i; i = e[i].next) {
			int v = e[i].to; if (~level[v] || !e[i].cap) continue;
			level[v] = level[x] + 1, que.push(v);
		}
	}
	return ~level[T];
}
LL dfs(int x, LL f) {
	if (x == T || !f) return f;
	LL res = 0;
	for (int &i = iter[x]; ~i; i = e[i].next) {
		int v = e[i].to;
		if (e[i].cap && level[v] == level[x] + 1) {
			LL d = dfs(v, min(f, e[i].cap));
			if (d) {
				e[i].cap -= d, e[i ^ 1].cap += d;
				f -= d, res += d;
				if (!f) break;
			}
		}
	}
	if (!res) level[x] = -1;
	return res;
}
LL dinic() {
	LL res = 0;
	while (bfs()) res += dfs(S, INF);
	return res;
}
int N, x[MAX_N], y[MAX_N], w[MAX_N];
map<pair<int, int>, int> mp;
int main () {
#ifndef ONLINE_JUDGE
    freopen("cpp.in", "r", stdin);
#endif
	clearGraph();
	scanf("%d", &N);
	for (int i = 1; i <= N; i++) scanf("%d %d %d", x + i, y + i, w + i), mp[{x[i], y[i]}] = i;
	S = 0, T = N << 1 | 1;
	for (int i = 1; i <= N; i++) {
		if (label(x[i], y[i]) == 0) Add_Edge(S, i, INF);
		Add_Edge(i, i + N, w[i]);
		if (label(x[i], y[i]) == 3) Add_Edge(i + N, T, INF);
	}
	LL sum = accumulate(&w[1], &w[N + 1], 0ll);
	for (int o = 1; o <= N; o++) {
		if (label(x[o], y[o]) == 3) continue;
		for (int i = 0; i < 4; i++) {
			int nx = x[o] + dx[i], ny = y[o] + dy[i];
			if (label(nx, ny) != label(x[o], y[o]) + 1 || mp.find({nx, ny}) == mp.end()) continue;
			int Id = mp[{nx, ny}];
			Add_Edge(o + N, Id, INF);
		}
	}
	printf("%lld\n", sum - dinic());
    return 0;
}