// #define DEBUGGING
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) begin(V), end(V)
#define ALLR(V) rbegin(V), rend(V)
using ll = std::int64_t;
using ull = std::uint64_t;
using PLL = std::pair<ll, ll>;
using TLL = std::tuple<ll, ll, ll>;
template <typename T> using V = std::vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return V<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec
using namespace std;

#ifdef DEBUGGING
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

const size_t SIZE1 = 102;
const size_t SIZE2 = 5000;
const ll inf = 5e15;
PLL dp[2][SIZE2];

bool solve() {
    ll N;
    cin >> N;
    if (!N) return false;

    V<ll> P(N);
    for (ll &e : P) cin >> e;
    
    fill(ALL(dp[0]), PLL(-inf, inf));
    dp[0][0] = PLL(0, 0);

    auto get_v = [&](ll i, ll use, bool inc) {
        PLL p = dp[0][i];
        p.second += use;
        if (inc) p.first++;
        return p;
    };

    auto upd = [&](ll i, PLL p) {
        auto &cur = dp[1][i];
        if (cur.first != p.first) chmax(cur, p);
        else chmin(cur, p);
    };

    for (ll pi = 0; pi < N; pi++) {
        ll p = P[pi];
        copy(ALL(dp[0]), dp[1]);
        for (ll j = 0; j < SIZE2; j++) for (ll k = 0; k <= 5; k++) {
            ll use = 1000 * k;
            if (1000 <= use - p) break;
            if (p <= use) {
                if (500 <= use - p && (j + use - p - 500) < SIZE2) upd(j + use - p - 500, get_v(j, use, true));
                if (j + use - p < SIZE2) {
                    if (p + 500 <= j + use) upd(j + use - (p + 500), get_v(j, use, true));
                    upd(j + use - p, get_v(j, use, false));
                }
            }
            
            ll rest = p - use;
            if (0 <= rest) {
                if (500 <= j - rest) upd(j - rest - 500, get_v(j, use, true));
                if (rest <= j) upd(j - rest, get_v(j, use, false));
            } else if (-500 < rest) {
                rest = 500 + rest;
                if (rest <= j) upd(j - rest, get_v(j, use, true));
            }
        }
        copy(ALL(dp[1]), dp[0]);
    }

    ll cnt = 0, sum = 0;
    for (ll j = 0; j < SIZE2; j++) {
        ll a, b;
        tie(a, b) = dp[0][j];
        if (cnt < a) {
            cnt = a;
            sum = b - 500 * cnt - j;
        } else if (cnt == a) {
            chmin(sum, b - 500 * cnt - j);
        }
    }

    cout << cnt << ' ' << sum << endl;
    return true;
}

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



Measured memory_bytes: 3324