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 INF 10000000000

tuple<int,int,int> a[1005];
vector<int> b;
int x,y,z,w;


int n;
long long capacity[2005][2005];
vector<vector<int>> adj;

long long bfs(int s, int t, vector<int>& parent) {
    fill(parent.begin(), parent.end(), -1);
    parent[s] = -2;
    queue<pair<int, long long>> q;
    q.push({s, INF});

    while (!q.empty()) {
        int cur = q.front().first;
        long long flow = q.front().second;
        q.pop();
        
        for (int next : adj[cur]) {
            if (parent[next] == -1 && capacity[cur][next]) {
                parent[next] = cur;
                long long new_flow = min(flow, capacity[cur][next]);
                if (next == t)
                    return new_flow;
                q.push({next, new_flow});
            }
        }
    }

    return 0;
}

long long maxflow(int s, int t) {
    long long flow = 0;
    vector<int> parent(n);
    long long new_flow;

    while (new_flow = bfs(s, t, parent)) {
        flow += new_flow;
        int cur = t;
        while (cur != s) {
            int prev = parent[cur];
            capacity[prev][cur] -= new_flow;
            capacity[cur][prev] += new_flow;
            cur = prev;
        }
    }

    return flow;
}


void addEdge(int i, int j, long long k){
    adj[i].push_back(j);
    capacity[i][j]=k;
    adj[j].push_back(i);
    capacity[j][i]=0;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin>>n;
    for(int i=0; i<n; i++) cin>>get<1>(a[i])>>get<0>(a[i])>>get<2>(a[i]);
    sort(a,a+n);

    long long x=INF;
    for(int i=0; i<n; i++)
        if(get<0>(a[i])!=x){
            x=get<0>(a[i]);
            b.push_back(i);
        } b.push_back(n);

    adj.resize(2*n+2);
    int s=2*n,t=2*n+1;


    /*for(int i=0; i<2*n+2; i++)
        for(int j=0; j<2*n+2; j++)
            capacity[i][j]=INF;*/

    int prev=5;
    for(int i=0; i<b.size()-1; i++){
        prev=5;
        for(int j=b[i]; j<b[i+1]; j++){
            switch( (abs(get<0>(a[j]))%2)*2 + abs(get<1>(a[j]))%2 ){
                case 1:
                    if(prev==0 && get<1>(a[j-1])+1==get<1>(a[j])) addEdge(2*j,2*j-1,INF);
                    prev=1;break;
                case 0:
                    if(prev==1 && get<1>(a[j-1])+1==get<1>(a[j])) addEdge(2*j-2,2*j+1,INF);
                    prev=0;break;
                case 2:
                    if(prev==3 && get<1>(a[j-1])+1==get<1>(a[j])) addEdge(2*j,2*j-1,INF);
                    prev=2;break;
                case 3:
                    if(prev==2 && get<1>(a[j-1])+1==get<1>(a[j])) addEdge(2*j-2,2*j+1,INF);
                    prev=3;break;
            }
        }
    }
    
    for(int i=0; i<n; i++){
        if( abs(get<1>(a[i]))%2==1 && abs(get<0>(a[i]))%2==1 ) 
            addEdge(2*i,t,INF);
        else if( abs(get<1>(a[i]))%2==1 && abs(get<0>(a[i]))%2==0 )
            addEdge(s,2*i+1,INF);
    }
    
    for(int i=0; i<b.size()-2; i++){
        if( get<0>(a[b[i]])+1< get<0>(a[b[i+1]]) ) continue;
        x=b[i], y=b[i+1];
        while(x<b[i+1]&&y<b[i+2]){
            while( x<b[i+1] && y<b[i+2] && get<1>(a[x]) > get<1>(a[y]) ) y++;
            while( x<b[i+1] && y<b[i+2] && get<1>(a[x]) < get<1>(a[y]) ) x++;
            if(x>=b[i+1] || y>=b[i+2]) break;
            if(get<1>(a[x])==get<1>(a[y])){
                if( abs(get<1>(a[x]))%2==0 && abs(get<0>(a[x]))%2==0 ) addEdge(2*x,2*y+1,INF);
                if( abs(get<0>(a[x]))%2==1 && abs(get<1>(a[x]))%2==0 ) addEdge(2*y,2*x+1,INF);
                x++, y++;
            }
        }
    }

    
    for(int i=0; i<n; i++)
        addEdge(2*i+1,2*i,get<2>(a[i]));


    long long sum=0;
    for(int i=0; i<n; i++) sum+=get<2>(a[i]);
    //if(n==1000) cout<<sum<<"\n";
    n=2*n+2;

    /*for(int i=0; i<n; i++){
        cout<<i<<": ";
        for(int next: adj[i])
            cout<<next<<","<<capacity[i][next]<<" ";
        cout<<"\n";
    }*/

    cout<<sum-maxflow(s,t);
    
}