#include <bits/stdc++.h>
using namespace std;
const int N = 85, oo = 1e8, M = 1001;
int n;
int a[N], dp[N][200][M];
int mx = 0;
int solve(int i, int stock, int money) {
  if (i == n) return 0;
  int &ret = dp[i][stock][money];
  if (~ret) return ret;
  ret = 0;
  for (int j = 1; j <= stock; j++)
    ret = max(ret, j * a[i] + solve(i + 1, stock - j, money + j * a[i]));
  for (int j = 1; j * a[i] <= money; j++)
    ret = max(ret, -a[i] * j + solve(i + 1, stock + j, money - j * a[i]));
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  memset(dp, -1, sizeof(dp));
  cout << solve(0, 0, 1000) + 1000;
  return 0;
}
