#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  for (long long& e : a) cin >> e;
  long long maxi = 1000;
  for (int i = 0; i < n - 1; ++i) {
    long long dp[500000] = {};
    for (int j = 1; j <= maxi; ++j) dp[j] = j;
    for (int j = a[i]; j <= maxi; ++j)
      dp[j] = max(dp[j], dp[j - a[i]] + a[i + 1]);
    maxi = *max_element(dp, dp + maxi + 1);
  }
  cout << maxi << endl;
  return 0;
}
