#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

const int INF = 500002;
int p[102];
P dp[102][102][502];
bool visited[102][102][502];
int n;

P dfs(int pos, int r, int ex){
    if(pos == n) return P(0, 0);
    if(visited[pos][r][ex]) return dp[pos][r][ex];
    int pay = 1000;
    while(pay < p[pos]) pay += 1000;
    int nex = ex + pay - p[pos];
    int nr = r + nex / 500;
    nex %= 500;
    P ret = dfs(pos+1, r, ex);
    if(nr > 0){
        P res = dfs(pos+1, nr-1, nex);
        ret = max(ret, P(res.first + 1, res.second - p[pos]));
    }else{
        P res = dfs(pos+1, nr, nex);
        ret = max(ret, P(res.first, res.second - p[pos]));
    }
    dp[pos][r][ex] = ret;
    visited[pos][r][ex] = true;
    return ret;
}

int main(){
    while(true){
        cin >> n;
        if(n == 0) break;

        for(int i=0;i<n;i++){
            cin >> p[i];
        }

        memset(visited, 0, sizeof(visited));
        P ans = dfs(0, 0, 0);
        cout << ans.first << " " << -ans.second << endl;
    }

    return 0;
}