#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

pair<int,int> dp[101][100000];

bool solve(){
  int n, p;
  
  scanf("%d", &n);

  if(n == 0) return false;
  
  for(int i=0;i<=n;i++){
    for(int j=0;j<=n*499;j++){
      dp[i][j] = {-INF, 0};
    }
  }

  dp[0][0] = {0, 0};

  for(int i=0;i<n;i++){
    scanf("%d", &p);
    int p2 = p;
    p %= 1000; 
    for(int j=0;j<=i*499;j++){
      //1000円のみ
      dp[i+1][j + (1000-p)%500] = max(dp[i+1][j+(1000-p)%500],
                                      {dp[i][j].first + (1 <= p && p <= 500), dp[i][j].second - p2});

      //小銭で価格+500円払う
      if(p + 500 <= j){
        dp[i+1][j - (p+500)] = max(dp[i+1][j - (p+500)],
                                   {dp[i][j].first + 1, dp[i][j].second - p2});
      }

      //札+小銭で価格+500円払う
      if(p >= 501 && j >= p-500){
        dp[i+1][j - (p-500)] = max(dp[i+1][j-(p-500)],
                                   {dp[i][j].first + 1, dp[i][j].second - p2});
      }

      //買わない
      dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
    }
  }

  pair<int,int> ans = {0, 0};
  
  for(int i=0;i<=n*499;i++){
    ans = max(ans, dp[n][i]);
  }

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

  return true;
}

int main(){
  while(solve());
  
  return 0;
}

