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>
template <typename _Tp>void read(_Tp &x){
	char ch(getchar());bool f(false);while(!isdigit(ch))f|=ch==45,ch=getchar();
	x=ch&15,ch=getchar();while(isdigit(ch))x=x*10+(ch&15),ch=getchar();
	if(f)x=-x;
}
template <typename _Tp,typename... Args>void read(_Tp &t,Args &...args){read(t);read(args...);}
typedef std::pair<int,int> pi;
typedef long long ll;
const int N=2005;
const ll INF=1e18;
struct edge{int v,nxt;ll w;}c[N<<4];
int front[N],ec=-1;
inline void addedge(int u,int v,ll w){
	if(u==-1||v==-1)return;
	c[++ec]=(edge){v,front[u],w},front[u]=ec;
	c[++ec]=(edge){u,front[v],0},front[v]=ec;
}
int _q[N],_l,_r,cur[N],dep[N],S,T,nc;
bool bfs(){
	memset(dep,-1,(nc+3)<<2),memcpy(cur,front,(nc+3)<<2),_q[_l=_r=1]=S,dep[S]=0;
	while(_l!=_r+1){
		int x=_q[_l++];
		for(int i=cur[x];~i;i=c[i].nxt)if(c[i].w){
			int v=c[i].v;
			if(dep[v]==-1)dep[v]=dep[x]+1,_q[++_r]=v;
		}
	}
	return ~dep[T];
}
ll dfs(int x,ll flow){
	if(x==T||!flow)return flow;
	ll f=0,rf;
	for(int &i=cur[x];~i;i=c[i].nxt)if(c[i].w){
		int v=c[i].v;
		if(dep[v]==dep[x]+1&&(rf=dfs(v,std::min(flow,c[i].w)))){
			flow-=rf,f+=rf;
			c[i].w-=rf,c[i^1].w+=rf;
			if(!flow)return f;
		}
	}
	return f;
}
ll dinic(){
	ll ans=0;
	while(bfs())ans+=dfs(S,INF);
	return ans;
}
int X[N],Y[N],W[N],n;
struct node{
	int x,y,id;
	inline bool operator < (const node &o)const{return x==o.x?y<o.y:x<o.x;}
}t[N];
inline int getid(int x,int y){
	int id=std::lower_bound(t+1,t+n+1,(node){x,y,0})-t;
	return id==n+1||t[id].x!=x||t[id].y!=y?-1:t[id].id;
}
int main(){
	memset(front,-1,sizeof(front));
	read(n);
	ll all=0;
	for(int i=1;i<=n;++i)read(X[i],Y[i],W[i]),t[i]={X[i],Y[i],i},all+=W[i];
	std::sort(t+1,t+n+1);
	S=n+n+1,T=S+1,nc=T;
	for(int i=1;i<=n;++i){
		int x=X[i],y=Y[i];
		addedge(i,i+n,W[i]);
		if(x%2&&y%2==0)addedge(i+n,getid(x-1,y),INF),addedge(i+n,getid(x+1,y),INF),addedge(S,i,INF);
		else if(x%2==0&&y%2==0)addedge(i+n,getid(x,y-1),INF),addedge(i+n,getid(x,y+1),INF);
		else if(x%2==0&&y%2)addedge(i+n,getid(x+1,y),INF),addedge(i+n,getid(x-1,y),INF);
		else if(x%2&&y%2)addedge(i+n,T,INF);
	}
	printf("%lld\n",all-dinic());
	return 0;
}