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

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

  int maxstr = 0;
  string ansstr;
  for (auto x : mp) {
    if (x.first.size() >= maxstr) {
      maxstr = x.first.size();
      ansstr = x.first;
    }

  }
  cout << maxv << " " << ansstr << endl;

}

