#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  vector<int> C(N - 1);
  for (int i = 0; i < N; i++) {
    if (i != N - 1) {
      cin >> A.at(i) >> B.at(i) >> C.at(i);
    }
    if (i == N - 1) {
      cin >> A.at(i) >> B.at(i);
    }
  }
  int k = 0;
  for (int i = 0; i < N; i++) {
    if (i == 0) {
      k = k + B.at(0);
    } else if (A.at(i - 1) != A.at(i)) {
      k = k + B.at(A.at(i));
    } else {
      k = k + C.at(A.at(i - 1));
    }
  }
  cout << k << endl;
}
