func_code_string: #include <bits/stdc++.h>   using namespace std;   template <class T>   void debug(T a, T b) {     ;   }   template <class T>   void chmin(T& a, const T& b) {     if (a > b) a = b;   }   template <class T>   void chmax(T& a, const T& b) {     if (a < b) a = b;   }   namespace std {   template <class S, class T>   ostream& operator<<(ostream& out, const pair<S, T>& a) {     out <<  (  << a.first <<  ,  << a.second <<  ) ;     return out;   }   }  // namespace std   const int INF = 7e8;   int n;   int ar[300005];   int sum[300005];   vector<int> Tpos, Opos;   int solve1(int a, int b, int A, int B) {     if (B == INF) return INF;     if (b == INF) return INF;     int Tlen = B - b;     int tmp = sum[b] * 1000;     int pt = sum[b] * 100;     int Trange = Tlen * 2000;     tmp += max(0, Trange - pt);     pt -= min(Trange, pt);     tmp += 1000;     pt += 100;     int rest = (sum[n] - sum[B + 1]) * 1000;     tmp += max(0, rest - pt);     return tmp;   }   int solve2(int a, int b, int A, int B) {     if (a == -1) return INF;     if (A == -1) return INF;     int Tlen = a - A;     int tmp = sum[A] * 1000;     int pt = sum[A] * 100;     tmp += max(0, 1000 - pt);     pt -= min(pt, 1000);     int Trange = Tlen * 2000;     tmp += Trange;     pt += Tlen * 200;     int rest = (sum[n] - sum[a + 1]) * 1000;     tmp += max(0, rest - pt);     return tmp;   }   int main() {     cin >> n;     Opos.push_back(-1);     Tpos.push_back(-1);     for (int i = 0; i < (n); ++i) {       int a;       scanf( %d , &a);       ar[i] = a / 1000;       if (ar[i] == 1)         Opos.push_back(i);       else         Tpos.push_back(i);     }     Tpos.push_back(INF);     Opos.push_back(INF);     for (int i = 0; i < (n); ++i) sum[i + 1] = sum[i] + ar[i];     int res = INF;     for (int i = 0; i < (n + 1); ++i) {       int tmp = sum[i] * 1000;       int pt = sum[i] * 100;       int rest = (sum[n] - sum[i]) * 1000;       tmp += max(0, rest - pt);       chmin(res, tmp);     }     int prev = res;     for (int i = 0; i < ((int)Tpos.size() - 1); ++i) {       int a = Tpos[i], b = Tpos[i + 1];       int B = *lower_bound((Opos).begin(), (Opos).end(), b);       int A = *(--lower_bound((Opos).begin(), (Opos).end(), a));       int X = solve1(a, b, A, B);       int Y = solve2(a, b, A, B);       chmin(res, X);       chmin(res, Y);     }     cout << res << endl;     return 0;   }   