#include <iostream>
#include <cstdlib>
#include <algorithm>

using namespace std;

#define INF 100000000
#define OTU 5000
int d[101][OTU][2],oturi,otusum;

bool otu(int p){
    int j=0;
    while(p>=10000)p-=10000;
    while(p>=1000)p-=1000;
    while(p>=500){
        p-=500;
        j++;
    }
    oturi=500-p;
    
    if(!p)return j%2+1;
    return j%2;
}
int main()
{
    
   while(1){
        int n,p[102];
        cin>>n;
        if(!n)return 0;
       for(int i=0;i<n;i++){
           cin>>p[i+1];
       }
       otusum=1;
       for(int sum=0;sum<101;sum++)
           for(int j=0;j<OTU;j++){
            d[sum][j][0]=INF;
            d[sum][j][1]=INF;
       }
        d[0][0][0]=0;    
       for(int i=1;i<=n;i++){
           otusum+=500;
           otusum=min(otusum,OTU);
           if(p[i]%1000==0){
               for(int j=0;j<otusum-500;j++){
                   d[0][j][i%2]=d[0][j][(i-1)%2];
                   for(int sum=1;sum<=i;sum++)
                       d[sum][j][i%2]=min(d[sum][j][(i-1)%2],d[sum-1][j+500][(i-1)%2]+p[i]);
               }
               for(int j=otusum-500;j<otusum;j++)
                   for(int sum=0;sum<=i;sum++)d[sum][j][i%2]=d[sum][j][(i-1)%2];
           continue;
           }
            if(otu(p[i])){
                for(int j=0;j<oturi;j++){
                    d[0][j][i%2]=d[0][j][(i-1)%2];
                    for(int sum=1;sum<=i;sum++)
                    d[sum][j][i%2]=min(d[sum-1][j+500-oturi][(i-1)%2]+p[i],d[sum][j][(i-1)%2]);
                }
                for(int j=oturi;j<otusum-500+oturi;j++){
                    d[0][j][i%2]=min(d[0][j][(i-1)%2],d[0][j-oturi][(i-1)%2]+p[i]);
                    for(int sum=1;sum<=i;sum++)
                    d[sum][j][i%2]=min(d[sum][j-oturi][(i-1)%2]+p[i],min(d[sum-1][j+500-oturi][(i-1)%2]+p[i],d[sum][j][(i-1)%2]));
                }
                for(int j=otusum-500+oturi;j<otusum;j++){
                    d[0][j][i%2]=min(d[0][j][(i-1)%2],d[0][j-oturi][(i-1)%2]+p[i]);
                    for(int sum=1;sum<=i;sum++)
                    d[sum][j][i%2]=min(d[sum][j-oturi][(i-1)%2]+p[i],d[sum][j][(i-1)%2]);
                }
            }
           else{
               for(int j=0;j<oturi;j++){
                    d[0][j][i%2]=d[0][j][(i-1)%2];
                    for(int sum=1;sum<=i;sum++)
                    d[sum][j][i%2]=d[sum][j][(i-1)%2];
                }
                for(int j=oturi;j<otusum;j++){
                    d[0][j][i%2]=d[0][j][(i-1)%2];
                    for(int sum=1;sum<=i;sum++)
                    d[sum][j][i%2]=min(d[sum-1][j-oturi][(i-1)%2]+p[i],d[sum-1][j][(i-1)%2]+p[i]);
                }
            }
          // int ans=INF;
       //for(int sum=100;sum>=0;sum--){
         //  for(int j=0;j<1000;j++){
           // ans=min(d[sum][j][i%2],ans);
             //  if(d[sum][j][i%2]<INF)
               //cout<<"i "<<i<<" sum "<<sum<<" ans "<<ans<<" oturi "<<j<<endl;
           //}
           //if(ans<INF){
             //  cout<<"I　 "<<i<<" sum "<<sum<<" ans "<<ans<<endl;
               //break;
         //  }
       //}
       
       }
       int ans=INF;
       for(int sum=100;sum>=0;sum--){
           for(int j=0;j<OTU;j++){
            ans=min(d[sum][j][n%2],ans);
           }
           if(ans<INF){
               cout<<sum<<" "<<ans<<endl;
               break;
           }
       }  
       
    }
}


Measured memory_bytes: 7008