#include <iostream>
#include <queue>
#include <cstring>
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], c[N], p[N];
LL res;
int head[N], to[M], nxt[M], w[M], h[M], dis[N], tot = 1;
inline void add(int a, int b, int c){
	to[++ tot] = b; nxt[tot] = head[a]; w[tot] = c; head[a] = tot;
	to[++ tot] = a; nxt[tot] = head[b]; w[tot] = 0; head[b] = tot;
}
inline int bfs(){
	queue<int> que; que.push(S); memset(h, 0, sizeof(h)); h[S] = 1;
	while(!que.empty()){
		int u = que.front(); que.pop();
		for(int i = head[u] ; i ; i = nxt[i])
			if(w[i] && !h[to[i]])
				h[to[i]] = h[u] + 1, que.push(to[i]);
	}
	return h[T];
}
inline int dfs(int x, int f){
	if(x == T) return f; int fl = 0;
	for(int i = head[x] ; i && f ; i = nxt[i]){
		if(w[i] && h[to[i]] == h[x] + 1){
			int mi = dfs(to[i], min(f, w[i]));
			w[i] -= mi; w[i ^ 1] += mi; fl += mi; f -= mi;
		}
	}
	if(!fl) h[x] = -1;
	return fl;
}
inline LL dinic(){
	LL res = 0;
	while(bfs()) res += dfs(S, INF);
	return res;
}
int main(){
	int n; scanf("%d", &n); LL res = 0;
	for(int i = 1 ; i <= n ; i ++){
		scanf("%d %d %d", &x[i], &y[i], &c[i]);
		p[i] = 2 * (x[i] & 1) + (y[i] & 1);
	}
	S = 0; T = 2 * n + 1;
	for(int i = 1 ; i <= n ; i ++){
		add(i, i + n, c[i]);
		res += c[i];
		if(p[i] == 3) add(i + n, T, INF);
		if(p[i] == 2) add(S, i, INF);
	}
	for(int i = 1 ; i <= n ; i ++){
		for(int j = 1 ; j <= n ; j ++){
			if(i != j && max(abs(x[i] - x[j]), abs(y[i] - y[j])) <= 1){
				if(p[i] == 2 && p[j] == 0) add(i + n, j, INF);
				if(p[i] == 0 && p[j] == 1) add(i + n, j, INF);
				if(p[i] == 1 && p[j] == 3) add(i + n, j, INF);
			}
		}
	}
	cout << res - dinic() << endl;
	return 0;
}