#include <iostream>
#include <string.h>
using namespace std ;

typedef struct _string_mode
{
	char str[33] ;
	short num ;
} stm ;


int main()
{
	char get[33] ;
	char longest[33] = { '\0' } ;
	stm string[1000] ;
	int mode = 0;
	int i = 0, j ;

	while( cin >> get )
	{
		if( strlen(longest) < strlen(get) )	strcpy( longest,get ) ;

		i ++ ;
		strcpy( string[i].str, get ) ;
		string[i].num = 1 ;
		for( j = 0 ; j < i ; j ++ )
		{
			if( strcmp(string[j].str,string[i].str) == 0 )
			{
				string[j].num += string[i].num ;
				if( mode < string[j].num ){ mode = string[j].num ; }
				break ;
			}
		}
	}

	for( j = 0 ; j < i ; j ++ )
	{
		if( string[j].num == mode )
		{
			cout << string[j].str << " " << longest << endl ;
			break ;
		}
	}

	return 0 ;
}