#include<bits/stdc++.h>
using namespace std;

#define pb          push_back
#define F           first
#define S           second
#define rep(i,a,b)  for(int i=a; i<b; i++)
#define all(a)      (a).begin(),(a).end()
// #define wa(x)       cout << (#x) << " -------- " << (x) << endl
#define line1	    printf("---------------------------\n")

#define wa //
#define printf //

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

void pvi(auto v){
	for(auto it:v) cout << it << " ";
	cout << endl;
}

void solve();
signed main() {
	//ios_base::sync_with_stdio(false); cin.tie(NULL);

	int t=1;
	cin>>t;
	while(t--) solve();
	return 0;
}

//___________________________________________________________________________________________________________

vector<vi> g;
vector<vi> seen;

int tim;
int n,k;

int check(int x, int y, int xr, int yr){

	// int t = (y-yr)/3;

	// y = y + 2*t;

	if(y > n-1 || g[x][y]==0) return 1;
	else {
		printf("Check for %d,%d failed \n", x,y);
		return 0;
	}
}

void dfs(int xr,int yr){

	stack<pii> st;
	vi r(n,0);
	seen.assign(3,r);

	st.push({xr,yr});

	while(!st.empty()){

		int x = st.top().F;
		int y = st.top().S;
		st.pop();

		line1;
		wa(x);
		wa(y);

		if(y >= n){
			cout << "YES" << endl;
			return;
		}

		if(seen[x][y]) continue;

		seen[x][y] = 1;

		if(!check(x,y+1,xr,yr)){
			// printf("No1\n");
			// cout << "NO" << endl;
			// return;
			continue;
		}

		printf("Trying here\n");
		if(!seen[x][y+1]) {
			if(check(x,y+1,xr,yr) && check(x,y+2,xr,yr) && check(x,y+3,xr,yr)){
				printf("Here success\n");
				st.push({x,y+3});
			}
			// else{
			// 	printf("No2\n");
			// 	cout << "NO" << endl;
			// 	return;
			// }
		}

		printf("Trying up\n");
		if(x!=0 && !seen[x-1][y+1]) {
			if(check(x-1,y+1,xr,yr) && check(x-1,y+2,xr,yr) && check(x-1,y+3,xr,yr)){
				printf("Up success\n");
				st.push({x-1,y+3});
			}
			// else{
			// 	printf("No3\n");
			// 	cout << "NO" << endl;
			// 	return;
			// }
		}

		printf("Trying down\n");
		if(x!=2 && !seen[x+1][y+1]) {
			if(check(x+1,y+1,xr,yr) && check(x+1,y+2,xr,yr) && check(x+1,y+3,xr,yr)){
				printf("Down success\n");
				st.push({x+1,y+3});
			}
			// else{
			// 	printf("No4\n");
			// 	cout << "NO" << endl;
			// 	return;
			// }
		}
	}

	printf("Stack empty.\n");
	cout << "NO" << endl;
}

void solve() {

	g.clear();

	int x,y;
	cin>>n>>k;

	rep(i,0,3){
		vi r;

		rep(j,0,n){
			char t;
			cin>>t;

			if(t == '.') r.pb(0);
			else if (t == 's') {
				r.pb(0);
				x = i;
				y = j;
			}
			else (r.pb(t-'A'+1));
		}

		rep(j,0,10) r.pb(0);
		// pvi(r);
		g.pb(r);
	}

	n += 10;

	dfs(x,y);
}


#include <iostream>
#include <string>
#include <cstring>
using namespace std;

const int N = 105;
int t, n, k;
char g[4][N];
bool vs[4][N], flag = 0;

int dx[] = {1, 0, -1};

void dfs(int x, int y) {
    vs[x][y] = 1;

    //cout << "***"  << x << " " << y << endl;
    if(y >= n) { flag = 1; return; }
    if(g[x][y + 1] != '.') return;
    //y += 1;
    //y++;
    for(int i = 0; i < 3; ++i)  {
        int nx = x + dx[i], ny = y + 1;
        if(nx < 1 || nx > 3 || ny > n + 1) continue;
        if(g[nx][ny + 1] == '.' && g[nx][ny] == '.' && !vs[nx][ny + 2] && g[nx][ny + 3] == '.') dfs(nx, ny + 2);
    }
}

int main() {
    cin >> t;

    while(t--) {
        cin >> n >> k;
        memset(vs, 0, sizeof vs);
        for(int i = 1; i <= 3; ++i) cin >> (g[i] + 1);

        for(int i = 1; i <= 3; ++i) {
            for(int j = n + 1; j <= n + 5; ++j) g[i][j] = '.';
        }
        flag = 0;
        for(int i = 1; i <= 3; ++i) if(g[i][1] == 's') dfs(i, 1);

        cout << (flag ? "YES" : "NO") << endl;
    }
}


#include <iostream>
#include <string>
#include <cstring>
using namespace std;

const int N = 105;
int t, n, k;
char g[4][N];
bool vs[4][N], flag = 0;

int dx[] = {1, 0, -1};

void dfs(int x, int y) {
    vs[x][y] = 1;

    //cout << "***"  << x << " " << y << endl;
    if(y >= n) flag = 1;
    if(g[x][y + 1] != '.') return;
    //y += 1;
    //y++;
    for(int i = 0; i < 3; ++i)  {
        int nx = x + dx[i], ny = y + 1;
        if(nx < 1 || nx > 3 || ny > n + 1) continue;
        if(g[nx][ny + 1] == '.' && g[nx][ny] == '.') dfs(nx, ny + 2);
    }
}

int main() {
    cin >> t;

    while(t--) {
        cin >> n >> k;
        memset(vs, 0, sizeof vs);
        for(int i = 1; i <= 3; ++i) cin >> (g[i] + 1);

        flag = 0;
        for(int i = 1; i <= 3; ++i) if(g[i][1] == 's') dfs(i, 1);

        cout << (flag ? "YES" : "NO") << endl;
    }
}


#include <iostream>
#include <string>
#include <cstring>
using namespace std;

const int N = 105;
int t, n, k;
char g[4][N];
bool vs[4][N], flag = 0;

int dx[] = {1, 0, -1};

void dfs(int x, int y) {
    vs[x][y] = 1;

    //cout << "***"  << x << " " << y << endl;
    if(y >= n) { flag = 1; return; }
    if(g[x][y + 1] != '.') return;
    //y += 1;
    //y++;
    for(int i = 0; i < 3; ++i)  {
        int nx = x + dx[i], ny = y + 1;
        if(nx < 1 || nx > 3 || ny > n + 1) continue;
        if(g[nx][ny + 1] == '.' && g[nx][ny] == '.' && !vs[nx][ny + 2]) dfs(nx, ny + 2);
    }
}

