#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(long long i=0;i<n;i++)
#define REP1(i,n) for(long long i=1;i<=n;i++)
#define REP2D(i,j,h,w) for(long long i=0;i<h;i++) for(long long j=0;j<w;j++)
#define REP2D1(i,j,h,w) for(long long i=1;i<=h;i++) for(long long j=1;j<=w;j++)
#define PER(i,n) for(long long i=((n)-1);i>=0;i--)
#define PER1(i,n) for(long long i=(n);i>0;i--)
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define FORE(i,a,b) for(long long i=(a);i<=(b);i++)
#define ITE(arr) for(auto ite=(arr).begin();ite!=(arr).end();++ite)
#define ALL(a) (a.begin()),(a.end())
#define RAN(a) (a),(a+sizeof(a)/sizeof(a[0]))
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define YNPRT(b) cout<<((b)?"Yes":"No")<<endl
#define REV(arr) reverse(ALL(arr))
#define PRT(a) cout<<a<<endl;
#define PRTLST(arr,num) REP(_i,num) cout<<_i<<" - "<<arr[_i]<<endl;
#define PRTLST2(arr2,d1,d2) REP(_i,d1) REP(_j,d2) cout<<_i<<","<<_j<<" : "<<arr2[_i][_j]<<endl;
#define PRTLST2D(arr2,d1,d2) do{cout<<"L\t";REP(_i,d2) cout<<_i<<"\t"; cout<<endl; REP(_i,d1){cout<<_i<<"\t";REP(_j,d2){cout<<arr2[_i][_j]<<"\t";}cout<<endl;}}while(0);
#define MIN(target,v1) (target)=min(target,v1)
#define MAX(target,v1) (target)=max(target,v1) 
#define P1 first
#define P2 second
#define PB push_back
#define UB upper_bound
#define LB lower_bound
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INF_INT = 2147483647;
const ll INF_LL = 9223372036854775807LL;
const ull INF_ULL = 18446744073709551615Ull;
const ll P = 92540646808111039LL;
const int Move[4][2] = {-1,0,0,1,1,0,0,-1};
const int Move_[8][2] = {-1,0,-1,-1,0,1,1,1,1,0,1,-1,0,-1,-1,-1};

//---------------------
#define MAXN 101
#define INF (1<<20)
//---------------------

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p) {os<<"( "<<p.P1<<" , "<<p.P2<<" )";return os;}

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {ITE(v) os << (ite-v.begin()) << " : " << *ite <<endl;return os;}

bool Cmp(const pii& a, const pii& b){
	return a.P1==b.P1 ? a.P2>b.P2 : a.P1<b.P1 ; 
}

int n,p[MAXN];
pii dp[2][MAXN*499];


bool init(){
	ZERO(p);
	REP2D(i,j,2,MAXN*499) dp[i][j]=pii(0,INF);
	cin>>n;
	if(n==0) return false;
	REP1(i,n) cin>>p[i];
	
	//sort(p+1,p+n+1,mycmp);
	
	return true;
}

void maxopr(pii& a, pii b){
	if(Cmp(a,b)) a=b;
}

int main(){
	while(init()){
	  	dp[1][0]=pii(0,0); // not buy
	  	int firstchange=(1000-(p[1]%1000))%1000; 
	  	maxopr(dp[1][firstchange%500],pii(firstchange/500,p[1])); // buy & 1000
		for(int i=1;i<=n-1;i++){
			int cur=i%2;
			int next=1-cur;
			REP(j,MAXN*499){
				if(dp[cur][j].P2>=INF) continue;
				pii curdp=dp[cur][j];
				maxopr(dp[next][j],curdp); // not buy
				int change=(1000-(p[i+1]%1000))%1000;
				if(change>=500) {maxopr(dp[next][j+change-500],pii(curdp.P1+1,curdp.P2+p[i+1]));} // buy & 1000
				else {
					maxopr(dp[next][j+change],pii(curdp.P1,curdp.P2+p[i+1])); // buy & 1000
					if(j>=500-change) maxopr(dp[next][j-(500-change)],pii(curdp.P1+1,curdp.P2+p[i+1])); // buy & change
				}
			}
		}
		pii ret=dp[n%2][0];
		REP(j,MAXN*499) {if(dp[n%2][j].P2>=INF) continue; maxopr(ret,dp[n%2][j]);}
		cout<<ret.P1<<" "<<ret.P2<<endl;
	}
	return 0;
}



Measured memory_bytes: 3800