#include <bits/stdc++.h>
#define forr(i,a,b) for(int i=(a);i<(b);i++)
#define forn(i,n) forr(i,0,n)
#define dforn(i,n) for(int i=n-1;i>=0; i--)
#define forall(it, v) for(auto it=v.begin();it!=v.end();it++)
#define sz(c) ((int)c.size())
#define rsz resize
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fst first
#define snd second

#ifdef ANARAP

#else

#endif

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;

#define INF 1000100100100100

struct Edge {
	int u, v;
	ll cap, flow;
	Edge() {}
	Edge(int u, int v, ll cap): u(u), v(v), cap(cap), flow(0) {}
};
struct Dinic {
	int N;
	vector<Edge> E;
	vector<vector<int>> g;
	vector<int> d, pt;
	Dinic(int N): N(N), E(0), g(N), d(N), pt(N) {} //clear and init
	void addEdge(int u, int v, ll cap)
	{
		if (u != v)
		{
			E.emplace_back(Edge(u, v, cap));
			g[u].emplace_back(E.size() - 1);
			E.emplace_back(Edge(v, u, 0));
			g[v].emplace_back(E.size() - 1);
		}
	}
	bool BFS(int S, int T)
	{
		queue<int> q({S});
		fill(d.begin(), d.end(), N + 1);
		d[S] = 0;
		while(!q.empty())
		{
			int u = q.front(); q.pop();
			if (u == T) break;
			for (int k: g[u])
			{
				Edge &e = E[k];
				if (e.flow < e.cap && d[e.v] > d[e.u] + 1)
				{
					d[e.v] = d[e.u] + 1;
					q.emplace(e.v);
				}
			}
		}
		return d[T] != N + 1;
	}
	ll DFS(int u, int T, ll flow = -1)
	{
		if (u == T || flow == 0) return flow;
		for (int &i = pt[u]; i < g[u].size(); ++i)
		{
			Edge &e = E[g[u][i]];
			Edge &oe = E[g[u][i]^1];
			if (d[e.v] == d[e.u] + 1)
			{
				ll amt = e.cap - e.flow;
				if (flow != -1 && amt > flow) amt = flow;
				if (ll pushed = DFS(e.v, T, amt))
				{
					e.flow += pushed;
					oe.flow -= pushed;
					return pushed;
				}
			}
		}
		return 0;
	}
	ll maxFlow(int S,int T) //O(V^2*E), unit nets: O(sqrt(V)*E)
	{
		ll total = 0;
		while(BFS(S, T))
		{
			fill(pt.begin(), pt.end(), 0);
			while (ll flow = DFS(S, T)) total += flow;
		}
		return total;
	}
};


int main(){
	#ifdef ANARAP
		freopen("input.in", "r", stdin);
		
	#endif
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin >> n;
	int curid = 2;
	map<ii,int> mid;
	ll sum = 0;
	Dinic dinic(2*n+2);
	forn(i,n)
	{
		int x,y,w;
		cin >> x >> y >> w;
		sum += w;
		mid[mp(x,y)] = curid;
		dinic.addEdge(curid, curid+1, w);
		curid += 2;
	}
	ii vaux[4] = {{1,0},{0,0},{0,1},{1,1}};
	forall(it, mid)
	{
		int x = it->fst.fst, y = it->fst.snd, id = it->snd;
		forn(i,4)
		{
			if(abs(x)%2 == vaux[i].fst && abs(y)%2 == vaux[i].snd)
			{
				if(i == 0) dinic.addEdge(0, id, INF);
				if(i == 3) dinic.addEdge(id+1, 1, INF);
				if(i < 3)
				{
					int dx,dy;
					if(i%2) dx = 0, dy = 1;
					else dx = 1, dy = 0;
					forn(_,2)
					{
						int xx = x+dx, yy = y+dy;
						if(mid.count(mp(xx,yy))) dinic.addEdge(id+1, mid[mp(xx,yy)], INF);
						dx *= -1;
						dy *= -1;
					}
				}
			}
		}
	}
	cout << sum-dinic.maxFlow(0,1) << '\n';
	return 0;
}
