#include <iostream>
#include <vector>
#include <string>
using namespace std;

class MNode {
private:
	const string key;
	int value;
	MNode *left, *right;
public:
	MNode(string k, int v);
	~MNode();
	MNode* find(string k);
	int& Value() { return value; }
};

MNode::MNode(string k, int v) : key(k), value(v) {
	left = nullptr;
	right = nullptr;
}

MNode::~MNode() {
	if (left != nullptr)
		delete left;
	if (right != nullptr)
		delete right;
}

MNode* MNode::find(string k) {
	if (key == k)
		return this;
	else if (k < key) {
		if (left == nullptr) {
			left = new MNode(k, 0);
			return left;
		}
		else
			return left->find(k);
	}
	else {
		if (right== nullptr) {
			right = new MNode(k, 0);
			return right;
		}
		else
			return right->find(k);
	}
}

class StrIntMap {
private:
	MNode *root;
	const string center;
public:
	StrIntMap();
	~StrIntMap();
	int& operator [](string str) {
		return (root->find(str))->Value();
	}
};

StrIntMap::StrIntMap() : center("n") {
	root = new MNode(center, 0);
}

StrIntMap::~StrIntMap() {
	delete root;
}

int main() {
	string str;
	StrIntMap m;
	int maxlen = 0, maxnum = 0;
	string maxlen_str, maxnum_str;
	while (cin >> str) {
		if (++m[str] > maxnum) {
			maxnum = m[str];
			maxnum_str = str;
		}
		if (str.size() > maxlen) {
			maxlen = str.size();
			maxlen_str = str;
		}
	}
	cout << maxnum_str << ' ' << maxlen_str << endl;
}
