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

int main()
{
    string line;
    string field;
    map<string, int> mp;
    string frequently_word;
    string max_num_word;
    int freq_count = 0;
    int max_letter_num = 0;

    getline(cin, line);    
    istringstream stream(line);

    /* ??????????????????????????? */
    while (getline(stream, field, ' '))
    {
        /* ?????§????????°?????????????????? */
        if(field.size() > max_letter_num)
        {
            max_num_word = field;
        }
        /* ????????????????????°??????????????? */
        if(mp.count(field)) 
        {
            mp[field]++; 
        }
        else
        {
            mp[field] = 1;
        }
 
    }
    /* ??????????????????????????? */
    for(auto itr = mp.begin(); itr != mp.end(); ++itr)
    {
        if(itr->second > freq_count)
        {
            frequently_word = itr->first;
        }
    }
    cout << frequently_word << " " << max_num_word << endl;

    return 0;
}