#include "bits/stdc++.h"
using namespace std;

int main() {
	map<string, long long> mp;
	string S;
	while (cin >> S) mp[S]++;
	long long MAXA = 0, MAXB = 0;
	for (auto it = mp.begin(); it != mp.end(); it++) {
		MAXA = max(MAXA, it->second);
		MAXB = max(MAXB, (long long)(it->first.size()));
	}
	for (auto it = mp.begin(); it != mp.end(); it++) {
		if (it->second == MAXA) cout << it->first << " ";
	}
	for (auto it = mp.begin(); it != mp.end(); it++) {
		if (it->first.size() == MAXB) cout << it->first << endl;
	}
}
