#include<iostream>
#include<string>
#include<map>
using namespace std;

int main() {
	map<string, int> ms;
	string s, ans, ans2;
	int max = 0, max2 = 0;
	
	while (cin >> s) {
		ms[s]++;
		if (max2 < ms[s]) {
			max2 = ms[s];
			ans2 = s;
		}
		if (max < s.size()) {
			max = s.size();
			ans = s;
		}
		
	}
	cout << ans2 << " " << ans << endl;
}
