program mede;

type    tmeda=record
        a, b:integer;
        c:longint;
        got:boolean;
        end;

        tprod=record
        med:array[1..20000] of longint;
        nmed:longint;
        p:real;
        end;


var
n, p:longint;
data:array[1..20000] of tmeda;
prod:array[1..2000] of tprod;

procedure Unos;
var f:text;
i:longint;
begin
assign(f, 'mede.in');
reset(f);
readln(f, n);
for i:=1 to n do readln(f, data[i].a, data[i].b, data[i].c);
close(f);
end;

///

function cutdown:longint;
var tmp, i:longint;
begin
tmp:=data[1].a;
for i:=2 to n do if data[i].a<tmp then tmp:=data[i].a;
for i:=1 to n do
        begin
        data[i].a:=data[i].a-tmp+1;
        data[i].b:=data[i].b-tmp+1;
        end;
tmp:=data[1].b;
for i:=2 to n do if data[i].b>tmp then tmp:=data[i].b;
for i:=1 to 2000 do prod[i].nmed:=0;
cutdown:=tmp;
end;

procedure ToProd;
var
i, j:longint;
begin
for i:=1 to n do
        for j:=data[i].a to data[i].b do
                begin
                prod[j].nmed:=prod[j].nmed+1;
                prod[j].med[prod[j].nmed]:=i;
                end;

end;

procedure ValueSort;
var i, j, sum:longint;
tmp:tprod;
begin
for i:=1 to p do
        begin
        sum:=0;
        for j:=1 to prod[i].nmed do sum:=sum+data[prod[i].med[j]].c;
        prod[i].p:=sum/prod[i].nmed;
        end;
for i:=2 to p-1 do
        for j:=i+1 to p do
                if prod[i].p<prod[j].p then
                        begin
                        tmp:=prod[i];
                        prod[i]:=prod[j];
                        prod[j]:=tmp;
                        end;
end;

procedure Shop;
var i, j, maxc, imed:longint;
begin
for i:=1 to n do data[i].got:=false;

for i:=1 to p do
        begin
        maxc:=data[prod[i].med[1]].c;
        for j:=1 to prod[i].nmed do
                if (data[prod[i].med[j]].c>maxc) and (data[prod[i].med[j]].got=false) then
                        begin
                        imed:=prod[i].med[j];
                        maxc:=data[prod[i].med[j]].c;
                        end;
        data[imed].got:=true;
        end;
end;

procedure Output;
var i, sum:longint;
f:text;
begin
sum:=0;
for i:=1 to n do
        if data[i].got=false then sum:=sum+data[i].c;
assign(f, 'mede.out');
rewrite(f);
writeln(f, sum);
end;

///

begin
Unos;
p:=cutdown;
ToProd;
ValueSort;
Shop;
Output;
end.