#include <iostream>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <map>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,b) FOR(i,0,b)
#define PB push_back
#define MP make_pair
typedef pair<double,double> P;
int main(){
  map<string,int> data;
  string s[1000];
  int cnt=0;
  while(cin>>s[cnt]){
    if(data[s[cnt]]==1)data[s[cnt]]++;
    else data[s[cnt]]=1;
    cnt++;
  }
  string ans[2];
  int m[2]={0,0};
  for(int i=0;i<cnt;i++){
    if(s[i].size()>m[1]){
      ans[1]=s[i];m[1]=s[i].size();
    }
    if(data[s[i]]>m[0]){
      ans[0]=s[i];m[0]=data[s[i]];
    }
  }
  cout<<ans[0]<<" "<<ans[1]<<endl;
}