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

int main(){
  string s;
  string ansstr;
  string maxv;
  map<string, int> mp;
  while (cin >> s) {
    mp[s]++;
    maxv = mp.rbegin()->first;

    int maxstr = 0;
    for (auto x : mp) {
      if (x.first.size() >= maxstr) {
        maxstr = x.first.size();
        ansstr = x.first;
      }
    }
  }
  cout << maxv << " " << ansstr << endl;
  return 0;
}
