#include "pch.h"
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
#include <iomanip>


#define rep(i,n) for(int i=0; i< (n); ++i)

using namespace std;

int main()
{
  int N;
  cin >> N;

  int sum = 0;
  vector<int> A(N), C(N - 1);
  for (int i = 0; i < N; ++i)
  {
    int B;
    cin >> A[i] >> B;
    if (i != N - 1)cin >> C[i];

    sum += B;
  }

  for (int i = 0; i < N - 2; ++i)
  {
    if (A[i + 1] == A[i] + 1) sum += C[i];
  }

  cout << sum << endl;
}