
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <time.h>
#include <stdlib.h>
#include <set>
#include <stack>
#include <sstream>
#include <map>

using namespace std;

int main()
{
	map<string,int> mp;
	string s;
	getline(cin,s);
	string t,ls,ms;
	int n = 0;
	istringstream ss(s);
	while ( ss >> t )
	{
		int tn = ++mp[t];
		if ( t.size() > ls.size() )
			ls = t;
		if ( tn > n )
		{
			ms = t;
			n = tn;
		}
	}
	cout << ms << " " << ls;
	return 0;
}