Problem:
D: スキャナー / Scanner
問題文
ここに $N$ 枚の紙がある。あなたは $3$ 台のスキャナーを並列に用いることで、
全ての紙をスキャンしたいと考えている。それぞれの紙はスキャンにかかる時間が決まっており、
$i$ 番目の紙をスキャンするのにかかる時間は $T_i$ である。
紙をスキャンする順番は任意であるが、$1$ 台のスキャナーで複数の紙を同時にスキャンすることはできない。
全ての紙のスキャンが終了し、スキャンを行っているスキャナーがなくなるまでにかかる時間を最小化しなさい。
入力
$N$
$T_1$
$T_2$
$T_3$
$\vdots$
$T_N$
制約
$1 \leq N \leq 50$
$1 \leq T_i \leq 50$
入力は全て整数
出力
答えを $1$ 行で出力してください．
サンプル
サンプル入力1
4
1
1
1
1
サンプル出力1
2
サンプル入力2
9
15
20
27
4
10
7
34
30
36
サンプル出力2
61
サンプル入力3
6
20
18
46
16
9
48
サンプル出力3
55

Submitted solutions:

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define FOR(i,s,t) for(int i = s; i< t ;i++)

#define SZ(x) (int)x.size()
using LL = long long; using ll = LL;
const int INF = 1e9; const LL LINF = 1e18;

#define MAXT 1005
ll N;
vector<int> T;
bool memo[55][MAXT][MAXT];

void dfs(int n, int x, int y,ll sum) {
	if (memo[n][x][y]) return;
	memo[n][x][y] = true;
	if (n == N) return;
	if (x + T[n] < MAXT) dfs(n + 1, x + T[n], y,sum + T[n]);
	if (y + T[n] < MAXT) dfs(n + 1, x, y + T[n],sum + T[n]);
	if (sum - x - y + T[n] < MAXT) dfs(n + 1, x, y, sum + T[n]);
}

void solve() {
	cin >> N;
	T.resize(N);
	for (auto& in : T) { cin >> in; }
	sort(T.begin(), T.end());
	reverse(T.begin(), T.end());
	dfs(0, 0, 0, 0);
	int sum = accumulate(T.begin(), T.end(), 0);

	ll ans = LINF;
	for (int i = 0; i < MAXT; i++) {
		for (int j = 0; j < MAXT; j++) {
			if (memo[N][i][j] == false) continue;
			ll t = -1;
			t = max({ i,j,sum - i - j });
			ans = min(ans, t);
		}
	}
	cout << ans << endl;
}


int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	solve();
	return 0;
}
accuracy: 1
time_ms: 160
memory_kb: 52640
final_rank: 15

code_snippet: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }

bool dp[2501][2501];

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int sum = 0;
    vector<int> t(n);
    for (int i = 0; i < n; ++i) {
        cin >> t[i];
        sum += t[i];
    }
    dp[0][0] = true;
    for (int i = 0; i < n; ++i) {
        for (int j = 2500; j >= 0; --j) {
            for (int k = 2500; k >= 0; --k) {
                if (dp[j][k]) {
                    dp[j + t[i]][k] = true;
                    dp[j][k + t[i]] = true;
                }
            }
        }
    }
    int res = sum;
    for (int i = 0; i <= 2500; ++i) {
        for (int j = 0; j <= 2500; ++j) {
            if (dp[i][j]) {
                res = min(res, max({i, j, sum - i - j}));
            }
        }
    }
    cout << res << endl;
}
accuracy: 1
time_ms: 150
memory_kb: 8484
final_rank: 8

code_snippet: #pragma region Macros
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define drep(i,n) for(ll i = (n)-1;i >= 0;i--)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'
#define overload2(_1, _2, name, ...) name
#define vec(type, name, ...) vector<type> name(__VA_ARGS__)
#define VEC(type, name, size)\
    vector<type> name(size);\
    IN(name)
#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define VV(type, name, h, w)\
    vector<vector<type>> name(h, vector<type>(w));\
    IN(name)
#define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)\
    vector<vector<vector<vector<type>>>> name(a, vector<vector<vector<type>>>(b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))
#define fi first
#define se second
#define all(c) begin(c), end(c)
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
using namespace std;
template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
#define si(c) (int)(c).size()
#define INT(...)\
    int __VA_ARGS__;\
    IN(__VA_ARGS__)
#define LL(...)\
    ll __VA_ARGS__;\
    IN(__VA_ARGS__)
#define STR(...)\
    string __VA_ARGS__;\
    IN(__VA_ARGS__)
#define CHR(...)\
    char __VA_ARGS__;\
    IN(__VA_ARGS__)
#define DBL(...)\
    double __VA_ARGS__;\
    IN(__VA_ARGS__)
int scan() { return getchar(); }
void scan(int &a) { cin >> a; }
void scan(long long &a) { cin >> a; }
void scan(char &a) { cin >> a; }
void scan(double &a) { cin >> a; }
void scan(string &a) { cin >> a; }
template <class T, class S> void scan(pair<T, S> &p) { scan(p.first), scan(p.second); }
template <class T> void scan(vector<T> &);
template <class T> void scan(vector<T> &a) {
    for(auto &i : a) scan(i);
}
template <class T> void scan(T &a) { cin >> a; }
void IN() {}
template <class Head, class... Tail> void IN(Head &head, Tail &... tail) {
    scan(head);
    IN(tail...);
}
template <class T, class S> inline bool chmax(T &a, S b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T, class S> inline bool chmin(T &a, S b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
vi iota(int n) {
    vi a(n);
    iota(all(a), 0);
    return a;
}
template <typename T> vi iota(vector<T> &a, bool greater = false) {
    vi res(a.size());
    iota(all(res), 0);
    sort(all(res), [&](int i, int j) {
        if(greater) return a[i] > a[j];
        return a[i] < a[j];
    });
    return res;
}
#define UNIQUE(x) sort(all(x)), x.erase(unique(all(x)), x.end())
template <class T> T POW(T x, int n) {
    T res = 1;
    for(; n; n >>= 1, x *= x)
        if(n & 1) res *= x;
    return res;
}
vector<pll> factor(ll x) {
    vector<pll> ans;
    for(ll i = 2; i * i <= x; i++)
        if(x % i == 0) {
            ans.push_back({i, 1});
            while((x /= i) % i == 0) ans.back().second++;
        }
    if(x != 1) ans.push_back({x, 1});
    return ans;
}
template <class T> vector<T> divisor(T x) {
    vector<T> ans;
    for(T i = 1; i * i <= x; i++)
        if(x % i == 0) {
            ans.pb(i);
            if(i * i != x) ans.pb(x / i);
        }
    return ans;
}
template <typename T> void zip(vector<T> &x) {
    vector<T> y = x;
    sort(all(y));
    for(int i = 0; i < x.size(); ++i) { x[i] = lb(y, x[i]); }
}
int popcount(ll x) { return __builtin_popcountll(x); }
int in() {
    int x;
    cin >> x;
    return x;
}
ll lin() {
    unsigned long long x;
    cin >> x;
    return x;
}
#define i128 __int128_t
#define ull unsigned long long int
template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
struct Setup_io {
    Setup_io() {
        ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
        cout << fixed << setprecision(15);
    }
} setup_io;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" :", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#define LOCAL
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#pragma endregion
//#include<atcoder/all>
//using namespace atcoder;
int main(){
    INT(n);
    VEC(int,a,n);
    vv(int,dp,n*51+1,n*51+1);
    dp[0][0] = 1;
    rep(i,n){
        vv(int,tmp,n*51+1,n*51+1);
        rep(j,n*51+1)rep(k,n*51+1){
            tmp[j][k] |= dp[j][k];
            if(j+a[i] <= n*51)tmp[j+a[i]][k] |= dp[j][k];
            if(k+a[i] <= n*51)tmp[j][k+a[i]] |= dp[j][k];
        }
        swap(dp,tmp);
    }
    int sum = 0;
    rep(i,n)sum += a[i];
    int ret = 100000;
    rep(j,n*51+1)rep(k,n*51+1){
        if(dp[j][k]){
            chmin(ret,max(j,max(k,sum-j-k)));
        }
    }
    cout << ret << endl;
    return 0;
}
accuracy: 1
time_ms: 870
memory_kb: 54308
final_rank: 18

code_snippet: // clang-format off
#include <bits/stdc++.h>
//#pragma GCC optimize ("-Ofast")
//#pragma GCC optimize ("unroll-loops")
#define int long long
#define endl '\n'
//#define double __float80
using namespace std;
#define fi first
#define se second
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; i++)
#define rep2(i, a, b) for (int i = (int)(a), i##_len=(b); i < i##_len; i++)
#define rep3(i, a, b) for (int i = (int)(a), i##_len=(b); i >= i##_len; i--)
#define rfor(i, a) for (auto &i: a)
#define all(obj) begin(obj), end(obj)
#define _max(x) *max_element(all(x))
#define _min(x) *min_element(all(x))
#define _sum(x) accumulate(all(x), 0LL)

const int MOD   = 1000000007;
// const int MOD    = 998244353;
 const int INF    = 1e18;
// const int INF    = 1e13 + 7;
// const int INF    = LLONG_MAX; // 9.2e18
const double EPS = 1e-20;
const double PI  = 3.14159265358979;
template <class T> using V = vector<T>;
template <class T> using VV = vector<vector<T>>;
template <class T> using VVV = vector<vector<vector<T>>>;
template <class T, class S>  using P = pair<T, S>;
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b;return true;}return false;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b;return true;}return false;}
int _ceil(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); }
template<class T> T chmod(T &a, T mod=MOD) {a =  a >= 0 ? a % mod : a - (mod * _ceil(a, mod)); return a;};
int _mod(int a, int mod=MOD) {return a >= 0 ? a % mod : a - (mod * _ceil(a, mod));}
double _mod(double a, int mod = MOD) { return fmod(a, mod) >= 0 ? fmod(a, mod) : fmod(a, mod) + mod; }
int _pow(int a, int b, int mod=MOD) {int res = 1;for (a %= mod; b; a = a * a % mod, b >>= 1)if (b & 1) res = res * a % mod;return res;}
vector<int> iota(int n){vector<int> ret(n); iota(begin(ret), end(ret), 0); return ret;}
struct mint {long long x;mint(long long x = 0): x((x % MOD + MOD) % MOD) {}mint operator-() const { return mint(-x); }mint &operator+=(const mint a) {if ((x += a.x) >= MOD) x -= MOD;return *this;}mint &operator-=(const mint a) {if ((x += MOD - a.x) >= MOD) x -= MOD;return *this;}mint &operator*=(const mint a) {(x *= a.x) %= MOD;return *this;}mint operator+(const mint a) const { return mint(*this) += a; }mint operator-(const mint a) const { return mint(*this) -= a; }mint operator*(const mint a) const { return mint(*this) *= a; }mint pow(long long n) const {mint ret(1), mul(x);while (n > 0) {if (n & 1) ret *= mul;mul *= mul;n >>= 1;}return ret;}mint inv() const {int a = x, b = MOD, u = 1, v = 0, t;while (b > 0) {t = a / b;swap(a -= t * b, b);swap(u -= t * v, v);}return mint(u);}mint &operator/=(const mint a) { return *this *= a.inv(); }mint operator/(const mint a) const { return mint(*this) /= a; }bool operator==(const mint a) const { return x == a.x; }bool operator!=(const mint a) const { return x != a.x; }friend istream &operator>>(istream &is, mint &a) { return is >> a.x; }friend ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }};
// clang-format on

