#K91067. Group and Count Characters

    ID: 37893 Type: Default 1000ms 256MiB

Group and Count Characters

Group and Count Characters

Given a string S consisting of uppercase English letters (A-Z), your task is to count the frequency of each character. The result should be printed in a sorted order such that the characters with higher frequency appear first. In case of a tie in frequency, sort the characters in alphabetical order.

Mathematically, if \(f(c)\) denotes the frequency of character \(c\), you need to output the characters in the order of decreasing \(f(c)\), and if \(f(c_1) = f(c_2)\), then \(c_1\) appears before \(c_2\) if \(c_1 < c_2\) (in lexicographical order).

Example: For the input string "ABBCCC", the correct output is:

C 3
B 2
A 1

inputFormat

The input consists of a single line containing the string S (1 ≤ |S| ≤ 105) composed only of uppercase English letters.

outputFormat

Output the counted frequency for each unique character in S on separate lines. Each line should contain the character and its frequency separated by a space.

## sample
ABBCCC
C 3

B 2 A 1

</p>