#include <iostream>
#include <map>
#include <string>
using namespace std;
int main() {
	string s, max="";
	map<string, int> m;
	while(cin >> s) {
		if(s.size() > max.size()) {
			max = s;
		}
		m[s]++;
	}
	map<string, int>::reverse_iterator p = m.rbegin();
	cout << (*p).first << " " << max << endl;
}