#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 2;
int ar[N], num1, num2, n;
vector<int> pos[2];
struct node {
  int sum, minpre;
};
node it[N << 2];
void tag(int idx, int l, int r) {
  if (l < r) {
    it[idx].sum = it[2 * idx].sum + it[2 * idx + 1].sum;
    it[idx].minpre =
        min(it[2 * idx].minpre, it[2 * idx].sum + it[2 * idx + 1].minpre);
  }
}
void init(int idx, int l, int r) {
  if (l == r) {
    it[idx].sum = it[idx].minpre = -ar[l];
    return;
  }
  init(2 * idx, l, (l + r) / 2);
  init(2 * idx + 1, (l + r) / 2 + 1, r);
  tag(idx, l, r);
}
void upd(int idx, int l, int r, int pos1, int val) {
  if (l > pos1 || r < pos1) {
    return;
  }
  if (l == r) {
    it[idx].sum = it[idx].minpre = val;
    return;
  }
  upd(2 * idx, l, (l + r) / 2, pos1, val);
  upd(2 * idx + 1, (l + r) / 2 + 1, r, pos1, val);
  tag(idx, l, r);
}
bool check(int val) {
  init(1, 1, n);
  int cnt, sum, now;
  for (int i = 0; i <= num1; i++) {
    if (val < i * 1000) {
      break;
    }
    if (i) {
      upd(1, 1, n, pos[0][i - 1], 100);
    }
    if (i == 0) {
      cnt = min(val / 2000, num2);
      for (int j = 0; j < cnt; j++) {
        upd(1, 1, n, pos[1][j], 200);
      }
      sum = val - i * 1000 - cnt * 2000;
      if (sum + it[1].minpre >= 0) {
        return true;
      }
      continue;
    }
    now = min((val - i * 1000) / 2000, num2);
    while (cnt > now) {
      cnt--;
      upd(1, 1, n, pos[1][cnt], -2000);
    }
    sum = val - i * 1000 - cnt * 2000;
    if (sum + it[1].minpre >= 0) {
      return true;
    }
  }
  return false;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int lef = 0, rig = 6e8, mid, i, j, k, l;
  cin >> n;
  num1 = num2 = 0;
  for (i = 1; i <= n; i++) {
    cin >> ar[i];
    if (ar[i] == 1000) {
      num1++;
      pos[0].push_back(i);
    } else {
      num2++;
      pos[1].push_back(i);
    }
  }
  while (rig > lef) {
    mid = (lef + rig) >> 1;
    if (check(mid)) {
      rig = mid;
    } else {
      lef = mid + 1;
    }
  }
  cout << lef;
}
