import string from collections import Counter while True: try: char_count = Counter(input()) sorted_count = sorted(char_count.items(), key=lambda x: (-x[1], x[0])) res="" for char, count in sorted_count: res+=char print(res) except: break