#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
template <class T>
inline bool setmin(T &a, T b) {
  if (a > b) return a = b, 1;
  return 0;
}
template <class T>
inline bool setmax(T &a, T b) {
  if (a < b) return a = b, 1;
  return 0;
}
template <class T>
inline T fast(T a, T b, T mod) {
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}
template <class T>
inline T russian(T a, T b, T mod) {
  long long res = 0;
  while (b) {
    if (b & 1) res = (res + a) % mod;
    a = (a + a) % mod;
    b >>= 1;
  }
  return res;
}
template <class T>
istream &operator>>(istream &os, vector<T> &container) {
  for (auto &u : container) os >> u;
  return os;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &container) {
  for (auto &u : container) os << u << " ";
  return os;
}
template <typename T>
inline T gcd(T a, T b) {
  while (b) swap(a %= b, b);
  return a;
}
const long long INF = 1e9 + 7;
const long long mod = 998244353;
const long long BIG_INF = 1e18 + 7;
const long long N = 1e6 + 7;
const int LOG = 17;
int n, m, k, q;
template <int SZ>
struct dodaj_znajdz_max {
  pair<int, long long> tree[SZ * 4 + 2];
  long long lazy[SZ * 4 + 2];
  int poz_max;
  long long wart_max;
  int T;
  dodaj_znajdz_max(long long val = 0) {
    T = 1;
    while (T <= SZ) T <<= 1;
    fill(lazy, lazy + T + T, 0);
    for (int i = T; i < T + T; i++) tree[i] = {i - T, val};
    for (int i = T - 1; i >= 1; i--) pull(i);
  }
  void add(int pocz, int kon, long long val) {
    ADD(pocz + T, kon + T + 1, 1, T, T + T, val);
  }
  pair<int, long long> ask(int pocz, int kon) {
    wart_max = -BIG_INF;
    ASK(T + pocz, T + kon + 1, 1, T, T + T);
    return {poz_max, wart_max};
  }

 private:
  void push(int u) {
    tree[u].second += lazy[u];
    long long pom = lazy[u];
    lazy[u] = 0;
    if (u >= T) return;
    lazy[u * 2] += pom;
    lazy[u * 2 + 1] += pom;
  }
  void pull(int u) {
    if (u < T)
      tree[u] = {
          (tree[u * 2].second > tree[u * 2 + 1].second ? tree[u * 2].first
                                                       : tree[u * 2 + 1].first),
          max(tree[u * 2].second, tree[u * 2 + 1].second) + lazy[u]};
    else {
      tree[u] = {tree[u].first, tree[u].second + lazy[u]};
      lazy[u] = 0;
    }
  }
  void ADD(int a, int b, int u, int lo, int hi, long long val) {
    push(u);
    if (a >= b) return;
    if (a == lo && b == hi) {
      lazy[u] += val;
      push(u);
      return;
    }
    push(u);
    int mid = (lo + hi) / 2;
    ADD(a, min(mid, b), u * 2, lo, mid, val);
    ADD(max(a, mid), b, u * 2 + 1, mid, hi, val);
    pull(u);
  }
  void ASK(int a, int b, int u, int lo, int hi) {
    push(u);
    if (a >= b) return;
    if (a == lo && b == hi) {
      if (tree[u].second > wart_max) {
        wart_max = tree[u].second;
        poz_max = tree[u].first;
      }
      return;
    }
    push(u);
    int mid = (lo + hi) / 2;
    ASK(a, min(mid, b), u * 2, lo, mid);
    ASK(max(a, mid), b, u * 2 + 1, mid, hi);
    pull(u);
  }
};
map<int, long long> mapa, mapa_rev;
map<pair<int, int>, long long> lol;
vector<pair<pair<int, int>, long long>> poziome, pionowe;
dodaj_znajdz_max<1000999> dzewo;
void zmapuj(vector<int> &tab) {
  sort((tab).begin(), (tab).end());
  tab.resize(unique((tab).begin(), (tab).end()) - tab.begin());
  for (int i = 0; i < (int)(tab).size(); i++) {
    mapa[tab[i]] = i;
    mapa_rev[i] = tab[i];
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  vector<int> id;
  for (int i = 0; i < n; i++) {
    int a, b;
    long long c;
    cin >> a >> b >> c;
    if (a > b) swap(a, b);
    lol[{a, b}] += c;
    id.push_back(a);
    id.push_back(b);
  }
  zmapuj(id);
  for (auto &u : lol) {
    poziome.push_back({{mapa[u.first.first], mapa[u.first.second]}, u.second});
    pionowe.push_back({{mapa[u.first.first], mapa[u.first.second]}, u.second});
  }
  sort((poziome).rbegin(), (poziome).rend());
  sort((pionowe).rbegin(), (pionowe).rend());
  int id_poziome = 0;
  int id_pionowe = 0;
  pair<int, int> best_poz = {-1, -1};
  long long best_wyn = -1;
  vector<long long> roznice;
  int chlew = 0;
  long long ost = -1;
  for (auto &u : mapa_rev) {
    if (chlew) roznice.push_back(u.second - ost);
    ost = u.second;
    chlew++;
  }
  reverse((roznice).begin(), (roznice).end());
  for (int i = (int)(id).size() - 1; i >= 0; i--) {
    if (i < (int)(id).size() - 1)
      dzewo.add(i + 1, (int)(id).size() - 1,
                -roznice[(int)(id).size() - 2 - i]);
    int last = id_poziome;
    while (id_poziome < (int)(poziome).size() &&
           poziome[id_poziome].first.first == i) {
      dzewo.add(poziome[id_poziome].first.second, (int)(id).size() - 1,
                poziome[id_poziome].second);
      id_poziome++;
    }
    pair<int, long long> best = dzewo.ask(i, (int)(id).size() - 1);
    if (best.second > best_wyn) {
      best_wyn = best.second;
      best_poz = {mapa_rev[i], mapa_rev[best.first]};
    }
  }
  if (best_wyn <= 0) {
    cout << 0 << '\n';
    cout << 1853245211 << ' ' << 1853245211 << ' ' << 1853245211 << ' '
         << 1853245211 << '\n';
    exit(0);
  }
  cout << best_wyn << '\n';
  cout << best_poz.first << ' ' << best_poz.first << ' ' << best_poz.second
       << ' ' << best_poz.second << '\n';
}