signed main() {
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    int N;
    cin >> N;
    vector<int> T(N);
    for (int i = 0; i < N; i++) {
        cin >> T[i];
    }
    vector<vector<bool>> dp(2500 + 1, vector<bool>(2500 + 1));
    dp[0][0] = true;
    for (int i = 0; i < N; i++) {
        int t                       = T[i];
        vector<vector<bool>> dp_new = dp;
        for (int j = 0; j < 2500 + 1; j++) {
            for (int k = 0; k < 2500 + 1; k++) {
                if (!dp[j][k]) {
                    continue;
                }
                if (j + t <= 2500) {
                    dp_new[j + t][k] = true;
                }
                if (k + t <= 2500) {
                    dp_new[j][k + t] = true;
                }
            }
        }
        dp = dp_new;
    }
    int ans   = INF;
    int T_sum = _sum(T);
    for (int j = 0; j < 2500 + 1; j++) {
        for (int k = 0; k < 2500 + 1; k++) {
            if (dp[j][k]) {
                ans = min(ans, max({j, k, T_sum - j - k}));
            }
        }
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 370
memory_kb: 4936
final_rank: 14

code_snippet: #line 2 "src/cp-template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull  = unsigned long long;
using i128 = __int128_t;
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; }

#line 2 "src/utility/rep_itr.hpp"
template < class T > struct itr {
    T i, d;
    constexpr itr(const T i) noexcept : i(i), d(1) {}
    constexpr itr(const T i, const T d) noexcept : i(i), d(d) {}
    void operator++() noexcept { i += d; }
    constexpr int operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept {
        return d > 0 ? i < x.i : i > x.i;
    }
};

template < class T > struct rep {
    const itr< T > s, t;
    constexpr rep(const T t) noexcept : s(0), t(t) {}
    constexpr rep(const T s, const T t) noexcept : s(s), t(t) {}
    constexpr rep(const T s, const T t, const T d) noexcept : s(s, d), t(t, d) {}
    constexpr auto begin() const noexcept { return s; }
    constexpr auto end() const noexcept { return t; }
};

template < class T > struct revrep {
    const itr < T > s, t;
    constexpr revrep(const T t) noexcept : s(t - 1, -1), t(-1, -1) {}
    constexpr revrep(const T s, const T t) noexcept : s(t - 1, -1), t(s - 1, -1) {}
    constexpr revrep(const T s, const T t, const T d) noexcept : s(t - 1, -d), t(s - 1, -d) {}
    constexpr auto begin() const noexcept { return s; }
    constexpr auto end() const noexcept { return t; }
};
#line 2 "src/utility/io.hpp"
namespace scanner {
    struct sca {
        template < class T > operator T() {
            T s; cin >> s; return s;
        }
    };
    struct vec {
        int n;
        vec(int n) : n(n) {}
        template < class T > operator vector< T >() {
            vector< T > v(n);
            for(T& x : v) cin >> x;
            return v;
        }
    };
    struct mat {
        int h,w;
        mat(int h, int w) : h(h), w(w) {}
        template < class T > operator vector< vector< T > >() {
            vector m(h, vector< T >(w));
            for(vector< T >& v : m) for(T& x : v) cin >> x;
            return m;
        }
    };
    struct speedup {
        speedup() {
            cin.tie(0);
            ios::sync_with_stdio(0);
        }
    } su;
}
scanner::sca in() { return scanner::sca(); }
scanner::vec in(int n) { return scanner::vec(n); }
scanner::mat in(int h, int w) { return scanner::mat(h, w); }

namespace printer {
    void precision(int d) {
        cout << fixed << setprecision(d);
    }
    void flush() {
        cout.flush();
    }
}
int print() { cout << '\n'; return 0; }
template < class head, class... tail > int print(head&& h, tail&&... t) {
    cout << h; if(sizeof...(tail)) cout << ' ';
    return print(forward<tail>(t)...);
}
template < class T > int print(vector< T > a, char sep = ' ') {
    int n = a.size();
    for(int i : rep(n)) cout << a[i] << (i != n - 1 ? sep : '\n');
    return 0;
}
template < class T > int print(vector< vector< T > > a) {
    if(a.empty()) return 0;
    int h = a.size(), w = a[0].size();
    for(int i : rep(h)) for(int j : rep(w)) cout << a[i][j] << (j != w - 1 ? ' ' : '\n');
    return 0;
}
#line 2 "src/utility/key_val.hpp"
template < class K, class V >
struct key_val {
    K key; V val;
    key_val() {}
    key_val(K key, V val) : key(key), val(val) {}
};
#line 2 "src/utility/vec_op.hpp"
template < class T >
key_val< int, T > max_of(const vector< T >& a) {
    int i = max_element(a.begin(), a.end()) - a.begin();
    return {i, a[i]};
}

template < class T >
key_val< int, T > min_of(const vector< T >& a) {
    int i = min_element(a.begin(), a.end()) - a.begin();
    return {i, a[i]};
}

template < class T >
T sum_of(const vector< T >& a) {
    T sum = 0;
    for(const T x : a) sum += x;
    return sum;
}

template < class T >
vector<ll> freq_of(const vector< T >& a, T L, T R) {
    vector<ll> res(R - L);
    for(const T x : a) res[x - L]++;
    return res;
}

template < class T >
vector<ll> freq_of(const vector< T >& a, T R) {
    return freq_of(a, T(0), R);
}

template < class T >
struct prefix_sum {
    vector< T > s;
    prefix_sum(const vector< T >& a) : s(a) {
        s.insert(s.begin(), T(0));
        for(int i : rep(a.size())) s[i + 1] += s[i];
    }
    // [L, R)
    T sum(int L, int R) {
        return s[R] - s[L];
    }
};
#line 2 "A.cpp"

int main() {
    int N = in();
    vector<int> T = in(N);
    int SUM = sum_of(T);
    auto h = [&](int x, int y) { return x * SUM + y; };
    vector<int> dp((SUM + 1) * (SUM + 1), 0);
    dp[h(0, 0)] = 1;
    for(int i : rep(N)) {
        vector<int> nt = dp;
        for(int x = 0; x <= SUM; x++) {
            for(int y = 0; y <= SUM; y++) {
                if(x + T[i] <= SUM) nt[h(x + T[i], y)] |= dp[h(x, y)];
                if(y + T[i] <= SUM) nt[h(x, y + T[i])] |= dp[h(x, y)];
            }
        }
        swap(dp, nt);
    }

    int ans = SUM;
    for(int x = 0; x <= SUM; x++) {
        for(int y = 0; y <= SUM; y++) {
            if(dp[h(x, y)]) {
                chmin(ans, max({x, y, SUM - (x + y)}));
            }
        }
    }
    print(ans);
}
accuracy: 1
time_ms: 410
memory_kb: 45596
final_rank: 16

code_snippet: #include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 28;
int main() {
  int N, T[50];
  static int dp[2][2501][2501];
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> T[i];
  }
  fill_n(**dp, 2 * 2501 * 2501, INF);
  dp[1][0][0] = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 2500; j >= 0; j--) {
      for (int k = 2500; k >= 0; k--) {
        if (j >= T[i])
          dp[i & 1][j][k] = min(dp[i & 1][j][k], dp[(i + 1) & 1][j - T[i]][k]);
        if (k >= T[i])
          dp[i & 1][j][k] = min(dp[i & 1][j][k], dp[(i + 1) & 1][j][k - T[i]]);
        dp[i & 1][j][k] = min(dp[i & 1][j][k], dp[(i + 1) & 1][j][k] + T[i]);
      }
    }
    fill_n(*dp[(i + 1) & 1], 2501 * 2501, INF);
  }
  int ret = INF;
  for (int i = 0; i <= 2500; i++) {
    for (int j = 0; j <= 2500; j++) {
      ret = min(ret, max(i, max(j, dp[(N + 1) & 1][i][j])));
    }
  }
  cout << ret << endl;
}
accuracy: 1
time_ms: 900
memory_kb: 51984
final_rank: 19

