#include <bits/stdc++.h>
using namespace std;
inline long long add(long long a, long long b) {
  return ((a % 1000000007LL) + (b % 1000000007LL)) % 1000000007LL;
}
inline long long mul(long long a, long long b) {
  return ((a % 1000000007LL) * (b % 1000000007LL)) % 1000000007LL;
}
inline long long sub(long long a, long long b) {
  return ((a % 1000000007LL) - (b % 1000000007LL) + 1000000007LL) %
         1000000007LL;
}
long long dp[101][10100];
long long findAns(long long i, long long j, long long money, long long a[],
                  long long n) {
  if (i == n) {
    return money;
  }
  if (dp[i][money] != -1) {
    return dp[i][money];
  }
  long long ret = findAns(i + 1, j, money, a, n);
  long long currMoney = money - a[i];
  long long cnt = j + 1;
  while (currMoney >= 0) {
    currMoney -= a[i];
    ++cnt;
  }
  ret = max(ret, findAns(i + 1, cnt - 1, currMoney + a[i], a, n));
  currMoney = money + a[i];
  cnt = j - 1;
  while (cnt >= 0) {
    currMoney += a[i];
    --cnt;
  }
  ret = max(ret, findAns(i + 1, cnt + 1, currMoney - a[i], a, n));
  return dp[i][money] = ret;
}
void Flash() {
  long long n;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  memset(dp, -1, sizeof(dp));
  long long ans = 1000;
  ans = max(ans, findAns(0, 0, 1000, a, n));
  cout << ans << "\n";
}
int main(int argc, char const *argv[]) {
  ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
  ;
  long long t = 1;
  for (long long i = 1; i <= t; i++) {
    Flash();
  }
  return 0;
}
