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:
// nauynix
// 23/04/2021
#include <bits/stdc++.h>
using namespace std;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define fi first
#define se second
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef long long int  ll;
const int INF = 1e9 + 7;
const int mod = 1e9 + 7;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int nxt() {int x;cin >> x;return x;}

struct MaxFlow
{
    int N;
    vector<vector<ll>> cap, adj;

    MaxFlow(int _N) {
        N = _N;
        cap.resize(N, vector<ll>(N));
        adj.resize(N);
    }

    void addEdge(int u, int v, int c) {
        adj[u].push_back(v);
        adj[v].push_back(u);
        cap[u][v] += c;
    }

    ll flow(int st, int nd) {
        queue<pair<int, ll>> bfs;
        vector<int> parent(N, -1);
        vector<bool> visited(N, false);

        bfs.push(make_pair(st, LLONG_MAX));
        parent[st] = -1;
        visited[st] = true;
        while (!bfs.empty()) {
            pair<int, ll> now = bfs.front();
            bfs.pop();
            if (now.first == nd) {
                int ix = now.first;
                while (ix != st) {
                    cap[parent[ix]][ix] -= now.second;
                    cap[ix][parent[ix]] += now.second;
                    ix = parent[ix];
                }
                return now.second;
            }
            for (int v : adj[now.first]) {
                if (cap[now.first][v] > 0) {
                    ll f = min(cap[now.first][v], now.second);
                    if (!visited[v]) {
                        parent[v] = now.first;
                        visited[v] = true;
                        bfs.push(make_pair(v, f));
                    }
                }
            }
        }
        return 0;
    }

    ll countMaxFlow(int st, int nd) {
        ll res = 0;
        while (1) {
            ll f = flow(st, nd);
            if (f == 0) break;
            res += f;
        }
        return res;
    }
};
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    vector<array<int, 3>> a[4];
    int n = nxt();
    map<PII, int> m;
    int cnt = 0;
    ll sum = 0;
    rep (i, 0, n) {
        array<int, 3> b;
        cin >> b[0] >> b[1] >> b[2];
        m[{b[0], b[1]}] = cnt;
        cnt+=2;
        if (b[0]%2 == 0 && b[1] % 2 == 0) a[1].pb(b);
        else if (b[1] % 2 == 0) a[0].pb(b);
        else if (b[0]%2 == 0) a[2].pb(b);
        else a[3].pb(b);
        sum += b[2];
    }
    // 0 is source, 1 is target
    // s - a[0] - a[0] - a[1] - a[1] - a[2] - a[2] - a[3] - a[3] - t
    MaxFlow mf(2 + n*2);
    int s = 2 + n*2 - 2;
    int t = 2 + n*2 - 1;
    for (auto &[x, y, w] : a[0]) {
        mf.addEdge(s, m[{x, y}], INF);
    }
    for (int i = 0; i < 4; i++) {
        for (auto &[x, y, w] : a[i]) {
            mf.addEdge(m[{x,y}], m[{x, y}]+1, w);
        }
    }
    for (int i = 0; i < 3; i++) {
        for (auto &[x1, y1, _] : a[i]) {
            for (auto &[x2, y2, _] : a[i+1]) {
                if (abs(x1-x2) + abs(y1-y2) == 1) {
                    mf.addEdge(m[{x1,y1}]+1, m[{x2,y2}], INF);
                }
            }
        }
    }
    for (auto &[x, y, w] : a[3]) {
        mf.addEdge(m[{x, y}]+1, t, INF);
    }
    printf("%lld\n", sum - mf.countMaxFlow(s, t));
    return 0;
}