code_snippet: #include <iostream>
#include <string.h>
#include <queue>
using namespace std;

int dp[2501][2501];

int main() {
	int n;
	int s1=0;
	cin>>n;
	memset(dp,0,sizeof(dp));
	dp[0][0]=1;
	for(int i=0;i<n;i++){
		int t;
		cin>>t;
		
		for(int x=s1;x>=0;x--){
			for(int y=s1;y>=0;y--){
				if(dp[x][y]==1){
					dp[x+t][y]=1;
					dp[x][y+t]=1;
				}
			}
		}
		s1+=t;;
	}
	int ans=s1;
	for(int x=0;x<=s1;x++){
		for(int y=0;y<=s1;y++){
			if(dp[x][y]==1){
				int z=s1-x-y;
				int t1=max(x,y);
				int t2=max(t1,z);
				if(t2<ans)ans=t2;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 27548
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    int n, v, s = 0;
    cin >> n;
    bool dp[901][901] = {};
    dp[0][0] = true;
    while(n--){
        cin >> v;
        s += v;
        for(int j = 900; j >= 0; j--){
            for(int k = 900; k >= 0; k--){
                if(j + v <= 900)dp[j + v][k] |= dp[j][k];
                if(k + v <= 900)dp[j][k + v] |= dp[j][k];
            }
        }
    }
    int ans = s;
    for(int j = 900; j >= 0; j--){
        for(int k = 900; k >= 0; k--){
            if(dp[j][k])ans = min(ans, max({s - j - k, j, k}));
        }
    }
    cout << ans << '\n';
}
accuracy: 1
time_ms: 30
memory_kb: 4208
final_rank: 1

code_snippet: #include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1000000007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

signed main(){
	cout<<fixed<<setprecision(10);
	
	constexpr int MAX = 51;
	int N;
	vector<int> t;
	vector<vector<bool>> dp;
	int ans = INF, sum = 0;
	
	cin>>N;
	
	dp.resize(N*MAX, vector<bool>(N*MAX));
	t.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>t[i];
		sum += t[i];
	}
	
	dp[0][0] = true;
	
	for(int i = 0; i < N; i++){
		for(int j = dp.size()-1; j >= 0; j--){
			for(int k = dp[j].size()-1; k >= 0; k--){
				if(!dp[j][k]) continue;
				if(j+t[i] < dp.size()) dp[j+t[i]][k] = true;
				if(k+t[i] < dp[j].size()) dp[j][k+t[i]] = true;
			}
		}
	}
	
	for(int i = 0; i < dp.size(); i++){
		for(int j = 0; j < dp.size(); j++){
			if(!dp[i][j]) continue;
			ans = min(ans, max({i, j, sum - i - j}));
		}
	}
	
	cout<<ans<<endl;
	
	return 0;
}
accuracy: 1
time_ms: 260
memory_kb: 4428
final_rank: 12

code_snippet: #include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
#define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE
#define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

namespace templates{
    ll modpow(ll x, ll b,ll mod=MOD){
        ll res = 1;
        while(b){
            if(b&1)res = res * x % mod;
            x = x * x % mod;
            b>>=1;
        }
        return res;
    }

    ll modinv(ll x){
        return modpow(x, MOD-2);
    }

    bool was_output = false;

    void print();
    template <class t> void print(const vector<t> &);
    template <class t, class u> void print(const pair<t, u> &);
    template <class t> void print(const t&);
    template <class Head, class... Tail> void print(const Head&, const Tail&...);

    template <class t> void println(const vector<vector<t>>&);
    template <class t> void println(const vector<t>&);
    template <class t> void println(const t&);
    template <class Head, class... Tail> void println(const Head&, const Tail&...);
    void println();
    void newline();

    void print(){
        return;
    }

    template <class t>
    void print(const vector<t>&x){
        for(const t&i:x)print(i);
    }
    template <class t, class u>
    void print(const pair<t,u>&p){
        print(p.first);
        print(p.second);
    }
    template <class t>
    void print(const t&x){
        if(was_output)cout<<" ";
        cout<<x;
        was_output = true;
    }
    template <class Head, class... Tail>
    void print(const Head&head,const Tail&...tail){
        print(head);
        print(tail...);
    }

    template<class t>
    void println(const vector<vector<t>>&x){
        for(vector<t> i:x)println(i);
    }
    template<class t>
    void println(const vector<t>&x){
        for(const t&i:x)print(i);
        println();
    }
    template <class t>
    void println(const t&x){
        print(x);
        println();
    }
    void println(){
        if(was_output){
            cout << endl;
            was_output = false;
        }
    }
    template <class Head, class... Tail>
    void println(const Head&head,const Tail&...tail){
        print(head);
        println(tail...);
    }

    void newline(){
        was_output = true;
        println();
    }

    template<class t>
    istream& operator>>(istream&is, vector<t>&x){
        for(auto &i:x)is >> i;
        return is;
    }

    template<class t, class u>
    istream& operator>>(istream&is, pair<t, u>&x){
        is >> x.first >> x.second;
        return is;
    }

    template<class t>
    ostream& operator<<(ostream&os, vector<t> &v){
        os << "{";
        for(t &i:v){
            os << i << ", ";
        }
        os << "}";
        return os;
    }

    template<class t = long long>
    t in(){
        t res; cin >> res; return res;
    }

    template<class t>
    vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
        sort(line.begin(),line.end(),comp);
        return line;
    }

    template<class t>
    vector<t> reversed(vector<t> line){
        reverse(line.begin(),line.end());
        return line;
    }
    string reversed(string str){
        reverse(str.begin(),str.end());
        return str;
    }

    long long gcd(long long a,long long b){
        while(b){
            a %= b;
            swap(a,b);
        }
        return a;
    }

    long long lcm(long long a,long long b){
        return a / gcd(a,b) * b;
    }

    class output_initializer{
    public:
        output_initializer(){
            ios::sync_with_stdio(false);
            cin.tie(nullptr);
            cout << setprecision(20);
        }
    };output_initializer OUTPUT_INITIALIZER_INSTANCE = output_initializer();
}

using namespace templates;

int func(){
    int n = in();
    const int N = 2501;
    vvector<char> dp1(N,vector<char>(N,false));
    dp1[0][0] = true;
    int sum = 0;
    rep(_,n){
        vvector<char> dp2(N,vector<char>(N,false));
        int v = in();
        sum += v;
        rep(i,N){
            rep(j,N){
                if(not dp1[i][j])continue;
                dp2[i][j] = true;
                dp2[i+v][j] = true;
                dp2[i][j+v] = true;
            }
        }
        swap(dp1,dp2);
    }
    int res = 10000000;
    rep(i,N){
        rep(j,N){
            if(dp1[i][j]){
                chmin(res,max({i,j,sum-i-j}));
            }
        }
    }
    return res;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    println(func());
    return 0;
}
accuracy: 1
time_ms: 220
memory_kb: 15512
final_rank: 13

code_snippet: #include<bits/stdc++.h>

#define int ll
#define rep(i, N) for(int i = 0; i < N; i++)
#define per(i, N) for(int i = N-1; i >= 0; i--)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define TakAo(ans) ans ? cout << "Takahashi\n" : cout << "Aoki\n"
#define YesNo(ans) ans ? cout << "Yes\n" : cout << "No\n"
#define yesno(ans) ans ? cout << "yes\n" : cout << "no\n"
#define YESNO(ans) ans ? cout << "YES\n" : cout << "NO\n"
#define equal(f1, f2) (abs(f1 - f2) <= EPS)
#define endl '\n'
#define fi first
#define se second
#define mkpr make_pair
#define mktpl make_tuple

using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using Tpl = tuple<int, int, int>;
using vvi = vector<vector<int>>;
using vvvec = vector<vector<vector<int>>>;

const ld EPS = 1e-8;
const ld Pi = acos(-1);
const ll INF = 1e9+10;
const int MOD = 998244353;
//const int MOD = 1e4+7;
const int NIL = -1;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, -1, 0, 1};

ll cel(ll a, ll b){ return (a + b - 1) / b; }
ll Gcd(ll a, ll b){ return b ? Gcd(b, a % b) : a; }
ll Lcm(ll a, ll b){ return a / Gcd(a, b) * b; }
ll sq(ll a){ return a * a; }
ll cube(ll a){ return a * a * a; }
ll powi(ll a, ll b){ ll res = 1; rep(i, b) res *= a; return res; }
template<class T> bool chmin(T &a, T b){ if(a > b){ a = b; return 1;} return 0; }
template<class T> bool chmax(T &a, T b){ if(a < b){ a = b; return 1;} return 0; }

