#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
constexpr int MOD = 1000000007;
const int INF = 1 << 30;
int dp[90][2000];
int main() {
  int n;
  cin >> n;
  vec a(n);
  for (int i = 0; i < (int)(n); i++) cin >> a[i];
  for (int i = 0; i < (int)(90); i++)
    for (int j = 0; j < (int)(2000); j++) dp[i][j] = -INF;
  dp[0][0] = 1000;
  for (int i = 0; i < (int)(n); i++) {
    int ni = i + 1;
    for (int j = 0; j < (int)(2000); j++) {
      int cur = dp[i][j];
      if (cur == -INF) continue;
      for (int k = 0; k <= j; k++)
        dp[ni][j - k] = max(dp[ni][j - k], dp[i][j] + a[i] * k);
      for (int k = 1; a[i] * k <= cur; k++)
        dp[ni][j + k] = max(dp[ni][j + k], dp[i][j] - a[i] * k);
    }
  }
  int res = -INF;
  for (int i = 0; i < (int)(3); i++) res = max(res, dp[n][i]);
  cout << res << "\n";
  return 0;
}
