#include <bits/stdc++.h>
using namespace std;
const int64_t INF = 1e18;
const pair<int64_t, int> MINFP = {-INF, 0};
template <typename T>
struct SetF {
  typedef function<void(T& a, T b)> func2;
  func2 f;
  T e;
  SetF() {}
  SetF(func2 f, T e) : f(f), e(e) {}
};
SetF<pair<int64_t, int> > setf_add(
    [](pair<int64_t, int>& a, pair<int64_t, int> b) { a.first += b.first; },
    {0, 0});
template <typename T>
struct GetF {
  typedef function<T(T a)> func1;
  typedef function<T(T a, int width)> func_int;
  typedef function<T(T a, T b)> func2;
  func2 f;
  func_int expand;
  T e;
  GetF() {}
  GetF(func2 f, func_int expand, T e) : f(f), expand(expand), e(e) {}
};
GetF<pair<int64_t, int> > getf_max(
    [](pair<int64_t, int> a, pair<int64_t, int> b) { return max(a, b); },
    [](pair<int64_t, int> a, int w) { return a; }, MINFP);
template <typename T>
struct LazySegtree {
  int n;
  vector<T> dat, laz;
  vector<bool> lazflag;
  SetF<T> setf;
  GetF<T> getf;
  LazySegtree() {}
  LazySegtree(int n_input, SetF<T> setf_input, GetF<T> getf_input) {
    initialize(n_input, setf_input, getf_input);
  }
  void initialize(int n_input, SetF<T> setf_input, GetF<T> getf_input) {
    n = 1;
    while (n < n_input) n <<= 1;
    setf = setf_input;
    getf = getf_input;
    dat.resize(2 * n - 1, getf.e);
    laz.resize(2 * n - 1, setf.e);
    lazflag.resize(2 * n - 1, false);
  }
  void build(vector<T>& A) {
    for (int k = 0; k < A.size(); k++) dat[k + n - 1] = A[k];
    for (int k = n - 2; k >= 0; k--)
      dat[k] = getf.f(dat[2 * k + 1], dat[2 * k + 2]);
  }
  void eval(int k, int l, int r) {
    if (!lazflag[k]) return;
    setf.f(dat[k], getf.expand(laz[k], r - l));
    if (r - l > 1) {
      setf.f(laz[2 * k + 1], laz[k]);
      setf.f(laz[2 * k + 2], laz[k]);
      lazflag[2 * k + 1] = lazflag[2 * k + 2] = true;
    }
    laz[k] = setf.e;
    lazflag[k] = false;
  }
  void update_between(int a, int b, T x) { update(a, b + 1, x, 0, 0, n); }
  void update(int a, int b, T x, int k, int l, int r) {
    eval(k, l, r);
    if (b <= l || r <= a) return;
    if (a <= l && r <= b) {
      setf.f(laz[k], x);
      lazflag[k] = true;
      eval(k, l, r);
    } else {
      update(a, b, x, 2 * k + 1, l, (l + r) / 2);
      update(a, b, x, 2 * k + 2, (l + r) / 2, r);
      dat[k] = getf.f(dat[2 * k + 1], dat[2 * k + 2]);
    }
  }
  void force_set(int a, T x) {
    get_between(a, a);
    int k = a + n - 1;
    dat[k] = x;
    while (k > 0) {
      k = (k - 1) / 2;
      dat[k] = getf.f(dat[2 * k + 1], dat[2 * k + 2]);
    }
  }
  T get_between(int a, int b) { return query(a, b + 1, 0, 0, n); }
  T query(int a, int b, int k, int l, int r) {
    eval(k, l, r);
    if (r <= a || b <= l) return getf.e;
    if (a <= l && r <= b) return dat[k];
    T vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
    T vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
    return getf.f(vl, vr);
  }
};
int main() {
  int N;
  static int X[500000], Y[500000], C[500000];
  cin >> N;
  vector<int> cmp;
  for (int i = 0; i < N; i++) {
    scanf("%d %d %d", &X[i], &Y[i], &C[i]);
    cmp.push_back(X[i]);
    cmp.push_back(Y[i]);
  }
  sort(cmp.begin(), cmp.end());
  cmp.erase(unique(cmp.begin(), cmp.end()), cmp.end());
  int sz = cmp.size();
  static vector<int> L2i[1000000];
  for (int i = 0; i < N; i++) {
    X[i] = lower_bound(cmp.begin(), cmp.end(), X[i]) - cmp.begin();
    Y[i] = lower_bound(cmp.begin(), cmp.end(), Y[i]) - cmp.begin();
    L2i[min(X[i], Y[i])].push_back(i);
  }
  const int OUT = 1e9 + 1;
  vector<int64_t> ans = {0, OUT, OUT};
  LazySegtree<pair<int64_t, int> > st(sz, setf_add, getf_max);
  vector<pair<int64_t, int> > ini(sz);
  for (int i = 0; i < sz; i++) ini[i] = {-cmp[i], i};
  st.build(ini);
  for (int l = sz - 1; l >= 0; l--) {
    for (int i : L2i[l]) {
      int r = max(X[i], Y[i]);
      st.update_between(r, sz - 1, {C[i], 0});
    }
    auto Res = st.get_between(l, sz - 1);
    int64_t val = Res.first + cmp[l];
    vector<int64_t> res = {val, cmp[l], cmp[Res.second]};
    ans = max(ans, res);
  }
  cout << ans[0] << endl;
  cout << ans[1] << " " << ans[1] << " " << ans[2] << " " << ans[2] << endl;
  return 0;
}
