#include <bits/stdc++.h>
using namespace std;
int x[500005], y[500005];
bool vis[500005];
long long c[500005];
vector<int> v;
inline int idx(int x) { return lower_bound(v.begin(), v.end(), x) - v.begin(); }
struct segtree {
  vector<pair<long long, long long> > v, lazy;
  int size = 1;
  segtree(int n) {
    size = 1;
    while (size < 2 * n) size <<= 1;
    v.resize(size);
    lazy.resize(size);
    for (int i = size / 2; i < size; i++) v[i].second = i - size / 2;
  }
  void push_down(int node, int start, int end) {
    if (!lazy[node].first) return;
    v[node].first += lazy[node].first;
    if (start != end) {
      lazy[node * 2].first += lazy[node].first;
      lazy[node * 2 + 1].first += lazy[node].first;
    }
    lazy[node].first = 0;
  }
  void add(int i, int j, long long val) { add(1, i, j, 0, size / 2 - 1, val); }
  void add(int node, int i, int j, int start, int end, long long val) {
    push_down(node, start, end);
    if (j < start || i > end)
      return;
    else if (i <= start && j >= end) {
      lazy[node].first += val;
      push_down(node, start, end);
    } else {
      add(node * 2, i, j, start, (start + end) / 2, val);
      add(node * 2 + 1, i, j, (start + end) / 2 + 1, end, val);
      v[node] = max(v[node * 2], v[node * 2 + 1]);
    }
  }
  pair<long long, long long> MAX(int i, int j) {
    return MAX(1, i, j, 0, size / 2 - 1);
  }
  pair<long long, long long> MAX(int node, int i, int j, int start, int end) {
    push_down(node, start, end);
    if (j < start || i > end)
      return {-0x7f7f7f7f7f7f7f7f, 0};
    else if (i <= start && j >= end)
      return v[node];
    else
      return max(MAX(node * 2, i, j, start, (start + end) / 2),
                 MAX(node * 2 + 1, i, j, (start + end) / 2 + 1, end));
  }
};
void solve() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i] >> c[i];
    if (x[i] <= 500000) vis[x[i]] = true;
    if (y[i] <= 500000) vis[y[i]] = true;
    v.push_back(x[i]);
    v.push_back(y[i]);
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  int m = v.size();
  vector<vector<int> > vv(m);
  segtree st(m + 5);
  long long ans = -0x7f7f7f7f7f7f7f7f;
  for (int i = 0; i < m; i++) {
    st.add(i, i, -v[i]);
  }
  for (int i = 0; i < n; i++) {
    int z = min(x[i], y[i]);
    int j = idx(z);
    vv[j].push_back(i);
    int zz = max(x[i], y[i]);
    int jj = idx(zz);
    st.add(jj, m - 1, c[i]);
  }
  int x1, y1, x2, y2;
  for (int i = 0; i < m; i++) {
    pair<long long, long long> val = st.MAX(i, m - 1);
    if (val.first + v[i] > ans) {
      ans = val.first + v[i];
      x1 = y1 = v[i];
      x2 = y2 = v[val.second];
    }
    for (int k : vv[i]) {
      int zz = max(x[k], y[k]);
      int jj = idx(zz);
      st.add(jj, m - 1, -c[k]);
    }
  }
  if (ans < 0) {
    ans = 0;
    for (int i = 0; i <= n; i++) {
      if (!vis[i]) {
        x1 = y1 = x2 = y2 = i;
        break;
      }
    }
  }
  cout << ans << endl;
  cout << x1 << " " << y1 << " " << x2 << " " << y2 << endl;
}
int main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) solve();
  return 0;
}
