S=sorted while 1: r=raw_input();g=map(set,zip(r,r[2:])[::4]) for x in g: for y in g:y|=x&y and x s=S(map(''.join,map(S,g)),key=len);print s[0],s[-1]