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 <stdio.h>
#include <stdlib.h>
#include <string.h>

#define N	1000
#define N_	(1 + N * 2 + 1)
#define M_	(N * 2 + N * 2)
#define INF	0x3f3f3f3f

int min(int a, int b) { return a < b ? a : b; }
int abs_(int a) { return a > 0 ? a : -a; }

int ij[M_], cc[M_ * 2], m_;
int *eh[N_], eo[N_], n_;

void append(int i, int h) {
	int o = eo[i]++;

	if (o >= 2 && (o & o - 1) == 0)
		eh[i] = (int *) realloc(eh[i], o * 2 * sizeof *eh[i]);
	eh[i][o] = h;
}

void add(int i, int j, int c) {
	int h = m_++;

	ij[h] = i ^ j, cc[h << 1 | 0] = c;
	append(i, h << 1 | 0), append(j, h << 1 | 1);
}

int dd[N_];

int bfs(int s, int t) {
	static int qu[N_];
	int i, head, cnt;

	for (i = 0; i < n_; i++)
		dd[i] = n_;
	head = cnt = 0;
	dd[s] = 0, qu[head + cnt++] = s;
	while (cnt) {
		int d, o;

		i = qu[cnt--, head++], d = dd[i] + 1;
		for (o = eo[i]; o--; ) {
			int h_ = eh[i][o];

			if (cc[h_]) {
				int h = h_ >> 1, j = i ^ ij[h];

				if (dd[j] > d) {
					dd[j] = d;
					if (j == t)
						return 1;
					qu[head + cnt++] = j;
				}
			}
		}
	}
	return 0;
}

int eo_[N_];

int dfs(int i, int t, int c) {
	int d, o;

	if (i == t)
		return c;
	d = dd[i] + 1;
	for (o = eo_[i]; o--; ) {
		int h_ = eh[i][o];

		if (cc[h_]) {
			int h = h_ >> 1, j = i ^ ij[h], f;

			if (dd[j] == d && (f = dfs(j, t, min(c, cc[h_])))) {
				cc[h_] -= f, cc[h_ ^ 1] += f;
				eo_[i] = o + 1;
				return f;
			}
		}
	}
	dd[i] = n_, eo_[i] = 0;
	return 0;
}

long long dinic(int s, int t) {
	long long sum;
	int f;

	sum = 0;
	while (bfs(s, t)) {
		memcpy(eo_, eo, n_ * sizeof *eo);
		while ((f = dfs(s, t, INF)))
			sum += f;
	}
	return sum;
}

int main() {
	static int xx[N], yy[N], ww[N], tt[N];
	int n, i, j;
	long long ans;

	scanf("%d", &n);
	ans = 0;
	for (i = 0; i < n; i++) {
		scanf("%d%d%d", &xx[i], &yy[i], &ww[i]);
		if (xx[i] % 2 != 0 && yy[i] % 2 == 0)
			tt[i] = 0;
		else if (xx[i] % 2 == 0 && yy[i] % 2 == 0)
			tt[i] = 1;
		else if (xx[i] % 2 == 0 && yy[i] % 2 != 0)
			tt[i] = 2;
		else
			tt[i] = 3;
		ans += ww[i];
	}
	n_ = 1 + n * 2 + 1;
	for (i = 0; i < n_; i++)
		eh[i] = (int *) malloc(2 * sizeof *eh[i]);
	for (i = 0; i < n; i++) {
		if (tt[i] == 0)
			add(0, 1 + (i << 1 | 0), INF);
		add(1 + (i << 1 | 0), 1 + (i << 1 | 1), ww[i]);
		if (tt[i] == 3)
			add(1 + (i << 1 | 1), n_ - 1, INF);
	}
	for (i = 0; i < n; i++)
		for (j = 0; j < n; j++)
			if (tt[i] + 1 == tt[j] && abs_(xx[i] - xx[j]) <= 1 && abs_(yy[i] - yy[j]) <= 1)
				add(1 + (i << 1 | 1), 1 + (j << 1 | 0), INF);
	ans -= dinic(0, n_ - 1);
	printf("%lld\n", ans);
	return 0;
}