#include <bits/stdc++.h>

using namespace std;

namespace {

    typedef double real;
    typedef long long ll;

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        os << "[" << vs[0];
        for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
        return os << "]";
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
        return is;
    }

    int N;
    vector<int> P;
    bool input() {
        cin >> N;
        if (N == 0) return false;
        P.clear(); P.resize(N); cin >> P;
        return true;
    }

    struct Pair : pair<int,int> {
        Pair(int a, int b) : pair<int,int>(a, b) {}
    };

    const int INF = 1<<28;
    bool operator<(const Pair& a, const Pair& b) {
        if (a.first == b.first) return a.second > b.second;
        return a.first < b.first;
    }
    Pair max(const Pair& a, const Pair& b) {
        return (b < a ? a : b);
    }

    const int MAX_R = 101 * 500 + 5;

    void solve() {
        vector<vector<Pair>> dp(N + 1, vector<Pair>(MAX_R, Pair(-INF, INF)));
        dp[0][0] = Pair(0, 0);
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < MAX_R; j++) {
                const auto& cur = dp[i][j];
                dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
                int p = P[i] % 1000;
                if (p == 0) {
                    if (j >= 500) {
                        auto& next = dp[i + 1][j - 500];
                        next = max(next, Pair(dp[i][j].first + 1, dp[i][j].second + P[i]));
                    }
                } else if (p <= 500) {
                    int nrem = j + (1000 - p) % 500;
                    auto& next = dp[i + 1][nrem];
                    next = max(next, Pair(cur.first + 1, cur.second + P[i]));
                } else {
                    int d = p % 500;
                    if (j >= d) {
                        auto& next = dp[i + 1][j - d];
                        next = max(next, Pair(cur.first + 1, cur.second + P[i]));
                    } else {
                        auto& next = dp[i + 1][j + 1000 - p];
                        next = max(next, Pair(cur.first, cur.second + P[i]));
                    }
                }
            }
        }
        auto ans = Pair(-INF, INF);
        for (int i = 0; i < MAX_R; i++) {
            ans = max(ans, dp[N][i]);
        }
        cout << ans.first << " " << ans.second << endl;
    }
}

int main() {
    while (input()) solve();
    return 0;
}