#if 0
#endif

#include <iostream>
#include <string>
#include <map>
using namespace std;
map<string, int> table;
int main()
{
    string /*入力用*/ word, /*最大頻度*/ frequent, /*最長*/ longest;
    size_t N = 0; /*文字列frequentの頻度*/
    while (cin >> word)
    {
        // table[word]を一つ増やす
        table[word] += 1;
        // table[word]がNより大きければ，Nとfrequentを更新
        if (table[word] > N)
        {
            N = table[word];
            frequent = word;
        }
        // word.size() > longest.size() ならlongest を更新
        if (word.size() > longest.size())
        {
            longest = word;
        }
    }
    //frequent と longest を出力
    cout << frequent << ' ' << longest << endl;
}

