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 <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cassert>
#include <map>
using namespace std;

#define LOG(f...) fprintf(stderr, f)

using ll = long long;

template<class T> void read(T &x) {
  char ch; x = 0;
  int f = 1;
  while (isspace(ch = getchar()));
  if (ch == '-') ch = getchar(), f = -1;
  do x = x * 10 + (ch - '0'); while(isdigit(ch = getchar()));
  x *= f;
}
template<class T, class ...A> void read(T &x, A&... args) { read(x), read(args...); }

template<class cap_t, class val_t, size_t node_c, size_t edge_c>
struct maxflow_graph {
  static_assert(sizeof(val_t) >= sizeof(cap_t), "result may overflow");

  struct edge {
    int v;
    cap_t f;
  } E[edge_c * 2];
  vector<int> G[node_c];
  size_t cur[node_c];
  int ec = 0;
  int s, t, nc;
  int h[node_c];

  void clear() {
    ec = 0;
    for (size_t i = 0; i < node_c; ++i) G[i].clear();
  }

  void link(int x, int y, int flow) {
    G[x].push_back(ec); E[ec++] = {y, flow};
    G[y].push_back(ec); E[ec++] = {x, 0};
  }

  bool bfs() {
    memset(h, -1, sizeof(int) * nc);
    h[s] = 0;
    int *q = new int[node_c], *ql = q - 1, *qr = q;
    *qr = s;
    while (ql != qr) {
      int x = *(++ql);
      if (x == t) break;
      for (int i : G[x]) {
        if (E[i].f != 0 && h[E[i].v] == -1)
          h[E[i].v] = h[x] + 1, *(++qr) = E[i].v;
      }
    }
    delete[] q;
    return h[t] != -1;
  }

  val_t augment(int x, val_t flow) {
    if (x == t) return flow;
    val_t res = 0;
    for (size_t &i = cur[x]; i != G[x].size(); ++i) {
      edge &e = E[G[x][i]];
      if (!e.f || h[e.v] != h[x] + 1) continue;
      cap_t aug = min<val_t>(e.f, flow);
      aug = augment(e.v, aug);
      res += aug; flow -= aug;
      e.f -= aug; E[G[x][i] ^ 1].f += aug;
      if (!flow) break;
    }
    if (!res) h[x] = -1;
    return res;
  }

  val_t maxflow() {
    int round = 0;
    val_t flow = 0;
    while (bfs()) {
      memset(cur, 0, sizeof(size_t) * nc);
      flow += augment(s, numeric_limits<val_t>::max());
      ++round;
    }
    return flow;
  }
};

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

maxflow_graph<int, ll, 2005, 3005> F;

map<pair<int, int>, pair<int, int>> P;

int id(int x, int y) { return ((y & 1) << 1) | ((x & 1) ^ (y & 1) ^ 1); }

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int n;
  read(n);
  ll sum = 0;
  F.s = 0; F.t = 2 * n + 1; F.nc = 2 * n + 2;
  for (int i = 1; i <= n; ++i) {
    int x, y, wt;
    read(x, y, wt);
    sum += wt;
    P[{x, y}] = {i, wt};
    F.link(2 * i - 1, 2 * i, wt);
  }
  for (const auto &[co, val] : P) {
    int ID = id(co.first, co.second);
    if (ID == 0) F.link(F.s, val.first * 2 - 1, numeric_limits<int>::max());
    if (ID == 3) F.link(val.first * 2, F.t, numeric_limits<int>::max());
    for (int d = 0; d < 4; ++d) {
      int x = co.first + dx[d], y = co.second + dy[d];
      auto it = P.find({x, y});
      if (it != P.end()) {
        if (id(x, y) == ID + 1)
          F.link(val.first * 2, it->second.first * 2 - 1, numeric_limits<int>::max());
      }
    }
  }
  printf("%lld\n", sum - F.maxflow());
  return 0;
}