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

int main() {
	map<string,int> data;
	string n;
	while (cin >> n) 
		data[n]++;
	
	//出現頻度が最も多い単語
	int max = 0;
	string maxt;
	map<string,int>::iterator it = data.begin();
	for ( ; it != data.end(); it++ ) {
		if ( (*it).second > max ){
			max = (*it).second;
			maxt = (*it).first;
		}
	}
	cout << maxt << " ";
		
	max = 0;
	//文字数が最も多い単語
	for ( it = data.begin(); it != data.end(); it++ ) {
		if ( (*it).first.size() > max ){
			max = (*it).first.size();
			maxt = (*it).first;
		}
	}
	cout << maxt << endl;
}