#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double Pi = acos(-1);
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
double dpow(double a, long long b) {
  double ans = 1.0;
  while (b) {
    if (b % 2) ans = ans * a;
    a = a * a;
    b /= 2;
  }
  return ans;
}
long long quick_pow(long long x, long long y) {
  long long ans = 1;
  while (y) {
    if (y & 1) {
      ans = ans * x % mod;
    }
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
pair<long long, long long> Max[maxn << 2];
long long lazy[maxn << 2];
long long w[maxn];
void push_up(int rt) { Max[rt] = max(Max[rt << 1], Max[rt << 1 | 1]); }
void build(int l, int r, int rt) {
  lazy[rt] = 0;
  if (l == r) {
    Max[rt].first = -w[l];
    Max[rt].second = l;
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, rt << 1);
  build(mid + 1, r, rt << 1 | 1);
  push_up(rt);
}
void push_down(int rt, int len) {
  if (lazy[rt]) {
    lazy[rt << 1] += lazy[rt];
    lazy[rt << 1 | 1] += lazy[rt];
    Max[rt << 1].first += lazy[rt];
    Max[rt << 1 | 1].first += lazy[rt];
    lazy[rt] = 0;
  }
}
void update(int L, int R, int val, int l, int r, int rt) {
  if (L <= l && r <= R) {
    Max[rt].first += val;
    lazy[rt] += val;
    return;
  }
  int mid = (l + r) >> 1;
  push_down(rt, r - l + 1);
  if (L <= mid) update(L, R, val, l, mid, rt << 1);
  if (R > mid) update(L, R, val, mid + 1, r, rt << 1 | 1);
  push_up(rt);
}
pair<long long, long long> query(int L, int R, int l, int r, int rt) {
  if (L <= l && r <= R) {
    return Max[rt];
  }
  int mid = (l + r) >> 1;
  push_down(rt, r - l + 1);
  pair<long long, long long> ans = make_pair(-INF, 0);
  if (L <= mid) ans = max(ans, query(L, R, l, mid, rt << 1));
  if (R > mid) ans = max(ans, query(L, R, mid + 1, r, rt << 1 | 1));
  return ans;
}
long long a[maxn], b[maxn], c[maxn];
vector<long long> vec;
vector<pair<long long, long long> > mp[maxn];
int Hash[maxn];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld%lld%lld", &a[i], &b[i], &c[i]);
    if (a[i] > b[i]) swap(a[i], b[i]);
    vec.push_back(a[i]);
    vec.push_back(b[i]);
    if (a[i] <= 1000000) Hash[a[i]] = 1;
    if (b[i] <= 1000000) Hash[b[i]] = 1;
  }
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  int sz = vec.size();
  for (int i = 0; i < sz; i++) w[i + 1] = vec[i] - vec[0];
  build(1, sz, 1);
  for (int i = 0; i < n; i++) {
    a[i] = lower_bound(vec.begin(), vec.end(), a[i]) - vec.begin() + 1;
    b[i] = lower_bound(vec.begin(), vec.end(), b[i]) - vec.begin() + 1;
    mp[a[i]].push_back(make_pair(b[i], c[i]));
    update(b[i], sz, c[i], 1, sz, 1);
  }
  long long ans = 0;
  long long x = -1, y = -1;
  for (int i = 1; i <= 1000001; i++) {
    if (!Hash[i]) {
      x = i;
      y = i;
      break;
    }
  }
  for (int i = 1; i <= sz; i++) {
    pair<long long, long long> tmp = query(i, sz, 1, sz, 1);
    if (tmp.first > ans) {
      ans = tmp.first;
      x = vec[i - 1];
      y = vec[tmp.second - 1];
    }
    for (auto p : mp[i]) update(p.first, sz, -p.second, 1, sz, 1);
    if (i != sz) update(i + 1, sz, vec[i] - vec[i - 1], 1, sz, 1);
  }
  printf("%lld\n", ans);
  printf("%lld %lld %lld %lld\n", x, x, y, y);
  return 0;
}
