#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using int64 = long long int;
template <typename T>
void chmax(T &a, T b) {
  a = max(a, b);
}
template <typename T>
void chmin(T &a, T b) {
  a = min(a, b);
}
template <typename T>
void chadd(T &a, T b) {
  a = a + b;
}
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
const int MAXP = 800000;
int dp[MAXP + 10];
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  int x = 1000;
  for (int i = 0; i + 1 < N; i++) {
    for (int j = 0; j <= x; j++) dp[j] = j;
    for (int k = 0; k <= x; k++)
      if (k - A[i] >= 0) chmax(dp[k], dp[k - A[i]] + A[i + 1]);
    int y = 0;
    for (int j = 0; j <= x; j++) chmax(y, dp[j]);
    x = y;
  }
  cout << x << endl;
  return 0;
}
