#include <algorithm>
#include <iostream>
#include <string>
#include <unordered_map>

using namespace std;

int main()
{
    string s;
    unordered_map<string, int> m;
    string longest;
    while (cin >> s) {
        m[s] += 1;
        if (s.size() > longest.size()) {
            longest = s;
        }
    }
    cout << max_element(begin(m), end(m),
                        [](const decltype(m)::value_type& a,
                           const decltype(m)::value_type& b) {
                            return a.second < b.second;
                        })
                ->first
         << ' ' << longest << endl;
}