import std.stdio, std.algorithm, std.string;
void main()
{
    int[string] count;
    int maxCount;
    string maxWord;

    auto input = readln.split;

    foreach(str; input)
    {
        ++count[str];
        if(maxCount < count[str])
        {
            maxCount = count[str];
            maxWord = str;
        }
    }

    size_t maxLen = 0;
    string maxLenWord;
    foreach(str; input)
    {
        if(maxLen < str.length)
        {
            maxLen = str.length;
            maxLenWord = str;
        }
    }
    writeln(maxWord, " ", maxLenWord);
}