#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
struct nod
{
int h, a, c;
}b[406];
int n;
int num[40005], f[40005];
bool cmp(nod a, nod b)
{return a.a < b.a;}
int main()
{
while(scanf("%d", &n) != EOF)
{
int i, ans, j;
for(i = 0; i < n; i ++)
scanf("%d %d %d", &b[i].h, &b[i].a, &b[i].c);
sort(b, b + n, cmp);
f[0] = 1;
ans = 0;
for(i = 0; i < n; i ++)
{
for(j = b[i].h; j <= b[i].a; j ++)
if(!f[j] && f[j - b[i].h] && num[j - b[i].h] < b[i].c)
{
//printf("%d\n",j);
f[j] = 1;
num[j] = num[j - b[i].h] + 1;
if(ans < j) ans = j;
}
for(j = b[i].h; j <= b[i].a; j ++) num[j] = 0;
}
printf("%d\n",ans);
for(i = 0; i < n; i ++) f[i] = 0;
}
}