// English Sentence

#include <iostream>
#include <string>
#include <map>

using namespace std;

int main(void)
{
        map<string, int> tango; // 単語とその登場回数を記録する
        string s, highfre_str, maxlen_str;
        int appear = 0;

        while (cin >> s) {
                ++tango[s];
        }

        for (map<string, int>::const_iterator it = tango.begin();
             it != tango.end(); ++it) {
                if (it->second > appear) {
                        highfre_str = it->first;
                        appear = it->second;
                }

                if (it->first.size() > maxlen_str.size()) {
                        maxlen_str = it->first;
                }
        }

        cout << highfre_str << " " << maxlen_str << endl;

        return 0;
}