#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define fi first
#define se second
#define int long long
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18 * 5;

P dp[110][50010];

P max(P p1, P p2){
    if(p1.fi > p2.fi) return p1;
    if(p1.fi < p2.fi) return p2;
    if(p1.se < p2.se) return p1;
    if(p1.se > p2.se) return p2;
    else return p1;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    while(n != 0){
        vector<int> p(n);
        REP(i, n) cin >> p[i];
        
        REP(i, n+1)REP(j, 50000) dp[i][j] = mp(-1, 0);
        dp[0][0] = mp(0, 0);
        REP(i, n){
            int req = p[i]%1000;
            if(req == 0) req = 1000;
            REP(j, 50000){
                if(dp[i][j].fi >= 0){
                    int c = req-500;
                    // 1000円払って 500円+小銭をGET
                    if(req <= 500) dp[i+1][j+(500-req)] = mp(dp[i][j].fi+1, dp[i][j].se+p[i]);
                    else{
                        // 1000+c円払って 500円を1枚GET
                        if(j >= c) dp[i+1][j-c] = max(dp[i+1][j-c], mp(dp[i][j].fi+1, dp[i][j].se+p[i]));
                        // 1000円払って 小銭をGET
                        dp[i+1][j+(1000-req)] = max(dp[i+1][j+(1000-req)], mp(dp[i][j].fi, dp[i][j].se+p[i]));
                        // 買わない
                        dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
                    }
                }
            }
        }
        P ans = mp(0, 0);
        REP(i, 50000){
            ans = max(ans, dp[n][i]);
        }
        cout << ans.fi << " " << ans.se << "\n";

        cin >> n;
    }
    return 0;
}
