#include <bits/stdc++.h>

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define ALL(x) x.begin(),x.end()
#define PB push_back
#define LL long long

const int maxzeni = 10000;

int dp[102][10001];
int pp[102];
int reals[102];

int money[102][10001];

void update2(int &a,int b,int &c,int d){
    if(a < b){
        a = b;
        c = d;
    }
    else if(a == b){
        if(c > d || c < 0) c = d;
    }
}

void update(int i,int zeni,int c,int real){
    int val = dp[i][zeni];
    //cout << "i:"<<i << "zeni:"<<zeni << "reals:"<< real <<endl;
    update2(dp[i+1][zeni],val,money[i+1][zeni],money[i][zeni]);

    if(zeni - c >= 500){
        update2(dp[i+1][zeni - c - 500],val+1,money[i+1][zeni - c - 500],money[i][zeni]+real);
    }

    if(1000 - c >= 500 && (1000 - c - 500+ zeni) <= maxzeni){
        update2(dp[i+1][1000 - c - 500 + zeni],val+1,money[i+1][1000 - c - 500+zeni],money[i][zeni]+real);
    }

    else{
        if(1000 + zeni - c >= 500 && 1000 + zeni - c <= maxzeni){
            update2(dp[i+1][1000 + zeni - c - 500],val+1,money[i+1][1000 + zeni - c - 500],money[i][zeni]+real);
        }
        else{
            update2(dp[i+1][1000 + zeni - c],val,money[i+1][1000 + zeni - c],money[i][zeni]+real);
        }
    }

}

int main()
{
    int p;
    while(scanf("%d",&p)&&p){
        memset(dp,-1,sizeof(dp));
        memset(money,-1,sizeof(money));
        _for(i,0,p) {
            scanf("%d",&pp[i]);
            reals[i] = pp[i];
            pp[i] %= 1000;
            if(pp[i] == 0) pp[i] = 1000;
        }

        dp[0][0] = 0;
        money[0][0] = 0;

        _for(i,0,p){
            _for(j,0,maxzeni){
                if(dp[i][j] >= 0){
                    update(i,j,pp[i],reals[i]);
                }
            }
        }

        int maxcoin = 0;
        int min_cost = 0;
        _for(j,0,maxzeni){
            if(dp[p][j] >= maxcoin){
                //cout << j <<" "<< money[p][j] <<endl;
                if(dp[p][j] > maxcoin){
                    maxcoin = dp[p][j];
                    min_cost = money[p][j];
                }
                else{
                    min_cost = min(min_cost,money[p][j]);
                }
            }
        }
        cout << maxcoin <<" "<<min_cost << endl;

    }
    return 0;
}
