#include using namespace std; void count_map_o(map &m, string key, int value){ if (m.find(key) == m.end()) { m.insert(make_pair(key, value)); } else m[key] += value; } int main(void){ int n; string ns, s; getline(cin, ns); n = stoi(ns); map m, m2; for (int i = 0; i < n; i++) { getline(cin, s); count_map_o(m, s, i+1); for (auto j = m.begin(); j != m.end(); j++) { count_map_o(m2, j->first, j->second); } } for (auto i = m2.begin(); i != m2.end(); i++) { cout << i->second << " " << i->first << endl; } }