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<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
#include<map>
typedef long long ll;
typedef unsigned un;
typedef std::vector<int> P;
typedef std::pair<int,int> pii;
ll read(){ll x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9')x=x*10+(c-'0'),c=getchar();return f*x;}
ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
template <typename T> bool umax(T& a,T t){if(t>a)return a=t,1;return 0;}
template <typename T> bool umin(T& a,T t){if(t<a)return a=t,1;return 0;}
/**********/
const int MAXN = 2011,INF=1e9+233;
struct edge{int v,w,nxt;}e[200011];
int cnt=1,last[MAXN],cur[MAXN];
void add_directed_edge(int u,int v,int w){e[++cnt].v=v,e[cnt].w=w,e[cnt].nxt=last[u],last[u]=cnt;}
void adde(int u,int v,int w){add_directed_edge(u,v,w),add_directed_edge(v,u,0);}

int dep[MAXN],Q[MAXN];
bool bfs(int s,int t,int n)
{
	for(int i=1;i<=n;++i)dep[i]=0,cur[i]=last[i];
	int qh=0,qt=0;
	Q[qt++]=s,dep[s]=1;
	while(qh<qt)
	{
		int u=Q[qh++];
		for(int i=last[u];i;i=e[i].nxt)
		{
			int v=e[i].v;
			if(e[i].w&&!dep[v])dep[v]=dep[u]+1,Q[qt++]=v;
		}
	}
	return dep[t];
}
int ex_flow(int u,int t,int flow=INF)
{
	if(u==t)return flow;
	int f=0;
	for(int& i=cur[u];i;i=e[i].nxt)
	{
		int v=e[i].v;
		if(dep[v]==dep[u]+1&&e[i].w)
		{
			int tmp=ex_flow(v,t, min(e[i].w,flow-f));
			e[i].w-=tmp,e[i^1].w+=tmp;
			f+=tmp;
			if(f==flow)return f;
		}
	}
	return f;
}
ll Dinic(int s,int t,int n)
{
	ll res=0;
	while(bfs(s,t,n))res+=ex_flow(s,t);
	return res;
}

pii p[MAXN];
int type[MAXN];
int main()
{
	int n=read(),S=n+n+1,T=S+1;
	ll sum=0;
	for(int i=1;i<=n;++i)
	{
		p[i].first=read(),p[i].second=read();
		if(p[i].second&1)type[i]=2+(p[i].first&1);
		else type[i]=!(p[i].first&1);
		if(type[i]==0)adde(S,i,INF);
		if(type[i]==3)adde(n+i,T,INF);
		int w=read();
		sum+=w;
		adde(i,n+i,w);
	}
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)
			if(i!=j&&abs(p[i].first-p[j].first)<=1&&abs(p[i].second-p[j].second)<=1)
			{
				if(type[i]+1==type[j])adde(n+i,j,INF);
			}
	printf("%lld\n",sum-Dinic(S,T,T));
	return 0;
}