#include <bits/stdc++.h>
#define PI 3.14159265359
using namespace std;

int main() {
	string s;
	int maxlen = 0;
	string maxstr = "";
	vector<pair<int, string> > v(1000, pair<int, string>(0, "-"));

	while (cin >> s) {
		if (s.size() > maxlen) {
			maxlen = s.size();
			maxstr = s;
		}

		for (int i = 0; i < v.size(); i++) {
			string &s2 = v.at(i).second;
			int &cnt = v.at(i).first;

			if (s2 == "-") {
				s2 = s;
				cnt = 1;
				break;
			}
			else {
				if (s2 == s) {
					cnt++;
					break;
				}
			}
		}
	}
	/*
	for (int i = 0; i < 10; i++) {
		int x = v.at(i).first;
		string s0 = v.at(i).second;

		cout << x << ' ' << s0 << endl;
	}*/

	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());

	cout << v.at(0).second << ' ' << maxstr << endl;
}
