#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
const long long INF = 1e18;
const int limit = (int)1e9 + 1;
int n, m;
int xx[N], yy[N], P[N << 2];
long long Max[N << 2], c[N], Tag[N << 2], b[N];
vector<pair<int, int> > q[N];
template <typename T>
inline void chkmax(T &x, T y) {
  x = max(x, y);
}
template <typename T>
inline void chkmin(T &x, T y) {
  x = min(x, y);
}
template <typename T>
inline void read(T &x) {
  T f = 1;
  x = 0;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -f;
  for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
  x *= f;
}
inline void pushup(int now) {
  if (Max[now << 1] > Max[now << 1 | 1])
    Max[now] = Max[now << 1], P[now] = P[now << 1];
  else
    Max[now] = Max[now << 1 | 1], P[now] = P[now << 1 | 1];
  return;
}
inline void build(int now, int l, int r) {
  if (l == r) {
    Max[now] = -b[l];
    P[now] = l;
    return;
  }
  int mid = (l + r) >> 1;
  build(now << 1, l, mid);
  build(now << 1 | 1, mid + 1, r);
  pushup(now);
}
inline void pushdown(int now) {
  if (Tag[now] != 0) {
    Max[now << 1] += Tag[now];
    Max[now << 1 | 1] += Tag[now];
    Tag[now << 1] += Tag[now];
    Tag[now << 1 | 1] += Tag[now];
    Tag[now] = 0;
  }
}
inline void modify(int now, int l, int r, int ql, int qr, long long val) {
  if (l == ql && r == qr) {
    Max[now] += val;
    Tag[now] += val;
    return;
  }
  pushdown(now);
  int mid = (l + r) >> 1;
  if (mid >= qr)
    modify(now << 1, l, mid, ql, qr, val);
  else if (mid + 1 <= ql)
    modify(now << 1 | 1, mid + 1, r, ql, qr, val);
  else
    modify(now << 1, l, mid, ql, mid, val),
        modify(now << 1 | 1, mid + 1, r, mid + 1, qr, val);
  pushup(now);
}
inline pair<long long, int> query(int now, int l, int r, int ql, int qr) {
  if (l == ql && r == qr) return make_pair(Max[now], P[now]);
  pushdown(now);
  int mid = (l + r) >> 1;
  if (mid >= qr)
    return query(now << 1, l, mid, ql, qr);
  else if (mid + 1 <= ql)
    return query(now << 1 | 1, mid + 1, r, ql, qr);
  else {
    pair<long long, int> ll = query(now << 1, l, mid, ql, mid);
    pair<long long, int> rr = query(now << 1 | 1, mid + 1, r, mid + 1, qr);
    if (ll.first > rr.first)
      return ll;
    else
      return rr;
  }
}
int main() {
  read(n);
  for (int i = 1; i <= n; ++i) {
    read(xx[i]);
    read(yy[i]);
    read(c[i]);
    if (xx[i] != 0) b[++m] = xx[i];
    if (yy[i] != 0) b[++m] = yy[i];
  }
  b[0] = 0;
  sort(b + 1, b + m + 1);
  m = unique(b + 1, b + m + 1) - b - 1;
  build(1, 0, m);
  for (int i = 1; i <= n; ++i) {
    int pos = lower_bound(b, b + m + 1, min(xx[i], yy[i])) - b;
    int pp = lower_bound(b, b + m + 1, max(xx[i], yy[i])) - b;
    q[pos + 1].push_back(make_pair(pp, -c[i]));
    modify(1, 0, m, pp, m, c[i]);
  }
  b[m + 1] = limit;
  pair<long long, pair<int, int> > ans = make_pair(0, make_pair(m + 1, m + 1));
  pair<long long, int> val = query(1, 0, m, 0, m);
  if (val.first > ans.first)
    ans = make_pair(val.first, make_pair(0, val.second));
  for (int i = 1; i <= m; ++i) {
    for (auto x : q[i]) modify(1, 0, m, x.first, m, x.second);
    Tag[1] += b[i] - b[i - 1];
    Max[1] += b[i] - b[i - 1];
    pair<long long, int> val = query(1, 0, m, i, m);
    if (val.first > ans.first)
      ans = make_pair(val.first, make_pair(i, val.second));
  }
  cout << ans.first << "\n";
  cout << b[ans.second.first] << ' ' << b[ans.second.first] << ' '
       << b[ans.second.second] << ' ' << b[ans.second.second] << "\n";
  return 0;
}
