#include <iostream>
using namespace std;

const int MAX_BANKNOTES = 8;
const string VALID_BANKNOTES[] = {"1", "5", "10", "20", "50", "100", "200", "500"};
int frqBankNotes[MAX_BANKNOTES] = {0};

int isValidBanknote(const string currNum) {
    for (int i = 0; i < MAX_BANKNOTES; ++i) {
        if (currNum == VALID_BANKNOTES[i]) {
            return i;
        }
    }
    return -1;
}

string getMostFrqBankNote(const int &noValidBanknotes) {
    if (noValidBanknotes == 0) {
        return "NU EXISTA";
    }
    int mostFrqIndex = 0;
    for (int i = 0; i < MAX_BANKNOTES; ++i) {
        if (frqBankNotes[i] >= frqBankNotes[mostFrqIndex]) {
            mostFrqIndex = i;
        }
    }
    return VALID_BANKNOTES[mostFrqIndex];
}

void splitNumbers(const string &text, int &noValidBanknotes) {
    const int len = (int)text.size();
    string currNum;
    for (int i = 0; i <= len; ++i) {
        if (isdigit(text[i]) && (text[i] != '0' || !currNum.empty())) {
            currNum += text[i];
        } else if (!currNum.empty()) {
            const int indexBankNote = isValidBanknote(currNum);
            if (indexBankNote >= 0) {
                ++frqBankNotes[indexBankNote];
                ++noValidBanknotes;
            }
            currNum.clear();
        }
    }
}

string formatResult(const int &noValidBanknotes) {
    return to_string(noValidBanknotes) + '\n' + getMostFrqBankNote(noValidBanknotes);
}

int main() {
    string text;
    int noValidBanknotes = 0;
    while (getline(cin, text)) {
        splitNumbers(text, noValidBanknotes);
    }
    cout << formatResult(noValidBanknotes);
    return 0;
}

