#include <bits/stdc++.h>
using namespace std;
const long long int maxr = 85;
long long int n;
long long int arr[maxr];
long long int dp[maxr][10000][100];
long long int solve(long long int idx, long long int yan, long long int stock) {
  if (idx == n) return yan;
  long long int &ans = dp[idx][yan][stock];
  if (ans != -1) return ans;
  long long int a = 0, b = 0, c = 0, times = 1;
  a = solve(idx + 1, yan, stock);
  while (yan >= times * arr[idx])
    b = max(b, solve(idx + 1, yan - times * arr[idx], stock + times)), times++;
  times = 0;
  while (stock >= times)
    c = max(c, solve(idx + 1, yan + times * arr[idx], stock - times)), times++;
  return ans = max({a, b, c});
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  for (long long int i = 0; i < n; i++) cin >> arr[i];
  memset(dp, -1, sizeof(dp));
  long long int ans = solve(0, 1000, 0);
  cout << ans << endl;
  return 0;
}
