#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int coin[2][55555],cost[2][55555];

void update(int i, int j, int c, int v){
	if(coin[i][j] < c){
		coin[i][j] = c;
		cost[i][j] = v;
	}else if(coin[i][j] == c){
		cost[i][j] = min(cost[i][j], v);
	}
}

int main(void){
	int n,p[111],i,j,r,c,a,b;
	bool flag;
	while(true){
		cin >> n;
		if(!n){
			break;
		}
		fill(coin[0],coin[2],0);
		fill(cost[0],cost[2],INF);
		cost[0][0] = 0;
		for(i=0; i<n; ++i){
			a = i%2;
			b = (i+1)%2;
			cin >> p[i];
			for(j=0; j<50000; ++j){
				update(b,j,coin[a][j],cost[a][j]);
				if(cost[a][j]>=INF){
					continue;
				}
				r = (p[i]+500)%1000;
				if(j>=r){
					update(b,j-r,coin[a][j]+1,cost[a][j]+p[i]);
				}
				r = (5000-p[i])%1000;
				if(r<500){
					update(b,j+r,coin[a][j],cost[a][j]+p[i]);
				}else{
					update(b,j+r-500,coin[a][j]+1,cost[a][j]+p[i]);
				}
			}
		}
		a = n%2; b = (n+1)%2;
		coin[b][0] = 0; cost[b][0] = INF;
		for(j=0; j<50000; ++j){
			if(cost[a][j]<INF){
				update(b,0,coin[a][j],cost[a][j]);
			}
		}
		cout << coin[b][0] << " " << cost[b][0] << endl;
	}
	return 0;
}

