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

typedef pair<int, int> P;

int main(){
    while(1){
        int n;
        cin >> n;
        if (n == 0) break;

        P ini = {0, 0};
        vector<P> change(500 * n, ini);
        vector<P> pre_change(500 * n, ini);

        for (int i = 0; i < n; i++){

            int p;
            cin >> p;

            if (p % 1000 == 0);
            else if (pre_change[(1000 - p % 1000) % 500] == ini){
                pre_change[(1000 - p % 1000) % 500].first = (p % 1000 > 0 && p % 1000 <= 500);
                pre_change[(1000 - p % 1000) % 500].second = p;
            }
            else if (pre_change[(1000 - p % 1000) % 500].first < (p % 1000 > 0 && p % 1000 <= 500)){
                pre_change[(1000 - p % 1000) % 500].first = (p % 1000 > 0 && p % 1000 <= 500);
                pre_change[(1000 - p % 1000) % 500].second = p;
            }
            else if (pre_change[(1000 - p % 1000) % 500].first == (p % 1000 > 0 && p % 1000 <= 500) && pre_change[p].second > p){
                pre_change[(1000 - p % 1000) % 500].second = p;
            }

            for (int j = 0; j < 500 * n; j++){
                if (change[j] == ini) continue;
                if (p % 1000 > 0 && p % 1000 <= 500){
                    if (pre_change[j + (1000 - p % 1000) % 500] == ini){
                        pre_change[j + (1000 - p % 1000) % 500].first = change[j].first + 1;
                        pre_change[j + (1000 - p % 1000) % 500].second = change[j].second + p;
                    }
                    else if (pre_change[j + (1000 - p % 1000) % 500].first < change[j].first + 1){
                        pre_change[j + (1000 - p % 1000) % 500].first = change[j].first + 1;
                        pre_change[j + (1000 - p % 1000) % 500].second = change[j].second + p;
                    }
                    else if (pre_change[j + (1000 - p % 1000) % 500].first == change[j].first + 1 && pre_change[j + (1000 - p % 1000) % 500].second > change[j].second + p){
                        pre_change[j + (1000 - p % 1000) % 500].second = change[j].second + p;
                    }
                }
                else if (p % 1000 > 0 && p % 1000 <= 500 + j){
                    if (pre_change[j - p % 500] == ini){
                        pre_change[j - p % 500].first = change[j].first + 1;
                        pre_change[j - p % 500].second = change[j].second + p;
                    }
                    else if (pre_change[j - p % 500].first < change[j].first + 1){
                        pre_change[j - p % 500].first = change[j].first + 1;
                        pre_change[j - p % 500].second = change[j].second + p;
                    }
                    else if (pre_change[j - p % 500].first == change[j].first + 1 && pre_change[j - p % 500].second > change[j].second + p){
                        pre_change[j - p % 500].second = change[j].second + p;
                    }
                }
                else if (p % 1000 == 0 && j >= 500){
                    if (pre_change[j - 500] == ini){
                        pre_change[j - 500].first = change[j].first + 1;
                        pre_change[j - 500].second = change[j].second + p;
                    }
                    else if (pre_change[j - 500].first < change[j].first + 1){
                        pre_change[j - 500].first = change[j].first + 1;
                        pre_change[j - 500].second = change[j].second + p;
                    }
                    else if (pre_change[j - 500].first == change[j].first + 1 && pre_change[j - 500].second > change[j].second + p){
                        pre_change[j - 500].second = change[j].second + p;
                    }
                }
                else if (p % 1000 != 0){
                    if (pre_change[j + (1000 - p % 1000)] == ini){
                        pre_change[j + (1000 - p % 1000)].first = change[j].first;
                        pre_change[j + (1000 - p % 1000)].second = change[j].second + p;
                    }
                    else if (pre_change[j + (1000 - p % 1000)].first < change[j].first){
                        pre_change[j + (1000 - p % 1000)].first = change[j].first;
                        pre_change[j + (1000 - p % 1000)].second = change[j].second + p;
                    }
                    else if (pre_change[j + (1000 - p % 1000)].first == change[j].first && pre_change[j + (1000 - p % 1000)].second > change[j].second + p){
                        pre_change[j + (1000 - p % 1000)].second = change[j].second + p;
                    }
                }
            }
            
            change = pre_change;
        }

        int c = 0;
        int s = 0;
        for (int i = 0; i < 500 * n; i++){
            if (change[i].first > c){
                c = change[i].first;
                s = change[i].second;
            }
            else if (change[i].first == c && change[i].second < s) s = change[i].second;
        }
        cout << c << " " << s << endl;
    }
}


Measured memory_bytes: 3632