s = []
while True:
    try:
        s.append(input())
    except:
        s.sort(key=lambda x: len(x))
        min_len = len(s[0])
        max_len = len(s[-1])
        while s and len(s[0]) == min_len:
            print(s.pop(0))
        while s and len(s[-1]) == max_len:
            print(s.pop(-1))
        break