#include <iostream>
#include <string>
#include <map>

using namespace std;

int main(){
  int max = 0;
  string str,maxs;
  map<string,int> M;
  while( cin >> str ){
    if(max < (int)str.size()){
      max = str.size();
      maxs = str;
    }
    M[str]++;
  }
  string fs;
  int m = 0;
  for( map<string,int>::iterator it = M.begin(); it != M.end(); it++ ){
    if(m < (*it).second){
      m = (*it).second;
      fs = (*it).first;
    }
  }
  cout << fs << " " << maxs << endl;
}