#include<iostream>
#include <map>

using namespace std;

int main()
{
	string wordMax;
	map<string, int> n;
	map<string, int>::iterator i, nMax;
	string a;

	wordMax = "";
	while (cin>>a) {
		if ( n.count(a) ) {	// aðkeyÉÂvfª éA»ÌlðCNg
			n[a] ++;
		} else {			// aðkeyÉÂvfªÈ¢A»ÌvfðÇÁ
			n.insert( map<string, int>::value_type(a, 1) );
		}
		if ( a.size() > wordMax.size() ) wordMax = a;
	}

	nMax = n.begin();
	for (i = n.begin(); i != n.end(); i++) {
		if ( (*i).second > (*nMax).second ) nMax = i;
	}

	cout<<(*nMax).first<<" "<<wordMax<<endl;

	return 0;
}