//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;   }