#include <bits/stdc++.h>
using namespace std;
int fastMax(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y; }
int fastMin(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x; }
const long long int MAXN = 5e5 + 10, P = 2 * MAXN;
const long long int INF = 1e15 + 42;
map<long long int, long long int> compress;
long long int x[MAXN], y[MAXN], c[MAXN], rev[P];
vector<pair<long long int, long long int>> at[P];
pair<long long int, long long int> seg[4 * P];
long long int lazy[4 * P];
void build(long long int node, long long int second, long long int e) {
  if (second > e) return;
  if (second == e) {
    seg[node] = {0, second};
    return;
  }
  long long int mid = (second + e) >> 1;
  build(2 * node, second, mid);
  build(2 * node + 1, mid + 1, e);
  seg[node] = max(seg[2 * node], seg[2 * node + 1]);
}
void propogate(long long int node, long long int second, long long int e) {
  seg[node].first += lazy[node];
  if (second != e) {
    lazy[2 * node] += lazy[node];
    lazy[2 * node + 1] += lazy[node];
  }
  lazy[node] = 0;
}
void update(long long int node, long long int second, long long int e,
            long long int qs, long long int qe, long long int val) {
  propogate(node, second, e);
  if (second > e || qs > e || qe < second) return;
  if (qs <= second && e <= qe) {
    lazy[node] += val;
    propogate(node, second, e);
    return;
  }
  long long int mid = (second + e) >> 1;
  update(2 * node, second, mid, qs, qe, val);
  update(2 * node + 1, mid + 1, e, qs, qe, val);
  seg[node] = max(seg[2 * node], seg[2 * node + 1]);
}
pair<long long int, long long int> query(long long int node,
                                         long long int second, long long int e,
                                         long long int qs, long long int qe) {
  propogate(node, second, e);
  if (second > e || qs > e || qe < second) return {-INF, 0LL};
  if (qs <= second && e <= qe) return seg[node];
  long long int mid = (second + e) >> 1;
  return max(query(2 * node, second, mid, qs, qe),
             query(2 * node + 1, mid + 1, e, qs, qe));
}
void solve() {
  long long int n;
  cin >> n;
  for (long long int i = (1); i <= (n); ++i) {
    cin >> x[i] >> y[i] >> c[i];
    if (x[i] > y[i]) swap(x[i], y[i]);
    compress[x[i]];
    compress[y[i]];
  }
  long long int lid = 0;
  for (auto &i : compress) {
    i.second = ++lid;
    rev[i.second] = i.first;
  }
  for (long long int i = (1); i <= (n); ++i) {
    at[compress[x[i]]].push_back({compress[y[i]], c[i]});
  }
  long long int ans = 0;
  pair<long long int, long long int> pt = {2e9, 2e9};
  build(1, 1, lid);
  for (long long int i = (1); i <= (lid); ++i) {
    update(1, 1, lid, i, i, -rev[i]);
  }
  for (long long int x = (lid); x >= (1); --x) {
    for (auto p : at[x]) {
      long long int y = p.first, cost = p.second;
      update(1, 1, lid, y, lid, cost);
    }
    auto q = query(1, 1, lid, x, lid);
    if (q.first + rev[x] > ans) {
      ans = q.first + rev[x];
      pt = {rev[x], rev[q.second]};
    }
  }
  cout << ans << '\n';
  cout << pt.first << " " << pt.first << " " << pt.second << " " << pt.second
       << '\n';
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int t;
  t = 1;
  for (long long int i = (1); i <= (t); ++i) {
    solve();
  }
}
