#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265358979323846;
const long long inf = 2e7, MOD = 998244353, MAX = 1e2 + 2;
int dp[81][81][50000], n;
int a[81];
int sol(int idx, int cnt, int money) {
  if (money < 0 || cnt < 0) return -inf;
  if (idx == n) return money;
  int &ret = dp[idx][cnt][money];
  if (~ret) return ret;
  ret = sol(idx + 1, cnt, money);
  ret = max(sol(idx, cnt + 1, money - a[idx]),
            max(sol(idx + 1, cnt + 1, money - a[idx]),
                max(sol(idx, cnt - 1, money + a[idx]),
                    max(sol(idx + 1, cnt - 1, money + a[idx]), ret))));
  return ret;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  memset(dp, -1, sizeof dp);
  cout << sol(0, 0, 1000);
}
