import std.stdio, std.string, std.conv;
import std.array, std.algorithm, std.range;

void main()
{
    int[string] c;
    string mw; c[mw]=0;
    string ml;
    foreach(w;readln().split())
    {
        if(w in c){ if(++c[w]>c[mw]) mw=w; }
        else c[w]=1;
        if(ml.length < w.length) ml=w;
    }
    writeln(mw," ",ml);
}