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 For(i,a,b) for(register int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(register int i=(a);i>=(b);--i)
#define int long long
using namespace std;
inline int read()
{
    char c=getchar();int x=0;bool f=0;
    for(;!isdigit(c);c=getchar())f^=!(c^45);
    for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
    if(f)x=-x;return x;
}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;

const int maxn=10007,maxm=100007,inf=0x3f3f3f3f3f3f3f3f;
int n,m,s,t,maxflow;
int dep[maxn],cur[maxn];
int tot=1,head[maxn];
struct edge{
	int to,nxt,w;
}e[maxm<<1];
inline void adde(int u,int v,int w){
	e[++tot]=(edge){v,head[u],w};
	head[u]=tot;
}
inline void add(int u,int v,int w){
	adde(u,v,w);
	adde(v,u,0);
}
bool bfs(int s,int t)
{
	queue<int>q;
	memcpy(cur,head,sizeof cur);
	memset(dep,63,sizeof dep);
	dep[s]=0;q.push(s);
	while(!q.empty())
	{
		int u=q.front();q.pop();
		for(int i=head[u];i;i=e[i].nxt)
		{
			int v=e[i].to;
			if(dep[v]==inf&&e[i].w){
				dep[v]=dep[u]+1;
                if(v==t)return 1;
				q.push(v);
			}
		}
	}return dep[t]<inf;
}
int dfs(int u,int t,int minn)
{
	if(!minn||u==t)return minn;
	int res=0;
	for(int i=cur[u];i;i=e[i].nxt)
	{
		int v=e[i].to;
		cur[u]=i;
		if(dep[v]!=dep[u]+1)continue;
		int flow=dfs(v,t,min(minn,e[i].w));
		if(!flow)continue;
		res+=flow,minn-=flow;
		e[i].w-=flow,e[i^1].w+=flow;
		if(!minn)break;
	}
    if(!res) dep[u]=0;
    return res;
}
inline int dinic(int s,int t)
{
	int maxflow=0,flow=0;
	while(bfs(s,t))while(flow=dfs(s,t,inf))maxflow+=flow;
	return maxflow;
}

int x[maxn],y[maxn],w[maxn],sum;
map<pii,int>mp;

signed main()
{
	n=read();
	For(i,1,n)x[i]=read(),y[i]=read(),w[i]=read(),
			mp[mkp(x[i],y[i])]=i,sum+=w[i];
	s=0,t=2*n+1;
	For(i,1,n)
	{
		add(i,i+n,w[i]);
		bool bx=(x[i]%2),by=(y[i]%2);
		int to;
		if(bx&&!by){
			add(s,i,inf);
			if(mp.count(mkp(x[i]+1,y[i])))
				add(i+n,mp[mkp(x[i]+1,y[i])],inf);
			if(mp.count(mkp(x[i]-1,y[i])))
				add(i+n,mp[mkp(x[i]-1,y[i])],inf);
		}
		else if(!bx&&!by){
			if(mp.count(mkp(x[i],y[i]-1)))
				add(i+n,mp[mkp(x[i],y[i]-1)],inf);
			if(mp.count(mkp(x[i],y[i]+1)))
				add(i+n,mp[mkp(x[i],y[i]+1)],inf);
		}
		else if(!bx&&by){
			if(mp.count(mkp(x[i]+1,y[i])))
				add(i+n,mp[mkp(x[i]+1,y[i])],inf);
			if(mp.count(mkp(x[i]-1,y[i])))
				add(i+n,mp[mkp(x[i]-1,y[i])],inf);
		}
		else add(i+n,t,inf);
	}
	sum -= dinic(s,t);
	cout<<sum;
    return 0;
}