#include <iostream>
#include <map>

using namespace std;

int main(){
  string s;
  string max;
  int maxsize  = 0;
  map <string, int> m;
  while(cin >> s)
  	m[s]++;
   if(s.size() > maxsize){
       max = s;
       maxsize = s.size();
   }

   map<string,int>::iterator it = m.begin();
   string freq;
   int maxfreq = 0;
   for(it; it != m.end();it++){
   	 int k = (*it).second;
   	  if(k > maxfreq ){
   	  	maxfreq = k;
   	  	freq = (*it).first;
   	  }
   }
   cout << freq << " " << max << endl;
}