#include <bits/stdc++.h>
using namespace std;
int main(){
  string s,ans1="",ans2;
  map<string,int> mp;
  while(cin >> s){
    if(ans1==""){
      ans1=s;
      ans2=s;
    }
    mp[s]++;
    if(mp[s]>mp[ans1]){
      ans1=s;
    }
    if(s.size()>ans2.size()){
      ans2=s;
    }
  }
  cout << ans1 << " " << ans2 << endl;
  return 0;
}
