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 int64 = long long;

const int N = 2005;

int pre[N], mcnt, s, t;
struct arc {
  int x;
  int64 f;
  int next;
} e[N * N];
void addarc(int x, int y, int64 z) {
  e[mcnt] = (arc){y, z, pre[x]}, pre[x] = mcnt++;
  e[mcnt] = (arc){x, 0, pre[y]}, pre[y] = mcnt++;
}
int d[N], cur[N], q[N];
bool bfs() {
  memset(d, -1, sizeof(d));
  int top = 0, bot = -1;
  q[++bot] = t, d[t] = 1;
  while (top != bot + 1) {
    int x = q[top++];
    for (int i = pre[x]; ~i; i = e[i].next) {
      int y = e[i].x;
      if (!~d[y] && e[i ^ 1].f) {
        d[y] = d[x] + 1, q[++bot] = y;
        if (y == s) return 1;
      }
    }
  }
  return 0;
}
int64 dfs(int x, int64 flow = 1LL << 60) {
  if (x == t || !flow) return flow;
  int64 sum = 0;
  for (int& i = cur[x]; ~i; i = e[i].next) {
    int y = e[i].x;
    int64 u;
    if (d[x] == d[y] + 1 && (u = dfs(y, min(flow, e[i].f)))) {
      e[i].f -= u, e[i ^ 1].f += u;
      sum += u, flow -= u;
      if (!flow) break;
    }
  }
  if (!sum) d[x] = -1;
  return sum;
}
int64 dinic() {
  int64 ans = 0;
  while (bfs()) {
    memcpy(cur, pre, sizeof(cur));
    ans += dfs(s);
  }
  return ans;
}

int n;
int X[N], Y[N];

int main() {
  scanf("%d", &n);
  mcnt = 0;
  memset(pre, -1, sizeof(pre));
  int64 sum = 0;
  s = n + n, t = s + 1;
  auto GetType = [&](int i) -> int {
    if (Y[i] % 2) {
      return 2 | (X[i] & 1);
    } else {
      return (~X[i] & 1);
    }
  };
  for (int i = 0; i < n; ++i) {
    int w;
    scanf("%d%d%d", &X[i], &Y[i], &w);
    addarc(i << 1, i << 1 | 1, w);
    sum += w;
    int type = GetType(i);
    if (type == 0) {
      addarc(s, i << 1, 1LL << 60);
    }
    if (type == 3) {
      addarc(i << 1 | 1, t, 1LL << 60);
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (abs(X[i] - X[j]) + abs(Y[i] - Y[j]) <= 1) {
        int type_i = GetType(i);
        int type_j = GetType(j);
        if (type_j == type_i + 1) {
          addarc(i << 1 | 1, j << 1, 1LL << 60);
        }
      }
    }
  }
  cout << sum - dinic() << endl;
}