#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[100][3];
  int n = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> a[i][j];
    }
  }
  int s = 1;
  int m = 0;
  int f = 0;
  int cou = 0;
  int back = 0;
  for (int k = 0; k < n; k++) {
    if (a[k][0] == s && a[k][1] != back) {
      back = s;
      s = a[k][1];
      m += a[k][2];
      cou++;
      k = -1;
    }
    if (k == n - 1) {
      for (int k2 = 0; k2 < n; k2++) {
        if (a[k2][1] == s && a[k2][0] != back) {
          back = s;
          s = a[k2][0];
          f += a[k2][2];
          cou++;
          k = -1;
          k2 = n;
        }
      }
    }
    if (cou == n) {
      k = n;
    }
  }
  if (m > f)
    cout << f << endl;
  else
    cout << m << endl;
  return 0;
}
