#include <iostream>
#include <functional>
#include <sstream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <utility>

using namespace std;
typedef pair<int,string> strpair;

int main(){
  vector<strpair> data;
  string str;
  getline(cin,str);
  istringstream iss(str);
  string word;
  while(iss>>word){
    auto it= find_if(data.begin(),data.end(),[word](pair<int,string> p){return p.second==word;});
    if(it==data.end()){
      data.push_back(pair<int,string>(1,word));
    }else{
      (*it).first++;
    }
  }

  sort(data.begin(),data.end(),greater<pair<int,string> >());
  int maxlength=0;
  string maxlengthword;
  for(auto word:data){
    int length=word.second.length();
    if(length>maxlength){
      maxlength=length;
      maxlengthword=word.second;
    }
  }
  cout<<data[0].second<<" "<<maxlengthword<<endl;

}