void Main(){
    int N, T[50], Tsum = 0; cin >> N;

    rep(i, N){
        cin >> T[i];
        Tsum += T[i];
    }
    
    const int smax = 1000;

    bool dp[2][smax][smax] = {};
    dp[1][0][0] = dp[1][T[0]][0] = dp[1][0][T[0]] = 1;

    for(int i = 1; i < N; i++){
        rep(j, smax){
            rep(k, smax){
                if(dp[i & 1][j][k]){
                    dp[i & 1][j][k] = 0;
                    dp[(i+1) & 1][j][k] = 1;
                    if(j + T[i] < smax) dp[(i+1) & 1][j + T[i]][k] = 1;
                    if(k + T[i] < smax) dp[(i+1) & 1][j][k + T[i]] = 1;
                }
            }
        }
    }

    ll ans = INF;
    rep(i, smax){
        rep(j, smax){
            if(dp[N & 1][i][j]){
                ans = min(max(i, max(j, Tsum - i - j)), ans);
            }
        }
    }

    cout << ans << endl;
}

signed main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 5400
final_rank: 2

code_snippet: #include<bits/stdc++.h>

#define int ll
#define rep(i, N) for(int i = 0; i < N; i++)
#define per(i, N) for(int i = N-1; i >= 0; i--)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define TakAo(ans) ans ? cout << "Takahashi\n" : cout << "Aoki\n"
#define YesNo(ans) ans ? cout << "Yes\n" : cout << "No\n"
#define yesno(ans) ans ? cout << "yes\n" : cout << "no\n"
#define YESNO(ans) ans ? cout << "YES\n" : cout << "NO\n"
#define equal(f1, f2) (abs(f1 - f2) <= EPS)
#define endl '\n'
#define fi first
#define se second
#define mkpr make_pair
#define mktpl make_tuple

using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using Tpl = tuple<int, int, int>;
using vvi = vector<vector<int>>;
using vvvec = vector<vector<vector<int>>>;

const ld EPS = 1e-8;
const ld Pi = acos(-1);
const ll INF = 1e9+10;
const int MOD = 998244353;
//const int MOD = 1e4+7;
const int NIL = -1;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, -1, 0, 1};

ll cel(ll a, ll b){ return (a + b - 1) / b; }
ll Gcd(ll a, ll b){ return b ? Gcd(b, a % b) : a; }
ll Lcm(ll a, ll b){ return a / Gcd(a, b) * b; }
ll sq(ll a){ return a * a; }
ll cube(ll a){ return a * a * a; }
ll powi(ll a, ll b){ ll res = 1; rep(i, b) res *= a; return res; }
template<class T> bool chmin(T &a, T b){ if(a > b){ a = b; return 1;} return 0; }
template<class T> bool chmax(T &a, T b){ if(a < b){ a = b; return 1;} return 0; }

void Main(){
    int N, T[50], Tsum = 0; cin >> N;

    rep(i, N){
        cin >> T[i];
        Tsum += T[i];
    }
    
    const int smax = 1000;

    bool dp[2][smax][smax] = {};
    dp[1][0][0] = dp[1][T[0]][0] = dp[1][0][T[0]] = 1;

    for(int i = 1; i < N; i++){
        rep(j, smax){
            rep(k, smax){
                if(j + k > smax) break;
                if(dp[i & 1][j][k]){
                    dp[(i+1) & 1][j][k] = 1;
                    if(j + T[i] < smax) dp[(i+1) & 1][j + T[i]][k] = 1;
                    if(k + T[i] < smax) dp[(i+1) & 1][j][k + T[i]] = 1;
                    dp[i & 1][j][k] = 0;
                }
            }
        }
    }

    ll ans = INF;
    rep(i, smax){
        rep(j, smax){
            if(dp[N & 1][i][j]){
                ans = min(max(i, max(j, Tsum - i - j)), ans);
            }
        }
    }

    cout << ans << endl;
}

signed main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}
accuracy: 0.35714285714285715
time_ms: 30
memory_kb: 5404
final_rank: 20

code_snippet: #include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1000000007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

signed main(){
	cout<<fixed<<setprecision(10);
	
	constexpr int MAX = 51;
	int N;
	vector<int> t;
	vector<vector<bool>> dp;
	int ans = INF, sum = 0;
	
	cin>>N;
	
	dp.resize(N*MAX, vector<bool>(N*MAX));
	t.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>t[i];
		sum += t[i];
	}
	
	dp[0][0] = true;
	
	for(int i = 0; i < N; i++){
		for(int j = dp.size()-1; j >= 0; j--){
			for(int k = dp[j].size()-1; k >= 0; k--){
				if(!dp[j][k]) continue;
				if(j+t[i] < dp.size()) dp[j+t[i]][k] = true;
				if(k+t[i] < dp[j].size()) dp[j][k+t[i]] = true;
			}
		}
	}
	
	for(int i = 0; i < dp.size(); i++){
		for(int j = 0; j < dp.size(); j++){
			if(!dp[i][j]) continue;
			ans = min(ans, max({i, j, sum - i - j}));
		}
	}
	
	cout<<ans<<endl;
	
	return 0;
}
accuracy: 1
time_ms: 250
memory_kb: 4412
final_rank: 11

code_snippet: #line 2 "/home/yuruhiya/programming/library/template/template.cpp"
#include <bits/stdc++.h>
#line 4 "/home/yuruhiya/programming/library/template/constants.cpp"
#include <string_view>
#line 7 "/home/yuruhiya/programming/library/template/constants.cpp"

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rfor(i, m, n) for (int i = (m); i >= (n); --i)
#define unless(c) if (!(c))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define range_it(a, l, r) (a).begin() + (l), (a).begin() + (r)

using namespace std;
using ll = long long;
using LD = long double;
using VB = vector<bool>;
using VVB = vector<VB>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VS = vector<string>;
using VD = vector<LD>;
using PII = pair<int, int>;
using VP = vector<PII>;
using PLL = pair<ll, ll>;
using VPL = vector<PLL>;
template <class T> using PQ = priority_queue<T>;
template <class T> using PQS = priority_queue<T, vector<T>, greater<T>>;
constexpr int inf = 1000000000;
constexpr long long inf_ll = 1000000000000000000ll, MOD = 1000000007;
constexpr long double PI = 3.14159265358979323846, EPS = 1e-12;
namespace CharacterClass {
	constexpr string_view
	    digit = "0123456789",
	    xdigit = "0123456789ABCDEFabcdef", lower = "abcdefghijklmnopqrstuvwxyz",
	    upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
	    alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
	    alnum = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
	    word = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz",
	    punct = R"(!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~)",
	    graph =
	        R"(!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~)",
	    print =
	        R"( !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~)",
	    blank = " \t", space = " \t\n\r\f\v";
}  // namespace CharacterClass
#line 7 "/home/yuruhiya/programming/library/template/Input.cpp"
using namespace std;

#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#define putchar_unlocked _putchar_nolock
#define fwrite_unlocked fwrite
#define fflush_unlocked fflush
#endif
class Scanner {
	static int gc() {
		return getchar_unlocked();
	}
	static char next_char() {
		char c;
		read(c);
		return c;
	}
	template <class T> static void read(T& v) {
		cin >> v;
	}
	static void read(char& v) {
		while (isspace(v = gc()))
			;
	}
	static void read(bool& v) {
		v = next_char() != '0';
	}
	static void read(string& v) {
		v.clear();
		for (char c = next_char(); !isspace(c); c = gc()) v += c;
	}
	static void read(int& v) {
		v = 0;
		bool neg = false;
		char c = next_char();
		if (c == '-') {
			neg = true;
			c = gc();
		}
		for (; isdigit(c); c = gc()) v = v * 10 + (c - '0');
		if (neg) v = -v;
	}
	static void read(long long& v) {
		v = 0;
		bool neg = false;
		char c = next_char();
		if (c == '-') {
			neg = true;
			c = gc();
		}
		for (; isdigit(c); c = gc()) v = v * 10 + (c - '0');
		if (neg) v = -v;
	}
	static void read(double& v) {
		v = 0;
		double dp = 1;
		bool neg = false, after_dp = false;
		char c = next_char();
		if (c == '-') {
			neg = true;
			c = gc();
		}
		for (; isdigit(c) || c == '.'; c = gc()) {
			if (c == '.') {
				after_dp = true;
			} else if (after_dp) {
				v += (c - '0') * (dp *= 0.1);
			} else {
				v = v * 10 + (c - '0');
			}
		}
		if (neg) v = -v;
	}
	static void read(long double& v) {
		v = 0;
		long double dp = 1;
		bool neg = false, after_dp = false;
		char c = next_char();
		if (c == '-') {
			neg = true;
			c = gc();
		}
		for (; isdigit(c) || c == '.'; c = gc()) {
			if (c == '.') {
				after_dp = true;
			} else if (after_dp) {
				v += (c - '0') * (dp *= 0.1);
			} else {
				v = v * 10 + (c - '0');
			}
		}
		if (neg) v = -v;
	}
	template <class T, class U> static void read(pair<T, U>& v) {
		read(v.first);
		read(v.second);
	}
	template <class T> static void read(vector<T>& v) {
		for (auto& e : v) read(e);
	}
	template <size_t N = 0, class T> static void read_tuple_impl(T& v) {
		if constexpr (N < tuple_size_v<T>) {
			read(get<N>(v));
			read_tuple_impl<N + 1>(v);
		}
	}
	template <class... T> static void read(tuple<T...>& v) {
		read_tuple_impl(v);
	}
	struct ReadVectorHelper {
		size_t n;
		ReadVectorHelper(size_t _n) : n(_n) {}
		template <class T> operator vector<T>() {
			vector<T> v(n);
			read(v);
			return v;
		}
	};
	struct Read2DVectorHelper {
		size_t n, m;
		Read2DVectorHelper(const pair<size_t, size_t>& nm) : n(nm.first), m(nm.second) {}
		template <class T> operator vector<vector<T>>() {
			vector<vector<T>> v(n, vector<T>(m));
			read(v);
			return v;
		}
	};

public:
	string read_line() const {
		string v;
		for (char c = gc(); c != '\n' && c != '\0'; c = gc()) v += c;
		return v;
	}
	template <class T> T read() const {
		T v;
		read(v);
		return v;
	}
	template <class T> vector<T> read_vector(size_t n) const {
		vector<T> a(n);
		read(a);
		return a;
	}
	template <class T> operator T() const {
		return read<T>();
	}
	int operator--(int) const {
		return read<int>() - 1;
	}
	ReadVectorHelper operator[](size_t n) const {
		return ReadVectorHelper(n);
	}
	Read2DVectorHelper operator[](const pair<size_t, size_t>& nm) const {
		return Read2DVectorHelper(nm);
	}
	void operator()() const {}
	template <class H, class... T> void operator()(H&& h, T&&... t) const {
		read(h);
		operator()(forward<T>(t)...);
	}

private:
	template <template <class...> class, class...> struct Multiple;
	template <template <class...> class V, class Head, class... Tail>
	struct Multiple<V, Head, Tail...> {
		template <class... Args> using vec = V<vector<Head>, Args...>;
		using type = typename Multiple<vec, Tail...>::type;
	};
	template <template <class...> class V> struct Multiple<V> { using type = V<>; };
	template <class... T> using multiple_t = typename Multiple<tuple, T...>::type;
	template <size_t N = 0, class T> void multiple_impl(T& t) const {
		if constexpr (N < tuple_size_v<T>) {
			auto& vec = get<N>(t);
			using V = typename remove_reference_t<decltype(vec)>::value_type;
			vec.push_back(read<V>());
			multiple_impl<N + 1>(t);
		}
	}

public:
	template <class... T> auto multiple(size_t h) const {
		multiple_t<T...> result;
		while (h--) multiple_impl(result);
		return result;
	}
} in;
#define inputs(T, ...) \
	T __VA_ARGS__;     \
	in(__VA_ARGS__)
