#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
	string in;
	vector <string>s;
	vector <int>a;
	int maxH = 0, maxL = 0;
	while (cin >> in) {
		s.push_back(in);
		a.push_back(0);
	}
	for (int i = 0; i < s.size(); i++) {
		if (a[i] == 0) {
			for (int j = i + 1; j < s.size(); j++) {
				if (s[i] == s[j])
					a[j] = ++a[i];
			}
			if (maxH < a[i])
				maxH = a[i];
		}
		if (maxL < s[i].length())
			maxL = s[i].length();
	}
	for (int i = 0; i < s.size(); i++) {
		if (maxH == a[i]) {
			cout << s[i] << " ";
			break;
		}
	}
	for (int i = 0; i < s.size(); i++) {
		if (maxL == s[i].length())
			cout << s[i]<<endl;
	}
	return 0;
}
