#include <bits/stdc++.h>
using namespace std;
int n;
int X[500005], Y[500005], C[500005];
vector<int> V;
vector<pair<int, int> > event[1000005];
long long dat[4000005], tag[4000005];
int N;
inline void pushdown(int v) {
  if (tag[v]) {
    dat[v << 1] += tag[v];
    dat[v << 1 | 1] += tag[v];
    tag[v << 1] += tag[v];
    tag[v << 1 | 1] += tag[v];
    tag[v] = 0;
  }
}
inline void update(int a, int b, int val, int v = 1, int l = 1, int r = N) {
  if (a <= l && r <= b)
    dat[v] += val, tag[v] += val;
  else if (b < l || r < a)
    return;
  else {
    int m = l + r >> 1;
    pushdown(v);
    update(a, b, val, v << 1, l, m);
    update(a, b, val, v << 1 | 1, m + 1, r);
    dat[v] = max(dat[v << 1], dat[v << 1 | 1]);
  }
}
inline int query(int v = 1, int l = 1, int r = N) {
  if (l == r)
    return l;
  else {
    int m = l + r >> 1;
    if (dat[v << 1] > dat[v << 1 | 1])
      return query(v << 1, l, m);
    else
      return query(v << 1 | 1, m + 1, r);
  }
}
const int INF = 1e9 + 7;
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= (n); ++i) {
    cin >> X[i] >> Y[i] >> C[i];
    V.push_back(X[i]);
    V.push_back(Y[i]);
  }
  sort(V.begin(), V.end());
  V.erase(unique(V.begin(), V.end()), V.end());
  N = V.size();
  for (int i = 1; i <= (n); ++i) {
    if (X[i] > Y[i]) {
      event[lower_bound(V.begin(), V.end(), Y[i]) - V.begin() + 1].push_back(
          make_pair(lower_bound(V.begin(), V.end(), X[i]) - V.begin() + 1,
                    C[i]));
    } else {
      event[lower_bound(V.begin(), V.end(), X[i]) - V.begin() + 1].push_back(
          make_pair(lower_bound(V.begin(), V.end(), Y[i]) - V.begin() + 1,
                    C[i]));
    }
  }
  long long ans = 0, DL, UR;
  for (int i = N; i >= 1; --i) {
    if (i < N) update(i + 1, N, V[i - 1] - V[i]);
    for (int j = 0; j < event[i].size(); ++j) {
      update(event[i][j].first, N, event[i][j].second);
    }
    if (dat[1] > ans) {
      ans = dat[1];
      DL = i;
      UR = query();
    }
  }
  if (ans == 0)
    printf("0\n%d %d %d %d\n", INF, INF, INF, INF);
  else {
    printf("%lld\n", ans);
    printf("%d %d %d %d", V[DL - 1], V[DL - 1], V[UR - 1], V[UR - 1]);
  }
  return 0;
}
