/*
	0029:English sentence
*/
#include	<iostream>
#include	<string>
#include	<map>

using namespace std;

typedef map<string, int> M_SI;

int main(void) {
	int maxlen = 0, maxcou = 0; 
	string buf_str, maxlenSen, maxcouSen;
	M_SI Sentence;
	
	while(1) {
		cin >> buf_str;
		if(cin.eof()) { break; }
		if(Sentence.empty() || Sentence.count(buf_str) == 0) {
			Sentence.insert( M_SI::value_type(buf_str, 1) );
		} else {
			M_SI::iterator it = Sentence.find(buf_str);
			(*it).second++;
		}
	}
	M_SI::iterator it = Sentence.begin();
	while(it != Sentence.end()) {
		string bff = (*it).first;
		int bfs = (*it).second, bfl = bff.size();
		
		if(maxlen < bfl) {
			maxlenSen = bff;
			maxlen = bfl;
		}
		if(maxcou < bfs) {
			maxcouSen = bff;
			maxcou = bfs;
		}
		it++;
	}
	cout << maxcouSen << ' ' << maxlenSen << endl;
	
	return 0;
}