• + 0 comments

    fixed: words = {}

    if name == 'main': s = input()

    # Count character frequencies
    for char in s:
        if char not in words:
            words[char] = 1
        else:
            words[char] += 1
    
    fixed = sorted(words.items(), key=lambda item: (-item[1], item[0]))
    
    
    for i, (char, freq) in enumerate(fixed):
        if i >= 3:  # Stop after printing the top 3
            break
        print(f"{char} {freq}")