#include <bits/stdc++.h>
using namespace std;
long long n, x, y, z, a[200], b[200], jum1, jum2;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> x >> y >> z;
    if (a[x] || b[y]) {
      a[y] = 1;
      b[x] = 1;
      jum1 += z;
    } else {
      a[x] = 1;
      b[y] = 1;
    }
    jum2 += z;
  }
  cout << min(jum1, jum2 - jum1) << '\n';
}
