//CLOCKS_PER_SEC
using namespace std;
#include<bits/stdc++.h>
#define sqr(x) 1ll*(x)*(x)
//#define sort stable_sort
#define ll long long
#define mk make_pair
#define pb push_back
#define in insert
#define mtr(x,y,z) mk(mk(x,y),z)
#define fi first
#define se second
#define lch(x) ((x)<<1)
#define rch(x) (((x)<<1)|1)
#define all(x) (x).begin(),(x).end()
#define titose CLOCKS_PER_SEC
#define fpi(x) freopen(x,"r",stdin);
#define fpo(x) freopen(x,"w",stdout);
#define fprio fpi("in.txt");fpo("out.txt");
#define fast ios_base::sync_with_stdio(false);
inline void read(int &x){int v=0,f=1;char c=getchar();while (!isdigit(c)&&c!='-') c=getchar();if (c=='-') f=-1; else v=(c&15);while (isdigit(c=getchar())) v=(v<<1)+(v<<3)+(c&15);x=v*f;}
inline void read(ll &x){ll v=0ll,f=1ll;char c=getchar();while (!isdigit(c)&&c!='-') c=getchar();if (c=='-') f=-1; else v=(c&15);while (isdigit(c=getchar())) v=(v<<1)+(v<<3)+(c&15);x=v*f;}
inline void readc(char &x){char c;while (((c=getchar())==' ')||c=='\n');x=c;}
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define si set<int>
//#define sl set<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define msi map<string,int>
#define msl map<string,ll>
#define piii pair<int,pii >
#define piipi pair<pii,int>
#define plll pair<ll,pll >
#define pllpl pair<pll,ll>
#define pqi priority_queue<int>
#define pql priority_queue<ll>
#define npqi priority_queue<int,vector<int>,greater<int> >
#define npql priority_queue<ll,vector<ll>,greater<ll> >
#define forup(i,a,b) for ((i)=(a);(i)<=(b);(i)++)
#define fordo(i,a,b) for ((i)=(a);(i)>=(b);(i)--)
#define rep(i,x) forup ((i),1,(x))
#define repd(i,x) fordo ((i),(x),1)
#define rep0(i,x) forup ((i),0,((int)(x))-1)
#define rep0d(i,x) fordo ((i),((int)(x))-1,0)
#define itr iterator
#define fe(itcalc,c) for(__typeof((c).begin()) itcalc=(c).begin();itcalc!=(c).end();itcalc++)
#define NO {cout<<"NO";return 0;}
#define YES {cout<<"YES";return 0;}
#define y0 y000000000000000000000000000
#define y1 y111111111111111111111111111
#define j0 j000000000000000000000000000
#define j1 j111111111111111111111111111
#define cl0(a) memset((a),(0),(sizeof((a))))
#define clz(a) memset((a),(0x16),(sizeof((a))))
#define clf(a) memset((a),(-(0x16)),(sizeof((a))))
#define inf 0x3bbbbbbb
#define lnf 0x2bbbbbbbbbbbbbbbll
//#define sqrt divi
#define p2(i) (1ll<<(i))
#define readi read
#define readll read
/*************************************************/
int n,m,i,j,s=0,t=2001,px[1005],py[1005],dis[2005],inq[2005];
map<pair<int,int>,int> mp;
struct edg
{
	int y;ll z;
}ee[1000005];
vector<int> e[2005];int tot;
ll sum;
void add(int x,int y,ll z)
{
//	cerr<<x<<' '<<y<<' '<<z<<endl;
	tot++;
	e[x].pb(tot+tot-2);e[y].pb(tot+tot-1);
	ee[tot+tot-2]=(edg){y,z};ee[tot+tot-1]=(edg){x,0};
}
bool bfs(int s,int t)
{
	queue<int> qx;qx.push(s);
	clz(dis);dis[s]=0;
	while(!qx.empty()){
		int x=qx.front();qx.pop();inq[x]=0;
		fe(it,e[x])if(ee[*it].z){
			if(dis[ee[*it].y]>dis[x]+1){
				dis[ee[*it].y]=dis[x]+1;
				if(!inq[ee[*it].y]){
					qx.push(ee[*it].y);
					inq[ee[*it].y]=1;
				}
			}
		}
	}
	return dis[t]<dis[t+1];
}
ll dfs(int x,int tt,ll flw)
{
	if(x==tt||flw==0)return flw;
	ll res=0;
	fe(it,e[x])if(ee[*it].z&&dis[ee[*it].y]==dis[x]+1){
		ll t=dfs(ee[*it].y,tt,min(ee[*it].z,flw));
		res+=t;flw-=t;ee[*it].z-=t;ee[(*it)^1].z+=t;
		if(!flw)break;
	}
	if(flw) dis[x]=-1;
	return res;
}
ll dinic(int s,int t)
{
	ll ans=0;
	while(bfs(s,t)){
		ans+=dfs(s,t,lnf);
	}
	return ans;
}
int main()
{
	read(n);
	rep(i,n){
		int z;read(py[i]);read(px[i]);read(z);
		sum+=z;
		add(i,i+n,z);mp[mk(px[i],py[i])]=i;
	}
	rep(i,n){
		int a=abs(px[i]&1),b=abs(py[i]&1);
		if(a==0){
			if(b==1){
				add(s,i,lnf);
				if(mp.count(mk(px[i],py[i]-1))){
					add(i+n,mp[mk(px[i],py[i]-1)],lnf);
				}
				if(mp.count(mk(px[i],py[i]+1))){
					add(i+n,mp[mk(px[i],py[i]+1)],lnf);
				}
			}
			else{
				if(mp.count(mk(px[i]-1,py[i]))){
					add(i+n,mp[mk(px[i]-1,py[i])],lnf);
				}
				if(mp.count(mk(px[i]+1,py[i]))){
					add(i+n,mp[mk(px[i]+1,py[i])],lnf);
				}
			}
		}
		if(a==1){
			if(b==0){
				if(mp.count(mk(px[i],py[i]-1))){
					add(i+n,mp[mk(px[i],py[i]-1)],lnf);
				}
				if(mp.count(mk(px[i],py[i]+1))){
					add(i+n,mp[mk(px[i],py[i]+1)],lnf);
				}
			}
			else{
				add(i+n,t,lnf);
			}
		}
	}
	cout<<sum-dinic(s,t)<<endl;
	return 0;
}
### Prompt

