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 <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
#include <vector>
#include <array>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define f first
#define s second

typedef array<ll, 4> T;
 
const ll inf = 0x3f3f3f3f3f3f3f3f;
const int mxn = 2002;
int n;
pii a[mxn];
ll b[mxn], f[mxn], h[mxn], d[mxn << 1];
vector<ll> v[mxn << 1];
vector<T> g[mxn];

void edg(int x, int y, ll z){
	g[x].push_back({y, (int)g[y].size(), 0, z});
	g[y].push_back({x, (int)g[x].size() - 1, 0, 0});
}
 
void psh(T &x, ll z){
	T &y = g[x[0]][x[1]];
	if(!b[x[0]] && z) v[h[x[0]]].push_back(x[0]);
	x[2] += z, y[2] -= z;
	b[x[0]] += z, b[y[0]] -= z;
}
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	
	for(int i = 0; i < n; i++) cin >> a[i].s.f >> a[i].s.s >> a[i].f;
	
	ll ret = 0;
	for(int i = 0; i < n; i++){
		int x = ((a[i].s.s & 1) << 1) | ((1 ^ a[i].s.f ^ a[i].s.s) & 1);
		ret += a[i].f;
		edg(i, n + i, a[i].f);
		if(!x) edg(2 * n, i, inf);
		if(x == 3) edg(n + i, 2 * n + 1, inf);
		for(int j = 0; j < n; j++){
			int y = ((a[j].s.s & 1) << 1) | ((1 ^ a[j].s.f ^ a[j].s.s) & 1);
			if(x + 1 == y && abs(a[i].s.f - a[j].s.f) <= 1 && 
			abs(a[i].s.s - a[j].s.s) <= 1) edg(n + i, j, inf);
		}
	}
	
	//flow
	h[2 * n] = 2 * n + 2, b[2 * n + 1] = 1, d[0] = 2 * n + 1;
	for(T &i : g[2 * n]) psh(i, i[3]);
	
	if(!v[0].empty()) for(int t = 0; ~t;){
		int x = v[t].back();
		v[t].pop_back();
		while(b[x] > 0){
			if(f[x] == g[x].size()){
				h[x] = inf;
				for(int i = 0; i < g[x].size(); i++){
					T &e = g[x][i];
					if(e[3] > e[2] && h[x] > h[e[0]] + 1){
						h[x] = h[e[0]] + 1, f[x] = i;
					}
				}
				d[h[x]]++, d[t]--;
				if(!d[t] && t < 2 * n + 2){
					for(int i = 0; i < 2 * n + 2; i++){
						if(t < h[i] && h[i] < 2 * n + 2){
							d[h[i]]--, h[i] = 2 * n + 3;
						}
					}
				}
				t = h[x];
			}else{
				T &e = g[x][f[x]];
				if(e[3] > e[2] && h[x] == h[e[0]] + 1){
					psh(e, min(b[x], e[3] - e[2]));
				}else{
					f[x]++;
				}
			}
		}
		while(~t && v[t].empty()) t--;
	}
	//end flow
	
	ret += b[2 * n];
	
	cout << ret << endl;
	
	return 0;
}