// Problem idea by Thomas Tang // Problem written by Thomas Tang // This solution written by Thomas Tang #include #include #include using namespace std; main() { map book; map::iterator bi; int n; string line; cin >> n; getline(cin, line); while (n--) { getline(cin, line); if (cin.eof()) break; string country = line.substr(0, line.find(' ')); bi = book.find(country); if (bi != book.end()) { book[country] = bi->second + 1; } else { book[country] = 1; } } for (bi = book.begin(); bi != book.end(); bi++) { cout << bi->first << " " << bi->second << "\n"; } }