#include <bits/stdc++.h>
using namespace std;

int main() {
        int N;
        while (cin >> N, N) {
                vector<vector<pair<int, int>>>dp(N + 1, vector<pair<int,int>>(101000, make_pair(INT_MIN / 6, INT_MAX / 6)));
                dp[0][0] = make_pair(0, 0);
                for (int i = 0; i < N; i++) {
                        int p;
                        cin >> p;
                        int q = p;
                        int num1000 = p / 1000;
                        p %= 1000;
                        // 500???????????°???????????´???
                        for (int j = 0; j < 100000 - p; j++) {
                                if (dp[i + 1][j + (1000 - p) % 1000].first < dp[i][j].first || (dp[i + 1][j + (1000 - p) % 1000].first == dp[i][j].first && dp[i + 1][j + (1000 - p) % 1000].second > dp[i][j].second + q) ) {
                                        dp[i + 1][j + (1000 - p) % 1000].first = dp[i][j].first;
                                        dp[i + 1][j + (1000 - p) % 1000].second = dp[i][j].second + q;
                                }
                        }

                        // 500????????????????????´???
                        if (p == 0) {
                                for (int j = 500 ; j < 100000; j++) {
                                        if (dp[i + 1][j - 500].first < dp[i][j].first + 1 || (dp[i + 1][j - 500].first == dp[i][j].first + 1 && dp[i + 1][j - 500].second > dp[i][j].second + q)) {
                                                dp[i + 1][j - 500].first = dp[i][j].first + 1;
                                                dp[i + 1][j - 500].second = dp[i][j].second + q;
                                        }
                                }
                        } else if (p >= 500) {
                                for (int j = p - 500 ; j < 100000; j++) {
                                        if (dp[i + 1][j + 500 - p].first < dp[i][j].first + 1 || (dp[i + 1][j + 500 - p].first == dp[i][j].first + 1 && dp[i + 1][j + 500 - p].second > dp[i][j].second + q)) {
                                                dp[i + 1][j + 500 - p].first = dp[i][j].first + 1;
                                                dp[i + 1][j + 500 - p].second = dp[i][j].second + q;
                                        }
                                }
                        } else {
                                for (int j = 0; j < 100000; j++) {
                                        if (dp[i + 1][j + 500 - p].first < dp[i][j].first + 1 || (dp[i + 1][j + 500 - p].first == dp[i][j].first + 1 && dp[i + 1][j + 500 - p].second > dp[i][j].second + q)) {
                                                dp[i + 1][j + 500 - p].first = dp[i][j].first + 1;
                                                dp[i + 1][j + 500 - p].second = dp[i][j].second + q;
                                        }
                                }
                        }

                        // ????????????????????´???
                        for (int j = 0; j < 100000; j++) {
                                if (dp[i + 1][j].first < dp[i][j].first || (dp[i + 1][j].first == dp[i][j].first && dp[i + 1][j].second > dp[i][j].second)) {
                                        dp[i + 1][j] = dp[i][j];
                                }
                        }
                }
                pair<int,int>ans = make_pair(INT_MIN, INT_MAX / 6);
                for (int j = 0; j < 101000; j++) {
                        if (ans.first < dp[N][j].first || (ans.first == dp[N][j].first && ans.second > dp[N][j].second)) {
                                ans = dp[N][j];
                        }
                }
                cout<<ans.first<<" "<<ans.second<<endl;
        }
}