#include <iostream>
#include <algorithm>
using namespace std;

struct entry {
    int score, cost;

    entry() {}
    entry(int a, int b): score(a), cost(b) {}

    bool operator < (const entry& o) const {
        return score == o.score ? cost > o.cost : score < o.score;
    }

    bool operator > (const entry& o) const {
        return score == o.score ? cost < o.cost : score > o.score;
    }
};

constexpr int INF = 1 << 28;

int N, P[100];

constexpr int LIM = 50050;
entry dp[105][LIM];

entry solve() {
    for (int i = 0; i <= N; ++i) for (int j = 0; j < LIM; ++j)
        dp[i][j] = entry(-INF, INF);
    dp[0][0] = entry(0, 0);

    for (int i = 0; i < N; ++i) {
        if (P[i] % 1000 <= 500) {
            int r = P[i]%1000 == 0 ? INF : 500 - P[i]%1000;
            int s = 500 + P[i]%1000;
            for (int j = 0; j < LIM; ++j) {
                dp[i+1][j] = dp[i][j];
                if (j >= r)
                    dp[i+1][j] = max(dp[i+1][j], entry(dp[i][j-r].score + 1, dp[i][j-r].cost + P[i]));
                if (j+s < LIM)
                    dp[i+1][j] = max(dp[i+1][j], entry(dp[i][j+s].score + 1, dp[i][j+s].cost + P[i]));
            }
        } else {
            int r = P[i]%1000 - 500;
            for (int j = 0; j < LIM; ++j) {
                dp[i+1][j] = dp[i][j];
                if (j+r < LIM)
                    dp[i+1][j] = max(dp[i+1][j], entry(dp[i][j+r].score + 1, dp[i][j+r].cost + P[i]));
                if (j-(500-r) >= 0)
                    dp[i+1][j] = max(dp[i+1][j], entry(dp[i][j-(500-r)].score, dp[i][j-(500-r)].cost + P[i]));
            }
        }
    }

    entry ans(0, 0);
    for (int i = 0; i < LIM; ++i) {
        ans = max(ans, dp[N][i]);
    }

    return ans;
}

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    while (true) {
        cin >> N;
        if (N == 0) break;
        for (int i = 0; i < N; ++i) cin >> P[i];
        entry ans = solve();
        cout << ans.score << " " << ans.cost << endl;
    }
    return 0;
}