#define ini(...) inputs(int, __VA_ARGS__)
#define inl(...) inputs(long long, __VA_ARGS__)
#define ins(...) inputs(string, __VA_ARGS__)
#line 7 "/home/yuruhiya/programming/library/template/Output.cpp"
#include <charconv>
#line 10 "/home/yuruhiya/programming/library/template/Output.cpp"
using namespace std;

struct BoolStr {
	const char *t, *f;
	BoolStr(const char* _t, const char* _f) : t(_t), f(_f) {}
} Yes("Yes", "No"), yes("yes", "no"), YES("YES", "NO"), Int("1", "0");
struct DivStr {
	const char *d, *l;
	DivStr(const char* _d, const char* _l) : d(_d), l(_l) {}
} spc(" ", "\n"), no_spc("", "\n"), end_line("\n", "\n"), comma(",", "\n"),
    no_endl(" ", "");
class Output {
	BoolStr B{Yes};
	DivStr D{spc};

public:
	void put(int v) const {
		char buf[12]{};
		if (auto [ptr, e] = to_chars(begin(buf), end(buf), v); e == errc{}) {
			fwrite(buf, sizeof(char), ptr - buf, stdout);
		} else {
			assert(false);
		}
	}
	void put(long long v) const {
		char buf[21]{};
		if (auto [ptr, e] = to_chars(begin(buf), end(buf), v); e == errc{}) {
			fwrite(buf, sizeof(char), ptr - buf, stdout);
		} else {
			assert(false);
		}
	}
	void put(bool v) const {
		put(v ? B.t : B.f);
	}
	void put(vector<bool>::reference v) const {
		put(v ? B.t : B.f);
	}
	void put(char v) const {
		putchar_unlocked(v);
	}
	void put(const char* v) const {
		fwrite_unlocked(v, 1, strlen(v), stdout);
	}
	void put(double v) const {
		printf("%.20f", v);
	}
	void put(long double v) const {
		printf("%.20Lf", v);
	}
	template <class T> void put(const T& v) const {
		cout << v;
	}
	template <class T, class U> void put(const pair<T, U>& v) const {
		put(v.first);
		put(D.d);
		put(v.second);
	}
	template <class InputIterater>
	void put_range(const InputIterater& begin, const InputIterater& end) const {
		for (InputIterater i = begin; i != end; ++i) {
			if (i != begin) put(D.d);
			put(*i);
		}
	}
	template <class T> void put(const vector<T>& v) const {
		put_range(v.begin(), v.end());
	}
	template <class T, size_t N> void put(const array<T, N>& v) const {
		put_range(v.begin(), v.end());
	}
	template <class T> void put(const vector<vector<T>>& v) const {
		for (size_t i = 0; i < v.size(); ++i) {
			if (i) put(D.l);
			put(v[i]);
		}
	}

	Output() = default;
	Output(const BoolStr& _boolstr, const DivStr& _divstr) : B(_boolstr), D(_divstr) {}
	Output& operator()() {
		put(D.l);
		return *this;
	}
	template <class H> Output& operator()(H&& h) {
		put(h);
		put(D.l);
		return *this;
	}
	template <class H, class... T> Output& operator()(H&& h, T&&... t) {
		put(h);
		put(D.d);
		return operator()(forward<T>(t)...);
	}
	template <class InputIterator>
	Output& range(const InputIterator& begin, const InputIterator& end) {
		put_range(begin, end);
		put(D.l);
		return *this;
	}
	template <class T> Output& range(const T& a) {
		range(a.begin(), a.end());
		return *this;
	}
	template <class... T> void exit(T&&... t) {
		operator()(forward<T>(t)...);
		std::exit(EXIT_SUCCESS);
	}
	Output& flush() {
		fflush_unlocked(stdout);
		return *this;
	}
	Output& set(const BoolStr& b) {
		B = b;
		return *this;
	}
	Output& set(const DivStr& d) {
		D = d;
		return *this;
	}
	Output& set(const char* t, const char* f) {
		B = BoolStr(t, f);
		return *this;
	}
} out;
#line 3 "/home/yuruhiya/programming/library/template/Step.cpp"
using namespace std;

template <class T> struct Step {
	using value_type = T;

	class iterator {
		value_type a, b, c;

	public:
		constexpr iterator() : a(value_type()), b(value_type()), c(value_type()) {}
		constexpr iterator(value_type _b, value_type _c, value_type _s)
		    : a(_b), b(_c), c(_s) {}
		constexpr iterator& operator++() {
			--b;
			a += c;
			return *this;
		}
		constexpr iterator operator++(int) {
			iterator tmp = *this;
			--b;
			a += c;
			return tmp;
		}
		constexpr const value_type& operator*() const {
			return a;
		}
		constexpr const value_type* operator->() const {
			return &a;
		}
		constexpr bool operator==(const iterator& i) const {
			return b == i.b;
		}
		constexpr bool operator!=(const iterator& i) const {
			return !(b == i.b);
		}
		constexpr value_type start() const {
			return a;
		}
		constexpr value_type size() const {
			return b;
		}
		constexpr value_type step() const {
			return c;
		}
	};
	constexpr Step(value_type b, value_type c, value_type s) : be(b, c, s) {}
	constexpr iterator begin() const {
		return be;
	}
	constexpr iterator end() const {
		return en;
	}
	constexpr value_type start() const {
		return be.start();
	}
	constexpr value_type size() const {
		return be.size();
	}
	constexpr value_type step() const {
		return be.step();
	}
	constexpr value_type sum() const {
		return start() * size() + step() * (size() * (size() - 1) / 2);
	}
	operator vector<value_type>() const {
		return to_a();
	}
	auto to_a() const {
		vector<value_type> result;
		result.reserve(size());
		for (auto i : *this) {
			result.push_back(i);
		}
		return result;
	}

private:
	iterator be, en;
};
template <class T> constexpr auto step(T a) {
	return Step<T>(0, a, 1);
}
template <class T> constexpr auto step(T a, T b) {
	return Step<T>(a, b - a, 1);
}
template <class T> constexpr auto step(T a, T b, T c) {
	return Step<T>(a, a < b ? (b - a - 1) / c + 1 : 0, c);
}
#line 8 "/home/yuruhiya/programming/library/template/Ruby.cpp"
using namespace std;

template <class F> struct Callable {
	F func;
	Callable(const F& f) : func(f) {}
};
template <class T, class F> auto operator|(const T& v, const Callable<F>& c) {
	return c.func(v);
}

