#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const int MX=1000;

int n,s[MX],t[MX],p[MX];
pair<int,pi> in[MX];
int dp[366][366];

int main()
{
	while(scanf("%d",&n),n)
	{
		rep(i,n)scanf("%d%d%d",&in[i].first,&in[i].second.first,&in[i].second.second);
		sort(in,in+n);
		rep(i,n)s[i]=in[i].first,t[i]=in[i].second.first,p[i]=in[i].second.second;
		
		rep(i,366)rep(j,366)dp[i][j]=0;
		
		rep(i,n)
		{
			for(int k=365;k>=0;k--)for(int j=s[i]-1;j>=0;j--)
			{
				dp[t[i]][k]=max(dp[t[i]][k],dp[j][k]+p[i]);
				dp[k][t[i]]=max(dp[k][t[i]],dp[k][j]+p[i]);
			}
		}
		int ans=0;
		rep(i,366)rep(j,366)ans=max(ans,dp[i][j]);
		printf("%d\n",ans);
	}
	return 0;
}