#include <bits/stdc++.h>
using namespace std;
long long inf = 1000000000000000000, mod = 1000000007, BS, k;
long long dp[100][10000][40], arr[100], n;
long long solve(long long nn, long long sum, long long st) {
  if (dp[nn][sum][st] != -1) return dp[nn][sum][st];
  long long num = -inf;
  if (nn == n - 1) {
    num = st * arr[nn] + sum;
    dp[nn][sum][st] = num;
    return num;
  }
  for (long long i = 0; i < 40; i++) {
    if (i <= st) {
      num = max(num, solve(nn + 1, sum + (st - i) * arr[nn], i));
    } else {
      if (sum - (i - st) * arr[nn] >= 0) {
        num = max(num, solve(nn + 1, sum - (i - st) * arr[nn], i));
      }
    }
  }
  dp[nn][sum][st] = num;
  return dp[nn][sum][st];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> arr[i];
  for (long long i = 0; i < 100; i++)
    for (long long j = 0; j < 10000; j++)
      for (long long k = 0; k < 20; k++) dp[i][j][k] = -1;
  cout << solve(0, 1000, 0);
}
