#include <iostream>
#include <string>
#include <map>
#include <sstream>
#include <algorithm>

std::map<std::string, int> mp;

void split(const std::string &str, char sep) {
    std::stringstream ss(str);
    std::string buf;
    while ( std::getline(ss, buf, sep)  ) {
        std::transform(buf.begin(), buf.end(), buf.begin(), tolower);
        if (mp.find(buf) != mp.end()) {
            mp[buf]++;
        } else {
            mp[buf] = 1;
        }
    }
    /*
    for (std::map<std::string, int>::iterator itr=mp.begin();itr!=mp.end(); itr++) {
        std::cout << itr->first << " : " << (itr->first).length() << std::endl;
    }
    */
}

void solve() {
    int m_freq = -1;
    std::string freq, len_str;
    std::string tmp_f;
    int         tmp_s;
    int m_len  = 0;
    for (std::map<std::string, int>::iterator itr=mp.begin(); itr!=mp.end(); itr++) {
        tmp_f = itr->first;
        tmp_s = itr->second;
        if (m_freq < tmp_s) {
            m_freq = tmp_s;
            freq   = tmp_f;
        }
        // std::cout << tmp_f << " : length ... " << tmp_f.length() << std::endl;
        if (m_len < tmp_f.length()) {
            m_len   = tmp_f.length();
            len_str = tmp_f;
        }
    }
    std::cout << freq << ' ';
    std::cout << len_str << std::endl;
}

int main() {
    std::string s;
    std::getline(std::cin, s);
    split(s, ' ');
    solve();
}

