#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;
typedef pair<int, int>P;

int main(){
    for(int n; cin>>n,n;){
        int mx = 0;
        vector<int>p(n);
        for(int i=0;i<n;i++){
            cin>>p[i];
        }
        map<P, int>dp[2];
        dp[0][P(0, 0)] = 0;
        for(int i=0;i<n;i++){
            map<P, int>::iterator it = dp[i%2].begin();
            for(;it!=dp[i%2].end();it++){
                int earn = (*it).first.first;
                int satsu = (*it).first.second;
                int pay = (*it).second;
                int zeni = satsu * 1000 - pay - earn * 500;

                //pass
                if(dp[(i+1)%2].find(P(earn, satsu)) == dp[(i+1)%2].end()){
                    dp[(i+1)%2][P(earn, satsu)] = pay;
                }
                else{
                    dp[(i+1)%2][P(earn, satsu)] = min(dp[(i+1)%2][P(earn, satsu)], pay);
                }

                //1000円だけで払う
                int turi = 1000 - p[i] % 1000, get500 = 0;
                if(turi == 1000)turi = 0;
                if(turi >= 500){
                    turi -= 500;
                    get500 = 1;
                }
                int nxtEarn = earn + get500;
                int nxtPay = pay + p[i];
                int nxtSatsu = satsu + p[i] / 1000 + (p[i] % 1000 == 0?0:1);
                if(dp[(i+1)%2].find(P(nxtEarn, nxtSatsu)) == dp[(i+1)%2].end()){
                    dp[(i+1)%2][P(nxtEarn, nxtSatsu)] = nxtPay;
                }
                else{
                    dp[(i+1)%2][P(nxtEarn, nxtSatsu)] = min(dp[(i+1)%2][P(nxtEarn, nxtSatsu)], nxtPay);
                }
                
                //500円もらえるように払う
                int need = abs((p[i] % 1000) - 500);
                if(zeni < need)continue;
                nxtEarn = earn + 1;
                nxtPay = pay + p[i];
                if(dp[(i+1)%2].find(P(nxtEarn, nxtSatsu)) == dp[(i+1)%2].end()){
                    dp[(i+1)%2][P(nxtEarn, nxtSatsu)] = nxtPay;
                }
                else{
                    dp[(i+1)%2][P(nxtEarn, nxtSatsu)] = min(dp[(i+1)%2][P(nxtEarn, nxtSatsu)], nxtPay);
                }

            }
            dp[i%2].clear();
        }
        int c = 0, s = 0;
        for(map<P, int>::iterator it = dp[n%2].begin(); it != dp[n%2].end(); it++){
            int earn = (*it).first.first;
            int satsu = (*it).first.second;
            int pay = (*it).second;
            int zeni = satsu * 1000 - pay - earn * 500;
            if(earn > c){
                c = earn;
                s = pay;
            }
            else if(earn == c && pay < s){
                c = earn;
                s = pay;
            }

        }
        cout<<c<<" "<<s<<endl;
    }

    return 0;
}
