#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>  
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000000000000000000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
pair<int, int> dp[2][99901];//左から1円,5円,10円,50円,100円
int main() {
	while (true) {
		int n;
		scanf("%d", &n);
		if (n == 0) return 0;
		for (int i = 1; i < 99901; ++i) {
			dp[0][i] = make_pair(-1000, 0);
			dp[1][i] = make_pair(-1000, 0);
		}
		dp[0][0] = make_pair(0, 0);
		dp[1][0] = make_pair(0, 0);
		for (int i = 0; i < n; ++i) {
			int now = 0;
			scanf("%d", &now);
			for (int j = 0; j < 99901; ++j) {
				if (dp[i % 2][j].first >= 0) {
					if (now % 1000 <= 500&&now % 1000 != 0) {
						int ok = 0;
						if (dp[(i + 1) % 2][j + 500 - now % 1000].first < dp[i % 2][j].first + 1) {
							ok = 1;
						}
						if (dp[(i + 1) % 2][j + 500 - now % 1000].first == dp[i % 2][j].first+1 && dp[(i + 1) % 2][j + 500 - now % 1000].first > dp[i % 2][j].second + now) {
							ok = 1;
						}
						if (ok == 1) {
							dp[(i + 1) % 2][j + 500 - now % 1000] = make_pair(dp[i % 2][j].first + 1, dp[i % 2][j].second + now);
						}
					}
					else {
						//not taking
						int ok = 0;
							int itr = j + (1000 - now % 1000) % 1000;
							if (dp[(i + 1) % 2][itr].first < dp[i % 2][j].first) {
								ok = 1;
							}
							if (dp[(i + 1) % 2][itr].first == dp[i % 2][j].first && dp[(i + 1) % 2][itr].first > dp[i % 2][j].second + now) {
								ok = 1;
							}
							if (ok == 1) {
								dp[(i + 1) % 2][itr] = make_pair(dp[i % 2][j].first, dp[i % 2][j].second + now);
							}
							ok = 0;
							itr = j;
							if (dp[(i + 1) % 2][itr].first < dp[i % 2][j].first)ok = 1;
							else if (dp[(i + 1) % 2][itr].first == dp[i % 2][j].first && dp[(i + 1) % 2][itr].second > dp[i % 2][j].second) ok = 1;
							if (ok == 1) dp[(i + 1) % 2][itr] = dp[i % 2][j];
							itr = j - (now % 1000 + 500) % 1000;
							if (itr < 0) continue;
							ok = 0;
							if (dp[(i + 1) % 2][itr].first < dp[i % 2][j].first + 1) ok = 1;
							if (dp[(i + 1) % 2][itr].first == dp[i % 2][j].first + 1 && dp[(i + 1) % 2][itr].second >= dp[i % 2][j].second + now) {
								ok = 1;
							}
							if (ok == 1) {
								dp[(i + 1) % 2][itr] = make_pair(dp[i % 2][j].first + 1, dp[i % 2][j].second + now);
							}
					}
				}
			}
		}
		pair<int, int> ans = make_pair(0, 0);
		for (int i = 0; i < 99901; ++i) {
			int ok = 0;
			if (ans.first < dp[n % 2][i].first) {
				ok = 1;
			}
			if (ans.first == dp[n % 2][i].first && ans.second > dp[n % 2][i].second) ok = 1;
			if (ok == 1) {
				ans = dp[n % 2][i];
			}
		}
		cout << ans.first << " " << ans.second << endl;
	}
}



Measured memory_bytes: 4716