//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx")

#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
typedef pair<int, int> i_i;
vector<i_i> Prev(100001), Next(100001);
int main() {
    while(true) {
        int n;
        cin >> n;
        if(n == 0) break;
        for(int i = 0; i <= 100000; i++) {
            Prev[i] = {-INF,0};
            Next[i] = {-INF,0};
        }
        Prev[0] = {0, 0};
        for(int i = 1; i <= n; i++) {
            int p;
            cin >> p;
            int nowchange = 1000 - ((p + 999) % 1000 + 1);
            //cerr << "P:" << p << endl;
            for(int change = 0; change <= 100000; change++) {
                /*
                for(int num = 0; num <= i; num++) {
                    Next[change][num] = Prev[change][num];
                    if(nowchange >= 500) {
                        if(change - nowchange + 500 >= 0 && num - 1 >= 0) {
                            Next[change][num] = min(Next[change][num], Prev[change - nowchange + 500][num-1] + p);
                        }
                    } else {
                        if(change - nowchange >= 0) {
                            Next[change][num] = min(Next[change][num], Prev[change - nowchange][num] + p);
                        }
                        if(change + 500 - nowchange <= 1000 * i && num - 1 >= 0) {
                            Next[change][num] = min(Next[change][num], Prev[change + 500 - nowchange][num-1] + p);
                        }
                    }
                }
            }
            */
                Next[change] = Prev[change];
                if(nowchange >= 500) {
                    if(change - nowchange + 500 >= 0) {
                        i_i tmp = Prev[change-nowchange+500];
                        tmp.second -= p;
                        tmp.first++;
                        Next[change] = max(Next[change], tmp);
                    }
                } else {
                    if(change - nowchange >= 0) {
                        i_i tmp = Prev[change-nowchange];
                        tmp.second -= p;
                        Next[change] = max(Next[change], tmp);
                    }
                    if(change + 500 - nowchange <= 100000) {
                        i_i tmp = Prev[change + 500 - nowchange];
                        tmp.second -= p;
                        tmp.first++;
                        Next[change] = max(Next[change], tmp);
                    }
                }
            }
            swap(Next, Prev);
        }
        /*
        int ansnum = 0;
        int ansval = 0;
        for(int change = 0; change <= 100000; change++) {
            for(int num = 0; num <= 100; num++) {
                if(Prev[change][num] < INF) {
                    if(num > ansnum) {
                        ansval = Prev[change][num];
                        ansnum = num;
                    } else if(num == ansnum && ansval > Prev[change][num]) {
                        ansval = Prev[change][num];
                    }
                }
            }
        }
        */
        i_i ans = {0, 0};
        for(int change = 0; change <= 100000; change++) {
            ans = max(ans, Prev[change]);
        }
        cout << ans.first << " " << -ans.second << endl;
    }
}


Measured memory_bytes: 4180