#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)


int main() {
    int n;
    cin>>n;
    int a[n],b[n+1],c[n-1];
    rep(i,n-1)cin>>a[i]>>b[i+1]>>c[i];
    cin>>a[n-1]>>b[n];
    int ans=0;
    rep(i,n-1){
        ans+=b[a[i]];
        if(a[i]+1=a[i+1])ans+=c[a[i]];
    }
    cout << ans+b[a[n-1]] <<endl;
}
