#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int n, br;
bool mark[22222];
long long res;

int min(int a, int b) {
    int res = a;
    if (b < a) res = b;
    return res;
}

struct nizzz {
    int poc, kr;
    long long vre;
} niz[22222];

struct cvor {
    int levo[2222];
    int desno[2222];
    int brL, brD;
} a[4222];

bool cmp(nizzz aa, nizzz bb) {
    return aa.vre > bb.vre;
}

int main() {
    FILE *ff = fopen("mede.in", "r");
    FILE *gg = fopen("mede.out", "w");
    int pocL, pocD, krL, krD, tacno;
    res = 0;
    fscanf(ff, "%d", &n);
    for (int i = 1; i <= n; i++) fscanf(ff, "%d%d%I64d", &niz[i].poc, &niz[i].kr, &niz[i].vre);
    sort(niz+1, niz+n+1, cmp);
    //for (int i = 1; i <= n; i++) printf("%d%d%I64d\n", niz[i].poc, niz[i].kr, niz[i].vre);
    for (int i = 1; i <= n; i++) mark[i] = false;
    mark[1] = true;
    a[niz[1].poc].desno[-niz[1].poc + niz[1].kr + 1]++;
    //printf("RADI  niz[1].poc = %d   niz[i].kr = %d   a[1].desno[2] = %d \n", niz[1].poc, niz[1].kr, a[1].desno[2]);
    a[niz[1].kr].levo[-niz[1].poc + niz[1].kr + 1]++;
    br = 1;

    for (int i = 2; i <= n; i++) {
        //printf("RADI %d", i);
        tacno = 0;
        mark[i] = true;
        a[niz[i].poc].desno[-niz[i].poc + niz[i].kr + 1]++;
        a[niz[i].kr].levo[-niz[i].poc + niz[i].kr + 1]++;
        //a[niz[i].poc].brD++;
        //a[niz[i].kr].brL++;
        br++;

        if (br > -niz[i].poc + niz[i].kr + 1) {
            //printf("RADI");
            pocL = 0;
            pocD = 0;
            krL = 0;
            krD = 0;

            pocL -= a[niz[i].poc].levo[1];
            for (int k = 1; k <= min(2000 - niz[i].poc + 1, 50); k++)
            for (int j = 1; j <= k; j++) {
                //printf("!1!  %d %d\n", j, k);
                pocD += a[niz[i].poc + k - j].desno[j];
                if (niz[i].poc - k + j > 0)
                    pocL += a[niz[i].poc - k + j].levo[j];
                if (pocD > k) tacno = 1;
                if (pocD + pocL == 2*k) tacno = 1;
            }

            krD -= a[niz[i].kr].desno[1];
            for (int k = 1; k <= min(niz[i].kr + 1, 50); k++)
            for (int j = 1; j <= k; j++) {
                //printf("!2! %d %d\n", j, k);
                krL += a[niz[i].kr - k + j].levo[j];
                if (niz[i].kr + k - j < 2010)
                    krD += a[niz[i].kr + k - j].desno[j];
                if (krL > k) tacno = 1;
                if (krL + krD == 2*k) tacno = 1;
            }

            if (tacno) {
                mark[i] = false;
                br--;
                a[niz[i].poc].desno[-niz[i].poc + niz[i].kr + 1]--;
                a[niz[i].kr].levo[-niz[i].poc + niz[i].kr + 1]--;
            }
        }
    }
    for (int i = 1; i <= n; i++) if (!mark[i]) {
        //printf("%d\n", i);
        res += niz[i].vre;
    }
    //for (int i = 1; i <= 3; i++) printf("%d ", a[2].levo[i]); printf("\n");
    fprintf(gg, "%I64d", res);
}


