#include <bits/stdc++.h>
using namespace std;
using LL = long long;
template <class T>
inline bool asMn(T &a, const T &b) {
  return a > b ? a = b, true : false;
}
template <class T>
inline bool asMx(T &a, const T &b) {
  return a < b ? a = b, true : false;
}
const LL infLL = 1e18;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
vector<int> com;
struct It {
  int n;
  vector<pair<LL, int> > mx;
  vector<LL> lz;
  It(int _n) : n(_n) {
    mx.assign(n << 2, {});
    lz.assign(n << 2, 0);
    build(1, 0, n - 1);
  }
  void build(int i, int Left, int Right) {
    if (Left == Right) {
      mx[i] = {-com[Left], Left};
      return;
    }
    build((i << 1), Left, ((Left + Right) >> 1));
    build((i << 1 | 1), ((Left + Right) >> 1) + 1, Right);
    mx[i] = max(mx[(i << 1)], mx[(i << 1 | 1)]);
  }
  void trueVal(int i, int Left, int Right) {
    if (!lz[i]) return;
    mx[i].first += lz[i];
    if (Left ^ Right) lz[(i << 1)] += lz[i], lz[(i << 1 | 1)] += lz[i];
    lz[i] = 0;
  }
  void add(int l, int r, int val, int i, int Left, int Right) {
    trueVal(i, Left, Right);
    if (r < Left || Right < l) return;
    if (l <= Left && Right <= r) {
      lz[i] = val;
      trueVal(i, Left, Right);
      return;
    }
    add(l, r, val, (i << 1), Left, ((Left + Right) >> 1));
    add(l, r, val, (i << 1 | 1), ((Left + Right) >> 1) + 1, Right);
    mx[i] = max(mx[(i << 1)], mx[(i << 1 | 1)]);
  }
  void add(int l, int r, int val) { add(l, r, val, 1, 0, n - 1); }
  pair<LL, int> get(int l, int r, int i, int Left, int Right) {
    trueVal(i, Left, Right);
    if (l <= Left && Right <= r) return mx[i];
    if (((Left + Right) >> 1) < l)
      return get(l, r, (i << 1 | 1), ((Left + Right) >> 1) + 1, Right);
    else if (r <= ((Left + Right) >> 1))
      return get(l, r, (i << 1), Left, ((Left + Right) >> 1));
    else
      return max(get(l, r, (i << 1), Left, ((Left + Right) >> 1)),
                 get(l, r, (i << 1 | 1), ((Left + Right) >> 1) + 1, Right));
  }
  pair<LL, int> get(int l, int r) { return get(l, r, 1, 0, n - 1); }
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<tuple<int, int, int> > p(n);
  for (auto &i : p) {
    cin >> get<0>(i) >> get<1>(i) >> get<2>(i);
    com.emplace_back(get<0>(i));
    com.emplace_back(get<1>(i));
  }
  com.emplace_back(0);
  sort((com).begin(), (com).end());
  com.erase(unique((com).begin(), (com).end()), com.end());
  It it(((int)(com).size()));
  vector<vector<pair<int, int> > > change(((int)(com).size()));
  for (auto &i : p) {
    get<0>(i) =
        (int)(lower_bound((com).begin(), (com).end(), get<0>(i)) - com.begin());
    get<1>(i) =
        (int)(lower_bound((com).begin(), (com).end(), get<1>(i)) - com.begin());
    change[min(get<0>(i), get<1>(i))].emplace_back(max(get<0>(i), get<1>(i)),
                                                   get<2>(i));
    it.add(max(get<0>(i), get<1>(i)), it.n - 1, get<2>(i));
  }
  tuple<LL, int, int> ans(0, com.back() + 1, com.back() + 1);
  for (int i = 0; i < ((int)(com).size()); ++i) {
    auto tmp = it.get(i, it.n - 1);
    asMx(ans, {com[i] + tmp.first, com[i], com[tmp.second]});
    for (const auto &j : change[i]) it.add(j.first, it.n - 1, -j.second);
  }
  cout << get<0>(ans) << '\n'
       << get<1>(ans) << ' ' << get<1>(ans) << ' ' << get<2>(ans) << ' '
       << get<2>(ans) << '\n';
  return 0;
}
