#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for (int i = (int)(a); (i) < (int)(b); (i)++)
#define rrep(i, a, b) for (int i = (int)(b) - 1; (i) >= (int)(a); (i)--)
#define all(v) v.begin(), v.end()

typedef long long ll;
template <class T> using V = vector<T>;
template <class T> using VV = vector<V<T>>;

/* 提出時これをコメントアウトする */
// #define LOCAL true

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define dbg(x) true
#endif

struct P{
    int x, y, r, id;
    P(int x=0, int y=0, int r=0, int id=0) : x(x), y(y), r(r), id(id) {}
    bool operator <(const P& other) const {
        return r < other.r;
    }
};

struct S{
    int a,b,c,d,id;
    S(int a=0, int b=0, int c=0, int d=0, int id=0) :a(a),b(b),c(c),d(d),id(id) {}
};

struct Point {
    int x, y;
    Point(int x=0, int y=0) : x(x),y(y) {}
    bool operator <(const Point& other) const {
        if (y != other.y) return y < other.y;
        return x < other.x;
    }
};

auto solve (int n, V<P>& v) -> V<S> {
    // 面積が小さいほうから見る
    sort(all(v));

    V<S> ret(n);
    set<Point> st;

    // version 1: (x,y), (x+1,y+1)
    rep(i,0,n) {
        ret[i] = S(v[i].x,v[i].y,v[i].x+1,v[i].y+1,v[i].id);
        st.insert(Point(v[i].x,v[i].y));
    }

    // version 2: 横だけに伸ばす
    // => cをできるだけ大きくする
    rep(i,0,n) {
        int c = ret[i].c;
        int d = ret[i].d;
        while (!st.count(Point(c,d-1)) && c < 10000) {
            if (c - ret[i].a >= v[ret[i].id].r) break;
            c++;
        }
        ret[i].c = c;
    }

    return ret;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    constexpr char endl = '\n';
    
    // input
    int n;
    cin >> n;
    V<P> v(n);
    rep(i,0,n) {
        cin >> v[i].x >> v[i].y >> v[i].r;
        v[i].id = i;
    }

    // solve
    auto ans = solve(n, v);

    // output
    V<int> a(n),b(n),c(n),d(n);
    rep(i,0,n) {
        a[ans[i].id] = ans[i].a;
        b[ans[i].id] = ans[i].b;
        c[ans[i].id] = ans[i].c;
        d[ans[i].id] = ans[i].d;
    }
    rep(i,0,n) {
        cout << a[i] << " " << b[i] << " " << c[i] << " " << d[i] << endl;
    }
    return 0;
}
#include <bits/stdc++.h>

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
//const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) {
  if(b < 0)b *= -1;
  return a > b && (a = b, true);
}

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  int N;
  cin >> N;
  vector< int > T(N);
  cin >> T;
  auto dp = make_v< int >(100001);
  fill_v(dp, inf);
  dp[0] = 0;
  for(auto &t : T) {
    auto dp2 = make_v< int >(100001);
    fill_v(dp2, inf);
    for(int i = 100000; i >= t; i--) {
      chmin(dp2[i], dp[i - t]);
    }
    for(int i = 100000; i >= 0; i--) {
      chmin(dp2[i], dp[i] + t);
    }
    dp = move(dp2);
  }
  int ret = inf;
  for(int i = 0; i < 100001; i++) {
    chmin(ret, max(dp[i], i));
  }
  cout << ret << "\n";
}