#include <cstdio>
#include <algorithm>

int n;
short int kraj[20005];


struct S
{
    short int a, b;
    long long  v;
} niz[20005];
bool operator < ( S s1, S s2)
{
    return s1.v>s2.v;
}
int main()
{
    freopen("mede.in","r",stdin);
    freopen("mede.out","w",stdout);
    long long res=0;
    scanf("%d",&n);
    for ( int i=0;i<n;i++)
    {
        scanf("%hd %hd %lld",&niz[i].a,&niz[i].b,&niz[i].v);
    }
    for ( int i=1;i<=2002;i++)
    kraj[i]=-1;

    std::sort( niz, niz + n );
    short int pos,kr,t;
    for ( short int i=0;i<n;i++)
    {
        pos=niz[i].a;
        kr=niz[i].b;
        while ( kraj[pos]!= -1 )
        {
            if ( kr < pos ) break;
            if ( kr < kraj[pos])
            {
                t=kr;
                kr=kraj[pos];
                kraj[pos]=t;
            }
            pos++;
        }
        if ( kr<pos )
            res+=niz[i].v;
        else
            kraj[pos]=kr;
    }
    printf("%lld\n",res);
    return 0;
}
