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>
#define fo(a,b,c) for (a=b; a<=c; a++)
#define fd(a,b,c) for (a=b; a>=c; a--)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
#define inf 2000000000
#define ll long long
//#define file
using namespace std;

struct type{int x,y,s,id,tp;} b[1001];
int a[80001][3],ls[2011],cur[2011],len;
int A[2][2]={{1,2},{0,3}};
int f[2011],g[2011];
int n,i,j,k,l,st,ed;
ll ans;

bool cmp1(type a,type b) {return a.x<b.x || a.x==b.x && a.y<b.y;}
bool cmp2(type a,type b) {return a.y<b.y || a.y==b.y && a.x<b.x;}
void NEW(int x,int y,int z) {++len;a[len][0]=y;a[len][1]=ls[x];ls[x]=len;a[len][2]=z;}
void New(int x,int y,int z) {NEW(x,y,z),NEW(y,x,0);}

int dfs(int t,int flow)
{
	int i,use=0,w;
	if (t==ed) return flow;
	
	for (i=cur[t]; i; i=a[i][1])
	if (f[t]==f[a[i][0]]+1 && a[i][2])
	{
		cur[t]=i;
		w=dfs(a[i][0],min(flow-use,a[i][2]));
		a[i][2]-=w,a[i^1][2]+=w;use+=w;
		if (flow==use) return flow;
	}
	cur[t]=ls[t];
	
	--g[f[t]];
	if (!g[f[t]]) {f[st]=ed+1;return use;}
	++f[t],++g[f[t]];
	return use;
}

int main()
{
	#ifdef file
	freopen("CF1517G.in","r",stdin);
	#endif
	
	scanf("%d",&n);len=1;
	fo(i,1,n) scanf("%d%d%d",&b[i].x,&b[i].y,&b[i].s),b[i].id=i,b[i].tp=A[b[i].x&1][b[i].y&1],ans+=b[i].s;
	
	st=n*2+1,ed=n*2+2;
	g[0]=ed;
	fo(i,1,n)
	if (!b[i].tp) New(st,i,b[i].s);
	else
	if (b[i].tp==3) New(i,ed,b[i].s);
	else
	New(i,i+n,b[i].s);
	
	sort(b+1,b+n+1,cmp1); fo(i,2,n) if (b[i].x==b[i-1].x && b[i].y==b[i-1].y+1 && b[i].tp==b[i-1].tp+1) New(b[i-1].id+(b[i-1].tp>0)*n,b[i].id,b[i].s);fo(i,1,n) b[i].y=-b[i].y;
	sort(b+1,b+n+1,cmp1); fo(i,2,n) if (b[i].x==b[i-1].x && b[i].y==b[i-1].y+1 && b[i].tp==b[i-1].tp+1) New(b[i-1].id+(b[i-1].tp>0)*n,b[i].id,b[i].s);fo(i,1,n) b[i].y=-b[i].y;
	sort(b+1,b+n+1,cmp2); fo(i,2,n) if (b[i].y==b[i-1].y && b[i].x==b[i-1].x+1 && b[i].tp==b[i-1].tp+1) New(b[i-1].id+(b[i-1].tp>0)*n,b[i].id,b[i].s);fo(i,1,n) b[i].x=-b[i].x;
	sort(b+1,b+n+1,cmp2); fo(i,2,n) if (b[i].y==b[i-1].y && b[i].x==b[i-1].x+1 && b[i].tp==b[i-1].tp+1) New(b[i-1].id+(b[i-1].tp>0)*n,b[i].id,b[i].s);fo(i,1,n) b[i].x=-b[i].x;
	
	while (f[st]<=ed) ans-=dfs(st,inf);
	printf("%lld\n",ans);
	
	fclose(stdin);
	fclose(stdout);
	return 0;
}