#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 55;
struct point {
  int x, y, w;
} p[maxn], q[maxn];
int n, cnt, c[maxn << 1];
long long tr[maxn << 3], lazy[maxn << 3], pos[maxn << 3];
int getid(int x) { return lower_bound(c, c + cnt, x) - c; }
inline void pushdown(int x) {
  tr[x << 1] += lazy[x];
  tr[x << 1 | 1] += lazy[x];
  lazy[x << 1] += lazy[x];
  lazy[x << 1 | 1] += lazy[x];
  lazy[x] = 0;
}
void build(int l, int r, int x) {
  if (l == r) {
    tr[x] = -c[r];
    pos[x] = r;
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, x << 1);
  build(mid + 1, r, x << 1 | 1);
  tr[x] = max(tr[x << 1], tr[x << 1 | 1]);
  if (tr[x] == tr[x << 1])
    pos[x] = pos[x << 1];
  else
    pos[x] = pos[x << 1 | 1];
}
void updata(int l, int r, int L, int R, int x, int w) {
  if (l > R || r < L) return;
  if (l >= L && r <= R) {
    tr[x] += w;
    lazy[x] += w;
    return;
  }
  if (lazy[x]) pushdown(x);
  int mid = (l + r) >> 1;
  updata(l, mid, L, R, x << 1, w);
  updata(mid + 1, r, L, R, x << 1 | 1, w);
  tr[x] = max(tr[x << 1], tr[x << 1 | 1]);
  if (tr[x] == tr[x << 1])
    pos[x] = pos[x << 1];
  else
    pos[x] = pos[x << 1 | 1];
}
void query(int l, int r, int L, int R, int x, long long &ans,
           long long &second) {
  if (l > R || r < L) return;
  if (l >= L && r <= R) {
    if (tr[x] >= ans) {
      ans = tr[x];
      second = pos[x];
    }
    return;
  }
  if (lazy[x]) pushdown(x);
  int mid = (l + r) >> 1;
  query(l, mid, L, R, x << 1, ans, second);
  query(mid + 1, r, L, R, x << 1 | 1, ans, second);
}
bool cmp(point a, point b) { return a.x < b.x; }
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d %d %d", &p[i].x, &p[i].y, &p[i].w);
    c[cnt++] = p[i].x;
    c[cnt++] = p[i].y;
  }
  sort(c, c + cnt);
  cnt = unique(c, c + cnt) - c;
  build(0, cnt - 1, 1);
  for (int i = 0; i < n; ++i) {
    int x = getid(p[i].x), y = getid(p[i].y);
    int L = min(x, y), R = max(x, y);
    updata(0, cnt - 1, R, cnt - 1, 1, p[i].w);
    q[i] = (point){L, R, p[i].w};
  }
  sort(q, q + n, cmp);
  long long res = 0, st = 2e9, ed = 2e9;
  for (int i = 0; i < n;) {
    long long ans = -2e9, second;
    query(0, cnt - 1, q[i].x, cnt - 1, 1, ans, second);
    ans += c[q[i].x];
    if (ans >= res) {
      res = ans;
      st = c[q[i].x];
      ed = c[second];
    }
    int j = i;
    while (j < n && q[j].x == q[i].x) {
      updata(0, cnt - 1, q[j].y, cnt - 1, 1, -q[j].w);
      j++;
    }
    i = j;
  }
  cout << res << '\n' << st << " " << st << " " << ed << " " << ed << '\n';
  return 0;
}
