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 <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;
typedef long long ll;
const int MAXN = 1005, INF = 1e9;
const ll INFL = 0x3f3f3f3f3f3f3f3f;

int head[MAXN<<1], tot = 1;

struct Edge{
	int u, to, next;
	ll flow;
}G[1000005];

inline void addEdge(int u, int v, int f){
	G[++tot].u = u;
	G[tot].to = v;
	G[tot].flow = f;
	G[tot].next = head[u];
	head[u] = tot;
}

inline void addFlow(int u, int v, ll f = INFL){
	addEdge(u,v,f);
	addEdge(v,u,0);
}

int n, x[MAXN], y[MAXN], w[MAXN], now[MAXN<<1], s = 0, t = 2001;
ll sumWi, dis[MAXN<<1], mxFlow;

bool BFS(int s, int t){
	for(int i = 0 ; i <= 2001 ; ++i) dis[i] = 0;
	queue<int> q;
	q.push(s);
	dis[s] = 1;
	now[s] = head[s];
	while(!q.empty()){
		int np = q.front(); q.pop();
		for(int i = head[np], to ; i ; i = G[i].next){
			to = G[i].to;
			if(dis[to]||!G[i].flow) continue;
			now[to] = head[to];
			dis[to] = dis[np] + 1;
			q.push(to);
		}
	}
	return dis[t];
}

inline ll DFS(int np, ll flow){
	if(np==t) return flow;
	ll res = 0;
	for(int i = now[np], to ; i ; i = G[i].next){
		now[np] = i;
		to = G[i].to;
		if(!G[i].flow||dis[to]^(dis[np]+1)) continue;
		ll k = DFS(to,min(flow,G[i].flow));
		if(k==0) dis[to] = 0;
		G[i].flow -= k;
		G[i ^ 1].flow += k;
		res += k;
		flow -= k;
	}
	return res;
}

void dinic(int s, int t){
	while(BFS(s,t)) mxFlow += DFS(s,INFL);
}

int main(){
	scanf("%d",&n);
	for(int i = 1 ; i <= n ; ++i){
		scanf("%d %d %d",&x[i],&y[i],&w[i]);
		sumWi += w[i];
	}
	for(int i = 1 ; i <= n ; ++i){
		addFlow(i,i+n,w[i]);
		if((x[i]&1)&&!(y[i]&1)) addFlow(s,i);
		if((x[i]&1)&&(y[i]&1)) addFlow(i+n,t);
	}
	
	for(int i = 1 ; i <= n ; ++i){
		for(int j = 1 ; j <= n ; ++j){
			if(i==j) continue;
			if(abs(x[i]-x[j])+abs(y[i]-y[j])>1) continue;
			if((x[i]&1)&&!(y[i]&1)&&!(x[j]&1)&&!(y[j]&1)) addFlow(i+n,j);
			if(!(x[i]&1)&&!(y[i]&1)&&!(x[j]&1)&&(y[j]&1)) addFlow(i+n,j);
			if(!(x[i]&1)&&(y[i]&1)&&(x[j]&1)&&(y[j]&1)) addFlow(i+n,j);
		}
	}
	
	dinic(s,t);
	
	// cout<<mxFlow<<endl;
	cout<<sumWi-mxFlow<<endl;
	
	return 0;
}