#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int inf = 1e9;

struct edge{
	int to, cost, cap, rev;
	edge(int to, int cost, int cap, int rev)
		:to(to),cost(cost),cap(cap),rev(rev){}
	edge(){}
};

int min_cost_flow(int s, int g, int f, vector<vector<edge> > &adj){
	int n = adj.size();
	int res = 0;
	while(f > 0){
		vector<int> prevv(n), preve(n);
		vector<int> mincost(n, inf);
		mincost[s] = 0;
		while(1){
			bool update = false;
			for(int i=0; i<n; i++){
				if(mincost[i] == inf) continue;
				for(int j=0; j<(int)adj[i].size(); j++){
					edge &e = adj[i][j];
					if(e.cap>0 && mincost[i] +e.cost < mincost[e.to]){
						mincost[e.to] = mincost[i] +e.cost;
						prevv[e.to] = i;
						preve[e.to] = j;
						update = true;
					}
				}
			}
			if(!update) break;
		}
		if(mincost[g] == inf){
			return -1;
		}
		
		int d = f;
		for(int v=g; v!=s; v=prevv[v]){
			d = min(d, adj[prevv[v]][preve[v]].cap);
		}
		f -= d;
		res += d*mincost[g];
		for(int v=g; v!=s; v=prevv[v]){
			edge &e = adj[prevv[v]][preve[v]];
			e.cap -= d;
			adj[v][e.rev].cap += d;
		}
	}
	return res;
}

int main(){
	while(1){
		int n;
		cin >> n;
		if(n==0) break;
		
		vector<vector<edge> > adj(366);
		for(int i=0; i<365; i++){
			adj[i].push_back(edge(i+1, 0, 2, adj[i+1].size()));
			adj[i+1].push_back(edge(i, 0, 0, adj[i].size()-1));
		}
		for(int i=0; i<n; i++){
			int a,b,w;
			cin >> a >> b >> w;
			a--; b--;
			adj[a].push_back(edge(b+1, -w, 1, adj[b+1].size()));
			adj[b+1].push_back(edge(a, w, 0, adj[a].size()-1));
		}
		cout << -min_cost_flow(0, 365, 2, adj) << endl;
	}
	return 0;
}
