#include <bits/stdc++.h>
using namespace std;
int hi1[1000000], hi2[1000000];
int main() {
  int n;
  cin >> n;
  int a, b, c, sum = 0, yo = 0;
  for (int i = 0; i < n; i++) {
    cin >> a >> b >> c;
    if (hi1[a] || hi2[b])
      yo += c, hi1[b] = hi2[a] = 1;
    else
      hi1[a] = hi2[b] = 1;
    sum += c;
  }
  cout << min(yo, sum - yo);
  return 0;
}