struct Sort_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			sort(begin(v), end(v), f);
			return v;
		});
	}
	template <class T> friend auto operator|(T v, [[maybe_unused]] const Sort_impl& c) {
		sort(begin(v), end(v));
		return v;
	}
} Sort;
struct SortBy_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			sort(begin(v), end(v),
			     [&](const auto& i, const auto& j) { return f(i) < f(j); });
			return v;
		});
	}
} SortBy;
struct RSort_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			sort(rbegin(v), rend(v), f);
			return v;
		});
	}
	template <class T> friend auto operator|(T v, [[maybe_unused]] const RSort_impl& c) {
		sort(rbegin(v), rend(v));
		return v;
	}
} RSort;
struct RSortBy_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			sort(begin(v), end(v),
			     [&](const auto& i, const auto& j) { return f(i) > f(j); });
			return v;
		});
	}
} RSortBy;
struct Reverse_impl {
	template <class T> friend auto operator|(T v, const Reverse_impl& c) {
		reverse(begin(v), end(v));
		return v;
	}
} Reverse;
struct Unique_impl {
	template <class T> friend auto operator|(T v, const Unique_impl& c) {
		v.erase(unique(begin(v), end(v), end(v)));
		return v;
	}
} Unique;
struct Uniq_impl {
	template <class T> friend auto operator|(T v, const Uniq_impl& c) {
		sort(begin(v), end(v));
		v.erase(unique(begin(v), end(v)), end(v));
		return v;
	}
} Uniq;
struct Rotate_impl {
	auto operator()(int&& left) {
		return Callable([&](auto v) {
			int s = static_cast<int>(size(v));
			assert(-s <= left && left <= s);
			if (0 <= left) {
				rotate(begin(v), begin(v) + left, end(v));
			} else {
				rotate(begin(v), end(v) + left, end(v));
			}
			return v;
		});
	}
} Rotate;
struct Max_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) { return *max_element(begin(v), end(v), f); });
	}
	template <class T> friend auto operator|(T v, const Max_impl& c) {
		return *max_element(begin(v), end(v));
	}
} Max;
struct Min_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) { return *min_element(begin(v), end(v), f); });
	}
	template <class T> friend auto operator|(T v, const Min_impl& c) {
		return *min_element(begin(v), end(v));
	}
} Min;
struct MaxPos_impl {
	template <class T> friend auto operator|(T v, const MaxPos_impl& c) {
		return max_element(begin(v), end(v)) - begin(v);
	}
} MaxPos;
struct MinPos_impl {
	template <class T> friend auto operator|(T v, const MinPos_impl& c) {
		return min_element(begin(v), end(v)) - begin(v);
	}
} MinPos;
struct MaxBy_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			auto max_it = begin(v);
			auto max_val = f(*max_it);
			for (auto it = next(begin(v)); it != end(v); ++it) {
				if (auto val = f(*it); max_val < val) {
					max_it = it;
					max_val = val;
				}
			}
			return *max_it;
		});
	}
} MaxBy;
struct MinBy_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			auto min_it = begin(v);
			auto min_val = f(*min_it);
			for (auto it = next(begin(v)); it != end(v); ++it) {
				if (auto val = f(*it); min_val > val) {
					min_it = it;
					min_val = val;
				}
			}
			return *min_it;
		});
	}
} MinBy;
struct MaxOf_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			auto max_val = f(*begin(v));
			for (auto it = next(begin(v)); it != end(v); ++it) {
				if (auto val = f(*it); max_val < val) {
					max_val = val;
				}
			}
			return max_val;
		});
	}
} MaxOf;
struct MinOf_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			auto min_val = f(*begin(v));
			for (auto it = next(begin(v)); it != end(v); ++it) {
				if (auto val = f(*it); min_val > val) {
					min_val = val;
				}
			}
			return min_val;
		});
	}
} MinOf;
struct Count_impl {
	template <class V> auto operator()(const V& val) {
		return Callable([&](auto v) { return count(begin(v), end(v), val); });
	}
} Count;
struct CountIf_impl {
	template <class F> auto operator()(const F& f) {
		return Callable([&](auto v) { return count_if(begin(v), end(v), f); });
	}
} CountIf;
struct Index_impl {
	template <class V> auto operator()(const V& val) {
		return Callable([&](auto v) -> optional<int> {
			auto result = find(begin(v), end(v), val);
			return result != end(v) ? optional(result - begin(v)) : nullopt;
		});
	}
} Index;
struct IndexIf_impl {
	template <class F> auto operator()(const F& f) {
		return Callable([&](auto v) -> optional<int> {
			auto result = find_if(begin(v), end(v), f);
			return result != end(v) ? optional(result - begin(v)) : nullopt;
		});
	}
} IndexIf;
struct FindIf_impl {
	template <class F> auto operator()(const F& f) {
		return Callable([&](auto v) -> optional<typename decltype(v)::value_type> {
			auto result = find_if(begin(v), end(v), f);
			return result != end(v) ? optional(*result) : nullopt;
		});
	}
} FindIf;
struct Sum_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			return accumulate(next(begin(v)), end(v), f(*begin(v)),
			                  [&](const auto& a, const auto& b) { return a + f(b); });
		});
	}
	template <class T> friend auto operator|(T v, const Sum_impl& c) {
		return accumulate(begin(v), end(v), typename T::value_type{});
	}
} Sum;
struct Includes {
	template <class V> auto operator()(const V& val) {
		return Callable([&](auto v) { return find(begin(v), end(v), val) != end(v); });
	}
} Includes;
struct IncludesIf_impl {
	template <class F> auto operator()(const F& f) {
		return Callable([&](auto v) { return find_if(begin(v), end(v), f) != end(v); });
	}
} IncludesIf;
struct RemoveIf_impl {
	template <class F> auto operator()(const F& f) {
		return Callable([&](auto v) {
			v.erase(remove_if(begin(v), end(v), f), end(v));
			return v;
		});
	}
} RemoveIf;
struct Each_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			for (const auto& i : v) {
				f(i);
			}
		});
	}
} Each;
struct Select_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			using value_type = typename decltype(v)::value_type;
			vector<value_type> result;
			for (const auto& i : v) {
				if (f(i)) result.push_back(i);
			}
			return result;
		});
	}
} Select;
struct Map_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			using result_type = invoke_result_t<F, typename decltype(v)::value_type>;
			vector<result_type> result;
			result.reserve(size(v));
			for (const auto& i : v) {
				result.push_back(f(i));
			}
			return result;
		});
	}
} Map;
struct Indexed_impl {
	template <class T> friend auto operator|(const T& v, Indexed_impl& c) {
		using value_type = typename T::value_type;
		vector<pair<value_type, int>> result;
		result.reserve(size(v));
		int index = 0;
		for (const auto& i : v) {
			result.emplace_back(i, index++);
		}
		return result;
	}
} Indexed;
struct AllOf_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			for (const auto& i : v) {
				if (!f(i)) return false;
			}
			return true;
		});
	}
} AllOf;
struct AnyOf_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			for (const auto& i : v) {
				if (f(i)) return true;
			}
			return false;
		});
	}
} AnyOf;
struct NoneOf_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			for (const auto& i : v) {
				if (f(i)) return false;
			}
			return true;
		});
	}
} NoneOf;

struct Tally_impl {
	template <class F> auto operator()(size_t max_val) {
		return Callable([&](auto v) {
			vector<size_t> result(max_val);
			for (const auto& i : v) {
				result[static_cast<size_t>(i)]++;
			}
			return result;
		});
	}
	template <class T, class value_type = typename T::value_type>
	friend auto operator|(const T& v, Tally_impl& c) {
		map<value_type, size_t> result;
		for (const auto& i : v) {
			result[i]++;
		}
		return result;
	}
} Tally;

template <class T> auto operator*(const vector<T>& a, size_t n) {
	T result;
	for (size_t i = 0; i < n; ++i) {
		result.insert(result.end(), a.begin(), a.end());
	}
	return result;
}
auto operator*(string a, size_t n) {
	string result;
	for (size_t i = 0; i < n; ++i) {
		result += a;
	}
	return result;
}
template <class T, class U> auto& operator<<(vector<T>& a, const U& b) {
	a.insert(a.end(), all(b));
	return a;
}
template <class T> auto& operator<<(string& a, const T& b) {
	a.insert(a.end(), all(b));
	return a;
}
template <class T, class U> auto operator+(vector<T> a, const U& b) {
	a << b;
	return a;
}
template <class T> auto operator+(string a, const T& b) {
	a << b;
	return a;
}
#line 7 "/home/yuruhiya/programming/library/template/functions.cpp"
using namespace std;

template <class T = long long> constexpr T TEN(size_t n) {
	T result = 1;
	for (size_t i = 0; i < n; ++i) result *= 10;
	return result;
}
template <class T, class U,
          enable_if_t<is_integral_v<T> && is_integral_v<U>, nullptr_t> = nullptr>
