#include<iostream>
#include<map>
#include<string>
using namespace std;
int main(){
	string b,mx; map<string,int> d;
	while(cin>>b){
		d[b]++; if(b.size()>mx.size())mx=b;
	}
	cout<<max_element(d.begin(),d.end())->first<<" "<<mx<<endl;
	return 0;
}