int main() {
    cin >> t;

    while(t--) {
        cin >> n >> k;
        memset(vs, 0, sizeof vs);
        for(int i = 1; i <= 3; ++i) cin >> (g[i] + 1);

        flag = 0;
        for(int i = 1; i <= 3; ++i) if(g[i][1] == 's') dfs(i, 1);

        cout << (flag ? "YES" : "NO") << endl;
    }
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define sz(x) ((int)x.size())
using namespace std;

typedef long long lli;
typedef pair<int,int> pii;

char str[3][110];
int vis[3][110];
int n=3,m,k;
bool endf;

const int dy[]={-1,1,0},dx[]={0,0,0};

bool go(int y,int x) {
	return y>=0 && x>=0 && y<n && x<m && !isupper(str[y][x]);
}
bool canGo(int d,int y,int x,pii &res) {
	x+=1;
	if(!go(y,x)) {
		if(x==m) endf=true;
		return false;
	}
	y+=dy[d],x+=dx[d];
	if(!go(y,x)) {
		if(x==m) endf=true;
		return false;
	}
	x+=1;
	if(!go(y,x)) {
		if(x==m) endf=true;
		return false;
	}
	x+=1;
	if(!go(y,x)) {
		if(x==m) endf=true;
		return false;
	}
	res = pii(y,x);
	return true;
}

bool bfs(int sy,int sx) {
	memset(vis,0,sizeof(vis));
	endf=false;

	queue<pii> que;
	que.push(pii(sy,sx));
	vis[sy][sx]=0;
	while(!que.empty()) {
		int y=que.front().fi, x=que.front().se;
		que.pop();
		for(int k=0;k<3;k++) {
			pii pos;
			if(canGo(k,y,x,pos) && !vis[pos.fi][pos.se]) {
				vis[pos.fi][pos.se]=1;
				que.push(pos);
			}
		}
	}

	return endf;
}

int main() {
	int test;
	scanf("%d",&test);
	while(test--) {
		scanf("%d%d",&m,&k);
		for(int i=0;i<n;i++) scanf("%s",str[i]);

		for(int i=0;i<n;i++) for(int j=0;j<m;j++) if(str[i][j]=='s') {
			puts(bfs(i,j) ? "YES" : "NO");
		}
	}
	return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define sz(x) ((int)x.size())
using namespace std;

typedef long long lli;
typedef pair<int,int> pii;

char str[3][110];
int vis[3][110];
int n=3,m,k;
bool endf;

const int dy[]={-1,1,0,0},dx[]={0,0,1,0};

bool go(int y,int x) {
	return y>=0 && x>=0 && y<n && x<m && !isupper(str[y][x]);
}
bool canGo(int d,int y,int x,pii &res) {
	x+=1;
	if(!go(y,x)) {
		if(x==m) endf=true;
		return false;
	}
	y+=dy[d],x+=dx[d];
	if(!go(y,x)) {
		if(x==m) endf=true;
		return false;
	}
	x+=1;
	if(!go(y,x)) {
		if(x==m) endf=true;
		return false;
	}
	x+=1;
	if(!go(y,x)) {
		if(x==m) endf=true;
		return false;
	}
	res = pii(y,x);
	return true;
}

bool bfs(int sy,int sx) {
	memset(vis,0,sizeof(vis));
	endf=false;

	queue<pii> que;
	que.push(pii(sy,sx));
	vis[sy][sx]=0;
	while(!que.empty()) {
		int y=que.front().fi, x=que.front().se;
		que.pop();
		for(int k=0;k<4;k++) {
			pii pos;
			if(canGo(k,y,x,pos) && !vis[pos.fi][pos.se]) {
				vis[pos.fi][pos.se]=1;
				que.push(pos);
			}
		}
	}

	return endf;
}

int main() {
	int test;
	scanf("%d",&test);
	while(test--) {
		scanf("%d%d",&m,&k);
		for(int i=0;i<n;i++) scanf("%s",str[i]);

		for(int i=0;i<n;i++) for(int j=0;j<m;j++) if(str[i][j]=='s') {
			puts(bfs(i,j) ? "YES" : "NO");
		}
	}
	return 0;
}


#include <iostream>
#include<bits/stdc++.h>
# define pb push_back
# define ll long long
# define mod 1000000007
# define mk make_pair
# define pii pair<int,int>
# define INF 0x3f3f3f3f
using namespace std;

int main() {
	int t;cin >> t;
	while(t--){
	    int n,k;cin >> n>>k;
	    //int t1=3,t2=n+10;
	    int a[3][n+10];
	    for(int i=0;i<3;i++)
	    {
	        for(int j=0;j<n+3;j++) a[i][j]=0;
	    }
	    int xi,yi=0;
	    for(int i=0;i<3;i++)
	    {
	        for(int j=0;j<n;j++)
	        {
	            char x;scanf(" %c",&x) ;
	            if(x=='s') xi=i;
	            else if(x=='.') a[i][j]=0;
	            else a[i][j]=1;
	        }
	    }
	    int flag=0;
	    queue<pii>q;q.push(mk(xi,yi));
	    while(q.size())
	    {
	        pii k=q.front();q.pop();
	        int x=k.first;int y=k.second;
	        if(y<n-1)
	        {
	            //cout << x << " " << y << "\n";
	            if(x>0 && a[x-1][y+1]==0 && a[x-1][y+2]==0 && a[x-1][y+3]==0 && a[x-1][y+4]==0) q.push(mk(x-1,y+3));
	            if(a[x][y+1]==0 && a[x][y+2]==0 && a[x][y+3]==0 && a[x][y+4]==0) q.push(mk(x,y+3));
	            if(x<2 && a[x+1][y+1]==0 && a[x+1][y+2]==0 && a[x+1][y+3]==0 && a[x+1][y+4]==0) q.push(mk(x+1,y+3));
	        }
	        else {flag=1;break;}
	    }
	    if(flag==0) cout << "NO"<< "\n";
	    else cout << "YES"<< "\n";

	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <stdlib.h>
#include <queue>
#include <set>
#include <iostream>
#include <stack>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
//#include <assert.h>
//#include <sstream>
using namespace std;

#define ll long long
#define ull unsigned long long
#define pii pair <int, int>
#define piii pair <int, pii>
#define vi vector <int>
#define vl vector <ll>
#define pll pair <ll, ll>
#define PI acos(-1)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define mem(a, b) memset(a, b, sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a)*(a))
#define inf 100000000
const int INF = 0x3f3f3f3f;
#define LINF 0x3f3f3f3f3f3f3f3fLL
#define mod 1000000007
#define mod1 1000000007
#define mod2 1000000009
#define b1 43
#define b2 41
#define EPS 1e-9
//define harmonic(n) 0.57721566490153286l+log(n)
#define nl puts("")
#define odd(n) ((n)&1)
#define even(n) (!((n)&1))
#define vsort(v) sort(v.begin(), v.end())
#define lc (node<<1)
#define rc ((node<<1)|1)
//loop
#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, n) for(int i = 1; i <= n; ++i)
#define forn(i, j, n) for(int i = j; i <= n; ++i)
//input
#define si(a) scanf("%d", &a)
#define sii(a, b) scanf("%d%d", &a, &b)
#define siii(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define sl(a) scanf("%lld", &a)
#define sll(a, b) scanf("%lld%lld", &a, &b)
#define slll(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define sd(a) scanf("%lf", &a)
#define sc(a) scanf("%c", &a)
#define sst(a) scanf("%s", a)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
//debug
#ifdef tahsin

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
	return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
	os << "{";
	for(auto it = v.begin(); it != v.end(); ++it) {
		if( it != v.begin() ) os << ", ";
		os << *it;
	}
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
	os << "[";
	for(auto it = v.begin(); it != v.end(); ++it) {
		if( it != v.begin()) os << ", ";
		os << *it;
	}
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
	os << "[";
	for(auto it = v.begin(); it != v.end(); ++it) {
		if( it != v.begin() ) os << ", ";
		os << it -> first << " = " << it -> second ;
	}
    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)

void faltu () { cerr << endl; }

template <typename T>
void faltu( T a[], int n ) {
	for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
	cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) { cerr << arg << ' '; faltu(rest...); }

#else
#define dbg(args...)
#endif

ll add(ll a, ll b, ll m = mod) {
	ll ret = a+b;
	if(ret >= m) ret -= m;
	return ret;
}

ll subtract(ll a, ll b, ll m = mod) {
	ll ret = a-b;
	if(ret < 0) ret += m;
	return ret;
}

ll mult(ll a, ll b, ll m = mod) {
	ll ret = a*b;
	if(ret >= m) ret %= m;
	return ret;
}

ll bigmod(ll a, ll b, ll m = mod) {
	ll ret = 1;
	while(b) {
		if(b&1) ret = mult(ret, a, m);
		b >>= 1; a = mult(a, a, m);
	}
	return ret;
}

ll inverse(ll n, ll m = mod) { return bigmod(n, mod-2, m); }

/*
bool base[1000010];
vi primes;
void sieve(int mx) {
	mx += 10;
	int x = sqrt(mx);
	for(int i = 3; i <= x; i += 2) if(base[i] == 0) for(int j = i*i, k = i<<1; j < mx; j += k) base[j] = 1;
	primes.PB(2);
	for(int i = 3; i < mx; i += 2) if(base[i] == 0) primes.PB(i);
}
*/

//Direction Array
//int fx[]={1, -1, 0, 0}; int fy[]={0, 0, 1, -1};
//int fx[]={0, 0, 1, -1, -1, 1, -1, 1}; int fy[]={-1, 1, 0, 0, 1, 1, -1, -1};

//bit manipulation
/*
bool checkBit(int n, int i) { return (n&(1<<i)); }
int setBit(int n, int i) { return (n|(1<<i)); }
int resetBit(int n, int i) { return (n&(~(1<<i))); }
*/
//end of template

#define mxn 300010
#define magic 200

int n;
int dp[2][magic+10];
int a[mxn];

int main () {
#ifdef tahsin
	freopen("in", "r", stdin);
//	freopen("out", "w", stdout);
#endif

	while(si(n) == 1) {
		rep(i, n) si(a[i]), a[i] /= 100;

		mem(dp, INF);
		dp[0][0] = 0;
		int now = 0, nxt = 1;

		rep(i, n) {
			mem(dp[nxt], INF);
			rep(j, magic) if(dp[now][j] < INF) {
				if(j+a[i]/10 < magic) {
					dp[nxt][j+a[i]/10] = min(dp[nxt][j+a[i]/10], a[i] + dp[now][j]);
				}
				dp[nxt][max(0, j-a[i])] = min(dp[nxt][max(0, j-a[i])], max(0, a[i]-j) + dp[now][j]);
			}
			swap(now, nxt);
		}

		int res = INF;
		rep(i, magic) res = min(res, dp[now][i]);

		printf("%lld\n", (ll) res*100);
	}

//	timeStamp;
	return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

const int MOD = 1000000007;
const int MX = 300005;

int n, a[MX], nex[MX][3], sum[MX];
int maxdis = 0;

void init() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> n;
	FOR(i,1,n+1) {
	    cin >> a[i];
	    sum[i] = sum[i-1]+a[i];
	}
	nex[n+1][1] = nex[n+1][2] = n+1;

	FORd(i,1,n+1) {
	    nex[i][1] = nex[i+1][1];
	    nex[i][2] = nex[i+1][2];
	    if (a[i] == 1000) nex[i][1] = i;
	    else if (a[i] == 2000) nex[i][2] = i;
	}
}

int main() {
    init();
	F0R(i,n+1) {
	    // let's pay cash for the first i
	    maxdis = max(maxdis,min(sum[n]-sum[i],sum[i]/10));

	    // then consider nex[i+1][1]
	    int co = nex[i+1][1];
	    if (co != n+1 && co != i+1) {
	        int cbal = sum[i]/10, cdis = 0;
	        int z = min(cbal,sum[co-1]-sum[i]);
	        cbal -= z, cdis += z;
	        cbal += 100;
	        z = min(cbal,sum[n]-sum[co]);
	        cdis += z;
	        maxdis = max(maxdis,cdis);
	    }

	    // nex[i+1][2]
	    co = nex[i+1][2];
	    if (co != n+1 && co != i+1) {
	        int cbal = sum[i]/10, cdis = 0;
	        int z = min(cbal,sum[co-1]-sum[i]);
	        cbal -= z, cdis += z;
	        cbal += 200;
	        z = min(cbal,sum[n]-sum[co]);
	        cdis += z;
	        maxdis = max(maxdis,cdis);
	    }
	}
	cout << sum[n]-maxdis;
}

// read!
// ll vs. int!


#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

const int MOD = 1000000007;
const int MX = 300005;

int n, a[MX], nex[MX][3], sum[MX];
int one[MX];
int maxdis = 0;

void init() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> n;
	FOR(i,1,n+1) {
	    cin >> a[i];
	    sum[i] = sum[i-1]+a[i];
	    one[i] = one[i-1];
	    if (a[i] == 1000) one[i] = i;
	}
	nex[n+1][1] = nex[n+1][2] = n+1;

	FORd(i,1,n+1) {
	    nex[i][1] = nex[i+1][1];
	    nex[i][2] = nex[i+1][2];
	    if (a[i] == 1000) nex[i][1] = i;
	    else if (a[i] == 2000) nex[i][2] = i;
	}
}

int main() {
    init();
	F0R(i,n+1) {
	    // let's pay cash for the first i
	    maxdis = max(maxdis,min(sum[n]-sum[i],sum[i]/10));
	    if (one[i]) {
	        int cbal = sum[one[i]-1]/10, cdis = 0;
	        int z = min(cbal,1000);
	        cbal -= z, cdis += z;
	        cbal += (sum[i]-sum[one[i]])/10;
	        z = min(cbal,sum[n]-sum[i]);
	        cdis += z;
	        maxdis = max(maxdis,cdis);
	    }

	    // then consider nex[i+1][1]
	    int co = nex[i+1][1];
	    if (co != n+1 && co != i+1) {
	        int cbal = sum[i]/10, cdis = 0;
	        int z = min(cbal,sum[co-1]-sum[i]);
	        cbal -= z, cdis += z;
	        cbal += 100;
	        z = min(cbal,sum[n]-sum[co]);
	        cdis += z;
	        maxdis = max(maxdis,cdis);
	    }

	    // nex[i+1][2]
	    co = nex[i+1][2];
	    if (co != n+1 && co != i+1) {
	        int cbal = sum[i]/10, cdis = 0;
	        int z = min(cbal,sum[co-1]-sum[i]);
	        cbal -= z, cdis += z;
	        cbal += 200;
	        z = min(cbal,sum[n]-sum[co]);
	        cdis += z;
	        maxdis = max(maxdis,cdis);
	    }
	}
	cout << sum[n]-maxdis;
}

// read!
// ll vs. int!


#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define print(v,r) f(i,0,r) cout<<v[i]<<" "; cout<<endl;
#define Get(x,y) scanf("%I64d%I64d",&x,&y);
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define Gett(x,y) scanf("%d%d",&x,&y);
#define f(i,a,b) for(int i=a;i<b;i++)
#define get(x) scanf("%I64d",&x);
#define gett(x) scanf("%d",&x);
#define ops(x) cout<<x<<" !"<<endl;
#define maxm(a,b) a=max(a,b);
#define minm(a,b) a=min(a,b);
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first

const int N=5e5+99,M=45,inf=1e9;

int n,t,a[N],dp[N][M],ans=inf;

int main(){
	cin>>n;
	f(i,1,n+1){ cin>>a[i];	a[i]/=1000; }
	f(i,1,M) dp[0][i]=inf;
	f(i,1,n+1)
		f(j,0,M){
			dp[i][j]=inf;
			if(j>=a[i])
				dp[i][j]=dp[i-1][j-a[i]]+a[i]*10;
			f(l,j+1,M)
				minm(dp[i][j],dp[i-1][l]+max(a[i]*10-(l-j),0));
		}
	f(i,0,M) minm(ans,dp[n][i]);
	cout<<ans*100ll;
}


#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define print(v,r) f(i,0,r) cout<<v[i]<<" "; cout<<endl;
#define Get(x,y) scanf("%I64d%I64d",&x,&y);
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define Gett(x,y) scanf("%d%d",&x,&y);
#define f(i,a,b) for(int i=a;i<b;i++)
#define get(x) scanf("%I64d",&x);
#define gett(x) scanf("%d",&x);
#define ops(x) cout<<x<<" !"<<endl;
#define maxm(a,b) a=max(a,b);
#define minm(a,b) a=min(a,b);
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first

const int N=5e5+99,M=25,inf=1e9;

int n,t,a[N],dp[N][M],ans=inf;

int main(){
	cin>>n;
	f(i,1,n+1){ cin>>a[i];	a[i]/=1000; }
	f(i,1,M) dp[0][i]=inf;
	f(i,1,n+1)
		f(j,0,M){
			dp[i][j]=inf;
			if(j>=a[i])
				dp[i][j]=dp[i-1][j-a[i]]+a[i]*10;
			f(l,j+1,M)
				minm(dp[i][j],dp[i-1][l]+max(a[i]*10-(l-j),0));
		}
	f(i,0,M) minm(ans,dp[n][i]);
	cout<<ans*100ll;
}


#include <iostream>
#include <algorithm>
#define MAXN 300010
#define MAX 400

using namespace std;

int n,a[MAXN];
int dp[MAXN][MAX];

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    for (int i = 0; i <= n; i++)
        for (int j = 0; j < MAX; j++)
            dp[i][j] = 1e9;
    dp[0][0] = 0;

    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < MAX; j++) {
            int x = a[i] / 100;
            if (j >= x) {
                dp[i][j - x] = min(dp[i][j-x], dp[i-1][j]);
            } else {
                dp[i][0] = min(dp[i][0], dp[i-1][j] + a[i] - 100 * j);
            }

            x = a[i] / 1000;
            if (j + x < MAX)
                dp[i][j + x] = min(dp[i][j+x], dp[i-1][j] + a[i]);
        }
    }

    int ans = dp[n][0];
    for (int i = 0; i < MAX; i++) {
        ans = min(ans, dp[n][i]);
    }
    cout << ans << '\n';
}


#include <iostream>
#include <algorithm>
#define MAXN 300010
#define MAX 1000

using namespace std;

int n,a[MAXN];
int dp[MAXN][MAX];

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    for (int i = 0; i <= n; i++)
        for (int j = 0; j < MAX; j++)
            dp[i][j] = 1e9;
    dp[0][0] = 0;

    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < MAX; j++) {
            int x = a[i] / 100;
            if (j >= x) {
                dp[i][j - x] = min(dp[i][j-x], dp[i-1][j]);
            } else {
                dp[i][0] = min(dp[i][0], dp[i-1][j] + a[i] - 100 * j);
            }

            x = a[i] / 1000;
            if (j + x < MAX)
                dp[i][j + x] = min(dp[i][j+x], dp[i-1][j] + a[i]);
        }
    }

    int ans = dp[n][0];
    for (int i = 0; i < MAX; i++) {
        ans = min(ans, dp[n][i]);
    }
    cout << ans << '\n';
}


//CF 853D Michael and Charging Stations
#include<iostream>
#include<cstdio>
using namespace std;

