#include<string>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
	string str;
	vector<string> cstr;
	getline(cin, str);

	int start = 0;
	for (int i = 0; i < str.size(); ++i){
		if (str[i] == ' '){
			cstr.push_back(str.substr(start,i - start));
			start = i+1;
		}
		if (i == str.size()-1){
			cstr.push_back(str.substr(start, i - start));
			start = i + 1;
		}
	}

	int maxl = 0,maxf = 0;
	for (auto& n : cstr){
		if (maxf < count(cstr.begin(), cstr.end(),n))			maxf = count(cstr.begin(), cstr.end(), n);
		if (n.size() > maxl)													maxl = n.size();
	}

	for (auto& n : cstr){
		vector<string> outs;
		if (maxf == count(cstr.begin(), cstr.end(), n)){
			cout << n << " ";
			break;
		}
	}

	for (auto& n : cstr){
		if (n.size() == maxl)
			cout << n << endl;
	}
	return 0;
}