#include<iostream>
#include<map>
#include<string>
using namespace std;

int main()
{
    map<string,int> m1;
    string str1, str2, str3;        //入力、頻度最大文字列、最長文字列

    int length = 0;
    while( cin >> str1 )
    {
        m1[str1]++;                 //出現頻度
        if( length < str1.size() )
        {
            length = str1.size();
            str3 = str1;
        }
    }

    int max = 0;
    for( map<string,int>::iterator itr = m1.begin(); itr != m1.end(); itr++ )
    {
        if( max < itr -> second )
        {
            max = itr -> second;
            str2 = itr -> first;
        }
    }

    cout << str2 << " " << str3 << endl;

    return 0;
}
