#if 0
????????£????????????15m
size_t????????£?????°?¢??????????????????£?????´??°N????????????????????????
#endif

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

map<string,int> table;
int main(){
	string word, M_frequent, longest;
	size_t N=0; //?????§???????????????????????????????????°
	while(cin>>word){
		table[word]++;
		if(table[word]>N){
			N=table[word];
			M_frequent=word;
		}
		if(word.size()>longest.size())
			longest=word;
	}
	cout<<M_frequent<<" "<<longest<<endl;
}