#include <bits/stdc++.h>
#define read() freopen("input", "r", stdin)
using namespace std;

int main(void)
{
	read();
	string s;
	map<string, int> m;
	int hm = 0;
	string mx, f;
	while(cin >> s){
		m[s] += 1;

		if(m[s] > hm){
			hm = m[s];
			f = s;
		}
		if(s.length() > mx.length())
			mx = s;
	}

	cout << f << " " << mx << endl;

	return 0;
}