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

int main(void)
{
	string s;
	map<string, int> m;

	string mx, f;
	while(cin >> s){
		m[s] += 1;

		if(s.length() > mx.length())
			mx = s;
	}

	map<string, int>::iterator it;
	int mn = 0;
	for(it = m.begin(); it != m.end(); it++)
		if(mn < it->second)
			f = it->first;

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

	return 0;
}