import std.stdio;
import std.string;
import std.conv;
void main(){
	int[string] diction;
	int max;
	string longest="";
	foreach( c ; readln().chomp().split() ){
		diction[c]++;
		if( max < diction[c] ){
			max = diction[c];
		}
		if( longest.length < c.length ){
			longest = c;
		}
	}
	foreach( c,i ; diction ){
		if( max == diction[c] ){
			write( c," " );
		}
	}
	writeln( longest );
}