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 <map>
#include <cstdio>
#include <cstring>
#include <algorithm>
typedef long long ll;
const int Maxn=1000;
const int Maxm=1000000;
const ll Inf=0x3f3f3f3f3f3f3f3fll;
int n;
struct Node{
    int x,y,w,id;
    friend bool operator <(Node a,Node b){
        return a.x<b.x;
    }
    Node(int _x=0,int _y=0,int _w=0,int _id=0){
        x=_x,y=_y,w=_w,id=_id;
    }
}a[Maxn+5];
int id[Maxn+5][2],id_tot;
int S,T;
struct Edge{
    int to,flow;
    ll cap,nxt;
}edge[Maxm<<1|5];
int head[Maxn<<1|5],tot;
void unuse_add_edge(int from,int to,ll cap){
    edge[++tot].to=to;
    edge[tot].cap=cap;
    edge[tot].flow=0;
    edge[tot].nxt=head[from];
    head[from]=tot;
}
void add_edge(int from,int to,ll cap){
    unuse_add_edge(from,to,cap);
    unuse_add_edge(to,from,0);
}
int qu[Maxn<<1|5],qu_f,qu_t;
int dep[Maxn<<1|5];
bool Dinic_bfs(){
    memset(dep,0,sizeof dep);
    dep[S]=1;
    qu_f=1,qu_t=0;
    qu[++qu_t]=S;
    while(qu_f<=qu_t){
        int u=qu[qu_f++];
        for(int i=head[u];i;i=edge[i].nxt){
            int v=edge[i].to;
            if(dep[v]||edge[i].flow==edge[i].cap){
                continue;
            }
            dep[v]=dep[u]+1;
            qu[++qu_t]=v;
        }
    }
    return dep[T]>0;
}
ll Dinic_dfs(int u,ll flow){
    if(u==T||flow==0){
        return flow;
    }
    ll sum=0;
    for(int i=head[u];i;i=edge[i].nxt){
        int v=edge[i].to;
        if(dep[v]!=dep[u]+1||edge[i].flow==edge[i].cap){
            continue;
        }
        ll op=std::min(edge[i].cap-edge[i].flow,flow-sum),f;
        if((f=Dinic_dfs(v,op))){
            sum+=f;
            edge[i].flow+=f;
            edge[((i-1)^1)+1].flow-=f;
            if(sum==flow){
                break;
            }
        }
    }
    if(sum==0){
        dep[u]=0;
    }
    return sum;
}
ll Dinic(){
    ll ans=0;
    while(Dinic_bfs()){
        ans+=Dinic_dfs(S,Inf);
    }
    return ans;
}
std::map<int,std::map<int,int> > mp;
int main(){
    scanf("%d",&n);
    ll sum=0;
    for(int i=1;i<=n;i++){
        scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].w);
        sum+=a[i].w;
        mp[a[i].x][a[i].y]=i;
    }
    for(int i=1;i<=n;i++){
        id[i][0]=++id_tot,id[i][1]=++id_tot;
        add_edge(id[i][0],id[i][1],a[i].w);
    }
    S=++id_tot,T=++id_tot;
    for(int i=1;i<=n;i++){
        if((a[i].x&1)&&(a[i].y&1)){
            add_edge(S,id[i][0],Inf);
            if(mp[a[i].x-1][a[i].y]){
                add_edge(id[i][1],id[mp[a[i].x-1][a[i].y]][0],Inf);
            }
            if(mp[a[i].x+1][a[i].y]){
                add_edge(id[i][1],id[mp[a[i].x+1][a[i].y]][0],Inf);
            }
        }
        else if(a[i].x&1){
            add_edge(id[i][1],T,Inf);
        }
        else if(a[i].y&1){
            if(mp[a[i].x][a[i].y-1]){
                add_edge(id[i][1],id[mp[a[i].x][a[i].y-1]][0],Inf);
            }
            if(mp[a[i].x][a[i].y+1]){
                add_edge(id[i][1],id[mp[a[i].x][a[i].y+1]][0],Inf);
            }
        }
        else{
            if(mp[a[i].x-1][a[i].y]){
                add_edge(id[i][1],id[mp[a[i].x-1][a[i].y]][0],Inf);
            }
            if(mp[a[i].x+1][a[i].y]){
                add_edge(id[i][1],id[mp[a[i].x+1][a[i].y]][0],Inf);
            }
        }
    }
    ll ans=Dinic();
    printf("%lld\n",sum-ans);
    return 0;
}