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>

using namespace std;

typedef pair<int ,int> pii;
const long long INF = 10000000000000000ll;

namespace Flow{
	const int maxv=2005;
	const int maxe=20080;
	int S,T,V,tot;
	int head[maxv],nxt[maxe<<1],to[maxe<<1],cap[maxe<<1];
	int lvl[maxv],que[maxv],cur[maxv];
	void init(){
		tot=0;
		memset(head,-1,sizeof(head));
	}
	void addedge(int u,int v,int c){
		nxt[tot]=head[u];to[tot]=v;cap[tot]=c;head[u]=tot++;
		nxt[tot]=head[v];to[tot]=u;cap[tot]=0;head[v]=tot++;
	}
	bool bfs(){
		for(int i=0;i<V;i++)lvl[i]=-1;
		lvl[S]=0;
		int ql=0,qr=0;
		que[qr++]=S;
		while(ql<qr){
			int x=que[ql++];
			for(int i=head[x];~i;i=nxt[i])if(cap[i]&&lvl[to[i]]<0)
				lvl[to[i]]=lvl[x]+1,que[qr++]=to[i];
		}
		return lvl[T]>=0;
	}
	int dfs(int x,int f){
		if(x==T)return f;
		for(int &i=cur[x];~i;i=nxt[i])if(cap[i]&&lvl[to[i]]==lvl[x]+1){
			int d=dfs(to[i],min(f,cap[i]));
			if(d){
				cap[i]-=d;
				cap[i^1]+=d;
				return d;
			}
		}
		return 0;
	}
	long long work(){
		long long res=0;
		while(bfs()){
			for(int i=0;i<V;i++)cur[i]=head[i];
			int f;
			while((f=dfs(S,INF))>0)res+=f;
		}
		return res;
	}
} 
map<pii, int> mp;
long long n, x[1005], y[1005], w[1005], z[1005];
int dx[9][3] = {{1, 1, 0}, {0, -1, -1}, {-1, -1, 0}, {0, 1, 1}, {-1, 0, 1}, {1, 0, -1}, {1, 0, -1}, {-1, 0, 1}};
int dy[9][3] = {{0, 1, 1}, {1, 1, 0}, {0, -1, -1}, {-1, -1, 0}, {0, 1, 1}, {0, 1, 1}, {0, -1, -1}, {0, -1, -1}};
long long rlt;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin >> n;
	for (int i = 0 ; i < n ; i ++) {
		cin >> x[i] >> y[i] >> w[i];
		rlt += w[i];
		z[i] = (x[i] & 1) * 2 + (y[i] & 1);
	}
	Flow::S=n<<1;Flow::T=n<<1|1;Flow::V=Flow::T+1;
	Flow::init();
	for (int i = 0; i < n; i ++) Flow::addedge(i, i + n, w[i]);
	for (int i = 0; i < n; i ++) {
		if (z[i] == 2) Flow::addedge(n * 2, i, INF);
		if (z[i] == 3) Flow::addedge(i + n, n * 2 + 1, INF);
	}
 
	for (int i = 0; i < n; i ++) {
		for (int j = 0; j < n; j ++) {
			if (abs(x[i] - x[j]) > 1 || abs(y[i] - y[j]) > 1) continue;
			if(z[i]==2&&z[j]==0)
				Flow::addedge(i + n,j, INF);
			if(z[i]==0&&z[j]==1)
				Flow::addedge(i + n,j, INF);
			if(z[i]==1&&z[j]==3)
				Flow::addedge(i + n,j, INF);
		}
	}
	cout << rlt - Flow::work() << endl;
	return 0;
}