constexpr auto div_ceil(T n, U m) {
	return (n + m - 1) / m;
}
template <class T, class U> constexpr auto div_ceil2(T n, U m) {
	return div_ceil(n, m) * m;
}
template <class T> constexpr T triangle(T n) {
	return (n & 1) ? (n + 1) / 2 * n : n / 2 * (n + 1);
}
template <class T> constexpr T nC2(T n) {
	return (n & 1) ? (n - 1) / 2 * n : n / 2 * (n - 1);
}
template <class T, class U> constexpr auto middle(const T& l, const U& r) {
	return l + (r - l) / 2;
}
template <class T, class U, class V>
constexpr bool in_range(const T& v, const U& lower, const V& upper) {
	return lower <= v && v < upper;
}
template <class T, enable_if_t<is_integral_v<T>, nullptr_t> = nullptr>
constexpr bool is_square(T n) {
	T s = sqrt(n);
	return s * s == n || (s + 1) * (s + 1) == n;
}
template <class T = long long> constexpr T BIT(int b) {
	return T(1) << b;
}
template <class T, class U, enable_if_t<is_integral_v<U>, nullptr_t> = nullptr>
constexpr T Pow(T a, U n) {
	assert(n >= 0);
	T result = 1;
	while (n > 0) {
		if (n & 1) {
			result *= a;
			n--;
		} else {
			a *= a;
			n >>= 1;
		}
	}
	return result;
}
template <class T, class U, enable_if_t<is_integral_v<U>, nullptr_t> = nullptr>
constexpr T Powmod(T a, U n, T mod) {
	assert(n >= 0);
	if (a > mod) a %= mod;
	T result = 1;
	while (n > 0) {
		if (n & 1) {
			result = result * a % mod;
			n--;
		} else {
			a = a * a % mod;
			n >>= 1;
		}
	}
	return result;
}
template <class T> bool chmax(T& a, const T& b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template <class T> bool chmin(T& a, const T& b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template <class T> int sz(const T& v) {
	return v.size();
}
template <class T, class U> int lower_index(const T& a, const U& v) {
	return lower_bound(all(a), v) - a.begin();
}
template <class T, class U> int upper_index(const T& a, const U& v) {
	return upper_bound(all(a), v) - a.begin();
}
template <class T> auto Slice(const T& v, size_t i, size_t len) {
	return i < v.size() ? T(v.begin() + i, v.begin() + min(i + len, v.size())) : T();
}
template <class T, class U = typename T::value_type> U Gcdv(const T& v) {
	return accumulate(next(v.begin()), v.end(), U(*v.begin()), gcd<U, U>);
}
template <class T, class U = typename T::value_type> U Lcmv(const T& v) {
	return accumulate(next(v.begin()), v.end(), U(*v.begin()), lcm<U, U>);
}
namespace internal {
	template <class T, size_t N> auto make_vector(vector<int>& sizes, const T& init) {
		if constexpr (N == 1) {
			return vector(sizes[0], init);
		} else {
			int size = sizes[N - 1];
			sizes.pop_back();
			return vector(size, make_vector<T, N - 1>(sizes, init));
		}
	}
}  // namespace internal
template <class T, size_t N>
auto make_vector(const int (&sizes)[N], const T& init = T()) {
	vector s(rbegin(sizes), rend(sizes));
	return internal::make_vector<T, N>(s, init);
}
#line 9 "/home/yuruhiya/programming/library/template/template.cpp"
#if __has_include(<library/dump.hpp>)
#include <library/dump.hpp>
#define LOCAL
#else
#define dump(...) ((void)0)
#endif

template <class T> constexpr T oj_local(const T& oj, const T& local) {
#ifndef LOCAL
	return oj;
#else
	return local;
#endif
}
#line 2 "a.cpp"

int main() {
	ini(n);
	VI a = in[n];
	int sum = a | Sum;

	auto dp = make_vector({sum + 1, sum + 1}, false);
	dp[0][0] = true;
	rep(i, n) {
		rrep(x, sum + 1) rrep(y, sum + 1) if (dp[x][y]) {
			if (x + a[i] <= sum) {
				dp[x + a[i]][y] = true;
			}
			if (y + a[i] <= sum) {
				dp[x][y + a[i]] = true;
			}
		}
	}

	int ans = inf;
	rep(x, sum + 1) rep(y, sum + 1) {
		if (dp[x][y]) {
			chmin(ans, max({x, y, sum - x - y}));
		}
	}
	out(ans);
}
accuracy: 1
time_ms: 240
memory_kb: 4216
final_rank: 10

code_snippet: #include <iostream>
#include <iomanip>
#include <array>
#include <bitset>
#include <algorithm>

constexpr int MAX_S = 50 * 17;
std::array<std::array<std::bitset<MAX_S + 1>, MAX_S + 1>, 2> dp;

int main(void){
    std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false);
    int n; std::cin >> n;
    dp[0][0][0] = true;
    int S = 0;
    for(int i = 0; i < n; ++i){
        int t; std::cin >> t; S += t;
        for(int o1 = 0; o1 + t <= MAX_S; ++o1) for(int o2 = 0; o2 <= MAX_S; ++o2) if(dp[0][o1][o2]) dp[1][o1 + t][o2] = true;
        for(int o1 = 0; o1 <= MAX_S; ++o1) for(int o2 = 0; o2 + t <= MAX_S; ++o2) if(dp[0][o1][o2]) dp[1][o1][o2 + t] = true;
        dp[0] = dp[1];
    }
    int res = std::numeric_limits<int>::max();
    for(int i = 0; i <= MAX_S and i < res; ++i){
        for(int j = std::max(0, S - i - res + 1), k = S - i - j; j <= MAX_S and j < res; ++j, --k) if(dp[0][i][j]){
            const int v = std::max({i, j, k});
            if(res > v) res = v;
        }
    }
    std::cout << res << '\n';

    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 3392
final_rank: 5

code_snippet: #include <iostream>
#include <vector>
using namespace std;


int main(void){
    
    long long N;
    vector<long long> T;
    int Tsum=0;

    cin >> N;
    for(int i=0;i<N;i++){
        long long t;
        cin >> t;
        Tsum+=t;
        T.push_back(t);
    }
    long long range = min(1000,Tsum);
    
    bool dp[2][1010][1010]={};
    dp[0][0][0]=true;
    
    for(int i=0;i<N;i++){
        for(int j=0;j<=range;j++){
            for(int k=0;k<=range;k++){
                dp[1][j][k]|=dp[0][j][k];
                if(j-T[i]>=0){
                    dp[1][j][k]|=dp[0][j-T[i]][k];
                }
                if(k-T[i]>=0){
                    dp[1][j][k]|=dp[0][j][k-T[i]];
                }
            }
        }


        for(int j=0;j<=range;j++){
            for(int k=0;k<=range;k++){
                dp[0][j][k]=dp[1][j][k];
                dp[1][j][k]=false;
            }
        }
    }
    

    int Ans = 10*Tsum;
    for(int j=0;j<=range;j++){
        for(int k=0;k<=range;k++){
            if(dp[0][j][k]){
                //cout << j  << " " << k << " " << Tsum-j-k << endl;
                int r = max(max(j,k),Tsum-j-k); 
                Ans=min(Ans,r);
            }
        }
    }

    
    cout << Ans << endl;

    return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 5440
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(){
	int N;
	cin>>N;
	vector<vector<int>> p(851,vector<int>(851));
	int S=0;
	p[0][0]=1;
	vector<int> q(N);
	for(int i=0;i<N;i++){
		cin>>q[i];
	}
	for(int k=0;k<N;k++){
		int a=q[k];
		for(int i=850;i>=0;i--){
			for(int j=850;j>=0;j--){
				if(p[i][j]==0){
					continue;
				}
				if(j+a<=850){
					p[i][j+a]=1;
				}
				if(i+a<=850){
					p[i+a][j]=1;
				}
			}
		}
		S+=a;
	}
	int Z=855;
	for(int i=0;i<851;i++){
		for(int j=0;j<851;j++){
			if(p[i][j]==1){
				Z=min(Z,max(S-i-j,max(i,j)));
			}
		}
	}
	cout<<Z<<endl;
}
accuracy: 1
time_ms: 30
memory_kb: 6320
final_rank: 3

code_snippet: #if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <cmath>
//#include <atcoder/all>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;


template<typename T, typename U>
std::enable_if_t<std::rank<T>::value == 0> fill_all(T& arr, const U& v) {
    arr = v;
}
template<typename ARR, typename U>
std::enable_if_t<std::rank<ARR>::value != 0> fill_all(ARR& arr, const U& v) {
    for (auto& i : arr) {
        fill_all(i, v);
    }
}

int32_t N;
int32_t T[50];
int dp[50][900][900];
int func(int i, int a, int b, int c)
{
    if (i == N) {
        return std::max({ a,b,c });
    }
    if (a >= 900 || b >= 900 || c >= 900) {
        return 1000;
    }

    auto& memo = dp[i][a][b];
    if (memo != -1) {
        return memo;
    }
    auto& t = T[i];
    memo = std::min({ func(i + 1,a + t, b,c), func(i + 1,a, b + t,c) , func(i + 1,a, b,c + t) });

    return memo;
}

int main()
{
    using std::endl;
    using std::cout;
    in.sync_with_stdio(false);
    out.sync_with_stdio(false);
    in.tie(nullptr);
    out.tie(nullptr);
    fill_all(dp, -1);

    in >> N ;
    for (size_t i = 0; i < N; i++)
    {
        in >> T[i];
    }

    out << func(0, 0, 0, 0) << endl;

    return 0;
}
#endif
accuracy: 1
time_ms: 280
memory_kb: 161412
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uint = unsigned;
using pcc = pair<char, char>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using tuplis = array<ll, 3>;
template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;
const ll LINF=0x1fffffffffffffff;
const ll MINF=0x7fffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
const int MODD=998244353;
const ld DINF=numeric_limits<ld>::infinity();
const ld EPS=1e-9;
const ld PI=3.1415926535897932;
const ll dx[] = {0, 1, 0, -1, 1, -1, 1, -1};
const ll dy[] = {1, 0, -1, 0, 1, 1, -1, -1};
#define overload4(_1,_2,_3,_4,name,...) name
#define overload3(_1,_2,_3,name,...) name
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i=n;i--;)
#define rrep2(i,n) for(ll i=n;i--;)
#define rrep3(i,a,b) for(ll i=b;i-->(a);)
#define rrep4(i,a,b,c) for(ll i=(a)+((b)-(a)-1)/(c)*(c);i>=(a);i-=c)
#define rrep(...) overload4(__VA_ARGS__,rrep4,rrep3,rrep2,rrep1)(__VA_ARGS__)
#define each1(i,a) for(auto&&i:a)
#define each2(x,y,a) for(auto&&[x,y]:a)
#define each3(x,y,z,a) for(auto&&[x,y,z]:a)
#define each(...) overload4(__VA_ARGS__,each3,each2,each1)(__VA_ARGS__)
#define all1(i) begin(i),end(i)
#define all2(i,a) begin(i),begin(i)+a
#define all3(i,a,b) begin(i)+a,begin(i)+b
#define all(...) overload3(__VA_ARGS__,all3,all2,all1)(__VA_ARGS__)
#define rall1(i) (i).rbegin(),(i).rend()
#define rall2(i,k) (i).rbegin(),(i).rbegin()+k
#define rall3(i,a,b) (i).rbegin()+a,(i).rbegin()+b
#define rall(...) overload3(__VA_ARGS__,rall3,rall2,rall1)(__VA_ARGS__)
#define sum(...) accumulate(all(__VA_ARGS__),0LL)
#define dsum(...) accumulate(all(__VA_ARGS__),0.0L)
#define Msum(...) accumulate(all(__VA_ARGS__),0_M)
#define elif else if
#define unless(a) if(!(a))
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;in(__VA_ARGS__)
#define Sort(a) sort(all(a))
#define Rev(a) reverse(all(a))
#define Uniq(a) sort(all(a));a.erase(unique(all(a)),end(a))
#define vec(type,name,...) vector<type>name(__VA_ARGS__)
#define VEC(type,name,size) vector<type>name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,w) vector<vector<type>>name(h,vector<type>(w));in(name)
#define vvv(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
template<class T> auto min(const T& a){ return *min_element(all(a)); }
template<class T> auto max(const T& a){ return *max_element(all(a)); }
inline ll popcnt(ull a){ return __builtin_popcountll(a); }
ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
template<class T> bool chmin(T& a, const T& b){ if(a > b){ a = b; return 1; } return 0; }
template<class T> bool chmax(T& a, const T& b){ if(a < b){ a = b; return 1; } return 0; }
template<class T, class U> bool chmin(T& a, const U& b){ if(a > T(b)){ a = b; return 1; } return 0; }
template<class T, class U> bool chmax(T& a, const U& b){ if(a < T(b)){ a = b; return 1; } return 0; }
vector<ll> iota(ll n, ll begin = 0){ vector<ll> a(n); iota(a.begin(), a.end(), begin); return a; }
vector<pll> factor(ull x){ vector<pll> ans; for(ull i = 2; i * i <= x; i++) if(x % i == 0){ ans.push_back({i, 1}); while((x /= i) % i == 0) ans.back().second++; } if(x != 1) ans.push_back({x, 1}); return ans; }
map<ll,ll> factor_map(ull x){ map<ll,ll> ans; for(ull i = 2; i * i <= x; i++) if(x % i == 0){ ans[i] = 1; while((x /= i) % i == 0) ans[i]++; } if(x != 1) ans[x] = 1; return ans; }
vector<ll> divisor(ull x){ vector<ll> ans; for(ull i = 1; i * i <= x; i++) if(x % i == 0) ans.push_back(i); rrep(ans.size() - (ans.back() * ans.back() == x)) ans.push_back(x / ans[i]); return ans; }
template<class T> unordered_map<T, ll> press(vector<T> a){ Uniq(a); unordered_map<T, ll> ans; rep(a.size()) ans[a[i]] = i; return ans; }
template<class T> map<T, ll> press_map(vector<T> a){ Uniq(a); map<T, ll> ans; rep(a.size()) ans[a[i]] = i; return ans; }
int scan(){ return getchar(); }
void scan(int& a){ scanf("%d", &a); }
void scan(unsigned& a){ scanf("%u", &a); }
void scan(long& a){ scanf("%ld", &a); }
void scan(long long& a){ scanf("%lld", &a); }
void scan(unsigned long long& a){ scanf("%llu", &a); }
void scan(char& a){ do{ a = getchar(); }while(a == ' ' || a == '\n'); }
void scan(float& a){ scanf("%f", &a); }
void scan(double& a){ scanf("%lf", &a); }
void scan(long double& a){ scanf("%Lf", &a); }
void scan(vector<bool>& a){ for(unsigned i = 0; i < a.size(); i++){ int b; scan(b); a[i] = b; } }
void scan(char a[]){ scanf("%s", a); }
void scan(string& a){ cin >> a; }
template<class T> void scan(vector<T>&);
template<class T, size_t size> void scan(array<T, size>&);
template<class T, class L> void scan(pair<T, L>&);
template<class T, size_t size> void scan(T(&)[size]);
template<class T> void scan(vector<T>& a){ for(auto&& i : a) scan(i); }
template<class T> void scan(deque<T>& a){ for(auto&& i : a) scan(i); }
template<class T, size_t size> void scan(array<T, size>& a){ for(auto&& i : a) scan(i); }
template<class T, class L> void scan(pair<T, L>& p){ scan(p.first); scan(p.second); }
template<class T, size_t size> void scan(T (&a)[size]){ for(auto&& i : a) scan(i); }
template<class T> void scan(T& a){ cin >> a; }
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){ scan(head); in(tail...); }
void print(){ putchar(' '); }
void print(bool a){ printf("%d", a); }
void print(int a){ printf("%d", a); }
void print(unsigned a){ printf("%u", a); }
void print(long a){ printf("%ld", a); }
void print(long long a){ printf("%lld", a); }
void print(unsigned long long a){ printf("%llu", a); }
void print(char a){ printf("%c", a); }
void print(char a[]){ printf("%s", a); }
void print(const char a[]){ printf("%s", a); }
void print(float a){ printf("%.15f", a); }
void print(double a){ printf("%.15f", a); }
void print(long double a){ printf("%.15Lf", a); }
void print(const string& a){ for(auto&& i : a) print(i); }
template<class T> void print(const complex<T>& a){ if(a.real() >= 0) print('+'); print(a.real()); if(a.imag() >= 0) print('+'); print(a.imag()); print('i'); }
template<class T> void print(const vector<T>&);
template<class T, size_t size> void print(const array<T, size>&);
template<class T, class L> void print(const pair<T, L>& p);
template<class T, size_t size> void print(const T (&)[size]);
template<class T> void print(const vector<T>& a){ if(a.empty()) return; print(a[0]); for(auto i = a.begin(); ++i != a.end(); ){ putchar(' '); print(*i); } }
template<class T> void print(const deque<T>& a){ if(a.empty()) return; print(a[0]); for(auto i = a.begin(); ++i != a.end(); ){ putchar(' '); print(*i); } }
template<class T, size_t size> void print(const array<T, size>& a){ print(a[0]); for(auto i = a.begin(); ++i != a.end(); ){ putchar(' '); print(*i); } }
template<class T, class L> void print(const pair<T, L>& p){ print(p.first); putchar(' '); print(p.second); }
template<class T, size_t size> void print(const T (&a)[size]){ print(a[0]); for(auto i = a; ++i != end(a); ){ putchar(' '); print(*i); } }
template<class T> void print(const T& a){ cout << a; }
int out(){ putchar('\n'); return 0; }
template<class T> int out(const T& t){ print(t); putchar('\n'); return 0; }
template<class Head, class... Tail> int out(const Head& head, const Tail&... tail){ print(head); putchar(' '); out(tail...); return 0; }
#ifdef DEBUG
inline ll __lg(ull x){ return 63 - __builtin_clzll(x); }
#define debug(...) { print(#__VA_ARGS__); print(":"); out(__VA_ARGS__); }
#else
#define debug(...) void(0)
#endif
int first(bool i = true){ return out(i?"first":"second"); }
int First(bool i = true){ return out(i?"First":"Second"); }
int yes(bool i = true){ return out(i?"yes":"no"); }
int Yes(bool i = true){ return out(i?"Yes":"No"); }
int No(){ return out("No"); }
int YES(bool i = true){ return out(i?"YES":"NO"); }
int NO(){ return out("NO"); }
int Yay(bool i = true){ return out(i?"Yay!":":("); }
int possible(bool i = true){ return out(i?"possible":"impossible"); }
int Possible(bool i = true){ return out(i?"Possible":"Impossible"); }
int POSSIBLE(bool i = true){ return out(i?"POSSIBLE":"IMPOSSIBLE"); }
void Case(ll i){ printf("Case #%lld: ", i); }



int main(){
    LL(n);
    vector dp(2501, vector<bool>(2501));
    dp[0][0] = 1;
    ll sum=0;
    while(n--){
        LL(t);
        sum+=t;
        rrep(2500)rrep(j,2500-i)if(dp[i][j]){
            if(i+t<=2500)dp[i+t][j]=1;
            if(j+t<=2500)dp[i][j+t]=1;
        }
    }
    ll ans=LINF;
    rep(2501)rep(j,2501)if(dp[i][j])chmin(ans,max({i,j,sum-i-j}));
    out(ans);
}
accuracy: 1
time_ms: 160
memory_kb: 4544
final_rank: 7

code_snippet: #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
#include<set>
#include<complex>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
    if(vec_n==-1)vec_n=vec_s.size();
    for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
    if(vec_n==-1)vec_n=vec_s.size();
    for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}


int main(){
    int n,m;
    int i,j,k;
    int a,b,c;
    vector<vector<int>> dp(1e3+7,vector<int>(1e3+7,INF));
    dp[0][0]=0;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a;
        for(j=min((int)1e3,50*i);j>=0;j--){
            for(k=min((int)1e3,50*i);k>=0;k--){
                if(dp[j][k]==INF)continue;
                if(j+a<1e3)dp[j+a][k]=min(dp[j][k],dp[j+a][k]);
                if(k+a<1e3)dp[j][k+a]=min(dp[j][k],dp[j][k+a]);
                dp[j][k]+=a;
            }
        }
    }
    int s=1e9;
    for(i=0;i<1e3;i++){
        for(j=0;j<1e3;j++){
            s=min(s,max({i,j,dp[i][j]}));
        }
    }
    cout<<s<<endl;
}
accuracy: 1
time_ms: 40
memory_kb: 7456
final_rank: 4