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;


const int c=2002;
int kezd, veg, pos[c], szint[c];
long long sok=1e14;
vector<int> sz[c], ki[c];
vector<long long> s[c];
void add(int a, int b, long long c) {
    ki[a].push_back(sz[b].size()), ki[b].push_back(sz[a].size());
    sz[a].push_back(b), sz[b].push_back(a);
    s[a].push_back(c), s[b].push_back(0);
}
long long dfs(int a, long long ert) {
    //cout << "dfs " << a << " " << ert << endl;
    if (a==veg) {
        return ert;
    }
    for (; pos[a]<sz[a].size(); pos[a]++) {
        int x=sz[a][pos[a]];
        long long suly=s[a][pos[a]];
        if (szint[x]==szint[a]+1 && suly) {
            long long add=dfs(x, min(ert, suly));
            if (add) {
                s[a][pos[a]]-=add;
                s[x][ki[a][pos[a]]]+=add;
                return add;
            }
        }
    }
    return 0;
}
bool bfs() {
    for (int i=kezd; i<=veg; i++) {
        szint[i]=0;
    }
    szint[kezd]=1;
    queue<int> q;
    q.push(kezd);
    while(q.size()>0) {
        int a=q.front();
        q.pop();
        for (int i=0; i<sz[a].size(); i++) {
            int x=sz[a][i];
            long long suly=s[a][i];
            if (suly && !szint[x]) {
                szint[x]=szint[a]+1;
                q.push(x);
            }
        }
    }
    return szint[veg];
}
long long dinic() {
    long long ans=0;
    while(bfs()) {
        for (int i=kezd; i<=veg; i++) {
            pos[i]=0;
        }
        while(long long add=dfs(kezd, sok)) {
            ans+=add;
        }
    }
    return ans;
}


int x[c], y[c], ert[c], suly[c], n;
long long sum;


int main()
{
    cin >> n;
    veg=2*n+1;
    for (int i=1; i<=n; i++) {
        cin >> x[i] >> y[i] >> suly[i];
        swap(x[i], y[i]);

        sum+=suly[i];
        if (x[i]%2==0) {
            ert[i]=2-(bool)(y[i]%2);
        } else {
            ert[i]=3+(bool)(y[i]%2);
        }
        //cout << "ert ";
        //cout << i << " " << ert[i] << "\n";
    }
    for (int i=1; i<=n; i++) {
        add(i+n, i, suly[i]);
        if (ert[i]==1) {
            add(kezd, i+n, sok);
        }
        if (ert[i]==4) {
            add(i, veg, sok);
        }
        for (int j=1; j<=n; j++) {
            if (i==j) {
                continue;
            }
            if (max(abs(x[i]-x[j]), abs(y[i]-y[j]))==1 && ert[j]==ert[i]+1) {
                //cout << "spec " << i << " " << j << "\n";
                add(i, j+n, sok);
            }
        }
    }
    cout << sum-dinic() << "\n";
    return 0;
}
/*
4
0 0 4
0 1 5
1 0 3
-1 1 2
*/