#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  unordered_map<int, int> um1, um2;
  um1[0] = 1000;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    um2 = um1;
    for (auto p : um1) {
      int s = p.first, m = p.second;
      for (int j = 0; j < s; j++) {
        um2[j] = max(um2[j], m + a * (s - j));
      }
      while (m >= 0) {
        um2[s] = max(um2[s], m);
        m -= a;
        s++;
      }
    }
    um1 = um2;
  }
  cout << um1[0] << endl;
}
