#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;
const long long int INF = 1e18;
const int N = 20;
long long int n;
long long int a[81];
long long int dp[81][2001][201][2];
long long int foo(long long int idx, long long int rem, long long int num,
                  long long int cn) {
  if (cn == 2) {
    return -INF;
  }
  if (idx == n) {
    return rem;
  }
  if (dp[idx][rem][num][cn] != -1) return dp[idx][rem][num][cn];
  long long int res = 0;
  long long int p = 0;
  long long int q = 0;
  for (int i = 0; i * a[idx] <= rem; i++) {
    res = max(foo(idx + 1, rem - i * a[idx], num + i, 0), res);
    res = max(foo(idx, rem - i * a[idx], num + i, cn + 1), res);
  }
  for (int i = 0; i <= num; i++) {
    res = max(foo(idx + 1, rem + i * a[idx], num - i, 0), res);
    res = max(foo(idx, rem + i * a[idx], num - i, cn + 1), res);
  }
  return dp[idx][rem][num][cn] = res;
}
void solve(int t) {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  memset(dp, -1, sizeof(dp));
  cout << foo(0, 1000, 0, 0) << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve(i);
  }
}
