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;

template <class T>
struct dinic {
    vector<pair<int, T>> edges;
    vector<vector<int>> adj;
    vector<int> level, ptr;
    int n, s, t;

    dinic(int n) : n(n), s(n - 1), t(n - 2) {
        adj.resize(n);
    }

    int add(int u, int v, T w) {
        adj[u].push_back(edges.size());
        adj[v].push_back(edges.size() + 1);
        edges.push_back({v, w});
        edges.push_back({u, 0});
        return edges.size() - 1;
    }

    bool bfs() {
        level.assign(n, -1);
        level[s] = 0;

        queue<int> que;
        que.push(s);

        while (!que.empty()) {
            int u = que.front();
            que.pop();

            for (auto e : adj[u]) {
                auto [c, w] = edges[e];
                if (w > 0 && level[c] == -1) {
                    level[c] = level[u] + 1;
                    if (c == t) {
                        return true;
                    }
                    que.push(c);
                }
            }
        }

        return false;
    }

    T dfs(int u, T flow) {
        if (u == t) {
            return flow;
        }

        T initial = flow;
        for ( ; ptr[u] < (int) adj[u].size() && flow > 0; ++ptr[u]) {
            int e = adj[u][ptr[u]];
            auto [c, w] = edges[e];
            if (w > 0 && level[c] == level[u] + 1) {
                T pushed = dfs(c, min(flow, w));
                edges[e ^ 1].second += pushed;
                edges[e].second -= pushed;
                flow -= pushed;
            }
        }

        return initial - flow;
    }

    T max_flow() {
        T ans = 0;
        while (bfs()) {
            ptr.assign(n, 0);
            ans += dfs(s, numeric_limits<T>::max());
        }
        return ans;
    }
};

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

    int n;
    cin >> n;

    long long sum = 0;
    map<array<int, 2>, int> tents;
    dinic<long long> flower(2 * n + 2);
    for (int i = 0; i < n; ++i) {
        int x, y, w;
        cin >> x >> y >> w;
        flower.add(i, n + i, w);
        tents[{x, y}] = i;
        sum += w;
    }

    for (auto [p, i] : tents) {
        auto [x, y] = p;
        if (x % 2 == 0) {
            for (auto d : {1, -1}) {
                if (tents.count({x + d, y})) {
                    if (y % 2 == 0) {
                        flower.add(n + tents[{x + d, y}], i, LLONG_MAX);
                    } else {
                        flower.add(n + i, tents[{x + d, y}], LLONG_MAX);
                    }
                }

                if (y % 2 == 0 && tents.count({x, y + d})) {
                    flower.add(n + i, tents[{x, y + d}], LLONG_MAX);
                }
            }
        } else {
            if (y % 2 == 0) {
                flower.add(flower.s, i, LLONG_MAX);
            } else {
                flower.add(n + i, flower.t, LLONG_MAX);
            }
        }
    }

    cout << sum - flower.max_flow() << "\n";
}