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:
/*---Author:HenryHuang---*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxm=2e6+5;
const ll maxn=2e5+5;
struct edge{
	ll to,nex,w;
}e[maxm<<1];
ll head[maxn],cur[maxn],cnt=1;
ll n,m,s,t;
void add(ll a,ll b,ll c){
	e[++cnt]=(edge){b,head[a],c};
	head[a]=cur[a]=cnt;//当前弧优化 
}
void addedge(ll a,ll b,ll c){
	add(a,b,c),add(b,a,0);
}
ll dis[maxn];
ll bfs(){
	memset(dis,0,sizeof dis);
	queue<int> Q;
	dis[s]=1;Q.push(s);
	for(ll i=s;i<=t;++i) cur[i]=head[i];
	while(!Q.empty()){
		ll u=Q.front();Q.pop();
		for(ll i=head[u];i;i=e[i].nex){
			ll v=e[i].to;
			if(e[i].w&&!dis[v]){
				dis[v]=dis[u]+1;
				Q.push(v);
			}
		}
	}
	return dis[t];
}
ll dfs(ll u,ll in){
	if(u==t) return in;
	ll out=0,tmp;
	for(ll &i=cur[u];i;i=e[i].nex){
		ll v=e[i].to;
		if(e[i].w&&dis[v]==dis[u]+1&&(tmp=dfs(v,min(in,e[i].w)))){
			e[i].w-=tmp;
			e[i^1].w+=tmp;
			in-=tmp;
			out+=tmp;
			if(!in) break;
		}
	}
	if(!out) dis[u]=0;
	return out;
}
ll calc(ll x,ll y){
	return ((y&1)<<1|((x&1)==(y&1)));
}
ll xx[maxn],yy[maxn];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>n;
	s=0,t=2*n+1;
	ll sum=0;
	for(ll i=1;i<=n;++i){
		ll z;cin>>xx[i]>>yy[i]>>z;
		sum+=z;
		addedge(i,i+n,z);
		if(calc(xx[i],yy[i])==0) addedge(s,i,1e9);
		if(calc(xx[i],yy[i])==3) addedge(i+n,t,1e9);
	}
	// for(int i=-5;i<=5;++i){
	// 	for(int j=-5;j<=5;++j){
	// 		cout<<calc(i,j);
	// 	}
	// 	cout<<'\n';
	// }
	for(ll i=1;i<=n;++i){
		for(int j=1;j<=n;++j){
			if(calc(xx[i],yy[i])+1==calc(xx[j],yy[j])&&abs(xx[i]-xx[j])+abs(yy[i]-yy[j])==1){
				addedge(i+n,j,1e9);
			}
		}
	}
	ll ans=0;
	while(bfs()) ans+=dfs(s,2e9);
	cout<<sum-ans<<'\n';
	return 0;
}
/*
10
-535541974 -572774963 799430338
-535541973 -572774960 348212269
-535541972 -572774962 236752893
-535541973 -572774963 657120913
-535541975 -572774961 155042637
-535541975 -572774962 81575270
-535541971 -572774961 888834471
-535541974 -572774961 899782743
-535541971 -572774960 614959267
-535541972 -572774961 816616774
*/
/*
10
-535541974 -572774963 799430338
-535541973 -572774960 348212269
-535541972 -572774962 236752893
-535541973 -572774963 657120913
-535541975 -572774961 155042637
-535541975 -572774962 81575270
-535541971 -572774961 888834471
-535541974 -572774961 899782743
-535541971 -572774960 614959267
-535541972 -572774961 816616774
*/