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 long long INF = 1e18, C = 1e14;

struct Dinic {
    struct Edge {
        int v, to;
        long long cap;
        Edge(int _v = 0, int _to = 0, long long _cap = 0)
            : v(_v)
            , to(_to)
            , cap(_cap)
        {
        }
    };
    vector<Edge> ed;
    vector<vector<int>> g;
    int S, T;
    int n;
    vector<int> dist;
    vector<int> idx;

    Dinic()
        : ed()
        , g()
        , S()
        , T()
    {
    }
    Dinic(int _n, int _S, int _T)
    {
        n = _n;
        S = _S;
        T = _T;
        g.resize(n);
        for (int i = 0; i < n; i++)
            g[i].clear();
        ed = vector<Edge>();
    }

    void addEdge(int v, int to, long long cap)
    {
        g[v].push_back((int)ed.size());
        ed.push_back(Edge(v, to, cap));
        g[to].push_back((int)ed.size());
        ed.push_back(Edge(to, v, 0));
    }

    bool BFS()
    {
        dist.resize(n);
        vector<int> q;
        for (int i = 0; i < n; i++)
            dist[i] = n;
        q.push_back(S);
        dist[S] = 0;
        for (int i = 0; i < (int)q.size(); i++) {
            int v = q[i];
            for (int id : g[v]) {
                Edge e = ed[id];
                if (e.cap <= 0)
                    continue;
                int u = e.to;
                if (dist[u] <= dist[v] + 1)
                    continue;
                dist[u] = dist[v] + 1;
                q.push_back(u);
            }
        }
        return dist[T] < n;
    }

    long long dfs(int v, long long flow)
    {
        if (v == T || flow == 0)
            return flow;
        long long res = 0;
        for (int& i = idx[v]; i < (int)g[v].size(); i++) {
            int id = g[v][i];
            Edge e = ed[id];
            int to = e.to;
            if (dist[to] != dist[v] + 1)
                continue;
            long long df = dfs(to, min(flow, e.cap));
            flow -= df;
            res += df;
            ed[id].cap -= df;
            ed[id ^ 1].cap += df;
            if (flow == 0)
                return res;
        }
        return res;
    }

    long long Flow()
    {
        idx.resize(n);
        long long res = 0;
        while (BFS()) {
            for (int i = 0; i < n; i++)
                idx[i] = 0;
            res += dfs(S, INF);
        }
        return res;
    }
} G;

const int N = 1010;
map<pair<int, int>, int> toId;
int n;
int a[N][3];

int getV(int x, int y)
{
    pair<int, int> t = make_pair(x, y);
    if (toId.count(t))
        return toId[t];
    return -1;
}

int main()
{
    scanf("%d", &n);
    int S = 2 * n, T = 2 * n + 1;
    G = Dinic(2 * n + 2, S, T);
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        scanf("%d%d%d", &a[i][0], &a[i][1], &a[i][2]);
        ans += a[i][2];
        G.addEdge(2 * i, 2 * i + 1, a[i][2]);
        toId[make_pair(a[i][0], a[i][1])] = i;
    }
    for (int i = 0; i < n; i++) {
        int x = a[i][0], y = a[i][1];
        if (x % 2 != 0) {
            if (y % 2 != 0) {
                G.addEdge(2 * i + 1, T, C);
            } else {
                G.addEdge(S, 2 * i, C);
                for (int xx = x - 1; xx <= x + 1; xx += 2) {
                    int v = getV(xx, y);
                    if (v != -1)
                        G.addEdge(2 * i + 1, 2 * v, C);
                }
            }
        } else {
            if (y % 2 != 0) {
                for (int xx = x - 1; xx <= x + 1; xx += 2) {
                    int v = getV(xx, y);
                    if (v != -1)
                        G.addEdge(2 * i + 1, 2 * v, C);
                }
            } else {
                for (int yy = y - 1; yy <= y + 1; yy += 2) {
                    int v = getV(x, yy);
                    if (v != -1)
                        G.addEdge(2 * i + 1, 2 * v, C);
                }
            }
        }
    }
    printf("%lld\n", ans - G.Flow());
    return 0;
}