#include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;



#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(auto i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()


const long long int INF = 9223372036854775807;

typedef long long int Weight;
struct Edge {
	int src, dst;
	Weight capacity;
	Weight cost;
	Edge(int src, int dst, Weight acap, Weight acost) :
		src(src), dst(dst), capacity(acap), cost(acost) { }
};
bool operator < (const Edge &e, const Edge &f) {
	return e.cost > f.cost;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;
#define RESIDUE(s,t) (capacity[s][t]-flow[s][t])


#define RCOST(u,v) (cost[u][v] + h[u] - h[v])

//グラフは有向で逆辺は無いものとする．

//Graph &ag
//有向で，任意の辺(u, v, capacity, cost) に対して逆辺(u, v, 0, -cost) があるグラフ．この条件を満たす上で単純グラフでなければならない．
//int s, int t
//フローの始点と終点．
//戻り値
//費用と流せた流量の対．
pair<Weight, Weight> minimumCostFlow(const Graph &ag, int s, int t) {

	//check　単純グラフになっているか？

	Graph g(ag);
	for (int i = 0; i < ag.size(); ++i) {
		for (int j = 0; j < ag[i].size(); ++j) {
			int d = ag[i][j].dst;
			int s = ag[i][j].src;

			bool ok = false;
			for (int k = 0; k < ag[d].size(); ++k) {
				if (ag[d][k].src == s) {
					ok = true;
					break;
				}
			}
			if (!ok) {
				g[d].push_back(Edge(d, s, 0, -ag[i][j].cost));
			}
		}
	}
	const int n = g.size();
	Matrix capacity(n, Array(n)), cost(n, Array(n)), flow(n, Array(n));
	REP(u, n) FOR(e, g[u]) {
		capacity[e->src][e->dst] += e->capacity;
		cost[e->src][e->dst] += e->cost;
	}
	pair<Weight, Weight> total; // (cost, flow)
	vector<Weight> h(n);

	for (Weight F = INF; F > 0; ) { // residual flow
		vector<Weight> d(n, INF); d[s] = 0;
		vector<int> p(n, -1);
		priority_queue<Edge> Q; // "e < f" <=> "e.cost > f.cost"
		for (Q.push(Edge(-2, s, 0, 0)); !Q.empty(); ) {
			Edge e = Q.top(); Q.pop();
			if (p[e.dst] != -1) continue;
			p[e.dst] = e.src;
			FOR(f, g[e.dst]) if (RESIDUE(f->src, f->dst) > 0) {
				if (d[f->dst] > d[f->src] + RCOST(f->src, f->dst)) {
					d[f->dst] = d[f->src] + RCOST(f->src, f->dst);
					Q.push(Edge(f->src, f->dst, 0, d[f->dst]));
				}
			}
		}
		if (p[t] == -1) break;

		Weight f = F;
		for (int u = t; u != s; u = p[u])
			f = min(f, RESIDUE(p[u], u));
		for (int u = t; u != s; u = p[u]) {
			total.first += f * cost[p[u]][u];
			flow[p[u]][u] += f; flow[u][p[u]] -= f;
		}
		F -= f;
		total.second += f;
		REP(u, n) h[u] += d[u];
	}
	return total;
}


int main() {
	const long long int max_day = 1000000;
	while (1) {
		Graph g(1400);
		int n; cin >> n;
		const int start = 367;
		const int goal = 368;
		g[start].push_back(Edge(start, 0, 2, 0));
		g[365].push_back(Edge(365, goal, 2, 0));
		for (int i = 0; i < 365; ++i) {
			g[i].push_back(Edge(i, i + 1, 2, max_day));
		}
		if (!n)break;
		for (int i = 0; i < n; ++i) {
			long long int ai, j, w; cin >> ai >> j >> w;
			long long int money = max_day*(j - ai + 1) - w;
			g[ai - 1].push_back(Edge(ai - 1, 400+i, 1, 0));
			g[400 + i].push_back(Edge(400 + i, j, 1, money));
		}
		long long int ans = max_day *2* 365 - minimumCostFlow(g, start, goal).first;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 49424