#include <bits/stdc++.h>
using namespace std;
const int maxN = 300000 + 13;
int a[maxN], N;
long long f[maxN][40];
int main() {
  scanf("%d", &N);
  for (int i = (1), _ed = (N + 1); i < _ed; i++) scanf("%d", &a[i]);
  memset(f, 0x3f, sizeof(f));
  f[0][0] = 0;
  for (int i = (1), _ed = (N + 1); i < _ed; i++) {
    int ta = a[i] / 1000;
    for (int j = (0), _ed = (40); j < _ed; j++) {
      f[i][j + ta] = min(f[i][j + ta], f[i - 1][j] + a[i]);
      if (j >= ta * 10)
        f[i][j - ta * 10] = min(f[i][j - ta * 10], f[i - 1][j]);
      else
        f[i][0] = min(f[i][0], f[i - 1][j] + (a[i] - j * 100));
    }
  }
  long long ans = f[N + 1][0];
  for (int i = (0), _ed = (40); i < _ed; i++) {
    if (ans > f[N][i]) ans = f[N][i];
  }
  cout << ans << endl;
  return 0;
}
