#include <iostream>
#include <fstream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <cstring>
#include <string.h>
#include <iomanip>
#include <queue>
#include <stack>
#include <complex>
#include <list>
#include <chrono>
#include <random>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef vector<int> VI;
#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define PB push_back
#define MP make_pair
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define FILL(A,value) memset(A,value,sizeof(A))
#define f first
#define s second
const int INF = 1000*1000*1000+47;
const LL LINF = (LL)INF*INF;
const int MAX = 2e5;
const double EPS = 1e-9;
const double PI = acos(-1.);
int n;
pair<int , PII> e[200];
VI g[4];
vector<VI> comp;
int used[4];
void dfs(int u, int col)
{
used[u] = col;
comp[col-1].PB(u);
FOR(i,0,SZ(g[u]))
{
int v = g[u][i];
if (!used[v])
{
dfs(v, col);
}
}
}
int ban = 0;
int f(VI x)
{
int nep = 0;
int p = 0;
FOR(i,0,x.size())
{
if (g[x[i]].size()%2 == 0)
{
p++;
} else
{
nep++;
}
}
int res = 0;
FOR(i,0,n)
{
if (i == ban)
continue;
int xx = e[i].s.f;
FOR(j,0,x.size())
{
if (x[j] == xx)
{
res+=e[i].f;
break;
}
}
}
if (nep == 4)
{
res=-INF;
}
return res;
}
int main()
{
ios_base::sync_with_stdio(0);
//freopen("In.txt", "r", stdin);
cin >> n;
FOR(i,0,n)
{
int x,y,z;
cin >> x >> y >> z;
x--; z--;
//g[x].PB(z);
//g[z].PB(x);
e[i] = MP(y, MP(x,z));
}
int ans = 0;
FOR(i,-1,n)
{
ban = i;
FOR(i,0,4)
g[i].clear();
FOR(i,0,n)
{
if (i == ban)
continue;
g[e[i].s.f].PB(e[i].s.s);
g[e[i].s.s].PB(e[i].s.f);
}
comp.clear();
FILL(used, 0);
int c = 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