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;
#define LL long long
#define pa pair<int,int>
const int N=1100;
const int inf=2147483647;
LL read()
{
	LL x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=x*10ll+ch-'0',ch=getchar();
	return x*f;
}
int n,st,ed;LL w[N];
map<pa,int>mp;
struct Edge
{
	int y,next;LL d;
}e[N<<4];
int len=1,last[N<<1];
void ins(int x,int y,LL d)
{
	int t=++len;
	e[t].y=y;e[t].d=d;e[t].next=last[x];last[x]=t;
}
void addedge(int x,int y,LL d){ins(x,y,d),ins(y,x,0);}
int h[N<<1];
bool bfs()
{
    memset(h,0,sizeof(h));h[st]=1;
    queue<int>q;q.push(st);
    while(!q.empty())
    {
        int x=q.front();q.pop();
        for(int i=last[x];i;i=e[i].next)
        {
            int y=e[i].y;
            if(e[i].d&&!h[y])h[y]=h[x]+1,q.push(y);
        }
    }
    return h[ed];
}
LL dfs(int x,LL f)
{
    if(x==ed)return f;
    LL s=0,t;
    for(int i=last[x];i;i=e[i].next)
    {
        int y=e[i].y;
        if(e[i].d>0&&h[y]==h[x]+1&&s<f)
        {
            t=dfs(y,min(e[i].d,f-s));
            s+=t;e[i^1].d+=t;e[i].d-=t;
        }
    }
    if(!s)h[x]=0;
    return s;
}
int type(int x,int y)
{
	x=(x&1),y=(y&1);
	if(!x&&!y)return 2;
	if(x&&!y)return 3;
	if(!x&&y)return 1;
	return 0;
}
int main()
{
	n=read();st=(n<<1)+1,ed=st+1;LL ans=0;
	for(int i=1;i<=n;i++)
	{
		int x=read(),y=read();w[i]=read();ans+=w[i];
		mp[make_pair(x,y)]=i;
	}
	for(map<pa,int>::iterator i=mp.begin();i!=mp.end();i++)
	{
		int x=i->first.first,y=i->first.second,o=i->second;
		addedge((o<<1)-1,o<<1,w[o]);
		if(type(x,y)==0)
		{
			addedge(st,(o<<1)-1,inf);
			if(mp[make_pair(x-1,y)])addedge(o<<1,(mp[make_pair(x-1,y)]<<1)-1,inf);
			if(mp[make_pair(x+1,y)])addedge(o<<1,(mp[make_pair(x+1,y)]<<1)-1,inf);
		}
		if(type(x,y)==1)
		{
			if(mp[make_pair(x,y-1)])addedge(o<<1,(mp[make_pair(x,y-1)]<<1)-1,inf);
			if(mp[make_pair(x,y+1)])addedge(o<<1,(mp[make_pair(x,y+1)]<<1)-1,inf);
		}
		if(type(x,y)==2)
		{
			if(mp[make_pair(x-1,y)])addedge(o<<1,(mp[make_pair(x-1,y)]<<1)-1,inf);
			if(mp[make_pair(x+1,y)])addedge(o<<1,(mp[make_pair(x+1,y)]<<1)-1,inf);
		}
		if(type(x,y)==3)addedge(o<<1,ed,inf);
	}
	while(bfs())ans-=dfs(st,inf);
	cout<<ans;
}