#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cerr<<(#v)<<":";for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;
#define printVS(vs) cerr<<(#vs)<<":"<<endl;for(auto(s):(vs)){cerr<<(s)<< endl;}
#define printVV(vv) cerr<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;}
#define printP(p) cerr<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cerr<<(#vp)<<":"<<endl;for(auto(p):(vp)){cerr<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cerr << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cerr << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
// const int inf = 1ll << 60;
const int INF = 1ll << 60;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

// const int INF = 99999999;
const int MAX_COST = 1000000;

struct edge { int to, cap, cost, rev; };

const int V = 367;
const int MAX_V = V;
const int F = 2;
const int s = 0;
const int t = 366;
int E;
vector<edge> G[MAX_V];
int h[MAX_V];                   // potential
int dist[MAX_V];
int prevv[MAX_V], preve[MAX_V]; // privious vertex, edge

void add_edge(int from, int to, int cap, int cost) {
    G[from].emplace_back((edge){to, cap, cost, (int)G[to].size()});
    G[to].emplace_back((edge){from, 0, -cost, (int)G[from].size() - 1});
}

// get min cost flow from s to t
// if we cannot flow f, then return -1
int min_cost_flow(int s, int t, int f) {
    int res = 0;
    fill(h, h + V, 0);
    while (f > 0) {
        // update h by dijkstra
        priority_queue<Pii, vector<Pii>, greater<Pii>> que;
        fill(dist, dist + V, INF);
        dist[s] = 0;
        que.push(Pii(0, s));
        while (!que.empty()) {
            Pii p = que.top(); que.pop();
            int v = p.second;
            if (dist[v] < p.first) continue;
            rep(i, G[v].size()) {
                edge &e = G[v][i];
                if (e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]) {
                    dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
                    prevv[e.to] = v;
                    preve[e.to] = i;
                    que.push(Pii(dist[e.to], e.to));
                }
            }
        }
        if (dist[t] == INF) {
            // no more flow
            return -1;
        }
        rep(v, V) h[v] += dist[v];

        // flow as much as possible along the minimum path from s to t
        int d = f;
        for (int v = t; v != s; v = prevv[v]) {
            d = min(d, (int)G[prevv[v]][preve[v]].cap);
        }
        f -= d;
        res += d * h[t];
        for (int v = t; v != s; v = prevv[v]) {
            edge &e = G[prevv[v]][preve[v]];
            e.cap -= d;
            G[v][e.rev].cap += d;
        }
    }
    return res;
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    while (cin >> E, E) {
        rep(i, V) {
            G[i].clear();
        }
        rep(i, V - 1) {
            add_edge(i, i + 1, 2, MAX_COST);
        }

        rep(i, E) {
            int u, v, w;
            cin >> u >> v >> w;
            add_edge(u, v + 1, 1, (v + 1 - u) * MAX_COST - w);
        }

        cout << F * (V - 1) * MAX_COST - min_cost_flow(0, V - 1, F) << endl;
    }

}

Measured memory_bytes: 3272