#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
inline void init() {
  cin.tie(nullptr);
  cout.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
int main() {
  init();
  int N;
  cin >> N;
  vector<int> A(N);
  for (int(i) = (0); (i) < (N); ++(i)) cin >> A[i];
  vector<vector<int>> dp(N + 1, vector<int>(16000, -1));
  dp[0][0] = 1000;
  dp[1][0] = 1000;
  for (int(i) = (0); (i) < (N); ++(i)) {
    for (int(j) = (0); (j) < (dp[i].size()); ++(j)) {
      chmax(dp[i + 1][j], dp[i][j]);
      if (j - 1 >= 0) {
        if (dp[i][j - 1] >= A[i]) chmax(dp[i + 1][j], dp[i][j - 1] - A[i]);
        if (dp[i + 1][j - 1] >= A[i])
          chmax(dp[i + 1][j], dp[i + 1][j - 1] - A[i]);
      }
    }
    for (int(j) = (dp[i].size()) - 1; (j) >= (0); --(j)) {
      if (j + 1 < dp[i].size()) {
        if (dp[i][j + 1] != -1) chmax(dp[i + 1][j], dp[i][j + 1] + A[i]);
        if (dp[i + 1][j + 1] != -1)
          chmax(dp[i + 1][j], dp[i + 1][j + 1] + A[i]);
      }
    }
  }
  cout << dp[N][0] << "\n";
  return 0;
}
