#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

typedef int Weight;
struct Edge {
  int src, dst;
  Weight capacity, cost;
  int rev;
  Edge(int src, int dst, Weight capacity, Weight cost) :
    src(src), dst(dst), capacity(capacity), cost(cost) { }
  Edge(int src, int dst, Weight capacity, Weight cost, int rev) :
    src(src), dst(dst), capacity(capacity), cost(cost), rev(rev) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.cost != f.cost ? e.cost > f.cost : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;

void add_edge(Graph &g, int s, int d, Weight cap, Weight cost) {
  g[s].push_back(Edge(s,d,cap,cost,g[d].size()));
  g[d].push_back(Edge(d,s,0,-cost,g[s].size()-1));
}

pair<Weight, Weight> minimumCostFlow3(Graph g, int s, int t) {
  const int n = g.size();
  pair<Weight, Weight> total; // (cost, flow)
  
  vector<Weight> h(n,INF);
  h[s] = 0;
  REP(k, n) REP(i, n) FOR(e,g[i]) if (e->capacity)
    h[e->dst] = min(h[e->dst], h[e->src] + e->cost);
  
  for (int F = INF; F > 0;) { // residual flow
    vector<Weight> d(n, INF); d[s] = 0;
    vector<int> pv(n,-1), pe(n);
    priority_queue<Edge> Q;
    for (Q.push(Edge(-2,s,0,0)); !Q.empty(); ) {
      Edge e = Q.top(); Q.pop();
      if (pv[e.dst] != -1) continue;
      pv[e.dst] = e.src;
      pe[e.dst] = e.rev;
      REP(i, g[e.dst].size()) {
        Edge &f = g[e.dst][i];
        if (f.capacity > 0 && d[f.dst] > d[f.src] + f.cost + h[f.src] - h[f.dst]) {
          d[f.dst] = d[f.src] + f.cost + h[f.src] - h[f.dst];
          Q.push(Edge(f.src, f.dst, 0, d[f.dst], i));
        }
      }
    }
    if (pv[t] == -1) break;
    Weight f = F;
    for (int u = t; u != s; u = pv[u])
      f = min(f, g[pv[u]][pe[u]].capacity);
    if (!f) break;
    for (int u = t; u != s; u = pv[u]) {
      total.first += f * g[pv[u]][pe[u]].cost;
      g[pv[u]][pe[u]].capacity -= f;
      g[u][g[pv[u]][pe[u]].rev].capacity += f;
    }
    F -= f;
    total.second += f;
    REP(u,n) if (h[u] != INF) h[u] += d[u];
  }
  return total;
}

int main() {
  int n;
  while(cin >> n, n) {
    Graph g(367);
    
    REP(i, n) {
      int a, b, w;
      cin >> a >> b >> w;
      add_edge(g, a-1, b, 1, -w);
    }
    REP(i, 366) {
      add_edge(g, i, i+1, 2, 0);
    }
    cout << -minimumCostFlow3(g, 0, 366).first << endl;
  }
}