#[derive(Hash, Clone, Default, Eq, PartialEq)]
struct State {
    one: usize,
    five: usize,
    ten: usize,
    fifty: usize,
    handred: usize,
}

use std::cmp::{max, min};
use std::collections::HashMap;
fn main() {
    let stdin = std::io::stdin();
    let mut sc = Scanner::new(stdin.lock());
    loop {
        let n = sc.read::<usize>();
        if n == 0 {
            break;
        }
        let ps: Vec<usize> = sc.read_vec(n);
        let mut dp = vec![(0, isize::min_value()); 1000 * 101 + 1];
        dp[0] = (0, 0);
        // 100, 500 * 100
        for p in ps {
            let mut ndp = dp.clone();
            for have in 0..1000 * 101 + 1 {
                let (max_500, spent) = dp[have];
                if spent == isize::min_value() {
                    continue;
                }
                let spent = (-spent) as usize;
                // Get 500
                let next_spent = spent + p;
                let pb = p % 1000;
                let rest = (1000 - pb) % 1000;
                let need = if rest < 500 { 500 - rest } else { 0 };
                let add = if rest < 500 { 0 } else { rest - 500 };
                if need > have {
                    continue;
                }
                let next_have = have - need + add;
                let next_500 = max_500 + 1;
                ndp[next_have] = max(ndp[next_have], (next_500, -(next_spent as isize)));
            }
            for have in 0..1000 * 101 + 1 {
                let (max_500, spent) = dp[have];
                if spent == isize::min_value() {
                    continue;
                }
                let spent = (-spent) as usize;
                // No 500
                let next_spent = spent + p;
                let pb = p % 1000;
                let rest = (1000 - pb) % 1000;
                let next_have = have + rest;
                let next_500 = max_500;
                ndp[next_have] = max(ndp[next_have], (next_500, -(next_spent as isize)));
            }
            dp = ndp;
        }
        let mut answer = (0, isize::min_value());
        for have in 0..1000 * 101 + 1 {
            let (max_500, spent) = dp[have];
            if spent == isize::min_value() {
                continue;
            }
            let spent = (-spent) as usize;
            let cand = (max_500, -(spent as isize));
            if answer < cand {
                answer = cand;
            }
        }
        println!("{} {}", answer.0, -answer.1);
    }
}

pub struct Scanner<R> {
    reader: R,
}

impl<R> Scanner<R> {
    pub fn new(reader: R) -> Scanner<R> {
        Scanner { reader }
    }
}

fn is_whitespace(b: u8) -> bool {
    b == b' ' || b == b'\n' || b == b'\r' || b == b'\t'
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        let buf = std::io::Read::bytes(self.reader.by_ref())
            .map(|b| b.expect("Read failed"))
            .skip_while(|&b| is_whitespace(b))
            .take_while(|&b| !is_whitespace(b))
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error")
    }

    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn read_chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}



Measured memory_bytes: 11072