#include <bits/stdc++.h>
using namespace std;
const unsigned long long N = 1e7;
const unsigned long long INF = 1e14;
const unsigned long long mod = 1e9 + 7;
map<int, map<pair<unsigned long long, unsigned long long>, unsigned long long>>
    dp;
vector<unsigned long long> v;
unsigned long long n;
unsigned long long first(unsigned long long x, unsigned long long second,
                         unsigned long long day) {
  if (day == n) return x;
  if (dp[day].count({x, second})) return dp[day][{x, second}];
  unsigned long long res = dp[day][{x, second}] = x;
  for (unsigned long long i = 0; i * v[day] <= x; i++)
    res = max(res, first(x - (i * v[day]), second + i, day + 1));
  for (int i = (0), ThxMK = (second + 1); i < ThxMK; ++i)
    res = max(res, first(x + (i * v[day]), second - i, day + 1));
  return dp[day][{x, second}] = res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  v = vector<unsigned long long>(n);
  for (int i = (0), ThxMK = (n); i < ThxMK; ++i) cin >> v[i];
  cout << first(1000, 0, 0) << endl;
}
