#include <cstdio>
#include <utility>
#include <algorithm>

using namespace std;

typedef pair<int,int> ans_t;

ans_t dp[105][50005];
int N;
int shops[105];

const ans_t& chmax(const ans_t& src,ans_t& target){
    if (src.first>target.first||(src.first==target.first&&src.second<target.second))
        return target=src;
    else 
        return target;
}

int main(){

    while(scanf("%d",&N)&&N){
        for(int i=1;i<=N;i++) scanf("%d",shops+i);

        for(int i=0;i<=N;i++)
            for(int change=0;change<=50003;change++) 
                dp[i][change]=ans_t(-1,0);

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

        ans_t ans(0,0);

        for(int i=0;i<N;i++){
            for(int change=0;change<=50000;change++){
                const auto &cost=dp[i][change];
                if (cost.first==-1) continue;

                chmax(cost,dp[i+1][change]);
                chmax(dp[i+1][change],ans);

                auto cur_price=shops[i+1];

                auto remain=(1000-cur_price%1000)%1000;
                auto new_change=remain%500,new_500=remain/500;
                chmax(ans_t(cost.first+new_500,cost.second+cur_price),
                    dp[i+1][min(change+new_change,50000)]);
                chmax(dp[i+1][min(change+new_change,50000)],ans);

                remain=(cur_price+500)%1000;
                if (change>=remain){
                    chmax(ans_t(cost.first+1,cost.second+cur_price),
                        dp[i+1][change-remain]
                    );
                    chmax(dp[i+1][change-remain],ans);
                }

            }
            // printf("%d %d\n",ans.first,ans.second);
        }

        printf("%d %d\n",ans.first,ans.second);
    }

    return 0;
}
