#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
#define make_pair mk
typedef pair<int, int> P;

int main(){
	string input;
	map<string, P> data;
	int maxlen = 0, maxcnt= 0;
	string lenst, cntst;
	while( cin >> input ){	
		if( data.find(input) == data.end() ){
			data.insert( pair<string, P>(input, P(input.size(), 1)) );
			//maxlen = max(maxlen, (int)input.size());
			if( maxlen < input.size() ){
				maxlen = input.size();
				lenst = input;
			}
		}else{
			//data[input].second++;
			if( maxcnt < data[input].second++ ){
				maxcnt = data[input].second;
				cntst = input;
			}
		}
	}
	/*map<string, P>::iterator it = data.begin();
	for( ; it != data.end(); it++ ){
		cout << (*it).first << "," << (*it).second.first << "," << (*it).second.second << endl;
	}*/
	cout << cntst << " " << lenst << endl;
}