<?php

$line = strtolower(trim(fgets(STDIN)));
$arr = explode(" ", $line);

$maxword = "";
$maxlenword = "";
$hash = array();
foreach($arr as $word){
	$hash[$word]++;
	
	if($hash[$maxword] < $hash[$word]){
	 	$maxword = $word;
	}
	if(strlen($maxlenword) < strlen($word)){
		$maxlenword = $word;
	}
}

echo "{$maxword} {$maxlenword}\n";