#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
vector<long long> tree, mxi, tag, a;
int T;
void push(int i, int l, int r) {
  if (tag[i]) {
    tree[i] += tag[i];
    if (l != r) {
      tag[((i << 1) + 1)] += tag[i];
      tag[((i << 1) + 2)] += tag[i];
    }
    tag[i] = 0;
  }
}
void pull(int i, int l, int r) {
  if (tree[((i << 1) + 1)] + tag[((i << 1) + 1)] >=
      tree[((i << 1) + 2)] + tag[((i << 1) + 2)]) {
    tree[i] = tree[((i << 1) + 1)] + tag[((i << 1) + 1)];
    mxi[i] = mxi[((i << 1) + 1)];
  } else {
    tree[i] = tree[((i << 1) + 2)] + tag[((i << 1) + 2)];
    mxi[i] = mxi[((i << 1) + 2)];
  }
}
void build(int i, int l, int r) {
  if (l == r) {
    tree[i] = a[l];
    mxi[i] = l;
    return;
  }
  int m = (l + r) >> 1;
  build(((i << 1) + 1), l, m);
  build(((i << 1) + 2), m + 1, r);
  pull(i, l, r);
}
int ql, qr, x;
long long v;
void update(int i, int l, int r) {
  if (ql <= l && r <= qr) {
    tag[i] += v;
    return;
  }
  int m = (l + r) >> 1;
  if (ql <= m) update(((i << 1) + 1), l, m);
  if (qr > m) update(((i << 1) + 2), m + 1, r);
  pull(i, l, r);
}
void query(int i, int l, int r) {
  push(i, l, r);
  if (ql <= l && r <= qr) {
    if (tree[i] > v) {
      v = tree[i];
      x = mxi[i];
    }
    return;
  }
  int m = (l + r) >> 1;
  if (ql <= m) query(((i << 1) + 1), l, m);
  if (qr > m) query(((i << 1) + 2), m + 1, r);
}
int main() {
  cin.tie(0), ios::sync_with_stdio(0);
  int n;
  cin >> n;
  vector<tuple<long long, long long, long long>> arr(n);
  vector<long long> all(n);
  for (int i = 0; i < n; i++) {
    long long l, r, c;
    cin >> l >> r >> c;
    if (l > r) swap(l, r);
    arr[i] = tie(l, r, c);
    all[i] = r;
  }
  sort(arr.begin(), arr.end());
  sort(all.begin(), all.end());
  all.resize(unique(all.begin(), all.end()) - all.begin());
  T = all.size();
  a.resize(T, 0);
  for (int i = 0; i < n; i++) {
    get<1>(arr[i]) =
        lower_bound(all.begin(), all.end(), get<1>(arr[i])) - all.begin();
    a[get<1>(arr[i])] += get<2>(arr[i]);
  }
  for (int i = 1; i < T; i++) a[i] += a[i - 1];
  for (int i = 0; i < T; i++) a[i] -= all[i];
  tree.resize(T * 4);
  tag.resize(T * 4, 0);
  mxi.resize(T * 4);
  build(0, 0, T - 1);
  long long ans = 0;
  int l = 1.5e9, r = l;
  for (int i = 0; i < n;) {
    int j = i + 1;
    while (j < n && get<0>(arr[i]) == get<0>(arr[j])) j++;
    for (int k = i; k < j; k++) {
      ql = lower_bound(all.begin(), all.end(), get<0>(arr[k])) - all.begin();
      qr = T - 1;
      v = -1e9;
      query(0, 0, T - 1);
      if (v + get<0>(arr[k]) > ans) {
        ans = v + get<0>(arr[k]);
        l = get<0>(arr[k]);
        r = all[x];
      }
    }
    for (int k = i; k < j; k++) {
      ql = get<1>(arr[k]);
      qr = T - 1;
      v = -get<2>(arr[k]);
      update(0, 0, T - 1);
    }
    i = j;
  }
  cout << ans << "\n";
  cout << l << " " << l << " " << r << " " << r << "\n";
  return 0;
}
