#include <iostream>
#include <cstring>
#include <string>
#include <cctype>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <deque>
#include <vector>
using namespace std;
#define endl "\n"
int main(){
int x,y,n,num,a[101][101]={};
cin >> n;
for(int i = 1;i<=n;i++){
cin >> x >> y >> num;
a[x][y]=num;
}
int s=0;
x=1,y=1;
while(x!=101&&y!=101){
if(a[x+1][y]>a[x][y+1]){
x++;
s+=a[x][y];
}else{
y++;
s+=a[x][y];
}
}
cout << s;
return 0;
}