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>
#define cs const
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
cs int oo = 1e9 + 7;
cs int N = 5e4;
int n, S, T, vl[N], cl[N]; 
map<pi, int> mp;
int fi[N], nxt[N], to[N], w[N], ec = 1;
void add(int x, int y, int z) {
	nxt[++ec] = fi[x], fi[x] = ec, to[ec] = y, w[ec] = z; 
	nxt[++ec] = fi[y], fi[y] = ec, to[ec] = x, w[ec] = 0; 
}
int d[N]; 
bool bfs() {
	queue<int> q; 
	q.push(S);
	memset(d, -1, (T + 1) << 2);
	d[S] = 0; 
	while(!q.empty()) {
		int x = q.front(); q.pop();
		for(int e = fi[x], v; e; e = nxt[e]) 
		if(w[e] && d[v = to[e]] == -1) {
			d[v] = d[x] + 1; 
			q.push(v);
			if(v == T) return 1;
		}
	} return 0;
}
int dfs(int u, int flw) {
	int ans = 0; 
	if(u == T) return flw;
	for(int e = fi[u], v; e; e = nxt[e])
	if(w[e] && d[v = to[e]] == d[u] + 1) {
		int dt = dfs(v, min(flw, w[e]));
		ans += dt, flw -= dt;
		w[e] -= dt, w[e ^ 1] += dt;
		if(!flw) break;
	}
	if(flw) d[u] = -1; 
	return ans;
}
ll dinic() {
	ll ans = 0;
	while(bfs()) ans += dfs(S, oo);
	return ans; 	
}
int main() {
	#ifdef FSYo
	freopen("1.in", "r", stdin);
	#endif
	cin >> n; 
	S = 0, T = 2 * n + 1; 
	ll ans = 0; 
	for(int i = 1, x, y, z; i <= n; i++) {
		scanf("%d%d%d", &x, &y, &z);
		ans += z; 
		static int o[2][2] = {1, 2, 0, 3};
		mp[pi(x, y)] = i; 
		int cx = (x % 2 + 2) & 1; 
		int cy = (y % 2 + 2) & 1; 
		cl[i] = o[cx][cy], vl[i] = z; 
		if(o[cx][cy] == 0) 
			add(S, i, oo);
		if(o[cx][cy] == 3)
			add(i + n, T, oo);
		add(i, i + n, z);
	}
	for(auto p : mp) {
		int x = p.fi.fi, y = p.fi.se, c = p.se;
		if(cl[c] & 1 ^ 1) {
			if(mp.count(pi(x - 1, y))) 
				add(c + n, mp[pi(x - 1, y)], oo);
			if(mp.count(pi(x + 1, y)))
				add(c + n, mp[pi(x + 1, y)], oo);
		}
		else if(cl[c] == 1) {
			if(mp.count(pi(x, y - 1)))
				add(c + n, mp[pi(x, y - 1)], oo);
			if(mp.count(pi(x, y + 1)))
				add(c + n, mp[pi(x, y + 1)], oo);
		}
	}
	cout << ans - dinic();
	return 0;
}