#define _USE_MATH_DEFINES
#include <iostream>
#include <queue>
#include <vector>
#include <math.h>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <cctype>
#include <cstdlib>
#include <string.h>
#include <utility>
#include <cstdio>
#include <set>
#include <map>
#include <boost/multiprecision/cpp_int.hpp>
#include <assert.h>
using namespace std;
namespace mp = boost::multiprecision;

#define INF (1 << 20)
#define EPS (1e-10)
#define EQ(a,b) (fabs((a)-(b)) < EPS)

#define ll long long
#define LL long long

int main() {
	string s;
	map<string, int> n;
	int maxl = 0;
	string maxls;
	while (cin >> s) {
		transform(s.begin(), s.end(), s.begin(), (int (*)(int))tolower);
		if (s.length() > maxl) {
			maxl = s.length();
			maxls = s;
		}
		auto res = n.find(s);
		if (res == n.end()) n.insert(make_pair(s, 1));
		else res->second++;
	}
	int maxn = 0;
	string maxns;
	for_each(n.begin(), n.end(), [&](pair<string, int> p) {
			if (p.second > maxn) {
			maxn = p.second;
			maxns = p.first;
			}
			});
	cout << maxns << ' ' << maxls << endl;
	return 0;
}