#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 7, mod = 1e9 + 7;
vector<pair<pair<int, int>, int> > usuwanie;
vector<int> zap;
map<int, int> mapa;
int n;
int aa[N], bb[N], cc[N];
struct tree {
  struct node {
    long long p = -1e16;
    long long sum = 0;
    int x = -1;
  };
  int base;
  vector<node> t;
  tree() {
    base = (1ll << 22);
    t.resize(2 * base + 5);
  }
  void repair(long long v) {
    if (v < base) {
      if (t[2 * v].p < t[2 * v + 1].p + t[2 * v].sum) {
        t[v] = t[2 * v + 1];
        t[v].p = t[2 * v + 1].p + t[2 * v].sum;
      } else {
        t[v] = t[2 * v];
      }
      t[v].sum = t[v * 2].sum + t[v * 2 + 1].sum;
    }
  }
  void add(long long v, int w) {
    v = mapa[v];
    v += base;
    t[v].sum += w;
    t[v].p += w;
    while (v > 1) {
      repair(v);
      v /= 2;
    }
  }
  pair<long long, int> query(long long v) {
    long long dod = v;
    v = mapa[v];
    v += base;
    node re = t[v];
    while (v > 1) {
      if (v % 2 == 1) {
        v /= 2;
        continue;
      }
      if (re.p < re.sum + t[v + 1].p) {
        re.p = re.sum + t[v + 1].p;
        re.x = t[v + 1].x;
      }
      re.sum += t[v + 1].sum;
      v /= 2;
    }
    return make_pair(re.p + dod, re.x);
  }
};
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  tree tr;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    aa[i] = a;
    bb[i] = b;
    cc[i] = c;
    usuwanie.push_back(make_pair(make_pair(min(a, b), max(a, b)), -c));
    zap.push_back(a);
    zap.push_back(b);
  }
  sort(usuwanie.begin(), usuwanie.end());
  reverse(usuwanie.begin(), usuwanie.end());
  sort(zap.begin(), zap.end());
  zap.resize(distance(zap.begin(), unique(zap.begin(), zap.end())));
  for (int i = 0; i < zap.size(); i++) {
    mapa[zap[i]] = i;
    tr.t[i + tr.base].x = zap[i];
    tr.t[i + tr.base].p = -zap[i];
  }
  for (int i = 0; i < n; i++) {
    tr.add(max(aa[i], bb[i]), cc[i]);
  }
  pair<long long, pair<int, int> > ans = make_pair(0, make_pair(2e9, 2e9));
  for (auto x : zap) {
    while (!usuwanie.empty() && usuwanie.back().first.first < x) {
      tr.add(usuwanie.back().first.second, usuwanie.back().second);
      usuwanie.pop_back();
    }
    pair<long long, int> ret = tr.query(x);
    if (ret.first > ans.first) {
      ans = make_pair(ret.first, make_pair(x, ret.second));
    }
  }
  cout << ans.first << endl;
  cout << ans.second.first << " " << ans.second.first << " ";
  cout << ans.second.second << " " << ans.second.second << endl;
}
