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

map <string, int> dic;

string lowerword(string word){
    for (int i=0; i<(int)word.size(); i++)
        word[i] = tolower(word[i]);
    return word;
}

int main(void){
	string s;

	while (cin>>s) dic[lowerword(s)]++;

	int l=0, m=0, tmp;
	string w1, w2;
	for (auto &x: dic){
		tmp = x.second;
		if (tmp>m){
			m = tmp;
			w1 = x.first;
		}
		tmp = x.first.size();
		if (tmp>l){
			l = tmp;
			w2 = x.first;
		}
	}
	cout<<w1<<" "<<w2<<endl;
	return 0;
}