int read(){
	int x=0;
	char c=getchar();
	while(c>='0'&&c<='9'){
		x=x*10+c-48;
		c=getchar();
	}
	return x;
}

int n,a[400005],sum,tmp,tot;

int main(){
	n=read();
	for(int i=1;i<=n;i++){
		a[i]=read()/100;
		sum+=a[i];
		tot+=(a[i]==10);
	}
	tmp=sum/11;
	if(sum<=110){
		tmp=sum/10-a[n]/10;
	}
	if(!tot&&tmp%2==1)tmp--;
	cout<<sum*100-tmp*100<<endl;
	return 0;
}


//Michael and Charging Stations
#include<iostream>
using namespace std;
#include<cstdio>
#define N 300005

int a[N],n,sum,cur,ans;

int read(){
    int x=0;char c=getchar();
    while(c>='0'&&c<='9'){
        x=x*10+c-48;
        c=getchar();
    }
    return x;
}

int main(){
    n=read();
    for(int i=1;i<=n;i++){
        a[i]=read()/100;
        sum+=a[i];
	}
	int k=sum/220;
	ans+=k*200;
	sum%=220;
	int i=n+1,temp=0;
	while(temp!=sum){
		temp+=a[--i];
	}

	for(;i<n;i++){
        if(cur>=a[i]){
            cur-=a[i];
            continue;
        }
        ans+=a[i];
        cur+=(a[i]/10);
        sum-=a[i];
    }
    ans+=(a[n]-cur);
    cout<<ans*100<<endl;
    return 0;
}

/*
8
2000
2000
2000
2000
2000
1000
1000
1000
*/


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <ctime>

using namespace std;

inline void Read( int & x ){
	x = 0;
	char ch;
	for( ch = getchar() ; ch < '0' || ch > '9' ; ch = getchar() );
	for( ; ch <= '9' && ch >= '0' ; ch = getchar() ) x = x * 10 + ch - '0';
}

const int maxn = 3e5 + 50;
const int inf = 0x3f3f3f3f;
#define lowbit( x ) ( ( x ) & ( - x ) )

int n , a[maxn] , lzy[maxn << 2] , mi[maxn << 2] , Pf[maxn << 2] , Gf[maxn << 2];
vector < int > v1,v2;

void Update( int ql , int qr , int x ){
	static int q[maxn] , l[maxn] , r[maxn];
	int i , j;
	for( i = j = 0 , l[j] = 1 , r[j] = n , q[j ++] = 1 ; i < j ; ++ i){
		if( ql <= l[i] and r[i] <= qr )
			lzy[q[i]] += x , mi[q[i]] += x;
		else{
			int mid = l[i] + r[i] >> 1;
			if( lzy[q[i]] ) lzy[q[i] << 1] += lzy[q[i]] , lzy[q[i] << 1 | 1] += lzy[q[i]] , mi[q[i] << 1] += lzy[q[i]] , mi[q[i] << 1 | 1] += lzy[q[i]] , lzy[q[i]] = 0;
			if( ql <= mid ) l[j] = l[i] , r[j] = mid , q[j ++] = q[i] << 1;
			if( qr > mid ) l[j] = mid + 1 , r[j] = r[i] , q[j ++] = q[i] << 1 | 1;
		}
	}
	for( i = j - 1 ; i >= 0 ; -- i)
		if( ql > l[i] or r[i] > qr )
			mi[q[i]] = min( mi[q[i] << 1] , mi[q[i] << 1 | 1] );
}

bool Check( int x ){
	memcpy( lzy , Pf , sizeof( lzy ) );
	memcpy( mi , Gf , sizeof( mi ) );
	int j = x / 2000 , k = 0;
	for(int i = 0 ; i < min( (int)v2.size() , j ) ; ++ i) Update( v2[i] , n , a[v2[i]] + a[v2[i]] / 10 );
	for(int w = 0 ; w * 1000 <= x ; ++ w){
		int b = ( x - 1000 * w ) / 2000 , remain = x - 1000 * w - 2000 * b;
		while( j > b ){
			-- j;
			if( j < v2.size() ) Update( v2[j] , n , - ( a[v2[j]] + a[v2[j]] / 10 ) );
		}
		while( k < w ){
			if( k < v1.size() ) Update( v1[k] , n , a[v1[k]] + a[v1[k]] / 10 );
			++ k;
		}
		if( remain + mi[1] >= 0 ) return true;
	}
	return false;
}

