#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, n) for (ll i = n - 1; i >= 0; i--)

template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

template <class T>
bool chmax(T &a, const T &b) {
    if (b > a) {
        a = b;
        return 1;
    }
    return 0;
}

struct Timer {
  private:
    chrono::high_resolution_clock::time_point start, end;

  public:
    Timer() { set(); }
    void set() { start = chrono::high_resolution_clock::now(); }
    int time() {
        end = chrono::high_resolution_clock::now();
        return chrono::duration_cast<chrono::milliseconds>(end - start).count();
    }
    void print() { cerr << "elapsed time: " << (double)time() / 1000 << " sec" << endl; }
};

struct Random {
  private:
    uint32_t a, b, c, d;

  public:
    Random(uint32_t seed = 517) { set_seed(seed); }
    void set_seed(uint32_t seed) {
        a = seed = 1812433253u * (seed ^ (seed >> 30));
        b = seed = 1812433253u * (seed ^ (seed >> 30)) + 1;
        c = seed = 1812433253u * (seed ^ (seed >> 30)) + 2;
        d = seed = 1812433253u * (seed ^ (seed >> 30)) + 3;
    }
    uint32_t operator()() {
        uint32_t t = (a ^ (a << 11));
        a = b;
        b = c;
        c = d;
        return d = (d ^ (d >> 19)) ^ (t ^ (t >> 8));
    }

    // [0,MAX)
    uint32_t operator()(int MAX) { return (uint64_t) operator()() * MAX >> 32; }

    // [L,R)
    uint32_t operator()(int L, int R) { return L + operator()(R - L); }

    // [0,1) の実数
    double drnd() { return (double)operator()() / (1LL << 32); }

    // 確率 p で true を返す
    bool prob(const double p) { return (uint32_t)(p * (1LL << 32)) > operator()(); }
};

double TL = 3500;
double start_temp = 2.5, end_temp = 0;

int n;
int x[222], y[222], r[222];
int a[222], b[222], c[222], d[222];

void put_rectangle(int idx){
int ma = -1;
  int xl, xr, yl, yr;
  int lim1 = 100, lim2 = 10000;
  for (int xlen = lim1; xlen <= lim2; xlen += (lim2 - lim1) / 20){
    int lim3 = x[idx] + 1 - xlen, lim4 = x[idx] + xlen;
    for (xl = lim3; xl <= lim4; xl += max(1,(lim4 - lim3) / 20)){
      xr = xl + xlen;
      if(xl<0||xr>10000)
        continue;
      int ul, dl;
      int ok = 0, ng = 10001;
      while (ng - ok > 1){
        int nlen = (ok + ng) / 2;
        yl = y[idx] + 1 - nlen, yr = y[idx] + 1;
        int flag = 1;
        if(yl<0||yr>10000)
          flag = 0;
        rep(i,n) if (i != idx && a[i] < xr && c[i] > xl && b[i] < yr && d[i] > yl) flag = 0;
        if(flag)
          ok = nlen;
        else
          ng = nlen;
      }
      ul = ok;
      ok = 0, ng = 10001;
      while(ng - ok > 1){
        int nlen = (ok + ng) / 2;
        yl = y[idx], yr = y[idx] + nlen;
        int flag = 1;
        if(yl<0||yr>10000)
          flag = 0;
        rep(i,n) if (i != idx && a[i] < xr && c[i] > xl && b[i] < yr && d[i] > yl) flag = 0;
        if(flag)
          ok = nlen;
        else
          ng = nlen;
      }
      dl = ok;
      if(ul != 0){
        chmin(ul, r[idx] / xlen);
        chmin(dl, r[idx] / xlen + 1 - ul);
        if(chmax(ma, xlen * (ul + dl - 1))){
          yl = y[idx] + 1 - ul, yr = y[idx] + dl;
          a[idx] = xl, c[idx] = xr, b[idx] = yl, d[idx] = yr;
        }
      }
    }
  }
}

int main(){
  Timer T;
  Random rnd;
  cin >> n;
  rep(i, n) cin >> x[i] >> y[i] >> r[i];
  vector<pair<int, int>> v;
  rep(i, n) v.pb(mp(r[i], i));
  sort(all(v));
  int idx[n];
  rep(i, n) idx[i] = v[i].second;
  rep(i, n) a[i] = x[i], b[i] = y[i], c[i] = x[i] + 1, d[i] = y[i] + 1;
  rep(i, n) put_rectangle(idx[i]);
  rep(i, n) cout << a[i] << " " << b[i] << " " << c[i] << " " << d[i] << endl;
}
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<ll(n);i++)
#define REP(i,k,n) for(ll i=k;i<ll(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define UNIQUE(a) sort(all(a));a.erase(unique(all(a)),a.end())
#define decimal cout<<fixed<<setprecision(10)
#define summon_tourist cin.tie(0);ios::sync_with_stdio(false)
using ll=long long;
using P=pair<ll,ll>;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
constexpr ll inf=1001001001001001;
constexpr int INF=1001001001;
constexpr int mod=998244353;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
void YesNo(bool b){if(b)out("Yes");else out("No");}
void yesno(bool b){if(b)out("yes");else out("no");}
void YESNO(bool b){if(b)out("YES");else out("NO");}
ll modpow(ll a,ll b){ll c=1;while(b>0){if(b&1){c=a*c%mod;}a=a*a%mod;b>>=1;}return c;}
vi calc(ll x){vi v;while(x>0){v.eb(x%10);x/=10;}reverse(all(v));return v;}

int main(){
    ll n; cin>>n;
    vector<P> col(n+1,P(INF,-INF));
    ll m=0; //色の最大
    rep(i,n){
        ll x,c;
        cin>>x>>c;
        chmax(m,c);
        chmin(col[c].fi,x);
        chmax(col[c].se,x);
    }
    //outvp(col);
    //out(m);
    vvi dp(m+1,vi(2,0));
    col[0]=P(0,0);
    REP(i,1,m+1){
        if(col[i].fi==INF){
            dp[i]=dp[i-1];
            col[i]=col[i-1];
            continue;
        }
        ll ltol=dp[i-1][0]+abs(col[i].se-col[i-1].fi);
        ll ltor=dp[i-1][0]+abs(col[i].fi-col[i-1].fi);
        ll rtol=dp[i-1][1]+abs(col[i].se-col[i-1].se);
        ll rtor=dp[i-1][1]+abs(col[i].fi-col[i-1].se);
        ll get=abs(col[i].se-col[i].fi);
        dp[i][0]=min(ltol,rtol)+get;
        dp[i][1]=min(ltor,rtor)+get;
    }
    out(min(dp[m][0]+abs(col[m].fi),dp[m][1]+abs(col[m].se)));
    //outvv(dp);
}