#include <bits/stdc++.h>
using namespace std;

int main(){
  vector<string> S;
  vector<int> cnt;

  string s, ans1, ans2; int mode = 0, longest = 0;
  while(cin >> s){
    bool new_word = true;

    for(int i=0; i<S.size(); i++){
      if(S[i] == s){
        new_word = false;
        cnt[i]++; 
        break;
      }
    }

    if(new_word){
      S.push_back(s);
      cnt.push_back(1);
      if(s.length() > longest){
        longest = s.length();
        ans2 = s;
      }
    }
  }

  for(int i=0; i<cnt.size(); i++) mode = max(mode, cnt[i]);

  for(int i=0; i<cnt.size(); i++){
    if(mode == cnt[i]) ans1 = S[i];
  }

  cout << ans1 << " " << ans2 << endl;
}
  
  
