#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cassert>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <fstream>
#include <cmath>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define ITER(c) __typeof((c).begin())
#define PB(e) push_back(e)
#define FOREACH(i, c) for(ITER(c) i = (c).begin(); i != (c).end(); ++i)
#define MP(a, b) make_pair(a, b)
#define PARITY(n) ((n) & 1)

typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-10;


class MinCostFlow{
  
  typedef pair<int, int> P;
  class edge{
  public:
    int to, cap, cost, rev;
    edge(){}
    edge(int to, int cap, int cost, int rev) : to(to),cap(cap),cost(cost),rev(rev){}
  };
  
  int infinity;
  int SIZE;
  vector<int> dist;
  vector<int> h;
  vector<int> prevv;
  vector<int> preve;
  vector<vector<edge> > G;
public:
  MinCostFlow(int V) : SIZE(V),dist(vector<int>(V)),h(vector<int>(V)),
		       prevv(vector<int>(V)), preve(vector<int> (V)), 
		       G(vector<vector<edge> >(V)){ 
    infinity = 1000 * 1000 * 1000 + 7;
  }
  void add_edge(int from, int to, int cap, int cost){
    G[from].push_back(edge(to, cap, cost, G[to].size()));
    G[to].push_back(edge(from, 0, -cost, G[from].size()-1));
  }
  void init(int size = 0){
    if(size > 0){
      dist.resize(size);
      h.resize(size);
      prevv.resize(size);
      preve.resize(size);
      G.resize(size);
    }
    for(int i = 0; i < (int)G.size(); i++) G[i].clear();
  }
  
  int min_cost_flow(int s, int t, int f){
    int res = 0;
    fill(h.begin(), h.end(), 0);
    while(f > 0){
      priority_queue<P, vector<P>, greater<P> > que;
      fill(dist.begin(), dist.end(), infinity);
      dist[s] = 0;
      que.push(P(0, s));
      while(!que.empty()){
	P p = que.top(); que.pop();
	int v  = p.second;
	if(dist[v] < p.first) continue;
	for(int i =  0; i < (int)G[v].size(); i++){
	  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(P(dist[e.to], e.to));
	  }
	}
      }
      
      if(dist[t] == infinity) return -1;
      for(int v = 0; v < SIZE; v++) h[v] += dist[v];
      
      int d = f;
      for(int v = t; v != s; v = prevv[v]){
	d = min(d, 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;
  }
};


int main(){
  int n;
  while(cin >> n && n){

    const int year = 365;
    int s = 0;
    int t = year + 2;;
    MinCostFlow mfc(t + 1);

    REP2(i, 1, year + 1) mfc.add_edge(i, i + 1, INF, 0);
    mfc.add_edge(s, 1, 2, 0);
    mfc.add_edge(year + 1, t, 2, 0);
    int ans = 0;
    
    REP(i, n){
      int a, b, w;
      cin >> a >> b >> w;
      b++;
      
      ans += w;
      mfc.add_edge(b, a, 1, w);
      mfc.add_edge(s, b, 1, 0);
      mfc.add_edge(a, t, 1, 0);
    }
    cout << ans - mfc.min_cost_flow(s, t, 2 + n) << endl;
    
  }
  return 0;
}

Measured memory_bytes: 1376