#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define WRAP(y,x,h,w) (0<=y && y<h && 0<=x && x<w)

typedef long long ll;
typedef unsigned long long ull;
typedef string str;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vd> vvd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1,0,1,0 }; const int dy[] = { 0,1,0,-1 };

int main() {
	int n;
	while (cin>>n,n) {
		vi va(n);
		REP(i, n)
			cin >> va[i];
		vector<pii> state(500 * n, {-1,9999999});
		state[0] = { 0,0 };
		REP(i, n) {
			vector<pii> state2 = state;
			REP(j, 500 * n) {
				if (state[j].first != -1) {
					if (va[i] % 1000 != 0 && va[i] % 1000 <= 500) {
						if (state2[j + (500 - va[i] % 500) % 500].first < state[j].first + 1) {
							state2[j + (500 - va[i] % 500) % 500].first = state[j].first + 1;
							state2[j + (500 - va[i] % 500) % 500].second = state[j].second + va[i];
						}
						else if(state2[j + (500 - va[i] % 500) % 500].first == state[j].first + 1){
							if (state2[j + (500 - va[i] % 500) % 500].second > state[j].second + va[i]) {
								state2[j + (500 - va[i] % 500) % 500].second = state[j].second + va[i];
							}
						}
					}
					else {
						//buy all1000
						if (va[i] % 1000 != 0) {//1000??????????????§x%1000==0????????????????????????????§?
							if (state2[j + (1000 - (va[i]%1000))].first < state[j].first) {
								state2[j + (1000 - (va[i] % 1000))].first = state[j].first;
								state2[j + (1000 - (va[i] % 1000))].second = state[j].second + va[i];
							}
							else if (state2[j + (1000 - (va[i] % 1000))].first == state[j].first) {
								if (state2[j + (1000 - (va[i] % 1000))].second > state[j].second + va[i]) {
									state2[j + (1000 - (va[i] % 1000))].second = state[j].second + va[i];
								}
							}
						}
						//buy want500
						if (va[i] % 1000 == 0 && j >= 500) {
							if (state2[j -500].first < state[j].first + 1) {
								state2[j - 500].first = state[j].first + 1;
								state2[j - 500].second = state[j].second + va[i];
							}
							else if (state2[j - 500].first == state[j].first + 1) {
								if (state2[j - 500].second > state[j].second + va[i]) {
									state2[j - 500].second = state[j].second + va[i];
								}
							}
						}
						if (va[i] % 1000 > 500 && j >= va[i] % 500) {
							if (state2[j - (va[i] % 500)].first < state[j].first + 1) {
								state2[j - (va[i] % 500)].first = state[j].first + 1;
								state2[j - (va[i] % 500)].second = state[j].second + va[i];
							}
							else if (state2[j - (va[i] % 500)].first == state[j].first + 1) {
								if (state2[j - (va[i] % 500)].second > state[j].second + va[i]) {
									state2[j - (va[i] % 500)].second = state[j].second + va[i];
								}
							}
						}
					}
				}
			}
			state = state2;
		}
		int ans=-1, ans2=9999999;
		REP(i, 500 * n) {
			if (ans < state[i].first) {
				ans = state[i].first;
				ans2= state[i].second;
			}
			else if (ans == state[i].first) 
			{
				if (ans2 > state[i].second) {
					ans2 = state[i].second;
				}
			}
		}
		cout << ans << " " << ans2 << endl;
	}
	return 0;
}

Measured memory_bytes: 3564