#include <bits/stdc++.h>
using namespace std;
int n, a[82], ans;
map<int, map<int, map<int, bool> > > vis;
void dfs(int date, int money, int cnt) {
  if (money < 0) return;
  if (cnt < 0) return;
  if (date == n + 1) {
    ans = max(ans, money);
    return;
  }
  if (vis[date][cnt][money]) return;
  vis[date][cnt][money] = 1;
  dfs(date + 1, money, cnt);
  dfs(date, money - a[date], cnt + 1);
  dfs(date, money + a[date], cnt - 1);
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  dfs(1, 1000, 0);
  cout << ans;
  return 0;
}
