#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define fi first
#define sc second
#define mp make_pair
pair<int,int> dp[105][100005];
int n,p[105];
void chh(pair<int,int> &a,pair<int,int> &b){
	if(a.fi < b.fi) a = b;
	else if(a.fi == b.fi) a.sc = min(a.sc,b.sc);
}
int main(){
	while(1){
		cin>>n; if(!n) return 0;
		for(int i=1;i<=n;i++) cin>>p[i];
		for(int i=0;i<105;i++) for(int j=0;j<100005;j++) dp[i][j] = mp(-10000,100000000);
		dp[0][0] = mp(0,0);
		for(int i=0;i<n;i++){
			for(int j=0;j<=1000*i;j++){
				if(dp[i][j].fi < 0) continue; //cout <<i << " " <<j<< endl;
				if(dp[i+1][j].fi < dp[i][j].fi) dp[i+1][j] = dp[i][j];
				else if(dp[i+1][j].fi == dp[i][j].fi) dp[i+1][j].sc = min(dp[i+1][j].sc,dp[i][j].sc);
				
				if(p[i+1]%1000 == 0){
					if(j>=500){
						pair<int,int> Q=mp(dp[i][j].fi+1,dp[i][j].sc+p[i+1]) ;
						chh(dp[i+1][j-500],Q);
					}
				}
				else if(p[i+1]%1000 <= 500){
					pair<int,int> Q=mp(dp[i][j].fi+1,dp[i][j].sc+p[i+1]) ;
					chh(dp[i+1][j+500-(p[i+1]%1000)],Q);
				}
				else{
					if(j+500-(p[i+1]%1000)>=0){
						pair<int,int> Q=mp(dp[i][j].fi+1,dp[i][j].sc+p[i+1]) ;
						chh(dp[i+1][j+500-(p[i+1]%1000)],Q);
					}
					pair<int,int> Q=mp(dp[i][j].fi,dp[i][j].sc+p[i+1]) ;
					chh(dp[i+1][j+1000-(p[i+1]%1000)],Q);
				}
			}
		}
		pair<int,int> ans = mp(-10000,100000000);
		for(int i=0;i<=n;i++){
		for(int j=0;j<100005;j++){
			if(ans.fi < dp[i][j].fi) ans = dp[i][j];
			else if(ans.fi == dp[i][j].fi) ans.sc = min(ans.sc,dp[i][j].sc);
		}}
		cout <<ans.fi<<" " << ans.sc << endl;
	}
}