#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int p[101];
pint dp[101][60001];
int INF=1000100010;
int main(){
    int n;
    while(cin>>n,n){
        rep(i,n) cin>>p[i];
        FOR(i,0,n+1)rep(j,50001) dp[i][j]={0,-INF};
        dp[0][0]={0,0};
        rep(i,n){
            int cp=p[i];
            rep(j,50001){
                if(dp[i][j]==pint(0,-INF)) continue;
                dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
                if(p[i]%1000==0){
                    if(j<500) continue;
                    else{
                        pint tmp=dp[i][j];
                        tmp.second-=cp;++tmp.first;
                        dp[i+1][j-500]=max(dp[i+1][j-500],tmp);
                    }
                    continue;
                }
                if(cp%1000>500){
                    if(cp%1000-500<=j){
                        pint tmp=dp[i][j];
                        tmp.second-=cp;
                        dp[i+1][j+1000-cp%1000]=max(dp[i+1][j+1000-cp%1000],tmp);
                        ++tmp.first;
                        dp[i+1][j-cp%1000+500]=max(dp[i+1][j-cp%1000+500],tmp);
                    }
                    else{
                        pint tmp=dp[i][j];
                        tmp.second-=cp;
                        dp[i+1][j+1000-cp%1000]=max(dp[i+1][j+1000-cp%1000],tmp);
                    }
                }
                else{
                    pint tmp=dp[i][j];
                    tmp.second-=cp;++tmp.first;
                    dp[i+1][j+1000-cp%1000-500]=max(dp[i+1][j+1000-cp%1000-500],tmp);
                }
            }
        }
        pint mx={0,-INF};
        rep(i,n+1)rep(j,50001) mx=max(mx,dp[i][j]);
        cout<<mx.first<<" "<<-mx.second<<endl;
    }
    return 0;
}
