#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  int m = 1000;
  vector<int> dp(1000001, -inf);
  for (int i = 0; i <= m; ++i) {
    dp[i] = 0;
  }
  for (int i = 0; i + 1 < n; ++i) {
    dp.assign(dp.size(), 0);
    for (int j = 0; j <= m; ++j) {
      dp[j] = j;
    }
    for (int j = a[i]; j <= m; ++j) {
      dp[j] = max(dp[j], dp[j - a[i]] + a[i + 1]);
    }
    m = max(m, *max_element(dp.begin(), dp.end()));
  }
  cout << m << '\n';
  return 0;
}
