#include <bits/stdc++.h>

using namespace std;

int main() {
	int mval = 0;
	string s, buf, a, b;
	map<string, int> m;
	getline(cin, s);
	stringstream ss(s);
	while(ss >> buf) {
		m[buf] += 1;
		if(mval < m[buf]) mval = m[buf];
	}
	for(auto &v: m) {
		if(v.first.length() > b.length()) b = v.first;
		if(v.second == mval) a = v.first;
	}
	cout << a << " " << b << endl;
	return 0;
}

