#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define long long long
using pi = pair<int, int>;

pi dp[500][105];
pi before[500][105];
const int inf = 1145141919;

pi ch(pi a, pi b)
{
    if (a.second >= inf) {
        return b;
    }
    else if(b.second >= inf)
    {
        return a;
    }
    
    
    if(a.first == b.first)
    {
        if(a.second < b.second) {
            return a;
        }
        else{
            return b;
        }
        
    }
    else
    {
        if (a.first > b.first)
            return a;
        else
            return b;
    }
    
}
int main()
{
    while (true)
    {
        int N;
        cin >> N;
        if (N == 0)
            return 0;

        rep(i, 500) rep(j, 105)
        {
            dp[i][j] = pi(0, inf);
        }

        dp[0][0] = pi(0, 0);

        rep(t, N)
        {
            int P;
            cin >> P;

            swap(dp, before);
            rep(i, 500) rep(j, 105)
            {
                dp[i][j] = pi(0, inf);
            }

            int X = P % 1000;
            

            if (0 < X && X <= 500)
            {
                //にせ500を使わない
                //before[i][j][k]から遷移

                rep(i, 500) rep(j, 103)
                {
                    int k = before[i][j].first;
                    int cost = before[i][j].second;
                    //買わない
                    dp[i][j] = ch(before[i][j], dp[i][j]);
                    //買う
                    int tsuri = (1000 - X) % 500;
                    int next = i + tsuri;
                    int nise = 0;
                    if (next >= 500)
                    {
                        next -= 500;
                        nise++;
                    }
                    dp[next][j + nise] = ch(dp[next][j + nise], pi(k + 1, cost + P));
                }
            }
            else
            {
                //にせ500を使える
                rep(i, 500) rep(j, 103)
                {
                    int k = before[i][j].first;
                    int cost = before[i][j].second;
                    //買わない
                    dp[i][j] = ch(before[i][j], dp[i][j]);

                    //買うけどにせ500使わない
                    int tsuri = (1000 - X) % 500;
                    int next = i + tsuri;

                    int shin = 0;
                    if (next >= 500)
                    {
                        next -= 500;
                        shin++;
                    }
                    dp[next][j] = ch(dp[next][j], pi(k + shin, cost + P));

                    // にせ500使う
                    if (j > 0)
                    {
                        tsuri = (1500 - X) % 500;
                        next = i + tsuri;

                        int nise = 0;
                        if (next >= 500)
                        {
                            next -= 500;
                            nise++;
                        }

                        dp[next][j - 1 + nise] = ch(dp[next][j - 1 + nise], pi(k + 1, cost + P));
                    }
                }
            }

            // rep(i, 500) rep(j, 105) rep(k, 105)
            // {
            //     if(dp[i][j][k] < inf)
            //     {
            //         cout << t << " " << i << " " << j << " " << k << " " << dp[i][j][k] << endl;
            //     }
            // }
        }

        pi ans = pi(0, 0);
        rep(i, 500)
        {
            rep(j, 105)
            {
                ans = ch(ans, dp[i][j]);
            }
        }

        cout << ans.first << " " << ans.second << "\n";
    }
}



Measured memory_bytes: 3868