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


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 add_edge(int i, int j, long long c){
    adj[i].push_back(j);
    capacity[i][j]=c;
    adj[j].push_back(i);
    capacity[j][i]=0;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int arr[1000][3];

    cin>>n;
    for(int i=0; i<n; i++) cin>>arr[i][0]>>arr[i][1]>>arr[i][2];

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

    for(int i=0; i<n; i++) add_edge(2*i+1,2*i,arr[i][2]);

    auto get_step = [&](int i) -> int {
		int x = arr[i][0] & 1;
		int y = arr[i][1] & 1;
		return (!y) * 2 + (x ^ y);
	};

    for(int i=0; i<n; i++){
        if(get_step(i)==0) add_edge(s,2*i+1,INF);
        if(get_step(i)==3) add_edge(2*i,t,INF);
    }

    for(int i=0; i<n; i++)
        for(int j=0; j<n; j++){
            if(abs(arr[i][0]-arr[j][0]) + abs(arr[i][1]-arr[j][1]) == 1 && get_step(j)-get_step(i) == 1) add_edge(2*i,2*j+1,INF);
        }

    long long sum=0;
    for(int i=0; i<n; i++) sum+=arr[i][2];
    //if(n==1000) cout<<sum<<"\n";
    n=2*n+2;
    cout<<sum-maxflow(s,t);
    
}