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 inf 1e9+8
#define eps 1e-6
#define mp make_pair
#define pb push_back
#define fr first
#define sd second
#define pa pair<ll,ll>
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define REP(i,a,b) for(ll i=a;i>=b;i--)
#define MEM(a) memset(a,0,sizeof(a))
#define M 2000010
#define N 5010
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
inline ll read()
{
	char ch=getchar();
	ll s=0,w=1;
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
	return s*w;
}
inline ll lowbit(ll x){return x&(-x);}
struct edge
{
	ll nxt,to,fl;
}e[M<<1];
ll head[N],cur[N],cnt=1;
ll n;
ll x[N],y[N],w[N],b[2][2];
ll ans,S,T;
ll dep[N];queue<ll>Q;
map<pa,ll>ma;
inline void add(ll x,ll y,ll fl)
{
	e[++cnt]=(edge){head[x],y,fl};head[x]=cnt;
	e[++cnt]=(edge){head[y],x,+0};head[y]=cnt;
}
inline ll bfs()
{
	FOR(i,S,T)dep[i]=0,cur[i]=head[i];while(!Q.empty())Q.pop();
	Q.push(S);dep[S]=1;
	while(!Q.empty())
	{
		ll x=Q.front();Q.pop();
		for(ll i=head[x];i;i=e[i].nxt)if(e[i].fl&&!dep[e[i].to])
		{
			ll y=e[i].to;dep[y]=dep[x]+1;Q.push(y);
			if(y==T)return 1;
		}
	}
	return 0;
}
ll dfs(ll x,ll flow)
{
	if(x==T)return flow;
	ll res=0;
	for(ll &i=cur[x];i;i=e[i].nxt)if(dep[e[i].to]==dep[x]+1&&e[i].fl)
	{
		if(res==flow)return res;
		ll y=e[i].to,fl=dfs(y,min(e[i].fl,flow-res));
		res+=fl;e[i].fl-=fl,e[i^1].fl+=fl;
	}
	if(!res)dep[x]=0;
	return res;
}
inline ll Dinic()
{
	ll ans=0;
	while(bfs()){ans+=dfs(S,inf);}
	return ans;
}
int main()
{
	//ios::sync_with_stdio(false);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	b[0][0]=1,b[1][0]=0,b[0][1]=2,b[1][1]=3;
	n=read();FOR(i,1,n)x[i]=read(),y[i]=read(),w[i]=read();
	FOR(i,1,n)ma[mp(x[i],y[i])]=i;
	FOR(i,1,n)ans+=w[i];S=0;T=n*2+1;
	FOR(i,1,n)add(i,i+n,w[i]);
	FOR(i,1,n)
	{
		ll t=b[x[i]&1][y[i]&1];
		if(t==0)add(S,i,inf);
		if(t==3)add(i+n,T,inf);
		FOR(j,1,n)if(abs(x[i]-x[j])+abs(y[i]-y[j])<=1&&b[x[j]&1][y[j]&1]==t+1)add(i+n,j,inf),add(i+n,j,inf),add(i+n,j,inf);
	}
	//cout<<"GG:"<<Dinic()<<'\n';
	cout<<ans-Dinic()<<'\n';
	return 0;
}
/*
9
2 2 100
1 1 1
1 2 1
1 3 1
2 1 1
2 3 1
3 1 1
3 2 1
3 3 1
*/