#include <bits/stdc++.h>
using namespace std;
long long ans;
long long dp[80][2000][20];
long long find(long long arr[], long long n, long long pos, long long have,
               long long c) {
  if (pos == n) {
    ans = max(ans, c);
    return 0;
  }
  if (dp[pos][c][have] != -1) {
    return dp[pos][c][have];
  }
  long long res = 0;
  for (long long i = 0; i <= have; i++) {
    long long a =
        find(arr, n, pos + 1, have - i, c + i * arr[pos]) + i * arr[pos];
    res = max(a, res);
  }
  for (long long i = 0; i <= c / arr[pos]; i++) {
    long long b =
        find(arr, n, pos + 1, have + i, c - i * arr[pos]) - i * arr[pos];
    res = max(b, res);
  }
  dp[pos][c][have] = res;
  return res;
}
void solve() {
  long long n;
  cin >> n;
  long long arr[n];
  for (long long i = 0; i < n; i++) cin >> arr[i];
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < 2000; j++) {
      for (long long k = 0; k < 20; k++) dp[i][j][k] = -1;
    }
  }
  find(arr, n, 0, 0, 1000);
  cout << ans << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
