#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<bitset>
#include<vector>
using namespace std;

typedef long long ll;
typedef unsigned int ui;

ll read() {
	ll x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch))x=x*10+(ch^48),ch=getchar();
	return x*f;
}
void write(ll x) {
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+48);
}
void writes(ll x) {write(x),putchar(' ');}
void Writes(ll x) {write(x),putchar('\n');}

#define N 1010
#define mp make_pair
#define INF 0x3f3f3f3f3f3f3f3f
const int dx[]={0,0,1,-1};
const int dy[]={1,-1,0,0};


int n;
map <pair<int,int>,int> dots; 
int px[N],py[N],val[N],type[N];
int S,T;
int cur[N<<1],head[N<<1],ver[N<<3],nxt[N<<3],tot=1;
ll cap[N<<3],sum;
int dep[N<<1];
void add(int x,int y,ll z) {
	ver[++tot]=y,nxt[tot]=head[x],head[x]=tot,cap[tot]=z;
	ver[++tot]=x,nxt[tot]=head[y],head[y]=tot,cap[tot]=0;
}
inline int In(int x) {return x;}
inline int Out(int x){return x+n;}

bool bfs() {
	memset(dep,0,sizeof dep);
	memcpy(cur,head,sizeof head);
	queue <int> q;
	dep[S]=1,q.push(S);
	while(!q.empty()) {
		int x=q.front();q.pop();
		for(int i=head[x];i;i=nxt[i]) {
			int y=ver[i];
			if(!dep[y] and cap[i]) {
				dep[y]=dep[x]+1;
				q.push(y);
				if(y == T)	return 1;
			}
		}	
	}	
	return 0;
}

ll find(int x,ll limit) {
	if(x == T)	return limit;
	ll flow=0;
	for(int i=cur[x];i and flow<limit;i=nxt[i]) {
		int y=ver[i];
		if(dep[y] == dep[x] +1 and cap[i]) {
			ll k=find(y,min(cap[i],limit-flow));
			if(!k)	dep[y]=0;
			else 	flow+=k,cap[i]-=k,cap[i^1]+=k;
		}
	}
	return flow;
}

ll dinic() {
	ll maxflow=0;
	while(bfs())
		maxflow+=find(S,INF);
	return maxflow;
}

signed main() {
	n=read();
	for(int i=1;i<=n;++i) {
		px[i]=read(),py[i]=read(),val[i]=read();
		sum+=val[i];
		if(px[i] % 2 != 0 and py[i] % 2 == 0)
			type[i]=0;
		else if(px[i] % 2 == 0 and py[i] % 2 == 0)
			type[i]=1;
		else if(px[i] % 2 == 0 and py[i] % 2 != 0)
			type[i]=2;
		else if(px[i] % 2 != 0 and py[i] % 2 != 0)
			type[i]=3;
		dots[mp(px[i],py[i])]=i;
	}
	S=2*n+1,T=2*n+2;
	for(int i=1;i<=n;++i) {
		if(type[i] == 0)
			add(S,In(i),INF);
		add(In(i),Out(i),val[i]);
		if(type[i] == 3)
			add(Out(i),T,INF);
		for(int j=0;j<4;++j) {
			int nx=px[i]+dx[j],ny=py[i]+dy[j];
			map<pair<int,int>,int>::iterator it=dots.find(mp(nx,ny));
			if(it == dots.end())	continue;
			int id=(*it).second;
			if(type[i]+1 == type[id])
				add(Out(i),In(id),INF);
		}
	}
	
	Writes(sum-dinic());
	return 0;
}






### Prompt

Create a solution in Cpp for the following 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>

### Response

```cpp
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<bitset>
#include<vector>
using namespace std;

typedef long long ll;
typedef unsigned int ui;

ll read() {
	ll x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch))x=x*10+(ch^48),ch=getchar();
	return x*f;
}
void write(ll x) {
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+48);
}
void writes(ll x) {write(x),putchar(' ');}
void Writes(ll x) {write(x),putchar('\n');}

#define N 1010
#define mp make_pair
#define INF 0x3f3f3f3f3f3f3f3f
const int dx[]={0,0,1,-1};
const int dy[]={1,-1,0,0};


int n;
map <pair<int,int>,int> dots; 
int px[N],py[N],val[N],type[N];
int S,T;
int cur[N<<1],head[N<<1],ver[N<<3],nxt[N<<3],tot=1;
ll cap[N<<3],sum;
int dep[N<<1];
void add(int x,int y,ll z) {
	ver[++tot]=y,nxt[tot]=head[x],head[x]=tot,cap[tot]=z;
	ver[++tot]=x,nxt[tot]=head[y],head[y]=tot,cap[tot]=0;
}
inline int In(int x) {return x;}
inline int Out(int x){return x+n;}

bool bfs() {
	memset(dep,0,sizeof dep);
	memcpy(cur,head,sizeof head);
	queue <int> q;
	dep[S]=1,q.push(S);
	while(!q.empty()) {
		int x=q.front();q.pop();
		for(int i=head[x];i;i=nxt[i]) {
			int y=ver[i];
			if(!dep[y] and cap[i]) {
				dep[y]=dep[x]+1;
				q.push(y);
				if(y == T)	return 1;
			}
		}	
	}	
	return 0;
}

ll find(int x,ll limit) {
	if(x == T)	return limit;
	ll flow=0;
	for(int i=cur[x];i and flow<limit;i=nxt[i]) {
		int y=ver[i];
		if(dep[y] == dep[x] +1 and cap[i]) {
			ll k=find(y,min(cap[i],limit-flow));
			if(!k)	dep[y]=0;
			else 	flow+=k,cap[i]-=k,cap[i^1]+=k;
		}
	}
	return flow;
}

ll dinic() {
	ll maxflow=0;
	while(bfs())
		maxflow+=find(S,INF);
	return maxflow;
}

signed main() {
	n=read();
	for(int i=1;i<=n;++i) {
		px[i]=read(),py[i]=read(),val[i]=read();
		sum+=val[i];
		if(px[i] % 2 != 0 and py[i] % 2 == 0)
			type[i]=0;
		else if(px[i] % 2 == 0 and py[i] % 2 == 0)
			type[i]=1;
		else if(px[i] % 2 == 0 and py[i] % 2 != 0)
			type[i]=2;
		else if(px[i] % 2 != 0 and py[i] % 2 != 0)
			type[i]=3;
		dots[mp(px[i],py[i])]=i;
	}
	S=2*n+1,T=2*n+2;
	for(int i=1;i<=n;++i) {
		if(type[i] == 0)
			add(S,In(i),INF);
		add(In(i),Out(i),val[i]);
		if(type[i] == 3)
			add(Out(i),T,INF);
		for(int j=0;j<4;++j) {
			int nx=px[i]+dx[j],ny=py[i]+dy[j];
			map<pair<int,int>,int>::iterator it=dots.find(mp(nx,ny));
			if(it == dots.end())	continue;
			int id=(*it).second;
			if(type[i]+1 == type[id])
				add(Out(i),In(id),INF);
		}
	}
	
	Writes(sum-dinic());
	return 0;
}






```