#include<bits/stdc++.h>
using namespace std;
const int N=3005,M=1e5+5,inf=0x3f3f3f3f;
typedef long long ll;
int n,s,t;
int x[N],y[N],w[N],p[N];
ll ans=0;
struct Flow{
	int b[M],nt[M],p[N],cap[M],cur[N],num=1;
	int d[N];
	queue<int> q;
	inline void add(int u,int v,int w){
		//printf("%d %d %d\n",u,v,w);
		++num;b[num]=v,nt[num]=p[u],cap[num]=w;p[u]=num;
		++num;b[num]=u,nt[num]=p[v],cap[num]=0;p[v]=num;
	}
	inline int bfs(){
		memset(d,-1,sizeof(d));
		d[s]=0;q.push(s);
		while(!q.empty()){
			int u=q.front();q.pop();
			for(int i=p[u];i;i=nt[i]){
				int v=b[i];
				if(cap[i]>0&&d[v]<0){
					d[v]=d[u]+1;
					q.push(v);
				}
			}
		}
		return d[t]!=-1;
	}
	inline int dfs(int u,int f){
		if(u==t) return f;
		int w,tot=0;
		for(int &i=cur[u];i;i=nt[i]){
			int v=b[i];
			if(cap[i]>0&&d[v]==d[u]+1&&(w=dfs(v,min(f,cap[i])))){
				cap[i]-=w,cap[i^1]+=w;
				f-=w,tot+=w;
				if(f<=0) break;
			}
		}
		return tot;
	}
	inline ll max_flow(){
		ll flow=0;
		while(bfs()){
			memcpy(cur,p,sizeof(p));
			flow+=dfs(s,inf);
		}
		return flow;
	}
}Fl;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		scanf("%d%d%d",&x[i],&y[i],&w[i]);
		p[i]=(x[i]&1)*2+(y[i]&1);ans+=w[i];
	}
	s=0,t=2*n+1;
	for(int i=1;i<=n;i++){
		Fl.add(i,i+n,w[i]);
		if(p[i]==2) Fl.add(s,i,inf);
		if(p[i]==3) Fl.add(i+n,t,inf);
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++){
			if(i==j) continue;
			if((unsigned int)abs(x[i]-x[j])+(unsigned int)abs(y[i]-y[j])<=1){
				if(p[i]==2&&p[j]==0) Fl.add(i+n,j,inf);
				if(p[i]==0&&p[j]==1) Fl.add(i+n,j,inf);
				if(p[i]==1&&p[j]==3) Fl.add(i+n,j,inf);
			}
		} 
	printf("%lld",ans-Fl.max_flow());
	return 0;
}