#include<iostream>
#include<map>
using namespace std;
int main(){
  map<string,int> word;
  string s,as,bs;
  int an = 0;
  while(cin >>s){
    word[s]++;
    if(word[s]>an){
      an = word[s];
      as = s;
    }
    if(s.size()>bs.size()) bs = s;
  }
  cout <<as<<" "<<bs<<endl;
  return 0;
}