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

#ifdef _MSC_VER
#define __typeof__ decltype
#endif

#define ITER(c)         __typeof__((c).begin())
#define FOREACH(it, c)  for (ITER(c) it=(c).begin(); it != (c).end(); ++it)
#define MAX(p1,p2)      (((p1)>(p2))?(p1):(p2))

map<string,int> m;

int main(){
    string s, maxs;
    int max = 0;
    while(cin >> s){
        m[s]++;
        if(maxs.length() < s.length()) maxs = s;
    }
    FOREACH(it,m) max = MAX(max, it->second);
    FOREACH(it,m){
        if(it->second == max){
            cout << it->first << " " << maxs << endl;
            break;
        }
    }
    return 0;
}