#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
struct Box
{
int h, w, d;
};
bool compare(const Box &a, const Box &b)
{
return (a.w * a.d) > (b.w * b.d);
}
int main()
{
int n;
cin >> n;
vector<Box> boxes(n);
for (int i = 0; i < n; ++i)
{
cin >> boxes[i].w >> boxes[i].d >> boxes[i].h;
}
sort(boxes.begin(), boxes.end(), compare);
vector<int> msh(n);
for (int i = 0; i < n; i++)
{
msh[i] = boxes[i].h;
}
for (int i = 1; i < n; i++)
{
for (int j = 0; j < i; j++)
{
if (boxes[i].w <= boxes[j].w && boxes[i].d <= boxes[j].d && msh[i] < msh[j] + boxes[i].h)
{
msh[i] = msh[j] + boxes[i].h;
}
}
}
int max = -1;
for (int i = 0; i < n; i++)
{
if (max < msh[i])
{
max = msh[i];
}
}
cout << max << endl;