File size: 1,481 Bytes
c4b0eef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include<iostream>
#include<algorithm>
#include<sstream>
#include<fstream>
#include<utility>
#include<cstdlib>
#include<cstring>
#include<string>
#include<bitset>
#include<vector>
#include<cstdio>
#include<cctype>
#include<cmath>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#define ll long long
#define sc scanf
#define pf printf
#define pi 2*acos(0.0)
using namespace std;

struct Map
{
    char c;
    int count;
};

bool compare(Map a, Map b)

{
    if(a.count > b.count )
    {
        return true;
    }
    else if(a.count == b.count)
    {
        return a.c < b.c;
    }
    else
    {
        return false;
    }
//    return a.c < b.c ;
}
int main()

{
    char c;
    string s;
    Map str[26];
    for(int i=0; i<26; i++)
    {
        str[i].c = i + 'A';
        str[i].count = 0;
    }
    int cases, len;
    cin>>cases;
    cin.ignore();
    while(cases--)
    {
        getline(cin, s);
        len = s.length();
        for(int i=0; i<len; i++)
        {
            c = s[i];
            if('a'<=c && c <='z')
            {
                 str[c - 'a'].count++;
            }
            else if('A' <= c && c <= 'Z')
            {
                str[c - 'A'].count++;
            }
        }
    }

    sort(str, str+26,compare);
    for(int i=0; i<26; i++)
    {
        if(str[i].count==0) break;
        cout<<str[i].c<<" "<<str[i].count<<endl;
    }

}