Develop a solution in Cpp to the problem described below:

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>

### Response

```cpp
//CLOCKS_PER_SEC
using namespace std;
#include<bits/stdc++.h>
#define sqr(x) 1ll*(x)*(x)
//#define sort stable_sort
#define ll long long
#define mk make_pair
#define pb push_back
#define in insert
#define mtr(x,y,z) mk(mk(x,y),z)
#define fi first
#define se second
#define lch(x) ((x)<<1)
#define rch(x) (((x)<<1)|1)
#define all(x) (x).begin(),(x).end()
#define titose CLOCKS_PER_SEC
#define fpi(x) freopen(x,"r",stdin);
#define fpo(x) freopen(x,"w",stdout);
#define fprio fpi("in.txt");fpo("out.txt");
#define fast ios_base::sync_with_stdio(false);
inline void read(int &x){int v=0,f=1;char c=getchar();while (!isdigit(c)&&c!='-') c=getchar();if (c=='-') f=-1; else v=(c&15);while (isdigit(c=getchar())) v=(v<<1)+(v<<3)+(c&15);x=v*f;}
inline void read(ll &x){ll v=0ll,f=1ll;char c=getchar();while (!isdigit(c)&&c!='-') c=getchar();if (c=='-') f=-1; else v=(c&15);while (isdigit(c=getchar())) v=(v<<1)+(v<<3)+(c&15);x=v*f;}
inline void readc(char &x){char c;while (((c=getchar())==' ')||c=='\n');x=c;}
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define si set<int>
//#define sl set<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define msi map<string,int>
#define msl map<string,ll>
#define piii pair<int,pii >
#define piipi pair<pii,int>
#define plll pair<ll,pll >
#define pllpl pair<pll,ll>
#define pqi priority_queue<int>
#define pql priority_queue<ll>
#define npqi priority_queue<int,vector<int>,greater<int> >
#define npql priority_queue<ll,vector<ll>,greater<ll> >
#define forup(i,a,b) for ((i)=(a);(i)<=(b);(i)++)
#define fordo(i,a,b) for ((i)=(a);(i)>=(b);(i)--)
#define rep(i,x) forup ((i),1,(x))
#define repd(i,x) fordo ((i),(x),1)
#define rep0(i,x) forup ((i),0,((int)(x))-1)
#define rep0d(i,x) fordo ((i),((int)(x))-1,0)
#define itr iterator
#define fe(itcalc,c) for(__typeof((c).begin()) itcalc=(c).begin();itcalc!=(c).end();itcalc++)
#define NO {cout<<"NO";return 0;}
#define YES {cout<<"YES";return 0;}
#define y0 y000000000000000000000000000
#define y1 y111111111111111111111111111
#define j0 j000000000000000000000000000
#define j1 j111111111111111111111111111
#define cl0(a) memset((a),(0),(sizeof((a))))
#define clz(a) memset((a),(0x16),(sizeof((a))))
#define clf(a) memset((a),(-(0x16)),(sizeof((a))))
#define inf 0x3bbbbbbb
#define lnf 0x2bbbbbbbbbbbbbbbll
//#define sqrt divi
#define p2(i) (1ll<<(i))
#define readi read
#define readll read
/*************************************************/
int n,m,i,j,s=0,t=2001,px[1005],py[1005],dis[2005],inq[2005];
map<pair<int,int>,int> mp;
struct edg
{
	int y;ll z;
}ee[1000005];
vector<int> e[2005];int tot;
ll sum;
void add(int x,int y,ll z)
{
//	cerr<<x<<' '<<y<<' '<<z<<endl;
	tot++;
	e[x].pb(tot+tot-2);e[y].pb(tot+tot-1);
	ee[tot+tot-2]=(edg){y,z};ee[tot+tot-1]=(edg){x,0};
}
bool bfs(int s,int t)
{
	queue<int> qx;qx.push(s);
	clz(dis);dis[s]=0;
	while(!qx.empty()){
		int x=qx.front();qx.pop();inq[x]=0;
		fe(it,e[x])if(ee[*it].z){
			if(dis[ee[*it].y]>dis[x]+1){
				dis[ee[*it].y]=dis[x]+1;
				if(!inq[ee[*it].y]){
					qx.push(ee[*it].y);
					inq[ee[*it].y]=1;
				}
			}
		}
	}
	return dis[t]<dis[t+1];
}
ll dfs(int x,int tt,ll flw)
{
	if(x==tt||flw==0)return flw;
	ll res=0;
	fe(it,e[x])if(ee[*it].z&&dis[ee[*it].y]==dis[x]+1){
		ll t=dfs(ee[*it].y,tt,min(ee[*it].z,flw));
		res+=t;flw-=t;ee[*it].z-=t;ee[(*it)^1].z+=t;
		if(!flw)break;
	}
	if(flw) dis[x]=-1;
	return res;
}
ll dinic(int s,int t)
{
	ll ans=0;
	while(bfs(s,t)){
		ans+=dfs(s,t,lnf);
	}
	return ans;
}
int main()
{
	read(n);
	rep(i,n){
		int z;read(py[i]);read(px[i]);read(z);
		sum+=z;
		add(i,i+n,z);mp[mk(px[i],py[i])]=i;
	}
	rep(i,n){
		int a=abs(px[i]&1),b=abs(py[i]&1);
		if(a==0){
			if(b==1){
				add(s,i,lnf);
				if(mp.count(mk(px[i],py[i]-1))){
					add(i+n,mp[mk(px[i],py[i]-1)],lnf);
				}
				if(mp.count(mk(px[i],py[i]+1))){
					add(i+n,mp[mk(px[i],py[i]+1)],lnf);
				}
			}
			else{
				if(mp.count(mk(px[i]-1,py[i]))){
					add(i+n,mp[mk(px[i]-1,py[i])],lnf);
				}
				if(mp.count(mk(px[i]+1,py[i]))){
					add(i+n,mp[mk(px[i]+1,py[i])],lnf);
				}
			}
		}
		if(a==1){
			if(b==0){
				if(mp.count(mk(px[i],py[i]-1))){
					add(i+n,mp[mk(px[i],py[i]-1)],lnf);
				}
				if(mp.count(mk(px[i],py[i]+1))){
					add(i+n,mp[mk(px[i],py[i]+1)],lnf);
				}
			}
			else{
				add(i+n,t,lnf);
			}
		}
	}
	cout<<sum-dinic(s,t)<<endl;
	return 0;
}
```