var
 n,zadnji,i,j,q,min:longint;
 a,b,mesto,c,place:array[0..20000]of longint;
 r:array[0..200000]of int64;
 mark:array[0..200000]of boolean;
 f,g:text;
 nadjen:boolean;
 max,res:int64;
Procedure kvik(l,d:longint);
 var
  i,j,k1,k2,p:longint;
 begin
  i:=l;j:=d;
  k1:=b[(l+d)div 2];
  k2:=a[(l+d)div 2];
  repeat
   while (b[i]<k1)or((b[i]=k1)and(a[i]<k2)) do inc(i);
   while (b[j]>k1)or((b[j]=k1)and(a[j]>k2)) do dec(j);
   if i<=j then begin
    p:=a[i];a[i]:=a[j];a[j]:=p;
    p:=b[i];b[i]:=b[j];b[j]:=p;
    p:=c[i];c[i]:=c[j];c[j]:=p;
    inc(i);
    dec(j);
   end
  until i>j;
  if i<d then kvik(i,d);
  if j>l then kvik(l,j);
 end;
begin
 assign(f,'mede.in'); reset(f);
 assign(g,'mede.out');rewrite(g);
 readln(f,n);
 max:=0;  res:=0;
 for i:=1 to n do begin
  readln(f,a[i],b[i],c[i]);
  res:=res+c[i];
  if b[i]>max then max:=b[i];
 end;
 for i:=1 to max do mesto[i]:=0;
 kvik(1,n);
 r[1]:=c[1];
 mesto[b[1]]:=1;zadnji:=b[1];
 for i:=2 to n do

 if b[i]>=zadnji+1 then begin
  zadnji:=b[i];
  mesto[zadnji]:=i;
  r[i]:=r[i-1]+c[i];
  end
 else begin
  nadjen:=false;min:=c[i];q:=i;
  for j:=zadnji downto 1 do
   begin
       if mesto[j]=0 then begin
         q:=j;
         break;
       end;
       if (c[mesto[j]]<min) then
          begin
             min:=c[mesto[j]];
             q:=j;
          end;
       if (a[mesto[j]]<=j-1) then mark[j]:=true;
       if (not mark[j])then nadjen:=true;
   end;
  if (not nadjen ) then begin
   r[i]:=r[i-1]+c[i];
   if mesto[j]=0 then
     for j:=q to zadnji-1 do mesto[j]:=mesto[j+1]
   else
      for j:=1 to zadnji-1 do mesto[j]:=mesto[j+1];
   mesto[zadnji]:=i;
  end
  else begin
   r[i]:=r[i-1]+c[i]-min;
   for j:=q to zadnji-1 do mesto[j]:=mesto[j+1];
    if (q<>i) then mesto[zadnji]:=i;
  end;
 end;
 writeln(g,res-r[n]);
 close(f);
 close(g);
end.

