#include "bits/stdc++.h"
using namespace std;
pair<int,string> namesize[1000];
map<string, int> table;
string word;
int i = 0;

int main() {
    while (cin >> word) {
        namesize[i].second = word;
        namesize[i].first = word.size();
        i++;
        table[word] += 1;
    }
    int max=0;
    string maxword;
    for (map<string,int>::iterator p = table.begin(); p != table.end(); ++p) {
        if (max < p->second) {
            max = p->second;
            maxword = p->first;
        }
    }
    sort(namesize, namesize + i);
    reverse(namesize, namesize + i);
    cout << maxword << " " << namesize[0].second<<endl;



}
