#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse4,fma")

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

using ll = int64_t;
using ull = uint64_t;

using f32 = double;
using f64 = long double;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using u128 = __uint128_t;

using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;
using i128 = __int128_t;

using vi = vector<int>;
using vb = vector<bool>;

using pii = pair<int, int>;
using vpi = vector<pii>;

using pll = pair<ll, ll>;
using vpl = vector<pll>;

using rng = default_random_engine;


// template <typename T>
// using minpq = priority_queue<T, vector<T>, greater<T>>;


/* =-- order statistics tree and gp_hash_table --= */

// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// template <class T> using Tree = tree<T, null_type, less<T>,
// 	rb_tree_tag, tree_order_statistics_node_update>;


template<class F>
class y_combinator_result {
	F f_;
public:
	template<class T>
	explicit y_combinator_result(T &&f)
		: f_(forward<T>(f)) {}

	template<class ...Args>
	decltype(auto) operator()(Args &&...args) {
		return f_(ref(*this), forward<Args>(args)...);
	}
};

template<class F> decltype(auto) y_combinator(F &&f) {
	return y_combinator_result<decay_t<F>>(forward<F>(f));
}


template <typename T, typename U>
inline bool ckmin(T &x, const U &y) {
	return x>y ? x=y,1 : 0; }

template <typename T, typename U>
inline bool ckmax(T &x, const U &y) {
	return x<y ? x=y,1 : 0; }


#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define np next_permutation
#define sz(v) int(v.size())
#define all(v) begin(v), end(v)

#define loop while (9+10 != 21)

#define ctz __builtin_ctzll // count trailing zeros
#define clz __builtin_clzll // count leading zeros
#define bitpar __builtin_parityll // parity of number of set bits
#define popcnt __builtin_popcountll // number of set bits

const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};

const int INF = 20000'69420;
const ll INFL = 9e18;
const int M1 = 1'000'000'007;
const int M2 =   998'244'353;
const int maxn = 1'000'005;
const int maxg = 2'005;

int a[maxn];
bitset<maxn> b;

void solve() {
	int n, s = 0; cin >> n;
	b.reset(); b[0] = 1;
	for (int i = 0; i < n; ++i)
		cin >> a[i], s += a[i],
		b |= b << a[i];
	
	for (int t = s/2; t >= 0; --t)
		if (b[t]) { cout << s-t << '\n'; return; }
}



int main() {
	cin.tie(nullptr) ->
	sync_with_stdio(false);
	cin.exceptions(cin.failbit);

	int T = 1; // cin >> T;
	while (T--) solve();
}
#include <bits/stdc++.h>

#define ll long long
#define ii pair<int, int>
#define pll pair<ll, ll>
#define dd pair<double, double>
#define vi vector<int>
#define vl vector<ll>
#define vd vector<double>
#define vii vector<ii>
#define vll vector<pll>
#define vdd vector<dd>
#define vvi vector<vi>
#define vvl vector<vl>
#define vvd vector<vd>
#define vvii vector<vii>
#define vvll vector<vll>
#define vvdd vector<vdd>
#define fi first
#define se second
#define uni(v) v.erase(unique(v.begin(), v.end()), v.end())
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (ll) a / __gcd(a, b) * b
#define prt(v) \
    for (auto& i : v) cout << i << " \n"[&i == &v.back()]

using namespace std;

void print();
template <typename T, typename... Args>
void print(T x, Args... args);

void solve(int T) {
    int n;
    cin >> n;
    vi a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];

    int res = 0;
    for (int i = 0; i < n; ++i)
        for (int x = a[i], j = i; j < n; ++j, x = min(x, a[j]))
            res = max(res, x * (j - i + 1));
    
    cout << res << '\n';
}
int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

    int t = 1;
    // cin >> t;
    for (int i = 0; i++ < t;) solve(i);

    return 0;
}

void print() { cout << "\n"; }
template <typename T, typename... Args>
void print(T x, Args... args) {
    if (sizeof...(args)) {
        cout << x << ' ';
        print(args...);
    } else {
        cout << x << '\n';
    }
}