#include <bits/stdc++.h>
using namespace std;
const int Mn = 5e5 + 17;
const int INF = 1e9 + 66;
int a[2 * Mn];
struct info {
  long long sum, rmx;
  int pos;
  info() {}
  info(long long _v, int _p) { sum = _v, rmx = _v, pos = _p; }
  friend info operator+(const info &i, const info &j) {
    info rnt;
    rnt.sum = i.sum + j.sum;
    if (j.rmx > i.rmx + j.sum) {
      rnt.rmx = j.rmx;
      rnt.pos = j.pos;
    } else {
      rnt.rmx = i.rmx + j.sum;
      rnt.pos = i.pos;
    }
    return rnt;
  }
};
struct S {
  int x, y, c;
  S() {}
  S(int _x, int _y, int _c) { x = _x, y = _y, c = _c; }
} pt[Mn];
inline bool cmp(S x, S y) { return x.y < y.y; }
struct tree {
  int left, right;
  info mes;
} tree[Mn * 2 * 4];
void build(int l, int r, int x) {
  tree[x].left = l, tree[x].right = r;
  if (l == r) {
    tree[x].mes = info(0ll, l);
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, x << 1);
  build(mid + 1, r, x << 1 | 1);
}
void update(int x, int pos, long long v) {
  if (tree[x].left == tree[x].right) {
    tree[x].mes = info(tree[x].mes.sum + v, tree[x].left);
    return;
  }
  int mid = (tree[x].left + tree[x].right) >> 1;
  if (pos <= mid)
    update(x << 1, pos, v);
  else
    update(x << 1 | 1, pos, v);
  tree[x].mes = tree[x << 1].mes + tree[x << 1 | 1].mes;
}
info query(int x, int l, int r) {
  if (l <= tree[x].left && tree[x].right <= r) return tree[x].mes;
  int mid = (tree[x].left + tree[x].right) >> 1;
  if (r <= mid) return query(x << 1, l, r);
  if (l >= mid + 1) return query(x << 1 | 1, l, r);
  return query(x << 1, l, r) + query(x << 1 | 1, l, r);
}
int main() {
  int n, tail = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    int x, y, c;
    scanf("%d%d%d", &x, &y, &c);
    pt[i] = S(x, y, c);
    a[++tail] = x, a[++tail] = y;
  }
  sort(a + 1, a + tail + 1);
  tail = unique(a + 1, a + tail + 1) - a - 1;
  for (int i = 1; i <= n; ++i) {
    pt[i].x = lower_bound(a + 1, a + tail + 1, pt[i].x) - a;
    pt[i].y = lower_bound(a + 1, a + tail + 1, pt[i].y) - a;
    if (pt[i].x > pt[i].y) swap(pt[i].x, pt[i].y);
  }
  sort(pt + 1, pt + n + 1, cmp);
  build(1, tail, 1);
  long long ans = 0;
  int pos1 = 0, pos2 = 0;
  for (int i = 1, j = 1; i <= tail; ++i) {
    while (j <= n && pt[j].y <= i) update(1, pt[j].x, pt[j].c), ++j;
    info tmp = query(1, 1, i);
    if (tmp.rmx > ans) ans = tmp.rmx, pos1 = tmp.pos, pos2 = i;
    update(1, i, a[i] - a[i + 1]);
  }
  if (!ans) {
    printf("0\n%d %d %d %d\n", INF, INF, INF, INF);
    return 0;
  }
  printf("%I64d\n", ans);
  printf("%d %d %d %d\n", a[pos1], a[pos1], a[pos2], a[pos2]);
  return 0;
}
