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

int main(){
  int m=0,f=0;
  multiset<string> a;
  string s,ms,mf;
  while(cin>>s){
    a.insert(s);
    if(m<s.size())ms=s;m=s.size();
    if(f<a.count(s))mf=s;f=a.count(s);
  }
  //cout<<f<<" "<<m;////////
  cout<<mf<<" "<<ms<<endl;
  return 0;
}