#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORR(i, b, a) for (int i = (a - 1); i >= (b); i--)
#define ALL(vec) (vec).begin(), (vec).end()
int get_int() {
  int tmp;
  cin >> tmp;
  return tmp;
}
int main() {
  while (true) {
    const int n = get_int();
    if (n == 0) return 0;
    auto dp = vector<vector<int>>(n + 10, vector<int>(5 * n + 50, -1));
    dp[0][0] = 0;
    REP(ni, n) {
      auto p = get_int();
      int rest = p % 1000;
      int sheet = p / 1000;
      if (rest == 0) {
        FORR(i, 0, n + 1) FORR(j, 0, 5 * n + 1) {
          // 小銭と1000円で買う
          if (i - 1 >= 0 and j - sheet + 1 >= 0 and
              dp[i - 1][j - sheet + 1] >= 0) {
            int buy = dp[i - 1][j - sheet + 1] - 500;
            dp[i][j] = max(dp[i][j], buy);
          }
        }
      } else if (rest > 500) {
        FORR(i, 0, n + 1) FORR(j, 0, 5 * n + 1) {
          // 1000円で買う (小銭のみ得る)
          if (j - 1 - sheet >= 0 and dp[i][j - 1 - sheet] >= 0) {
            int buy = dp[i][j - 1 - sheet] + 1000 - rest;
            dp[i][j] = max(dp[i][j], buy);
          }
          // 小銭と1000円で買う
          if (i - 1 >= 0 and j - sheet >= 0 and dp[i - 1][j - sheet] >= 0) {
            int buy = dp[i - 1][j - sheet] - (rest - 500);
            dp[i][j] = max(dp[i][j], buy);
          }
        }
      } else {
        // 買うに決まっている,ついでにuse_get円得ちゃう
        int use_get = 500 - rest;
        FORR(i, 1, n + 1) FORR(j, sheet, 5 * n + 1) {
          if (dp[i - 1][j - sheet] < 0) continue;
          dp[i][j] = max(dp[i][j], dp[i - 1][j - sheet] + use_get);
        }
      }
    }
    [&]() {
      // C++クソでは
      FORR(i, 0, n + 1) {
        int min_val = 10000000;
        bool is_ok = false;
        FOR(j, 0, 5 * n + 1) {
          if (dp[i][j] == -1) continue;
          auto val = -(dp[i][j] - (500 * i) - (1000 * j));
          if (min_val > val) {
            min_val = val;
            is_ok = true;
          }
        }
        if (is_ok) {
          cout << i << " " << min_val << endl;
          return;
        }
      }
    }();
  }
}
