• + 0 comments

    All TestCases Passed

    from collections import Counter
    
    if __name__ == '__main__':
        s = input().strip()
        # Count the occurrences of each character
        count = Counter(s)
        # Sort by frequency (descending) and then alphabetically for ties
        sorted_count = sorted(count.items(), key=lambda x: (-x[1], x[0]))
        # Print the top three characters
        for char, freq in sorted_count[:3]:
            print(char, freq)