{$mode objfpc}

{ $define REDIRECT}

type idx = word;
     tim = longint;

{$ifdef VER70}
const MAXN = 1000;
{$else}
const MAXN = 50000;
{$endif}


type TMeet = record
               a,b     : tim;
               v       : longint;
               ori_num : idx;
             end;
{$ifdef VER70}
     TEst = longint;

const ZeroEst:TEst = 0;
{$else}
{$inline on}
     TEst = record
              v : longint;
              t : tim;
            end;
const ZeroEst:TEst = (v:0; t:0);

function cmp(const e1,e2:TEst):integer; inline;
Begin
  if e1.v > e2.v then begin
    cmp:=+$80; exit
  end;
  if e1.v < e2.v then begin
    cmp:=-$80; exit
  end;
  if e1.t < e2.t then begin
    cmp:=+1; exit
  end;
  if e1.t > e2.t then begin
    cmp:=-1; exit
  end;
  cmp:=0;
End;

operator < (const e1,e2:TEst) res:boolean; inline;
begin
  res:=cmp(e1,e2)<0;
end;

operator + (const e1,e2:TEst) res:TEst; inline;
begin
  res.v := e1.v + e2.v;
  res.t := e1.t + e2.t;
end;
{$endif}

type TChoice = record
                 this_selected : boolean;
                 prev : idx;
               end;

     MeetArr = array[1..MAXN] of TMeet;
     EstArr = array[0..MAXN] of TEst;
     ChoiceArr = array[0..MAXN] of TChoice;
     OutputArr = array[1..MAXN] of byte;

var N:idx;
    meets:MeetArr;
    est:EstArr;
    choice:ChoiceArr;
    out_arr:OutputArr;



procedure QuickSort(var A: MeetArr; Lo, Hi: idx);

procedure Sort(l, r: idx);
var
  i, j : idx;
  x    : tim;
  y    : TMeet;
begin
  i := l; j := r; x := a[idx((longint(l)+longint(r)) DIV 2)].b;
  repeat
    while a[i].b < x do i := i + 1;
    while x < a[j].b do j := j - 1;
    if i <= j then
    begin
      y := a[i]; a[i] := a[j]; a[j] := y;
      i := i + 1; j := j - 1;
    end;
  until i > j;
  if l < j then Sort(l, j);
  if i < r then Sort(i, r);
end;

begin {QuickSort};
  Sort(Lo,Hi);
end;


procedure ReadData;
var i:idx;
Begin
{$ifdef REDIRECT}
  assign(input,'chief3.dat'); reset(input);
{$endif}
  read(N);
  for i:=1 to N do begin
    read(meets[i].a,meets[i].b,meets[i].v);
    meets[i].ori_num:=i;
  end;

  close(input);

End;

procedure DP_Solve;
  function search_k(the_i:idx):idx;
  var the_a:tim;
      l,r,m:idx;
  begin
    the_a:=meets[the_i].a;
    if meets[1].b >=the_a then begin
      search_k := 0;
      exit
    end;
    l:=1; r:=the_i-1;
    while r>=l do begin
      m:=idx((longint(l)+longint(r)) div 2);
      if meets[m].b >= the_a then
        r:=m-1
      else
        l:=m+1;
    end;
    while meets[m+1].b < the_a do
      inc(m);
    while meets[m].b >= the_a do
      dec(m);
    search_k:=m;
  end;

{$ifdef VER70}
  function TheMeetEst(const the_meet:TMeet):TEst;
  begin
    TheMeetEst:=the_meet.v;
  end;
{$else}
  function TheMeetEst(const the_meet:TMeet):TEst;
  var res:TEst;
  begin
    res.v:=the_meet.v;
    res.t:=the_meet.b-the_meet.a;
    TheMeetEst:=res;
  end;
{$endif}
var i,k :idx;
    est_excl, est_incl :TEst;
Begin
  est[0]:=ZeroEst;
  choice[0].this_selected:=true;
  for i:=1 to N do begin
    k:=search_k(i);
    est_excl := est[i-1];
    est_incl := est[k] + TheMeetEst(meets[i]);
    if est_excl < est_incl then begin
      est[i]:=est_incl;
      choice[i].this_selected:=true;
      if choice[k].this_selected then
        choice[i].prev:=k
      else
        choice[i].prev:=choice[k].prev;
    end else begin
      est[i]:=est_excl;
      choice[i].this_selected:=false;
      if choice[i-1].this_selected then
        choice[i].prev:=i-1
      else
        choice[i].prev:=choice[i-1].prev;
    end;
  end
End;

procedure WriteRes;
var i,k:idx;
Begin
{$ifdef VER70}
  writeln(est[N]);
{$else}
  writeln(est[N].v,' ',est[N].t);
{$endif}
{  for i:=1 to N do out_arr[i]:=0;
  if choice[N].this_selected then
    k:=N
  else
    k:=choice[N].prev;
  while k>0 do begin
    out_arr[meets[k].ori_num]:=1;
    k:=choice[k].prev;
  end;
  for i:=1 to N do write(out_arr[i]);
  writeln;}
End;

var i:integer;

BEGIN
  ReadData;
  QuickSort(meets,1,N);
{  for i:=1 to N do
    writeln(meets[i].)}
  DP_Solve;
  WriteRes;
END.
