#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
int n, a[N];
long long s[N];
int pre[3][N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    s[i] = s[i - 1] + a[i];
  }
  for (int i = 1; i <= n; ++i) {
    pre[1][i] = pre[1][i - 1];
    pre[2][i] = pre[2][i - 1];
    pre[a[i] / 1000][i] = i;
  }
  long long res = s[n];
  for (int i = 1; i <= n; ++i) {
    long long dis = s[i] / 10;
    res = min(res, s[n] - min(dis, s[n] - s[i]));
    int x = pre[1][i];
    if (x) {
      assert(a[x] == 1000);
      long long sum = 0;
      sum += s[x - 1];
      dis = sum / 10;
      long long d = min(dis, (long long)a[x]);
      sum += a[x] - d;
      dis -= d;
      sum += s[i] - s[x];
      dis += (s[i] - s[x]) / 10;
      res = min(res, sum + s[n] - s[i] - min(dis, s[n] - s[i]));
      for (int k = 1; k <= 2; ++k) {
        int y = pre[k][x - 1];
        if (y) {
          long long sum = 0;
          sum += s[y - 1];
          dis = sum / 10;
          long long d = min(dis, (long long)a[y]);
          sum += a[y] - d;
          dis -= d;
          sum += s[x - 1] - s[y];
          dis += (s[x - 1] - s[y]) / 10;
          d = min(dis, (long long)a[x]);
          sum += a[x] - d;
          dis -= d;
          sum += s[i] - s[x];
          dis += (s[i] - s[x]) / 10;
          res = min(res, sum + s[n] - s[i] - min(dis, s[n] - s[i]));
        }
      }
    }
    x = pre[2][i];
    if (x) {
      assert(a[x] == 2000);
      long long sum = 0;
      sum += s[x - 1];
      dis = sum / 10;
      long long d = min(dis, (long long)a[x]);
      sum += a[x] - d;
      dis -= d;
      sum += s[i] - s[x];
      dis += (s[i] - s[x]) / 10;
      res = min(res, sum + s[n] - s[i] - min(dis, s[n] - s[i]));
      for (int k = 1; k <= 2; ++k) {
        int y = pre[k][x - 1];
        if (y) {
          long long sum = 0;
          sum += s[y - 1];
          dis = sum / 10;
          long long d = min(dis, (long long)a[y]);
          sum += a[y] - d;
          dis -= d;
          sum += s[x - 1] - s[y];
          dis += (s[x - 1] - s[y]) / 10;
          d = min(dis, (long long)a[x]);
          sum += a[x] - d;
          dis -= d;
          sum += s[i] - s[x];
          dis += (s[i] - s[x]) / 10;
          res = min(res, sum + s[n] - s[i] - min(dis, s[n] - s[i]));
        }
      }
    }
  }
  cout << res << endl;
}
