#include <iostream.h>


//#define REDIRECT_IN
//#define REDIRECT_OUT

#ifdef REDIRECT_IN
#include <fstream.h>
#else
#ifdef REDIRECT_OUT
#include <fstream.h>
#endif
#endif


typedef long tim;

#define TIM_MINUS_INFTY 0x80000000l
#define V_PLUS_INFTY    0x40000000l

typedef long idx;


#ifdef _DOS
typedef int bool;
#define true 1
#define false 0

const idx MAXN=500;
#else
const idx MAXN=50000;
#endif

struct Meet
{
tim a,b;
long v;
};

struct Est
{
long v;
tim t;
Est(void) : v(0), t(0) { };
Est(long v_, tim t_) : v(v_), t(t_) { };
Est(const Meet &m) : v(m.v), t(m.b-m.a) { };
};

inline Est operator + (const Est &e1, const Est &e2)
{
return Est(e1.v+e2.v, e1.t+e2.t);
};

inline int Est_cmp(const Est &e1, const Est &e2)
{
if(e1.v>e2.v)
 return +0x80;
if(e1.v<e2.v)
 return -0x80;
if(e1.t<e2.t)
 return +1;
if(e1.t>e2.t)
 return -1;
return 0;
};

inline int operator < (const Est &e1, const Est &e2)
{
return Est_cmp(e1,e2)<0;
}

inline int operator > (const Est &e1, const Est &e2)
{
return Est_cmp(e1,e2)>0;
}

idx N;
Meet meets[MAXN];

bool curr_choice[MAXN], best_choice[MAXN];

Est curr_est(0,0), best_est(0,0);


void ReadData(istream &in)
{
in >> N;
for(idx i=0;i<N;i++)
 in >> meets[i].a >> meets[i].b >> meets[i].v;
}

void WriteRes(ostream &out)
{
out << best_est.v << ' ' << best_est.t << endl;
/*
for(idx i=0;i<N;i++)
 out << best_choice[i] ? '1' : '0';
out << endl;
*/
}

template <class T>
T max(T x, T y)
{
  return (x > y) ? x : y;
};
template <class T>
T min(T x, T y)
{
  return (x < y) ? x : y;
};

bool any_isect(bool *curr_choice, idx new_i)
{
for(idx i=new_i;i<N;i++)
 if(curr_choice[i])
  {
  tim min_of_max = min(meets[i].b,meets[new_i].b),
      max_of_min = max(meets[i].a,meets[new_i].a);
  if(min_of_max >= max_of_min)
   return true;
  }
return false;
}

void Try(idx level, bool do_use, Est curr_est)
{
curr_choice[level]=do_use;
if(do_use)
 curr_est = curr_est + Est(meets[level]);

if(level>0)
 {
 Try(level-1, false, curr_est);
 if(!any_isect(curr_choice,level-1))
  Try(level-1, true, curr_est);
 }
else
 {
 if(curr_est > best_est)
  {
  best_est = curr_est;
  for(idx i=0; i<N; i++)
   best_choice[i]=curr_choice[i];
  }
 }
curr_choice[level]=false;
}

int main(void)
{
// cout << "before ReadData"; cout.flush();

#ifdef REDIRECT_IN
 {
 ifstream fin("chief3.dat");
 ReadData(fin);
 }
#else
ReadData(cin);
#endif

// cout << "before Try"; cout.flush();

Try(N,false,curr_est);

// cout << "after Try";  cout.flush();

#ifdef REDIRECT_OUT
 {
 ofstream fout("chief3.sol");
 WriteRes(fout);
 fout.close();
 }
#else
WriteRes(cout);
#endif

return 0;
}