#include <bits/stdc++.h>
using namespace std;
int n, x;
bool dp[505][5005], ok;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  dp[0][1000] = true;
  for (int i = 1; i <= n; ++i) {
    cin >> x;
    for (int p = 0; p < 501; ++p)
      for (int k = 0; k < 5001; ++k)
        if (dp[p][k]) {
          for (int pp = p - 1; pp >= 0; --pp) dp[pp][k + (p - pp) * x] = true;
          for (int pp = p + 1; pp < 501 && k >= (pp - p) * x; ++pp)
            dp[pp][k - (pp - p) * x] = true;
        }
  }
  for (int k = 5000; k; --k)
    for (int p = 0; p < 501; ++p)
      if (dp[p][k]) {
        cout << k;
        exit(0);
      }
  exit(0);
}
