#include <bits/stdc++.h>
using namespace std;
const int MAX = 105;
int g[MAX], v[MAX];
int main() {
  int n, res = 0, ans = 0;
  cin >> n;
  int f, t, c;
  for (int i = 0; i < n; ++i) {
    cin >> f >> t >> c;
    if (v[f] || g[t]) {
      res += c;
      g[f] = v[t] = 1;
    } else
      v[f] = g[t] = 1;
    ans += c;
  }
  cout << std::min(res, ans - res) << std::endl;
}
