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;
using ll = long long;
using ii = array<int, 2>;
map<ii, int> idx;

const int MAXN = 2020;
const int INF = 1e9 + 10;

struct edge {
    int to, rev;
    ll f, cap;
};

vector<edge> adj[MAXN];

void add_edge(int u, int v, int c) {
    edge a({v, (int)adj[v].size(), 0, c});
    edge b({u, (int)adj[u].size(), 0, 0});
    adj[u].push_back(a);
    adj[v].push_back(b);
}

int dis[MAXN], ptr[MAXN], src, snk;

bool bfs() {
    memset(dis, -1, sizeof dis);
    queue<int> q({src});
    dis[src] = 0;
    while(q.size()) {
        int u = q.front(); q.pop();
        for(auto e : adj[u]) {
            int v = e.to;
            if(dis[v] == -1 && e.f < e.cap) {
                dis[v] = dis[u] + 1;
                q.push(v);
            }
        }
    }
    return dis[snk] != -1;
}

ll dfs(int s, ll f) {
    if(s == snk || !f)
        return f;
    for(int &i = ptr[s]; i < adj[s].size(); i++) {
        auto &e = adj[s][i];
        int v = e.to;
        if(dis[v] != dis[s] + 1)
            continue;
        if(ll df = dfs(v, min(f, e.cap - e.f))) {
            e.f += df;
            adj[e.to][e.rev].f -= df;
            return df;
        }
    }
    return 0;
}

ll mf() {
    ll res = 0;
    while(bfs()) {
        memset(ptr, 0, sizeof ptr);
        while(ll df = dfs(src, INF))
            res += df;
    }
    return res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    set<ii> ps;
    int n;
    cin >> n;

    vector<array<int, 3>> inp;
    ll tot = 0;

    for(int i = 0; i < n; i++) {
        int x, y, w;
        cin >> x >> y >> w;
        ps.insert({x, y});
        inp.push_back({x, y, w});
        idx[{x, y}] = i;
        tot += w;
    }

    src = 2*n;
    snk = 2*n + 1;

    for(auto &[x, y, w] : inp) {
        int id = idx[{x, y}];
        add_edge(id, id + n, w);
        int xp = abs(x) % 2, yp = abs(y) % 2;
        if(xp) {
            if(yp) {
                // (1, 1)
                add_edge(id + n, snk, INF);
            }
            else {
                // (1, 0)
                add_edge(src, id, INF);
                if(ps.count({x + 1, y}))
                    add_edge(id + n, idx[{x + 1, y}], INF);
                if(ps.count({x - 1, y}))
                    add_edge(id + n, idx[{x - 1, y}], INF);
            }
        } else {
            if(yp) {
                // (0, 1)
                if(ps.count({x + 1, y}))
                    add_edge(id + n, idx[{x + 1, y}], INF);
                if(ps.count({x - 1, y}))
                    add_edge(id + n, idx[{x - 1, y}], INF);
            }
            else {
                // (0, 0)
                if(ps.count({x, y + 1}))
                    add_edge(id + n, idx[{x, y + 1}], INF);
                if(ps.count({x, y - 1}))
                    add_edge(id + n, idx[{x, y - 1}], INF);
            }
        }
    }

    cout << tot - mf() << '\n';
}