#include <bits/stdc++.h>

using namespace std;

#define INF 10000000000


int n;
long long capacity[2005][2005];
vector<vector<int>> adj;

long long bfs(int s, int t, vector<int>& parent) {
    fill(parent.begin(), parent.end(), -1);
    parent[s] = -2;
    queue<pair<int, long long>> q;
    q.push({s, INF});

    while (!q.empty()) {
        int cur = q.front().first;
        long long flow = q.front().second;
        q.pop();
        
        for (int next : adj[cur]) {
            if (parent[next] == -1 && capacity[cur][next]) {
                parent[next] = cur;
                long long new_flow = min(flow, capacity[cur][next]);
                if (next == t)
                    return new_flow;
                q.push({next, new_flow});
            }
        }
    }

    return 0;
}

long long maxflow(int s, int t) {
    long long flow = 0;
    vector<int> parent(n);
    long long new_flow;

    while (new_flow = bfs(s, t, parent)) {
        flow += new_flow;
        int cur = t;
        while (cur != s) {
            int prev = parent[cur];
            capacity[prev][cur] -= new_flow;
            capacity[cur][prev] += new_flow;
            cur = prev;
        }
    }

    return flow;
}

void add_edge(int i, int j, long long c){
    adj[i].push_back(j);
    capacity[i][j]=c;
    adj[j].push_back(i);
    capacity[j][i]=0;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int arr[1000][3];

    cin>>n;
    for(int i=0; i<n; i++) cin>>arr[i][0]>>arr[i][1]>>arr[i][2];

    adj.resize(2*n+2);
    int s=2*n,t=2*n+1;

    for(int i=0; i<n; i++) add_edge(2*i+1,2*i,arr[i][2]);

    auto get_step = [&](int i) -> int {
		int x = arr[i][0] & 1;
		int y = arr[i][1] & 1;
		return (!y) * 2 + (x ^ y);
	};

    for(int i=0; i<n; i++){
        if(get_step(i)==0) add_edge(s,2*i+1,INF);
        if(get_step(i)==3) add_edge(2*i,t,INF);
    }

    for(int i=0; i<n; i++)
        for(int j=0; j<n; j++){
            if(abs(arr[i][0]-arr[j][0]) + abs(arr[i][1]-arr[j][1]) == 1 && get_step(j)-get_step(i) == 1) add_edge(2*i,2*j+1,INF);
        }

    long long sum=0;
    for(int i=0; i<n; i++) sum+=arr[i][2];
    //if(n==1000) cout<<sum<<"\n";
    n=2*n+2;
    cout<<sum-maxflow(s,t);
    
}