def get_file(fn):
    with open(fn, 'r') as f:
        content = f.readlines()
        return list(sorted(set(map(lambda x: x.strip()[:2], content)) | \
                           set(map(lambda x: x.strip()[1:], content)) | \
                           set(map(lambda x: x.strip()[::2], content))))

def resort(lst):
    lst = [list(filter(lambda x: x[0] == c, lst)) for c in set(map(lambda x: x[0], lst))]
    lst.sort(key=lambda x: len(x))
    return ''.join(list(reversed(list(map(lambda x: x[0][0], lst[1:]))))) + lst[0][0]

print(resort(get_file('../resource/keylog.txt')))