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<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<time.h>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;

const int N=3e6+5;
const long long INF=0x7ffffffffffffff;

int n,s,t,xxx[N],yyy[N];

struct Edge {
	int next,to;
	long long flow;
}a[N<<1];

int head[N],sze=1;

inline void add(int u,int v,long long w) {a[++sze].next=head[u],a[sze].to=v,a[sze].flow=w,head[u]=sze;}
inline void insert(int u,int v,long long w) {add(u,v,w),add(v,u,0);}

int dis[N],cur[N],in[N],ot[N];
long long ans;

inline bool bfs() {
	queue <int> q;
	for(int i=s ; i<=t ; ++i) dis[i]=t,cur[i]=head[i];
	q.push(s),dis[s]=0;
	while(!q.empty()) {
		int u=q.front();q.pop();
		for(int i=head[u] ; i ; i=a[i].next) {
			int v=a[i].to;
			if(a[i].flow&&dis[v]>dis[u]+1) dis[v]=dis[u]+1,q.push(v);
		}
	}
	return dis[t]!=t;
}

long long dfs(int u,long long flow) {
	if(u==t) return flow;
	long long ret=0,rlow;
	for(int &i=cur[u] ; i ; i=a[i].next) {
		int v=a[i].to;
		if(dis[v]==dis[u]+1&&a[i].flow)
			if(rlow=dfs(v,min(a[i].flow,flow-ret))) {
				ret+=rlow,a[i].flow-=ret,a[i^1].flow+=ret;
				if(flow==ret) break ;
			}
	}
	return ret;
}

inline long long dinic() {
	long long flow=0;
	while(bfs())
		flow+=dfs(s,INF);
	return flow;
}

int zzz[N];

int main() {
	scanf("%d",&n),t=n*2+1;
	for(int i=1,x ; i<=n ; ++i) {
		scanf("%d%d",&xxx[i],&yyy[i]);
		if(xxx[i]&1) zzz[i]+=2;
		if(yyy[i]&1) zzz[i]+=1;
		scanf("%d",&x),in[i]=i*2-1,ot[i]=i*2;
		insert(in[i],ot[i],x);
		if(zzz[i]==2) insert(s,in[i],INF);
		if(zzz[i]==3) insert(ot[i],t,INF);
		ans+=x;
	}
	for(int i=1 ; i<=n ; ++i)
		for(int j=1 ; j<=n ; ++j)
			if(abs(xxx[i]-xxx[j])<2&&abs(yyy[i]-yyy[j])<2) {
				if(zzz[i]==2&&zzz[j]==0)
					insert(ot[i],in[j],INF);
				if(zzz[i]==0&&zzz[j]==1)
					insert(ot[i],in[j],INF);
				if(zzz[i]==1&&zzz[j]==3)
					insert(ot[i],in[j],INF);
			}
	long long t=ans-dinic();
	printf("%lld",t);
	return 0;
}