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;

typedef long long LL;

const int N=1000;
const LL INF=(1LL<<60)-1;

struct point{
  int x,y;
  point(int X=0,int Y=0){x=X;y=Y;}
  bool operator < (const point &p)const{return x<p.x||x==p.x&&y<p.y;}
};

int n,st,td,cn;
LL sum;
map<point,int>mp;
struct side{
  int y,next;
  LL f;
}e[N*50+9];
int lin[N*2+9],cs;

void Ins(int x,int y,LL f){e[++cs].y=y;e[cs].f=f;e[cs].next=lin[x];lin[x]=cs;}
void Ins_flow(int x,int y,LL f){Ins(x,y,f);Ins(y,x,0);}

void into(){
  scanf("%d",&n);
  cs=1;
  st=n*2+1;td=cn=n*2+2;
  for (int i=1;i<=n;++i){
	int x,y,v;
	scanf("%d%d%d",&x,&y,&v);
	swap(x,y);
	Ins_flow(i*2-1,i*2,v);
	mp[point(x,y)]=i*2-1;
	sum+=v;
  }
}

void Get_graph(){
  for (map<point,int>::iterator it=mp.begin();it!=mp.end();++it){
	int x=it->first.x,y=it->first.y;
	if (x&1&&y&1){
	  Ins_flow(st,mp[point(x,y)],INF);
	  if (mp.find(point(x,y-1))!=mp.end()) Ins_flow(mp[point(x,y)]+1,mp[point(x,y-1)],INF);
	  if (mp.find(point(x,y+1))!=mp.end()) Ins_flow(mp[point(x,y)]+1,mp[point(x,y+1)],INF);
	}else if (x&1&&y&1^1){
	  if (mp.find(point(x-1,y))!=mp.end()) Ins_flow(mp[point(x,y)]+1,mp[point(x-1,y)],INF);
	  if (mp.find(point(x+1,y))!=mp.end()) Ins_flow(mp[point(x,y)]+1,mp[point(x+1,y)],INF);
	}else if (x&1^1&&y&1){
	  Ins_flow(mp[point(x,y)]+1,td,INF);
	}else{
	  if (mp.find(point(x,y-1))!=mp.end()) Ins_flow(mp[point(x,y)]+1,mp[point(x,y-1)],INF);
	  if (mp.find(point(x,y+1))!=mp.end()) Ins_flow(mp[point(x,y)]+1,mp[point(x,y+1)],INF);
	}
  }
}

void work(){
  Get_graph();
}

int dis[N*2+9];
queue<int>q;

bool Bfs_dis(int st,int td){
  for (int i=1;i<=cn;++i) dis[i]=0;
  for (;!q.empty();q.pop());
  dis[st]=1;q.push(st);
  for (;!q.empty();){
	int t=q.front();q.pop();
	for (int i=lin[t];i;i=e[i].next)
	  if (e[i].f&&!dis[e[i].y]){
		dis[e[i].y]=dis[t]+1;
		if (e[i].y==td) return 1;
		q.push(e[i].y);
	  }
  }
  return dis[td];
}

int cur[N*2+9];

LL Dfs_flow(int k,int td,LL f){
  if (k==td||!f) return f;
  LL res=0;
  for (int &i=cur[k];i;i=e[i].next)
	if (e[i].f&&dis[k]+1==dis[e[i].y]){
	  LL t=Dfs_flow(e[i].y,td,min(f,e[i].f));
	  if (!t) dis[e[i].y]=0;
	  f-=t;res+=t;
	  e[i].f-=t;e[i^1].f+=t;
	  if (!f) return res;
	}
  return res;
}

LL Max_flow(int st,int td){
  LL res=0;
  for (;Bfs_dis(st,td);res+=Dfs_flow(st,td,INF))
	for (int i=1;i<=cn;++i) cur[i]=lin[i];
  return res;
}

void outo(){
  printf("%lld\n",sum-Max_flow(st,td));
}

int main(){
  into();
  work();
  outo();
  return 0;
}