int main( int argc , char * argv[] ){
	Read( n );
	for(int i = 1 ; i <= n ; ++ i){
		Read( a[i] );
		if( a[i] == 1000 ) v1.emplace_back( i );
		else v2.emplace_back( i );
	}
	for(int i = 1 ; i <= n ; ++ i) Update( i , n , - a[i] );
	memcpy( Pf , lzy , sizeof( lzy ) );
	memcpy( Gf , mi , sizeof( mi ) );
	int l = 0 , r = 600000000;
	while( l < r ){
		int mid = l + r >> 1;
		if( Check( mid ) ) r = mid;
		else l = mid + 1;
	}
	printf( "%d\n" , l );
	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>

const int maxn = 3e5 + 50;
const int inf = 0x3f3f3f3f;

int n , f[2][312] , cur = 0;

inline void Update( int & x , int y ){
	x = std::min( x , y );
}

int main( int argc , char * argv[] ){
	scanf( "%d" , & n );
	memset( f[cur] , 0x3f , sizeof( f[cur] ) );
	f[cur][0] = 0;
	while( n -- ){
		int x , pre = cur; cur ^= 1 ; memset( f[cur] , 0x3f , sizeof( f[cur] ) );
		scanf( "%d" , & x );
		for(int i = 0 ; i < 312 ; ++ i)
			if( f[pre][i] != inf ){
				if( i + x / 100 < 312 ) Update( f[cur][i + x / 100] , f[pre][i] + x );
				int used = std::min( x , i * 10 ) , j = ( x - used ) / 100;
				if( i - used / 10 + j < 312 ) Update( f[cur][i - used / 10 + j] , f[pre][i] + x - used );
			}
	}
	int ans = inf;
	for(int i = 0 ; i < 312 ; ++ i) ans = std::min( ans , f[cur][i] );
	printf( "%d\n" , ans );
	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int maxn = 3e5 + 50;
const int inf = 0x3f3f3f3f;

struct Node{
	int l , r , lzy , mi;
	void Update( int x ){
		lzy += x , mi += x;
	}
}tree[maxn << 2];

void Build( int l , int r , int o ){
	tree[o].l = l , tree[o].r = r , tree[o].lzy = tree[o].mi = 0;
	if( l < r ){
		int mid = l + r >> 1;
		Build( l , mid , o << 1 );
		Build( mid + 1 , r , o << 1 | 1 );
	}
}

void Re( int o ){
	if( tree[o].lzy ){
		tree[o << 1].Update( tree[o].lzy ) , tree[o << 1 | 1].Update( tree[o].lzy );
		tree[o].lzy = 0;
	}
}

void Ma( int o ){
	tree[o].mi = min( tree[o << 1].mi , tree[o << 1 | 1].mi );
}

void Moidfy( int ql , int qr , int x , int o ){
	int l = tree[o].l , r = tree[o].r;
	if( ql <= l && r <= qr ) tree[o].Update( x );
	else{
		int mid = l + r >> 1;
		Re( o );
		if( ql <= mid ) Moidfy( ql , qr , x , o << 1 );
		if( qr > mid ) Moidfy( ql , qr , x , o << 1 | 1 );
		Ma( o );
	}
}

int n , a[maxn];
vector < int > v1,v2;

bool Check( int x ){
	Build( 1 , n , 1 );
	for(int i = 1 ; i <= n ; ++ i) Moidfy( i , n , - a[i] , 1 );
	int j = x / 2000 , k = 0;
	for(int i = 0 ; i < min( (int)v2.size() , j ) ; ++ i) Moidfy( v2[i] , n , a[v2[i]] + a[v2[i]] / 10 , 1 );
	for(int w = 0 ; w * 1000 <= x ; ++ w){
		int b = ( x - 1000 * w ) / 2000 , remain = x - 1000 * w - 2000 * b;
		while( j >= b ){
			if( j < v2.size() ) Moidfy( v2[j] , n , - ( a[v2[j]] + a[v2[j]] / 10 + a[v2[j]] ) , 1 );
			-- j;
		}
		while( k < w ){
			if( k < v1.size() ) Moidfy( v1[k] , n , a[v1[k]] + a[v1[k]] / 10 , 1 );
			++ k;
		}
		if( remain + tree[1].mi >= 0 ) return true;
	}
	return false;
}

int main( int argc , char * argv[] ){
	scanf( "%d" , & n );
	for(int i = 1 ; i <= n ; ++ i){
		scanf( "%d" , a + i );
		if( a[i] == 1000 ) v1.emplace_back( i );
		else v2.emplace_back( i );
	}
	int l = 0 , r = 600000000;
	while( l < r ){
		int mid = l + r >> 1;
		if( Check( mid ) ) r = mid;
		else l = mid + 1;
	}
	printf( "%d\n" , l );
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int maxn = 3e5 + 50;
const int inf = 0x3f3f3f3f;

struct Node{
	int l , r , lzy , mi;
	void Update( int x ){
		lzy += x , mi += x;
	}
}tree[maxn << 2];

void Build( int l , int r , int o ){
	tree[o].l = l , tree[o].r = r , tree[o].lzy = tree[o].mi = 0;
	if( l < r ){
		int mid = l + r >> 1;
		Build( l , mid , o << 1 );
		Build( mid + 1 , r , o << 1 | 1 );
	}
}

void Re( int o ){
	if( tree[o].lzy ){
		tree[o << 1].Update( tree[o].lzy );
		tree[o << 1 | 1].Update( tree[o].lzy );
		tree[o].lzy = 0;
	}
}

void Ma( int o ){
	tree[o].mi = min( tree[o << 1].mi , tree[o << 1 | 1].mi );
}

void Moidfy( int ql , int qr , int x , int o ){
	int l = tree[o].l , r = tree[o].r;
	if( ql <= l && r <= qr ) tree[o].Update( x );
	else{
		int mid = l + r >> 1;
		Re( o );
		if( ql <= mid ) Moidfy( ql , qr , x , o << 1 );
		if( qr > mid ) Moidfy( ql , qr , x , o << 1 | 1 );
		Ma( o );
	}
}

int query( int x , int o ){
	int l = tree[o].l , r = tree[o].r;
	if( l == r ) return tree[o].mi;
	else{
		int mid = l + r >> 1 , ret;
		Re( o );
		if( x <= mid ) ret = query( x , o << 1 );
		else ret = query( x , o << 1 | 1 );
		Ma( o );
		return ret;
	}
}

int n , a[maxn];
vector < int > v1,v2;

bool Check( int x ){
	Build( 1 , n , 1 );
	for(int i = 1 ; i <= n ; ++ i) Moidfy( i , n , - a[i] , 1 );
	int j = x / 2000 , k = 0;
	for(int i = 0 ; i < min( (int)v2.size() , j ) ; ++ i) Moidfy( v2[i] , n , a[v2[i]] + a[v2[i]] / 10 , 1 );
	for(int w = 0 ; w * 1000 <= x ; ++ w){
		int b = ( x - 1000 * w ) / 2000 , remain = x - 1000 * w - 2000 * b;
		while( j > b ){
			-- j;
			if( j < v2.size() ) Moidfy( v2[j] , n , - ( a[v2[j]] + a[v2[j]] / 10 ) , 1 );
		}
		while( k < w ){
			if( k < v1.size() ) Moidfy( v1[k] , n , a[v1[k]] + a[v1[k]] / 10 , 1 );
			++ k;
		}
		if( remain + tree[1].mi >= 0 ) return true;
	}
	return false;
}

int main( int argc , char * argv[] ){
	scanf( "%d" , & n );
	for(int i = 1 ; i <= n ; ++ i){
		scanf( "%d" , a + i );
		if( a[i] == 1000 ) v1.emplace_back( i );
		else v2.emplace_back( i );
	}
	int l = 0 , r = 600000000;
	while( l < r ){
		int mid = l + r >> 1;
		if( Check( mid ) ) r = mid;
		else l = mid + 1;
	}
	printf( "%d\n" , l );
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}

const int maxn = 3e5 + 50;
const long long inf = 0x3f3f3f3f3f3f3f3f;

int n , a[maxn];
long long pf[maxn] , sf[maxn];

int main( int argc , char * argv[] ){
	n = read();
	long long ans = 0 , sum = 0;
	for(int i = 1 ; i <= n ; ++ i) a[i] = read() , ans += a[i] , sum += a[i];
	for(int i = 1 ; i <= n ; ++ i) pf[i] = pf[i - 1] + a[i];
	for(int i = n ; i >= 1 ; -- i) sf[i] = sf[i + 1] + a[i];
	for(int x = 1 ; x <= n ; ++ x){
		if( pf[x - 1] <= sf[x] * 10LL ) ans = min( ans , sum - pf[x - 1] / 10LL );
		else ans = min( ans , pf[x] );
	}
	printf( "%I64d\n" , ans );
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <ctime>

using namespace std;

const int maxn = 3e5 + 50;
const int inf = 0x3f3f3f3f;

int sum[maxn];

struct Node{
	int l , r , lzy , mi , cl;
	void Cl(){
		cl = 1;
		lzy = 0;
		mi = sum[r];
	}
	void Update( int x ){
		lzy += x , mi += x;
	}
}tree[maxn << 2];

void Build( int l , int r , int o ){
	tree[o].l = l , tree[o].r = r , tree[o].lzy = tree[o].mi = 0;
	if( l < r ){
		int mid = l + r >> 1;
		Build( l , mid , o << 1 );
		Build( mid + 1 , r , o << 1 | 1 );
	}
}

void Re( int o ){
	if( tree[o].cl ){
		tree[o << 1].Cl();
		tree[o << 1 | 1].Cl();
		tree[o].cl = 0;
	}
	if( tree[o].lzy ){
		tree[o << 1].Update( tree[o].lzy );
		tree[o << 1 | 1].Update( tree[o].lzy );
		tree[o].lzy = 0;
	}
}

void Ma( int o ){
	tree[o].mi = min( tree[o << 1].mi , tree[o << 1 | 1].mi );
}

void Moidfy( int ql , int qr , int x , int o ){
	int l = tree[o].l , r = tree[o].r;
	if( ql <= l && r <= qr ) tree[o].Update( x );
	else{
		int mid = l + r >> 1;
		Re( o );
		if( ql <= mid ) Moidfy( ql , qr , x , o << 1 );
		if( qr > mid ) Moidfy( ql , qr , x , o << 1 | 1 );
		Ma( o );
	}
}

int n , a[maxn];
vector < int > v1,v2;

bool Check( int x ){
	tree[1].Cl();
	int j = x / 2000 , k = 0;
	for(int i = 0 ; i < min( (int)v2.size() , j ) ; ++ i) Moidfy( v2[i] , n , a[v2[i]] + a[v2[i]] / 10 , 1 );
	for(int w = 0 ; w * 1000 <= x ; ++ w){
		int b = ( x - 1000 * w ) / 2000 , remain = x - 1000 * w - 2000 * b;
		while( j > b ){
			-- j;
			if( j < v2.size() ) Moidfy( v2[j] , n , - ( a[v2[j]] + a[v2[j]] / 10 ) , 1 );
		}
		while( k < w ){
			if( k < v1.size() ) Moidfy( v1[k] , n , a[v1[k]] + a[v1[k]] / 10 , 1 );
			++ k;
		}
		if( remain + tree[1].mi >= 0 ) return true;
	}
	return false;
}

int main( int argc , char * argv[] ){
	scanf( "%d" , & n );
	Build( 1 , n , 1 );
	for(int i = 1 ; i <= n ; ++ i){
		scanf( "%d" , a + i );
		sum[i] = sum[i - 1] - a[i];
		if( a[i] == 1000 ) v1.emplace_back( i );
		else v2.emplace_back( i );
	}
	int l = 0 , r = 600000000;
	while( l < r ){
		int mid = l + r >> 1;
		if( Check( mid ) ) r = mid;
		else l = mid + 1;
	}
	printf( "%d\n" , l );
	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>

const int maxn = 3e5 + 50;
const int inf = 0x3f3f3f3f;

int n , f[2][400] , cur = 0;

inline void Update( int & x , int y ){
	x = std::min( x , y );
}

int main( int argc , char * argv[] ){
	scanf( "%d" , & n );
	memset( f[cur] , 0x3f , sizeof( f[cur] ) );
	f[cur][0] = 0;
	while( n -- ){
		int x , pre = cur; cur ^= 1 ; memset( f[cur] , 0x3f , sizeof( f[cur] ) );
		scanf( "%d" , & x );
		for(int i = 0 ; i < 400 ; ++ i)
			if( f[pre][i] != inf ){
				if( i + x / 100 < 400 ) Update( f[cur][i + x / 100] , f[pre][i] + x );
				int used = std::min( x , i * 10 ) , j = ( x - used ) / 100;
				if( i - used / 10 + j < 400 ) Update( f[cur][i - used / 10 + j] , f[pre][i] + x - used );
				if( x == 2000 ){
					int used = std::min( 1000 , i * 10 ) , j = ( x - used ) / 100;
					if( i - used / 10 + j < 400 ) Update( f[cur][i - used / 10 + j] , f[pre][i] + x - used );
				}
			}
	}
	int ans = inf;
	for(int i = 0 ; i < 400 ; ++ i) ans = std::min( ans , f[cur][i] );
	printf( "%d\n" , ans );
	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>

const int maxn = 3e5 + 50;
const int inf = 0x3f3f3f3f;

int n , f[2][400] , cur = 0;

inline void Update( int & x , int y ){
	x = std::min( x , y );
}

int main( int argc , char * argv[] ){
	scanf( "%d" , & n );
	memset( f[cur] , 0x3f , sizeof( f[cur] ) );
	f[cur][0] = 0;
	while( n -- ){
		int x , pre = cur; cur ^= 1 ; memset( f[cur] , 0x3f , sizeof( f[cur] ) );
		scanf( "%d" , & x );
		for(int i = 0 ; i < 400 ; ++ i)
			if( f[pre][i] != inf ){
				if( i + x / 100 < 400 ) Update( f[cur][i + x / 100] , f[pre][i] + x );
				int used = std::min( x , i * 10 ) , j = ( x - used ) / 100;
				if( i - used / 10 + j < 400 ) Update( f[cur][i - used / 10 + j] , f[pre][i] + x - used );
			}
	}
	int ans = inf;
	for(int i = 0 ; i < 400 ; ++ i) ans = std::min( ans , f[cur][i] );
	printf( "%d\n" , ans );
	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>

const int maxn = 3e5 + 50;
const int inf = 0x3f3f3f3f;

int n , f[2][312] , cur = 0;

inline void Update( int & x , int y ){
	x = std::min( x , y );
}

int main( int argc , char * argv[] ){
	scanf( "%d" , & n );
	memset( f[cur] , 0x3f , sizeof( f[cur] ) );
	f[cur][0] = 0;
	while( n -- ){
		int x , pre = cur; cur ^= 1 ; memset( f[cur] , 0x3f , sizeof( f[cur] ) );
		scanf( "%d" , & x );
		for(int i = 0 ; i < 312 ; ++ i)
			if( f[pre][i] != inf ){
				if( i + x / 100 < 312 ) Update( f[cur][i + x / 100] , f[pre][i] + x );
				int used = std::min( x , i * 10 );
				if( i - used / 10 < 312 ) Update( f[cur][i - used / 10] , f[pre][i] + x - used );
			}
	}
	int ans = inf;
	for(int i = 0 ; i < 312 ; ++ i) ans = std::min( ans , f[cur][i] );
	printf( "%d\n" , ans );
	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>

const int maxn = 3e5 + 50;
const int inf = 0x3f3f3f3f;

int n , f[2][312] , cur = 0;

inline void Update( int & x , int y ){
	x = std::min( x , y );
}

int main( int argc , char * argv[] ){
	scanf( "%d" , & n );
	memset( f[cur] , 0x3f , sizeof( f[cur] ) );
	f[cur][0] = 0;
	while( n -- ){
		int x , pre = cur; cur ^= 1 ; memset( f[cur] , 0x3f , sizeof( f[cur] ) );
		scanf( "%d" , & x );
		for(int i = 0 ; i < 312 ; ++ i)
			if( f[pre][i] != inf ){
				if( i + x / 100 < 312 ) Update( f[cur][i + x / 100] , f[pre][i] + x );
				int used = std::min( x , i * 10 ) , j = ( x - used ) / 100;
				if( used == x && i - used / 10 + j < 312 ) Update( f[cur][i - used / 10 + j] , f[pre][i] + x - used );
			}
	}
	int ans = inf;
	for(int i = 0 ; i < 312 ; ++ i) ans = std::min( ans , f[cur][i] );
	printf( "%d\n" , ans );
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define PN printf("\n")
#define MODV 1000000007
#define HEXM 0x3b9aca07

typedef long long ll;
typedef double dbl;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
void addmod(int &a, ll b){a=(a+b); if(a>=MODV)a-=MODV;}
void mulmod(int &a, ll b){a=(a*b)%MODV;}
template<class T>bool domin(T &a, const T &b){return a>b?a=b,1:0;}
template<class T>bool domax(T &a, const T &b){return a<b?a=b,1:0;}
int gi(){int a;scanf("%d",&a);return a;}
ll gll(){ll a;scanf("%lld",&a);return a;}

#define MAXN 300007

int ans[2][2507];

int main() {
  int v=MODV;
  fill_n(ans[0],2507,v);
  fill_n(ans[1],2507,v);
  ans[0][0]=0;
  int n=gi(), ix, nx;

  for(int i=0;i<n;i++){
    int x=gi();
    int bo = x / 10;
    ix=(i&1);
    nx=ix^1;
    fill_n(ans[nx],2507,v);
    for(int j=0;j<2500;j++)
    if(ans[ix][j]<MODV){
      if(j<x){
        //all cash
        domin(ans[nx][j+bo],ans[ix][j]+x);

        //use bonus
        domin(ans[nx][0],ans[ix][j]+x-j);
      }else if(j<2000){
        domin(ans[nx][j-x],ans[ix][j]);
        domin(ans[nx][j+bo],ans[ix][j]+x);
      }else{
        domin(ans[nx][j-x],ans[ix][j]);
      }
    }
  }
  int fa=MODV;
  for(int i=0;i<2500;i++){
    domin(fa,ans[nx][i]);
  }
  cout<<fa<<endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define PN printf("\n")
#define MODV 1000000007
#define HEXM 0x3b9aca07

typedef long long ll;
typedef double dbl;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
void addmod(int &a, ll b){a=(a+b); if(a>=MODV)a-=MODV;}
void mulmod(int &a, ll b){a=(a*b)%MODV;}
template<class T>bool domin(T &a, const T &b){return a>b?a=b,1:0;}
template<class T>bool domax(T &a, const T &b){return a<b?a=b,1:0;}
int gi(){int a;scanf("%d",&a);return a;}
ll gll(){ll a;scanf("%lld",&a);return a;}

#define MAXN 300007
#define MAXD 34

int ans[2][MAXD];

int main() {
  int v=MODV;
  fill_n(ans[0],MAXD,v);
  fill_n(ans[1],MAXD,v);
  ans[0][0]=0;
  int n=gi(), ix, nx;

  for(int i=0;i<n;i++){
    int x=gi()/100;
    int bo = x / 10;
    ix=(i&1);
    nx=ix^1;
    fill_n(ans[nx],MAXD,v);
    for(int j=0;j<MAXD;j++)
    if(ans[ix][j]<MODV){
      if(j<x){
        //all cash
        domin(ans[nx][j+bo],ans[ix][j]+x);

        //use bonus
        domin(ans[nx][0],ans[ix][j]+x-j);
      }else if(j<30){
        domin(ans[nx][j-x],ans[ix][j]);
        domin(ans[nx][j+bo],ans[ix][j]+x);
      }else{
        domin(ans[nx][j-x],ans[ix][j]);
      }
    }
  }
  int fa=MODV;
  for(int i=0;i<MAXD;i++){
    domin(fa,ans[nx][i]);
  }
  cout<<fa*100<<endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define PN printf("\n")
#define MODV 1000000007
#define HEXM 0x3b9aca07

typedef long long ll;
typedef double dbl;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
void addmod(int &a, ll b){a=(a+b); if(a>=MODV)a-=MODV;}
void mulmod(int &a, ll b){a=(a*b)%MODV;}
template<class T>bool domin(T &a, const T &b){return a>b?a=b,1:0;}
template<class T>bool domax(T &a, const T &b){return a<b?a=b,1:0;}
int gi(){int a;scanf("%d",&a);return a;}
ll gll(){ll a;scanf("%lld",&a);return a;}

#define MAXN 300007

int ans[2][2507];

int main() {
  int v=MODV;
  fill_n(ans[0],2507,v);
  fill_n(ans[1],2507,v);
  ans[0][0]=0;
  int n=gi(), ix, nx;

  for(int i=0;i<n;i++){
    int x=gi()/100;
    int bo = x / 10;
    ix=(i&1);
    nx=ix^1;
    fill_n(ans[nx],2507,v);
    for(int j=0;j<2500;j++)
    if(ans[ix][j]<MODV){
      if(j<x){
        //all cash
        domin(ans[nx][j+bo],ans[ix][j]+x);

        //use bonus
        domin(ans[nx][0],ans[ix][j]+x-j);
      }else if(j<2000){
        domin(ans[nx][j-x],ans[ix][j]);
        domin(ans[nx][j+bo],ans[ix][j]+x);
      }else{
        domin(ans[nx][j-x],ans[ix][j]);
      }
    }
  }
  int fa=MODV;
  for(int i=0;i<2500;i++){
    domin(fa,ans[nx][i]);
  }
  cout<<fa*100<<endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define PN printf("\n")
#define MODV 1000000007
#define HEXM 0x3b9aca07

typedef long long ll;
typedef double dbl;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
void addmod(int &a, ll b){a=(a+b); if(a>=MODV)a-=MODV;}
void mulmod(int &a, ll b){a=(a*b)%MODV;}
template<class T>bool domin(T &a, const T &b){return a>b?a=b,1:0;}
template<class T>bool domax(T &a, const T &b){return a<b?a=b,1:0;}
int gi(){int a;scanf("%d",&a);return a;}
ll gll(){ll a;scanf("%lld",&a);return a;}

#define MAXN 300007
#define MAXD 1007

int ans[2][MAXD];

int main() {
  int v=MODV;
  fill_n(ans[0],MAXD,v);
  fill_n(ans[1],MAXD,v);
  ans[0][0]=0;
  int n=gi(), ix, nx;

  for(int i=0;i<n;i++){
    int x=gi()/100;
    int bo = x / 10;
    ix=(i&1);
    nx=ix^1;
    fill_n(ans[nx],MAXD,v);
    for(int j=0;j<MAXD;j++)
    if(ans[ix][j]<MODV){
      if(j<x){
        //all cash
        domin(ans[nx][j+bo],ans[ix][j]+x);

        //use bonus
        domin(ans[nx][0],ans[ix][j]+x-j);
      }else if(j<MAXD-100){
        domin(ans[nx][j-x],ans[ix][j]);
        domin(ans[nx][j+bo],ans[ix][j]+x);
      }else{
        domin(ans[nx][j-x],ans[ix][j]);
      }
    }
  }
  int fa=MODV;
  for(int i=0;i<MAXD;i++){
    domin(fa,ans[nx][i]);
  }
  cout<<fa*100<<endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define PN printf("\n")
#define MODV 1000000007
#define HEXM 0x3b9aca07

typedef long long ll;
typedef double dbl;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
void addmod(int &a, ll b){a=(a+b); if(a>=MODV)a-=MODV;}
void mulmod(int &a, ll b){a=(a*b)%MODV;}
template<class T>bool domin(T &a, const T &b){return a>b?a=b,1:0;}
template<class T>bool domax(T &a, const T &b){return a<b?a=b,1:0;}
int gi(){int a;scanf("%d",&a);return a;}
ll gll(){ll a;scanf("%lld",&a);return a;}

#define MAXN 300007

int ans[2][4007];

int main() {
  int v=MODV;
  fill_n(ans[0],4007,v);
  fill_n(ans[1],4007,v);
  ans[0][0]=0;
  int n=gi(), ix, nx;

  for(int i=0;i<n;i++){
    int x=gi();
    ix=(i&1);
    nx=ix^1;
    fill_n(ans[nx],4007,v);
    for(int j=0;j<2500;j++)
    if(ans[ix][j]<MODV){
      if(j<x){
        //all cash
        int bo = x / 10;
        domin(ans[nx][j+bo],ans[ix][j]+x);

        //use bonus
        domin(ans[nx][0],ans[ix][j]+x-j);
      }else{
        domin(ans[nx][j-x],ans[ix][j]);
      }
    }
  }
  int fa=MODV;
  for(int i=0;i<2500;i++){
    domin(fa,ans[nx][i]);
  }
  cout<<fa<<endl;

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define fr(a,b,c) for(int (a) = (b); (a) < (c); ++(a))
#define rp(a,b) fr(a,0,b)
#define fre(a,b) for(int a = adj[b]; ~a; a = ant[a])
#define cl(a,b) memset((a), (b), sizeof(a))
#define sc(a) scanf("%d", &a)
#define sc2(a,b) scanf("%d%d", &a, &b)
#define sc3(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define scs(s) scanf("%s", s)
#define pri(x) printf("%d\n", x)

#define iter(a) __typeof((a).begin())
#define fore(a,b) for(iter(b) a = (b).begin(); a != (b).end(); ++a)

#define st first
#define nd second
#define mp make_pair
#define pb push_back

#define db(x) cerr << #x << " == " << x << endl
#define dbs(x) cerr << x << endl
#define _ << ", " <<

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector< vi > vii;

const int oo = 0x3f3f3f3f;

#define N 300009

int n, a[N];

int pd[N][25];

int proc(int l, int ac) {
	if (l == n) return 0;

	int &ret = pd[l][ac];
	if (ret != -1) return ret;

	{
		int desc = min(ac, a[l]);
		ret = a[l] - desc + proc(l+1, ac-desc);
	}

	int ac2 = ac + (a[l]/10);
	if (ac2 < 22) ret = min(ret, a[l] + proc(l+1, ac2));

	return ret;
}

int main() {
	while (sc(n) == 1) {
		rp(i, n) {
			sc(a[i]);
			a[i] /= 100;
		}

		cl(pd, -1);
		pri(100*proc(0, 0));
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define fr(a,b,c) for(int (a) = (b); (a) < (c); ++(a))
#define rp(a,b) fr(a,0,b)
#define fre(a,b) for(int a = adj[b]; ~a; a = ant[a])
#define cl(a,b) memset((a), (b), sizeof(a))
#define sc(a) scanf("%d", &a)
#define sc2(a,b) scanf("%d%d", &a, &b)
#define sc3(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define scs(s) scanf("%s", s)
#define pri(x) printf("%d\n", x)

#define iter(a) __typeof((a).begin())
#define fore(a,b) for(iter(b) a = (b).begin(); a != (b).end(); ++a)

#define st first
#define nd second
#define mp make_pair
#define pb push_back

#define db(x) cerr << #x << " == " << x << endl
#define dbs(x) cerr << x << endl
#define _ << ", " <<

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector< vi > vii;

const int oo = 0x3f3f3f3f;

#define N 300009

int n, a[N];

int pd[N][55];

int proc(int l, int ac) {
	if (l == n) return 0;

	int &ret = pd[l][ac];
	if (ret != -1) return ret;

	{
		int desc = min(ac, a[l]);
		ret = a[l] - desc + proc(l+1, ac-desc);
	}

	int ac2 = ac + (a[l]/10);
	if (ac2 < 52) ret = min(ret, a[l] + proc(l+1, ac2));

	return ret;
}

int main() {
	while (sc(n) == 1) {
		rp(i, n) {
			sc(a[i]);
			a[i] /= 100;
		}

		cl(pd, -1);
		pri(100*proc(0, 0));
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,sum,bo,ans,x;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		sum+=x/1000;
		bo+=(x==1000);
	}
	int t=sum*10/11;
	if(sum<=11) t=sum-x/1000;
	if(!bo&&t%2==1) t--;
	printf("%d",sum*1000-t*100);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,sum,bo,ans,x,pp;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		sum+=x/1000;
		bo+=(x==1000);
	}
	int t=sum*10/11;
	if(sum<=11) t=sum-x/1000;
	if(!bo&&t%2==1) t--;
	printf("%d",sum*1000-t*100);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<typename S, typename T>
void xmin(S&a, T const&b){if(b<a) a=b;}
template<typename S, typename T>
void xmax(S&a, T const&b){if(b>a) a=b;}
const ll inf = 1e18;

template<class Segtree_Data>
struct Segtree{
    int N, height;
    vector<typename Segtree_Data::node_t> data;

    Segtree(int n):N(n), height(__builtin_clz(1)-__builtin_clz(N)), data(2*N, Segtree_Data::node_ne()){
        for(int i=N-1;i>=0;--i)
            data[i]=Segtree_Data::merge_nodes(data[i<<1], data[i<<1|1]);
    }
    void localUpdate(int pos, typename Segtree_Data::update_t const&val){
        Segtree_Data::update_node(data[pos], val);
    }
    void rePath(int pos){
        while(pos>>=1) data[pos] = Segtree_Data::merge_nodes(data[pos<<1], data[pos<<1|1]);
    }
    void update(int l, typename Segtree_Data::update_t const&val){
        l+=N;
        localUpdate(l, val);
        rePath(l);
    }
    typename Segtree_Data::node_t query(int l, int r){
        typename Segtree_Data::node_t retL=Segtree_Data::node_ne(), retR=Segtree_Data::node_ne();
        for(l+=N, r+=N;l<r;l>>=1, r>>=1){
            if(l&1)retL=Segtree_Data::merge_nodes(retL, data[l++]);
            if(r&1)retR=Segtree_Data::merge_nodes(data[--r], retR);
        }
        return Segtree_Data::merge_nodes(retL, retR);
    }
};
struct Segtreedata{
    // sum , msuff
    typedef pair<ll, ll> node_t;
    typedef ll update_t;
    static constexpr node_t node_ne() {return make_pair(0ll, 0ll);}
    static node_t merge_nodes(node_t const&left, node_t const&right){
        return node_t(left.first+right.first, max(left.second,right.second + left.first));
    }
    static void update_node(node_t &node, update_t const&update){
         node = make_pair(update, update);
    }
};

const int magic = 1;

signed main()
{
    #ifdef LOCAL_RUN
    freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
    int TTT; cin >> TTT; while(TTT--){
    #else
    cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
    #endif // LOCAL_RUN

    int n;
    cin >> n;
    Segtree<Segtreedata> st(n);
    vector<int> a(n);
    array<vector<int>, 3> ocs;
    for(auto &e:a) cin >> e;
    //reverse(a.begin(), a.end());
    for(int i=0;i<n;++i){
        auto &e = a[i];
        ocs[e/1000].push_back(i);
    }
    array<int, 3> cur;
    cur[1] = 0;
    cur[2] = (int)ocs[2].size();
    ll ret = inf;
    ll addcost = 0;
    for(int i=0;i<n;++i){
        if(a[i] == 1000){
            st.update(i, 1000);
        } else {
            st.update(i, -200);
            addcost+=2000;
        }
    }
    for(int &i=cur[1];i<=(int)ocs[1].size();++i){
        for(int iter = 0;iter<magic && cur[2] < (int)ocs[2].size();++iter){
            st.update(ocs[2][cur[2]], -200);
            addcost+=2000;
            ++cur[2];
        }
        ll curcost = st.query(0, n).second + addcost;
        //cerr << cur[1] << " / " << cur[2] << " : " << curcost << "\n";
        while(cur[2]){
            --cur[2];
            st.update(ocs[2][cur[2]], 2000);
            addcost-=2000;
            ll newcost = st.query(0, n).second + addcost;
            //cerr << cur[1] << " / " << cur[2] << " : " << newcost << "\n";
            if(newcost > curcost){
                break;
            }
            xmin(curcost, newcost);
        }
        //cerr << cur[1] << " ->" << cur[2] << " : " << curcost << "\n";
        xmin(ret, curcost);
        if(i == (int)ocs[1].size()) break;
        st.update(ocs[1][i], -100);
        addcost+=1000;
    }
    cout << ret << "\n";

    #ifdef LOCAL_RUN
    }
    #endif // LOCAL_RUN
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<typename S, typename T>
void xmin(S&a, T const&b){if(b<a) a=b;}
template<typename S, typename T>
void xmax(S&a, T const&b){if(b>a) a=b;}
const ll inf = 1e18;

template<class Segtree_Data>
struct Segtree{
    int N, height;
    vector<typename Segtree_Data::node_t> data;

    Segtree(int n):N(n), height(__builtin_clz(1)-__builtin_clz(N)), data(2*N, Segtree_Data::node_ne()){
        for(int i=N-1;i>=0;--i)
            data[i]=Segtree_Data::merge_nodes(data[i<<1], data[i<<1|1]);
    }
    void localUpdate(int pos, typename Segtree_Data::update_t const&val){
        Segtree_Data::update_node(data[pos], val);
    }
    void rePath(int pos){
        while(pos>>=1) data[pos] = Segtree_Data::merge_nodes(data[pos<<1], data[pos<<1|1]);
    }
    void update(int l, typename Segtree_Data::update_t const&val){
        l+=N;
        localUpdate(l, val);
        rePath(l);
    }
    typename Segtree_Data::node_t query(int l, int r){
        typename Segtree_Data::node_t retL=Segtree_Data::node_ne(), retR=Segtree_Data::node_ne();
        for(l+=N, r+=N;l<r;l>>=1, r>>=1){
            if(l&1)retL=Segtree_Data::merge_nodes(retL, data[l++]);
            if(r&1)retR=Segtree_Data::merge_nodes(data[--r], retR);
        }
        return Segtree_Data::merge_nodes(retL, retR);
    }
};
struct Segtreedata{
    // sum , msuff
    typedef pair<ll, ll> node_t;
    typedef ll update_t;
    static constexpr node_t node_ne() {return make_pair(0ll, 0ll);}
    static node_t merge_nodes(node_t const&left, node_t const&right){
        return node_t(left.first+right.first, max(left.second,right.second + left.first));
    }
    static void update_node(node_t &node, update_t const&update){
         node = make_pair(update, update);
    }
};

const int magic = 20;

signed main()
{
    #ifdef LOCAL_RUN
    freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
    int TTT; cin >> TTT; while(TTT--){
    #else
    cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
    #endif // LOCAL_RUN

    int n;
    cin >> n;
    Segtree<Segtreedata> st(n);
    vector<int> a(n);
    array<vector<int>, 3> ocs;
    for(auto &e:a) cin >> e;
    //reverse(a.begin(), a.end());
    for(int i=0;i<n;++i){
        auto &e = a[i];
        ocs[e/1000].push_back(i);
    }
    array<int, 3> cur;
    cur[1] = 0;
    cur[2] = (int)ocs[2].size();
    ll ret = inf;
    ll addcost = 0;
    for(int i=0;i<n;++i){
        if(a[i] == 1000){
            st.update(i, 1000);
        } else {
            st.update(i, -200);
            addcost+=2000;
        }
    }
    for(int &i=cur[1];i<=(int)ocs[1].size();++i){
        for(int iter = 0;iter<magic && cur[2] < (int)ocs[2].size();++iter){
            st.update(ocs[2][cur[2]], -200);
            addcost+=2000;
            ++cur[2];
        }
        ll curcost = st.query(0, n).second + addcost;
        //cerr << cur[1] << " / " << cur[2] << " : " << curcost << "\n";
        while(cur[2]){
            --cur[2];
            st.update(ocs[2][cur[2]], 2000);
            addcost-=2000;
            ll newcost = st.query(0, n).second + addcost;
            //cerr << cur[1] << " / " << cur[2] << " : " << newcost << "\n";
            if(newcost > curcost){
                break;
            }
            xmin(curcost, newcost);
        }
        //cerr << cur[1] << " ->" << cur[2] << " : " << curcost << "\n";
        xmin(ret, curcost);
        if(i == (int)ocs[1].size()) break;
        st.update(ocs[1][i], -100);
        addcost+=1000;
    }
    cout << ret << "\n";

    #ifdef LOCAL_RUN
    }
    #endif // LOCAL_RUN
    return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
long long a[300010],pres[300010],s[300010],d[300010];
int main(){
	int n;
	scanf("%d",&n);
	int i;
	for(i=1;i<=n;i++){
		scanf("%lld",&a[i]);
	}
	for(i=1;i<=n;i++){
		pres[i]=pres[i-1]+a[i];
	}
	long long max_=0,sum=0,dis=0;
	for(i=1;i<=n;i++){
		if(sum>=a[i]*10){
			sum-=a[i]*10;
			dis+=a[i];
		}
		else sum+=a[i];
		s[i]=sum;
		d[i]=dis;
	}
	for(i=1;i<=n;i++){
		max_=max(max_,d[i]+min(s[i]/10,pres[n]-pres[i]));
	}
	printf("%lld\n",pres[n]-max_);
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;
long long a[300010],pres[300010];
int main(){
	int n;
	scanf("%d",&n);
	int i;
	for(i=1;i<=n;i++){
		scanf("%lld",&a[i]);
	}
	sort(a+1,a+1+n,greater<int>());
	for(i=1;i<=n;i++){
		pres[i]=pres[i-1]+a[i];
	}
	long long max_=0;
	for(i=1;i<=n;i++){
		max_=max(max_,min(pres[i]/10ll,pres[n]-pres[i]));
	}
	printf("%lld\n",pres[n]-max_);
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
long long a[300010],pres[300010];
int main(){
	int n;
	scanf("%d",&n);
	int i;
	for(i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		pres[i]=pres[i-1]+a[i];
	}
	long long max_=0;
	for(i=1;i<=n;i++){
		max_=max(max_,min(pres[i]/10ll,pres[n]-pres[i]));
	}
	printf("%lld\n",pres[n]-max_);
	return 0;
}


#include<cstdio>
using namespace std;
int a[300010];
int main(){
	int n;
	scanf("%d",&n);
	int i;
	int sum=0,dis=0;
	bool flag=1;
	for(i=1;i<=n;i++){
		scanf("%d",&a[i]);
		a[i]=a[i]/1000;
		if(a[i]==1) flag=0;
		sum+=a[i];
	}
	if(sum<=11){
		sum;
		dis=sum-a[n];
		printf("%d\n",sum*1000-dis*100);
		return 0;
	}
	dis=sum*10/11;
	sum*=1000;
	if(flag==1&&(dis&1)) dis--;
	dis*=100;
	printf("%d\n",sum-dis);
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
long long a[300010],pres[300010];
int main(){
	int n;
	scanf("%d",&n);
	int i;
	for(i=1;i<=n;i++){
		scanf("%lld",&a[i]);
	}
	for(i=1;i<=n;i++){
		pres[i]=pres[i-1]+a[i];
	}
	long long max_=0;
	bool flag=0;
	for(i=1;i<=n;i++){
		if(a[i]==1000) flag=1;
		if(pres[i]/10<pres[n]-pres[i]){
			max_=max(max_,pres[i]/10);
		}
		else{
			long long tmp=pres[i]-(pres[n]-pres[i])*10,ans=pres[n]-pres[i];
			if(flag){
				tmp=tmp/100;
				ans+=tmp/11*100;
			}
			else{
				tmp=tmp/200;
				ans+=tmp/11*200;
			}
			max_=max(max_,ans);
		}
	}
	printf("%lld\n",pres[n]-max_);
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>

const int kN = 300000 + 5;
int n, a[kN];
int bonus[kN];
int next[kN];

int work()
{
    int total = 0;
    int cnt[2] = {};
    for (int i = 1; i <= n; ++ i) {
        cnt[a[i] == 20] ++;
        total += a[i];
        bonus[i] = bonus[i - 1] + a[i] / 10;
    }

    for (int i = n; i >= 1; -- i) {
        if (i < n && a[i + 1] == 10)
            next[i] = i + 1;
        else
            next[i] = next[i + 1];
    }

    int result = 2e9;
    int last[2] = {};
    int full = 0;

    for (int i = 1; i <= n; ++ i) {
        full += a[i];
        last[a[i] == 20] = i;
        result = std::min(result, full + std::max(0, total - full - full / 10));
        for (int j = 0; j < 2; ++ j) if (last[j]) {
            int w = std::min(bonus[last[j] - 1], a[last[j]]);
            result = std::min(result, full - w + std::max(0, total - full - bonus[i] + a[last[j]] / 10 + w));
            if (next[i] && next[i] != n) {
                result = std::min(result, full - w + a[next[i]] + std::max(0, total - full - bonus[i] + a[last[j]] + w - a[next[i]] - a[next[i]] / 10));
            }
        }
    }
    return result;
}

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++ i) {
        scanf("%d", a + i); a[i] /= 100;
    }
    printf("%d\n", work() * 100);
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>

const int kN = 300000 + 5;
int n, a[kN];

int calc_one(int z, std::vector<int> tc, int accept)
{
    int total = z * 10 - accept;
    for (int i = 0; i < tc.size(); ++ i)
        total += tc[i] * 10;

    int ret = total;
    int l = 1, r = z;
    while (l <= r) {
        int mid = l + r >> 1;
        if (total <= mid * 11) {
            ret = std::min(ret, mid * 10);
            r = mid - 1;
        } else {
            ret = std::min(ret, total - mid);
            l = mid + 1;
        }
    }
    return ret;
}

int calc(int x, int y, int z, std::vector<int> tc)
{
    if (2 * x <= y * 20) {
        return (x + y) * 20 - 2 * x + calc_one(z, tc, 0);
    } else {
        int left = 2 * x - y * 20;
        int accept = 0;
        for (int i = 0; i <= 10; ++ i) {
            int tmp = std::min(left, tc[i] * i);
            accept += tmp;
            left -= tmp;
        }
        return 20 * x + calc_one(z, tc, accept);
    }
}

int work()
{
    int cnt[2] = {};
    for (int i = 1; i <= n; ++ i) {
        cnt[a[i] == 20] ++;
    }

    int ret = 2e9;

    std::vector<int> tc(11);
    for (int i = n, x = cnt[1], y = 0, z = cnt[0]; i >= 0; -- i) {

        ret = std::min(ret, calc(x, y, z, tc));

        if (a[i] == 20) {
            x --;
            y ++;
            for (int j = 0; j + 2 <= 10; ++ j) {
                if (tc[j] != 0) {
                    tc[j + 2] ++;
                    tc[j] --;
                    break;
                }
            }
        } else {
            z --;
            tc[0] ++;
        }
    }

    return ret;
}

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++ i) {
        scanf("%d", a + i); a[i] /= 100;
    }
    printf("%d\n", work() * 100);
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>

const int kN = 300000 + 5;
int n, a[kN], limit;

int calc_one(int z, int milk)
{
    milk = std::min(milk, limit);
    int ret = z * 10 - milk;
    int l = 1, r = (z * 10 - milk) / 10;
    while (l <= r) {
        int mid = l + r >> 1;
        if (mid * 11 >= z * 10 - milk) {
            ret = std::min(ret, mid * 10);
            r = mid - 1;
        } else {
            ret = std::min(ret, z * 10 - milk - mid);
            l = mid + 1;
        }
    }
    return ret;
}

int work()
{
    for (int i = 1, j = n, left = 0; i <= j; ++ i) {
        while (i <= j && a[i] != 20) ++ i;
        if (left == 0) {
            while (i <= j && a[j] != 10) -- j;
            if (i <= j && a[j] == 10) {
                -- j;
                left += 10;
            }
        }
        if (i <= j && a[i] == 20 && left) {
            limit += 2;
            left -= 2;
        }
    }

    int cnt[2] = {};
    for (int i = 1; i <= n; ++ i)
        cnt[a[i] == 20] ++;

    int ret = 2e9;

    for (int x = 0; x <= cnt[1]; ++ x) {
        int y = cnt[1] - x;
        int z = cnt[0];
        if (x * 2 > y * 20)
            ret = std::min(ret, x * 20 + calc_one(z, x * 2 - y * 20));
        else
            ret = std::min(ret, (x + y) * 20 - x * 2 + calc_one(z, 0));
    }
    return ret;
}

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++ i) {
        scanf("%d", a + i); a[i] /= 100;
    }
    printf("%d\n", work() * 100);
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>

const int kN = 300000 + 5;
int n, a[kN];
int bonus[kN];
int next[kN];

int work()
{
    int total = 0;
    int cnt[2] = {};
    for (int i = 1; i <= n; ++ i) {
        cnt[a[i] == 20] ++;
        total += a[i];
        bonus[i] = bonus[i - 1] + a[i] / 10;
    }

    for (int i = n; i >= 1; -- i) {
        if (i < n && a[i + 1] == 10)
            next[i] = i + 1;
        else
            next[i] = next[i + 1];
    }

    int result = 2e9;
    int last[2] = {};
    int full = 0;

    for (int i = 1; i <= n; ++ i) {
        full += a[i];
        last[a[i] == 20] = i;
        result = std::min(result, full + std::max(0, total - full - full / 10));
        for (int j = 0; j < 2; ++ j) if (last[j]) {
            int w = std::min(bonus[last[j] - 1], a[i]);
            result = std::min(result, full - w + std::max(0, total - full - bonus[i] + a[last[j]] / 10 + w));
            if (next[i] && next[i] != n) {
                result = std::min(result, full - w + a[next[i]] + std::max(0, total - full - bonus[i] + a[last[j]] + w - a[next[i]] - a[next[i]] / 10));
            }
        }
    }
    return result;
}

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++ i) {
        scanf("%d", a + i); a[i] /= 100;
    }
    printf("%d\n", work() * 100);
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>

const int kN = 300000 + 5;
int n, a[kN];
int bonus[kN];
int next[kN];

int work()
{
    int total = 0;
    int cnt[2] = {};
    for (int i = 1; i <= n; ++ i) {
        cnt[a[i] == 20] ++;
        total += a[i];
        bonus[i] = bonus[i - 1] + a[i] / 10;
    }

    for (int i = n; i >= 1; -- i) {
        if (i < n && a[i + 1] == 10)
            next[i] = i + 1;
        else
            next[i] = next[i + 1];
    }

    int result = 2e9;
    int last[2] = {};
    int full = 0;

    for (int i = 1; i <= n; ++ i) {
        full += a[i];
        last[a[i] == 20] = i;
        result = std::min(result, full + std::max(0, total - full - full / 10));
        for (int j = 0; j < 2; ++ j) if (last[j]) {
            int b = bonus[last[j] - 1];
            int w = std::min(b, a[i]);
            result = std::min(result, full - w + std::max(0, total - full - b + w));
            if (next[i] && next[i] != n) {
                result = std::min(result, full - w + a[next[i]] + std::max(0, total - full - b + w - a[next[i]] - a[next[i]] / 10));
            }
        }
    }
    return result;
}

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++ i) {
        scanf("%d", a + i); a[i] /= 100;
    }
    printf("%d\n", work() * 100);
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>

const int kN = 300000 + 5;
int n, a[kN];
int bonus[kN];
int next[kN];

int work()
{
    int total = 0;
    int cnt[2] = {};
    for (int i = 1; i <= n; ++ i) {
        cnt[a[i] == 20] ++;
        total += a[i];
        bonus[i] = bonus[i - 1] + a[i] / 10;
    }

    for (int i = n; i >= 1; -- i) {
        if (i < n && a[i + 1] == 10)
            next[i] = i + 1;
        else
            next[i] = next[i + 1];
    }

    int result = 2e9;
    int last[2] = {};
    int full = 0;

    for (int i = 1; i <= n; ++ i) {
        full += a[i];
        last[a[i] == 20] = i;
        result = std::min(result, full + std::max(0, total - full - full / 10));
        for (int j = 0; j < 2; ++ j) if (last[j]) {
            int w = std::min(bonus[last[j] - 1], a[last[j]]);
            result = std::min(result, full - w + std::max(0, total - full - bonus[i] + a[last[j]] / 10 + w));
            if (next[i] && next[i] != n) {
                result = std::min(result, full - w + a[next[i]] + std::max(0, total - full - bonus[i] + a[last[j]] / 10 + w - a[next[i]] - a[next[i]] / 10));
            }
        }
    }
    return result;
}

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++ i) {
        scanf("%d", a + i); a[i] /= 100;
    }
    printf("%d\n", work() * 100);
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>

const int kN = 300000 + 5;
int n, a[kN], limit;

int calc_one(int z, int milk)
{
    milk = std::min(milk, limit);
    int ret = z * 10 - milk;
    int l = 1, r = (z * 10 - milk) / 10;
    while (l <= r) {
        int mid = l + r >> 1;
        if (mid * 11 >= z * 10 - milk) {
            ret = std::min(ret, mid * 10);
            r = mid - 1;
        } else {
            ret = std::min(ret, z * 10 - milk - mid);
            l = mid + 1;
        }
    }
    return ret;
}

int work()
{
    for (int i = 1, j = n, left = 0; i <= j; ++ i) {
        while (i <= j && a[i] != 20) ++ i;
        if (left == 0) {
            while (i <= j && a[j] != 10) -- j;
            if (i <= j && a[j] == 10) {
                -- j;
                left += 10;
            }
        }
        if (i <= n && a[i] == 20 && left) {
            limit += 2;
            left -= 2;
        }
    }

    int cnt[2] = {};
    for (int i = 1; i <= n; ++ i)
        cnt[a[i] == 20] ++;

    int ret = 2e9;

    for (int x = 0; x <= cnt[1]; ++ x) {
        int y = cnt[1] - x;
        int z = cnt[0];
        if (x * 2 > y * 20)
            ret = std::min(ret, x * 20 + calc_one(z, x * 2 - y * 20));
        else
            ret = std::min(ret, (x + y) * 20 - x * 2 + calc_one(z, 0));
    }
    return ret;
}

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++ i) {
        scanf("%d", a + i); a[i] /= 100;
    }
    printf("%d\n", work() * 100);
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>

const int kN = 300000 + 5;
int n, a[kN];
int bonus[kN];

int work()
{
    int total = 0;
    int cnt[2] = {};
    for (int i = 1; i <= n; ++ i) {
        cnt[a[i] == 20] ++;
        total += a[i];
    }

    int result = 2e9;
    int last[2] = {};
    int full = 0;

    for (int i = 1; i <= n; ++ i) {
        full += a[i];
        bonus[i] = bonus[i - 1] + a[i] / 10;
        last[a[i] == 20] = i;
        result = std::min(result, full + std::max(0, total - full - full / 10));
        for (int j = 0; j < 2; ++ j) if (last[j]) {
            int dt = std::min(bonus[last[j] - 1], a[last[j]]);
            result = std::min(result, full - dt + std::max(0, total - full - (full - a[last[j]]) / 10 + dt));
        }
    }
    return result;
}

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++ i) {
        scanf("%d", a + i); a[i] /= 100;
    }
    printf("%d\n", work() * 100);
}


#include<bits/stdc++.h>
using namespace std;
int Total;
int Array[400001];
int Sum,Count;
int main(void)
{
	register int i;
	cin>>Total;
	for(i=1;i<=Total;i++)
	{
		cin>>Array[i];
		Sum+=Array[i]/1000;
		Count+=(Array[i]==1000);
	}
	register int Tmp;
	Tmp=Sum*10/11;
	if(Sum<=11)
	{
		Tmp=Sum-Array[Total]/1000;
	}
	if(!Count&&Tmp%2==1)
	{
		Tmp--;
	}
	cout<<Sum*1000-Tmp*100<<endl;
	return 0;
}


// eddy1021
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long double LD;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
#define mod9 1000000009LL
#define mod7 1000000007LL
#define INF  1023456789LL
#define INF16 10000000000000000LL
#define eps 1e-9
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#ifndef ONLINE_JUDGE
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...)
#endif
inline LL getint(){
  LL _x=0,_tmp=1; char _tc=getchar();
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
inline LL add( LL _x , LL _y , LL _mod = mod7 ){
  _x += _y;
  return _x >= _mod ? _x - _mod : _x;
}
inline LL sub( LL _x , LL _y , LL _mod = mod7 ){
  _x -= _y;
  return _x < 0 ? _x + _mod : _x;
}
inline LL mul( LL _x , LL _y , LL _mod = mod7 ){
  _x *= _y;
  return _x >= _mod ? _x % _mod : _x;
}
LL mypow( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 1LL;
  LL _ret = mypow( mul( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = mul( _ret , _a , _mod );
  return _ret;
}
LL mymul( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 0LL;
  LL _ret = mymul( add( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = add( _ret , _a , _mod );
  return _ret;
}
inline bool equal( D _x ,  D _y ){
  return _x > _y - eps && _x < _y + eps;
}
#define Bye exit(0)
int __ = 1 , _cs;
/*********default*********/
#define N 303030
void build(){

}
int n , a[ N ] , sa[ N ];
void init(){
  n = getint();
  //srand( time( 0 ) );
  //n = 300000;
  for( int i = 0 ; i < n ; i ++ ){
    sa[ i ] = a[ i ] = getint() / 100;
    //sa[ i ] = a[ i ] = ( rand() % 2 + 1 ) * 10;
  }
  for( int i = n - 2 ; i >= 0 ; i -- )
    sa[ i ] += sa[ i + 1 ];
}
#define K 400
int dp[ 2 ][ K ];
void solve(){
  int ans = sa[ 0 ];
  for( int i = 1 ; i < K ; i ++ )
    dp[ 0 ][ i ] = -1;
  for( int i = 0 ; i < n ; i ++ ){
    int pre = i & 1 , cur = 1 - pre;
    for( int j = 0 ; j < K ; j ++ )
      dp[ cur ][ j ] = -1;
    int da = a[ i ] / 10;
    for( int j = 0 ; j < K ; j ++ ){
      if( dp[ pre ][ j ] == -1 ) continue;
      if( j + da < K ){
        int tdp = dp[ pre ][ j ] + a[ i ];
        int &to = dp[ cur ][ j + da ];
        if( to == -1 or tdp < to )
          to = tdp;
      }
      int tdp = dp[ pre ][ j ] + max( 0 , a[ i ] - j );
      int &to = dp[ cur ][ max( 0 , j - a[ i ] ) ];
      if( to == -1 or tdp < to )
        to = tdp;
    }
    int ssum = sa[ i + 1 ];
    for( int j = 0 ; j < K ; j ++ ){
      if( dp[ cur ][ j ] == -1 ) continue;
      int tans = dp[ cur ][ j ] + ssum;
      tans -= min( j , ssum );
      if( tans < ans )
        ans = tans;
    }
  }
  printf( "%d\n" , ans * 100 );
}
int main(){
  build();
  //__ = getint();
  while( __ -- ){
    init();
    solve();
  }
}


// eddy1021
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long double LD;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
#define mod9 1000000009LL
#define mod7 1000000007LL
#define INF  1023456789LL
#define INF16 10000000000000000LL
#define eps 1e-9
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#ifndef ONLINE_JUDGE
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...)
#endif
inline LL getint(){
  LL _x=0,_tmp=1; char _tc=getchar();
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
inline LL add( LL _x , LL _y , LL _mod = mod7 ){
  _x += _y;
  return _x >= _mod ? _x - _mod : _x;
}
inline LL sub( LL _x , LL _y , LL _mod = mod7 ){
  _x -= _y;
  return _x < 0 ? _x + _mod : _x;
}
inline LL mul( LL _x , LL _y , LL _mod = mod7 ){
  _x *= _y;
  return _x >= _mod ? _x % _mod : _x;
}
LL mypow( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 1LL;
  LL _ret = mypow( mul( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = mul( _ret , _a , _mod );
  return _ret;
}
LL mymul( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 0LL;
  LL _ret = mymul( add( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = add( _ret , _a , _mod );
  return _ret;
}
inline bool equal( D _x ,  D _y ){
  return _x > _y - eps && _x < _y + eps;
}
#define Bye exit(0)
int __ = 1 , _cs;
/*********default*********/
#define N 303030
void build(){

}
int n , a[ N ] , sa[ N ];
void init(){
  n = getint();
  //srand( time( 0 ) );
  //n = 300000;
  for( int i = 0 ; i < n ; i ++ ){
    sa[ i ] = a[ i ] = getint() / 100;
    //sa[ i ] = a[ i ] = ( rand() % 2 + 1 ) * 10;
  }
  for( int i = n - 2 ; i >= 0 ; i -- )
    sa[ i ] += sa[ i + 1 ];
}
#define K 400
int dp[ 2 ][ K ];
void solve(){
  int ans = sa[ 0 ];
  for( int i = 1 ; i < K ; i ++ )
    dp[ 0 ][ i ] = -1;
  for( int i = 0 ; i < n ; i ++ ){
    int pre = i & 1 , cur = 1 - pre;
    for( int j = 0 ; j < K ; j ++ )
      dp[ cur ][ j ] = -1;
    int da = a[ i ] / 10;
    for( int j = 0 ; j < K ; j ++ ){
      if( dp[ pre ][ j ] == -1 ) continue;
      if( j + da < K ){
        int tdp = dp[ pre ][ j ] + a[ i ];
        int &to = dp[ cur ][ j + da ];
        if( to == -1 or tdp < to )
          to = tdp;
      }
      if( j >= a[ i ] ){
        int &to = dp[ cur ][ j - a[ i ] ];
        if( to == -1 or dp[ pre ][ j ] < to )
          to = dp[ pre ][ j ];
      }
    }
    int ssum = sa[ i + 1 ];
    for( int j = 0 ; j < K ; j ++ ){
      if( dp[ cur ][ j ] == -1 ) continue;
      int tans = dp[ cur ][ j ] + ssum;
      tans -= min( j , ssum );
      if( tans < ans )
        ans = tans;
    }
  }
  printf( "%d\n" , ans * 100 );
}
int main(){
  build();
  //__ = getint();
  while( __ -- ){
    init();
    solve();
  }
}


#include<iostream>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
#include<cstdio>
#include<set>
#include<cstdlib>

using namespace std;
int dp[300005][50];
int n;
int a[300005];
const int inf=1e9+7;
int main()
{
	int i,j,x;
	scanf("%d", &n);
	for(i=1;i<=n;i++)
        {scanf("%d", &a[i]); a[i]/=100;}
    for(i=0;i<=300004;i++)
    {
        for(j=0;j<41;j++)
        {
            dp[i][j]=inf;
        }
    }
    dp[1][a[1]/10]=a[1];
    for(i=1;i<=n;i++)
    {
        x=a[i+1]/10;
        for(j=0;j<=40;j++)
        {
            if(dp[i][j]==inf) continue;
            dp[i+1][j+x]=min(dp[i+1][j+x],dp[i][j]+a[i+1]);
            if(j>=a[i+1])
            {
                dp[i+1][j-a[i+1]]=min(dp[i+1][j-a[i+1]],dp[i][j]);
            }
            else
            {
                dp[i+1][0]=min(dp[i+1][0],dp[i][j]+a[i+1]-j);
            }
        }
    }
    long long ans=inf;
    for(i=0;i<=35;i++)
    {
        ans=min(ans,1LL*dp[n][i]);
    }
    ans*=100;
    printf("%I64d", ans);
	return 0;
}


#include<iostream>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
#include<cstdio>
#include<set>
#include<cstdlib>

using namespace std;
int dp[300005][25];
int n;
int a[300005];
const int inf=1e9+7;
int main()
{
	int i,j,x;
	cin>>n;
	for(i=1;i<=n;i++)
        {cin>>a[i]; a[i]/=100;}
    for(i=0;i<=300004;i++)
    {
        for(j=0;j<24;j++)
        {
            dp[i][j]=inf;
        }
    }
    dp[1][a[1]/10]=a[1];
    for(i=1;i<=n;i++)
    {
        x=a[i+1]/10;
        for(j=0;j<=20;j++)
        {
            if(dp[i][j]==inf) continue;
            dp[i+1][j+x]=min(dp[i+1][j+x],dp[i][j]+a[i+1]);
            if(j>=a[i+1])
            {
                dp[i+1][j-a[i+1]]=min(dp[i+1][j-a[i+1]],dp[i][j]);
            }
            else
            {
                dp[i+1][0]=min(dp[i+1][0],dp[i][j]+a[i+1]-j);
            }
        }
    }
    long long ans=inf;
    for(i=0;i<=20;i++)
    {
        ans=min(ans,1LL*dp[n][i]);
    }
    ans*=100;
    cout<<ans<<endl;
	return 0;
}


#include<iostream>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
#include<cstdio>
#include<set>
#include<cstdlib>

using namespace std;
int dp[300005][50];
int n;
int a[300005];
const int inf=1e9+7;
int main()
{
	int i,j,x;
	cin>>n;
	for(i=1;i<=n;i++)
        {cin>>a[i]; a[i]/=100;}
    for(i=0;i<=300004;i++)
    {
        for(j=0;j<41;j++)
        {
            dp[i][j]=inf;
        }
    }
    dp[1][a[1]/10]=a[1];
    for(i=1;i<=n;i++)
    {
        x=a[i+1]/10;
        for(j=0;j<=40;j++)
        {
            if(dp[i][j]==inf) continue;
            dp[i+1][j+x]=min(dp[i+1][j+x],dp[i][j]+a[i+1]);
            if(j>=a[i+1])
            {
                dp[i+1][j-a[i+1]]=min(dp[i+1][j-a[i+1]],dp[i][j]);
            }
            else
            {
                dp[i+1][0]=min(dp[i+1][0],dp[i][j]+a[i+1]-j);
            }
        }
    }
    long long ans=inf;
    for(i=0;i<=35;i++)
    {
        ans=min(ans,1LL*dp[n][i]);
    }
    ans*=100;
    cout<<ans<<endl;
	return 0;
}


//This is getting accepted!
// I HATE BUG
// God Of The Bugs
// 12/11/2016
#include<bits/stdc++.h>

using namespace std;

#define ms(s, n) memset(s, n, sizeof(s))
#define FI first
#define SE second
#define pb push_back
#define mp make_pair
#define ll long long
#define sz(a) ((int)(a).size())
#define __builtin_popcount __builtin_popcounll
#define ld long double

typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<int, pii> ppi;

const double PI = acos(0) * 2;
const double EPS = 1e-8;
const ll MOD = 1e9 + 7;
const int MAXN = 3e5 + 5;
const ll oo = 1e18;
const double foo = 1e30;

template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcounll(s);}
template<class T> T sqr(T x) { return x * x; }

inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}

int n;
ll a[MAXN];
ll dp[MAXN][201];

int main() {
#ifndef ONLINE_JUDGE
    freopen("inp.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
#endif

	cin >> n;

	for (int i=1; i<=n; i++) scanf("%I64d", a + i);

	for (int i=0; i<=n; i++) {
		for (int j=0; j<=200; j++) dp[i][j] = oo;
	}

	dp[0][0] = 0;
	for (int i=1; i<=n; i++) {
		int bo = a[i] / 1000;
		for (int j=0; j+bo<=200; j++) {
			dp[i][j + bo] = min(dp[i][j + bo], dp[i - 1][j] + a[i]);
		}

		int cur = a[i] / 100;
		for (int j=0; j<=200; j++) {
			for (int t=0; t<=min(j, cur); t++) {
				int rem = (cur - t) * 100;
//				if (i == 3 && j == 3 && t == 3) cout << rem << endl;
				dp[i][j - t] = min(dp[i][j - t], dp[i - 1][j] + rem);
			}
		}
	}

	ll ans = oo;
	for (int i=0; i<=200; i++) {
		ans = min(ans, dp[n][i]);
	}

	cout << ans;

	return 0;
}


//This is getting accepted!
// I HATE BUG
// God Of The Bugs
// 12/11/2016
#include<bits/stdc++.h>

using namespace std;

#define ms(s, n) memset(s, n, sizeof(s))
#define FI first
#define SE second
#define pb push_back
#define mp make_pair
#define ll long long
#define sz(a) ((int)(a).size())
#define __builtin_popcount __builtin_popcounll
#define ld long double

typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<int, pii> ppi;

const double PI = acos(0) * 2;
const double EPS = 1e-8;
const ll MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
const ll oo = 1e18;
const double foo = 1e30;

template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcounll(s);}
template<class T> T sqr(T x) { return x * x; }

inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}

int n;
ll a[MAXN];
ll dp[MAXN][101];

int main() {
#ifndef ONLINE_JUDGE
    freopen("inp.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
#endif

	cin >> n;

	for (int i=1; i<=n; i++) scanf("%I64d", a + i);

	for (int i=0; i<=n; i++) {
		for (int j=0; j<=100; j++) dp[i][j] = oo;
	}

	dp[0][0] = 0;
	for (int i=1; i<=n; i++) {
		int bo = a[i] / 1000;
		for (int j=0; j+bo<=100; j++) {
			dp[i][j + bo] = min(dp[i][j + bo], dp[i - 1][j] + a[i]);
		}

		int cur = a[i] / 100;
		for (int j=0; j<=100; j++) {
			if (j < cur) {
				ll rem = (cur - j) * 100;
				dp[i][0] = min(dp[i][0], dp[i - 1][j] + rem);
			}
			else {
				dp[i][j - cur] = min(dp[i][j - cur], dp[i - 1][j]);
			}
		}
	}

	ll ans = oo;
	for (int i=0; i<=100; i++) {
		ans = min(ans, dp[n][i]);
	}

	cout << ans;

	return 0;
}


//This is getting accepted!
// I HATE BUG
// God Of The Bugs
// 12/11/2016
#include<bits/stdc++.h>

using namespace std;

#define ms(s, n) memset(s, n, sizeof(s))
#define FI first
#define SE second
#define pb push_back
#define mp make_pair
#define ll long long
#define sz(a) ((int)(a).size())
#define __builtin_popcount __builtin_popcounll
#define ld long double

typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<int, pii> ppi;

const double PI = acos(0) * 2;
const double EPS = 1e-8;
const ll MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
const ll oo = 1e18;
const double foo = 1e30;

template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcounll(s);}
template<class T> T sqr(T x) { return x * x; }

inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}

int n;
ll a[MAXN];
ll dp[MAXN][201];

int main() {
#ifndef ONLINE_JUDGE
    freopen("inp.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
#endif

	cin >> n;

	for (int i=1; i<=n; i++) scanf("%I64d", a + i);

	for (int i=0; i<=n; i++) {
		for (int j=0; j<=200; j++) dp[i][j] = oo;
	}

	dp[0][0] = 0;
	for (int i=1; i<=n; i++) {
		int bo = a[i] / 1000;
		for (int j=0; j+bo<=200; j++) {
			dp[i][j + bo] = min(dp[i][j + bo], dp[i - 1][j] + a[i]);
		}

		int cur = a[i] / 100;
		for (int j=0; j<=200; j++) {
			for (int t=0; t<=min(j, cur); t++) {
				int rem = (cur - t) * 100;
//				if (i == 3 && j == 3 && t == 3) cout << rem << endl;
				dp[i][j - t] = min(dp[i][j - t], dp[i - 1][j] + rem);
			}
		}
	}

	ll ans = oo;
	for (int i=0; i<=200; i++) {
		ans = min(ans, dp[n][i]);
	}

	cout << ans;

	return 0;
}


//This is getting accepted!
// I HATE BUG
// God Of The Bugs
// 12/11/2016
#include<bits/stdc++.h>

using namespace std;

#define ms(s, n) memset(s, n, sizeof(s))
#define FI first
#define SE second
#define pb push_back
#define mp make_pair
#define ll long long
#define sz(a) ((int)(a).size())
#define __builtin_popcount __builtin_popcounll
#define ld long double

typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<int, pii> ppi;

const double PI = acos(0) * 2;
const double EPS = 1e-8;
const ll MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
const int oo = 1e9;
const double foo = 1e30;

template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcounll(s);}
template<class T> T sqr(T x) { return x * x; }

inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}

int n;
ll a[MAXN];

int main() {
#ifndef ONLINE_JUDGE
    freopen("inp.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
#endif

	cin >> n;

	for (int i=0; i<n; i++) scanf("%I64d", a + i);

	ll bonus = 0;
	ll ans = 0;
	for (int i=0; i<n; i++) {
		if (bonus >= a[i]) {
			bonus -= a[i];
			continue;
		}
		if (i == n - 1) {
			ans += (a[i] - bonus);
			break;
		}

		ans += a[i];
		bonus += a[i] / 10;
	}

	cout << ans;

	return 0;
}


//This is getting accepted!
// I HATE BUG
// God Of The Bugs
// 12/11/2016
#include<bits/stdc++.h>

using namespace std;

#define ms(s, n) memset(s, n, sizeof(s))
#define FI first
#define SE second
#define pb push_back
#define mp make_pair
#define ll long long
#define sz(a) ((int)(a).size())
#define __builtin_popcount __builtin_popcounll
#define ld long double

typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<int, pii> ppi;

const double PI = acos(0) * 2;
const double EPS = 1e-8;
const ll MOD = 1e9 + 7;
const int MAXN = 3e5 + 5;
const ll oo = 1e18;
const double foo = 1e30;

template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcounll(s);}
template<class T> T sqr(T x) { return x * x; }

inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}

int n;
ll a[MAXN];
ll dp[MAXN][201];

int main() {
#ifndef ONLINE_JUDGE
    freopen("inp.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
#endif

	cin >> n;

	for (int i=1; i<=n; i++) scanf("%I64d", a + i);

	for (int i=0; i<=n; i++) {
		for (int j=0; j<=60; j++) dp[i][j] = oo;
	}

	dp[0][0] = 0;
	for (int i=1; i<=n; i++) {
		int bo = a[i] / 1000;
		for (int j=0; j+bo<=60; j++) {
			dp[i][j + bo] = min(dp[i][j + bo], dp[i - 1][j] + a[i]);
		}

		int cur = a[i] / 100;
		for (int j=0; j<=60; j++) {
			for (int t=0; t<=min(j, cur); t++) {
				int rem = (cur - t) * 100;
//				if (i == 3 && j == 3 && t == 3) cout << rem << endl;
				dp[i][j - t] = min(dp[i][j - t], dp[i - 1][j] + rem);
			}
		}
	}

	ll ans = oo;
	for (int i=0; i<=60; i++) {
		ans = min(ans, dp[n][i]);
	}

	cout << ans;

	return 0;
}


#include<bits/stdc++.h>
#define rg register
#define int long long
#define fp( i  ,x , y ) for( rg int i=(x); i<=(y); ++i )
#define fq( i , x , y ) for( rg int i=(y); i>=(x); --i )
using namespace std ;
int cnt1 , cnt2 ;
signed main( ) {
 int n , x , ans=0 , all=0 ;
 cin >> n ;
 fp( i , 1 , n ) {
  cin >> x ; all += x ;
  if( x == 1000 ) cnt1 ++ ; else cnt2 ++ ;
 }
 ans = all ;
 fp( i , 0 , cnt1 ) {
   int l=0 , r=cnt2 , mid , tans=cnt2 ;
   while( l<=r ) {
   	 mid=l+r>>1 ;
   	 if( ( mid*2000+i*1000 ) / 10 >= (cnt2-mid)*2000 + (cnt1-i)*1000 ) tans=mid , r=mid-1 ;
     else l=mid+1 ;
   }
   int tp = (tans*2000+i*1000) ;
   ans = min( ans ,  max( 0ll , (all-tp) - tp/10 ) + tp ) ;
   tans -- ; tp -= 2000 ;
   if( tans == -1 ) continue ;
   ans = min( ans ,  max( 0ll , (all-tp) - tp/10 ) + tp ) ;
 }
 cout << ans << '\n' ;
 return 0 ;
}


#include<bits/stdc++.h>
#define rg register
#define int long long
#define fp( i , x , y ) for( rg int i=(x); i<=(y); ++i )
#define fq( i , x , y ) for( rg int i=(y); i>=(x); --i )
using namespace std ;
const int N = 300005 ;
const int inf = (1e15) ;
int f[N][50] , n , a[N] ;
signed main( ) {
  cin >> n ;
  fp( i , 1 , n ) cin >> a[i] , a[i] /= 100 ;
  memset( f , 0x3f , sizeof(f) ) ;
  f[0][0] = 0 ;
  fp( i , 1 , n ) fp( j , 0 , 40 ) {
    if( j+a[i]/10 <= 40)
     f[i][j+a[i]/10] = min( f[i][j+a[i]/10] , f[i-1][j]+a[i] ) ;
    f[i][j-min(a[i],j)] = min( f[i][j-min(a[i],j)] , f[i-1][j] + a[i]-min(a[i],j) ) ;
  }
  int ans = inf ;
  fp( j , 0 , 40 ) ans = min( ans , f[n][j] ) ;
  cout << ans*100ll << '\n' ;
  return 0 ;
}