#include <iostream>
#include <map>
#include <string>

using namespace std;

int main()
{
	string s;
	string max_length_string = "";
	map<string, int> m;

	while (cin >> s) {
		m[s]++;
		if (s.size() > max_length_string.size() ) {
			max_length_string = s;
		}
	}

	// 最頻値を求める
	int max = 0;
	string mode = "";
#if 0
	for ( auto x : m ) {
		if (x.second > max) {
			mode = x.first;
			max = x.second;
		}
	}
#else
	for (map<string,int>::iterator it = m.begin(); it != m.end(); it++) {
		if (it->second > max) {
			mode = it->first;
			max = it->second;
		}
	}
#endif
	cout << mode << " " << max_length_string << endl;

	return 0;
}

