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

int main(void)
{
  char s[40] = {};
  char str[1001][40] = {};
  int i;
  int count[1001];
  int longest = 0;
  int max = 0;
  char ans[2][40] = {};
  while(scanf("%s", s) != EOF){
    if(longest < strlen(s)){
      strcpy(ans[0], s);
      longest = strlen(s);
    }
    
    for(i = 0;;i++) { 
      if(strcmp(s, str[i]) == 0 ){
	count[i]++;
	break;
      }
    
      if (count[i] == 0){
	count[i]++;
	strcpy(str[i], s);
	break;
      }
    }

    for(i = 0; i < 1001; i++)
      if( max < count[i] ){
	max = count[i];
	strcpy(ans[1], str[i]);
      }
  }
  
  printf("%s %s\n", ans[1], ans[0]);

  return 0;
}