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 rep(i,l,r) for (int i=l,i##end=r;i<=i##end;++i)
#define per(i,r,l) for (int i=r,i##end=l;i>=i##end;--i)
#define rep0(i,r) for (int i=0,i##end=r;i<i##end;++i)
#define pr pair<int,ll>
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pb push_back
using namespace std;
const int N=5e4+4; const ll INF=1e18; 
pr edges[N]; vector<int> G[N]; int m;
void adde(int u,int v,ll c){
	edges[m++]=mp(v,c),edges[m++]=mp(u,0);
	G[u].pb(m-2),G[v].pb(m-1);
}
int d[N],cur[N];
bool bfs(int s,int t){
	rep(i,0,t) d[i]=t+1,cur[i]=0;
	static int q[N]; int l=1,r=1; q[r]=s,d[s]=0;
	while (l<=r){
		int u=q[l++]; 
		rep0(i,G[u].size()){
			pr e=edges[G[u][i]];
			if (e.se&&d[u]+1<d[e.fi]) d[e.fi]=d[u]+1,q[++r]=e.fi;
		}
	}
	return d[t]!=t+1;
}
ll dfs(int u,ll a,int t){
	if (u==t||!a) return a;
	ll f=0,p;
	for (int& i=cur[u];i<G[u].size();++i){
		pr& e=edges[G[u][i]];
		if (d[e.fi]==d[u]+1&&(p=dfs(e.fi,min(a,e.se),t))){
			f+=p,a-=p,e.se-=p,edges[G[u][i]^1].se+=p;
			if (!a) break;
		}
	}
	return f;
}
ll dinic(int s,int t){
	ll ans=0;
	while (bfs(s,t)) ans+=dfs(s,INF,t); 
	return ans;
}
map<pair<int,int>,int> p;
int main(){
	int n,nd=0; scanf("%d",&n);
	int s=2*n,t=2*n+1; ll sum=0;
	rep(i,1,n){
		int x,y,w; scanf("%d%d%d",&x,&y,&w);
		sum+=w,p[mp(x,y)]=nd,adde(nd,nd+1,w);
		#define link(dx,dy,op) \
			if (p.count(mp(x+dx,y+dy))){ \
				int u=p[mp(x+dx,y+dy)]; \
				if (op) adde(nd+1,u,INF); \
				else adde(u+1,nd,INF); \
			}
		if (x%2&&y%2==0) adde(s,nd,INF);
		else if (x%2&&y%2) adde(nd+1,t,INF);
		link(-1,0,(x%2!=0)^(y%2!=0))
		link(1,0,(x%2!=0)^(y%2!=0))
		if (x%2==0){
			link(0,-1,y%2==0)
			link(0,1,y%2==0)
		}
		nd+=2;
	}
	printf("%lld\n",sum-dinic(s,t));
	return 0;
}