#include <bits/stdc++.h>
using namespace std;
vector<int> A(80);
int N, INF = 1 << 31;
int memo[80][100][10000];
bool vis[80][100][10000];
int DP(int i, int stock, int money) {
  if (i == N) return money;
  if (vis[i][stock][money]) return memo[i][stock][money];
  int res1 = -INF, res2 = -INF;
  for (int j = 0; j * A[i] <= money && stock < 100; ++j) {
    res1 = max(DP(i + 1, stock + j, money - j * A[i]), res1);
  }
  for (int j = 0; stock - j >= 0 && stock < 100; ++j) {
    res2 = max(DP(i + 1, stock - j, money + j * A[i]), res2);
  }
  memo[i][stock][money] = max(res1, res2);
  vis[i][stock][money] = true;
  return memo[i][stock][money];
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> N;
  for (int i = 0; i < N; ++i) cin >> A[i];
  cout << DP(0, 0, 1000);
}
