#include<stdio.h>
#include<string.h>

int main(){
  char s[1001];
  char word[1001][33];
  int cnt[1001],l[1001];
  char tmp[33];
  int len,pos,d,num,i,j;
  int mod,max;

  while(fgets(s,1001,stdin)){
    num = 0;
    len = strlen(s);
    pos = 0;
    while(pos<len){
      d = 0;
      while(pos+d<len && (s[pos+d]!=' ' && s[pos+d]!='\0')){
	tmp[d] = s[pos+d];
	d++;
      }
      tmp[d] = '\0';
      for(i=0;i<num;i++){
	if(d!=l[i])continue;
	for(j=0;j<l[i];j++)
	  if(tmp[j]!=word[i][j])break;
	if(j==l[i]){
	  cnt[i]++;
	  break;
	}
      }
      if(i==num){
	for(j=0;j<d;j++)word[num][j] = tmp[j];
	l[num] = d;
	cnt[num] = 0;
	num++;
      }
      pos+=d+1;
    }
    mod = 0;
    max = 0;
    for(i=1;i<num;i++){
      if(cnt[mod]<cnt[i])mod = i;
      if(l[max]<l[i])max = i;
    }
    printf("%s %s\n",word[mod],word[max]);
  }
  return 0;
}