#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;

#define MAXN 20000
#define INF 10000000
#define MAXP 2000
#define pb push_back

struct Meda {
   int a, b, c, id;
};

bool cmpMeda(Meda m1, Meda m2) {
   if(m1.c == m2.c) return m1.id < m2.id;
   return m1.c > m2.c;
}

int n;
Meda meda[MAXN + 50];

bool pop[MAXP + 50];
int levi[MAXP + 50];
int desni[MAXP + 50];
int indexL[MAXP + 50], indexD[MAXP + 50];

void Input() {
   FILE *fin = fopen("mede.in", "r");
   fscanf(fin, "%d", &n);

   for(int i = 0; i < n; i++) {
      fscanf(fin, "%d%d%d", &meda[i].a, &meda[i].b, &meda[i].c);
      meda[i].id = i;
   }
}

bool Ubaci(int index) {
   int l = meda[index].a, d = meda[index].b;
   vector<int> leviS, desniS;

   while(true) {
      if(leviS.size() == 0) {
         for(int k = l; k <= d; k++) {
         if(!pop[k]) {
            pop[k] = true;

            for(int poz = l; poz <= d; poz++) {
               if(levi[poz] > l) {
                  levi[poz] = l;
                  indexL[poz] = index;
               }

               if(desni[poz] < d) {
                  desni[poz] = d;
                  indexD[poz] = index;
               }
            }

               return true;
            }
         }
      } else {
         for(int k = l; k < leviS[leviS.size()-1]; k++) {
            if(!pop[k]) {
               pop[k] = true;

               for(int poz = leviS[0]; poz <= desniS[0]; poz++) {
               if(levi[poz] > leviS[0]) {
                  levi[poz] = leviS[0];
                  indexL[poz] = index;
               }

               if(desni[poz] < desniS[0]) {
                  desni[poz] = desniS[0];
                  indexD[poz] = index;
               }
               }

               return true;
            }
         }

         for(int k = desniS[desniS.size() - 1]; k <= d; k++) {
            if(!pop[k]) {
               pop[k] = true;
               for(int poz = leviS[0]; poz <= desniS[0]; poz++) {
               if(levi[poz] > leviS[0]) {
                  levi[poz] = leviS[0];
                  indexL[poz] = index;
               }

               if(desni[poz] < desniS[0]) {
                  desni[poz] = desniS[0];
                  indexD[poz] = index;
               }
               }

               return true;
            }
         }
      }

      leviS.pb(l);
      desniS.pb(d);

      if(l == levi[l] && desni[d] == d) return false;
      l = levi[l];
      d = desni[d];
   }
}

long long sol, tot;

void Solve() {
   sol = 0;
   tot = 0;

   for(int i = 1; i <= MAXP; i++) {
      pop[i] = false;
      levi[i] = INF;
      desni[i] = -INF;
   }

   sort(meda, meda + n, cmpMeda);

   for(int i = 0; i < n; i++) {
      tot += meda[i].c;
      if(Ubaci(i)) sol += meda[i].c;
   }

   sol = tot-sol;
   FILE *fout = fopen("mede.out", "w");
   fprintf(fout, "%lld\n", sol);
}

int main() {
   Input();
   Solve();
}
