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 ls i<<1
#define rs i<<1|1
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef vector<int> vct;
typedef pair<int,int> pii;
const int N=2010;
const int inf=1<<30;
ll read()
{
	ll a=0;
	char b=1,c;
	do if((c=getchar())==45)b=-1;while(c<48||c>57);
	do a=(a<<3)+(a<<1)+(c&15);while((c=getchar())>47&&c<58);
	return a*b;
}
void write(ll x,char c)
{
    if(x<0)putchar('-'),x=-x;
    char a[20],s=0;
    do a[++s]=x%10|48;while(x/=10);
    do putchar(a[s]);while(--s);
    putchar(c);
}
int head[N],nex[N<<2],to[N<<2],val[N<<2],cnt=1;
int n,y,z;
int dep[N];
ll ans;
queue<int>q;
void add(int u,int v,int w)
{
    nex[++cnt]=head[u];
    head[u]=cnt;
    to[cnt]=v;
    if(w)
    {
        val[cnt]=w;
        add(v,u,0);
    }
}
void push(int x,int w)
{
    dep[x]=w;
    q.push(x);
}
bool bfs()
{
    memset(dep,0,sizeof dep);
    push(y,1);
    while(!q.empty())
    {
        int x=q.front();
        q.pop();
        for(int i=head[x];i;i=nex[i])
        {
            int t=to[i];
            if(val[i]&&!dep[t])push(t,dep[x]+1);
        }
    }
    return dep[z];
}
ll dfs(int x,ll flow)
{
    if(x==z)return flow;
    ll used=0;
    for(int i=head[x];i;i=nex[i])
    {
        int t=to[i];
        if(val[i]&&dep[t]==dep[x]+1)
        {
            ll k=dfs(t,min(flow,val[i]*1LL));
            val[i]-=k;
            val[i^1]+=k;
            flow-=k;
            used+=k;
        }
    }
    if(!used)dep[x]=0;
    return used;
}
void dinic ()
{
    while(bfs())ans-=dfs(y,inf);
}
struct st
{
    int u,v,w;
    bool operator<(const st m)const
    {
        if(u!=m.u)return u<m.u;
        return v<m.v;
    }
}a[N>>1];
int getop(int l,int r)
{
    l&=1;
    r&=1;
    return r<<1|l==r;
}
void check(int u,st x)
{
    int v=lower_bound(a+1,a+1+n,x)-a;
    if(a[v].u==x.u&&a[v].v==x.v)add(u,v,inf);
}
int main()
{
    n=read();
    y=n<<1|1;
    z=y+1;
    for(int i=1;i<=n;++i)
    {
        a[i].u=read();
        a[i].v=read();
        ans+=a[i].w=read();
    }
    sort(a+1,a+1+n);
    for(int i=1;i<=n;++i)
    {
        int j=i+n;
        add(i,j,a[i].w);
        int op=getop(a[i].u,a[i].v);
        if(op==3)add(j,z,inf);
        else
        {
            if(!op)add(y,i,inf);
            if(op==1)
            {
                check(j,{a[i].u,a[i].v+1});
                check(j,{a[i].u,a[i].v-1});
            }
            else
            {
                check(j,{a[i].u+1,a[i].v});
                check(j,{a[i].u-1,a[i].v});
            }
        }
    }
    dinic();
    write(ans,'\n');
}