#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
using namespace std;
struct entry {
string name;
unsigned quantity;
};
vector<entry> readData()
{
vector<entry> data;
string line, name;
unsigned quantity;
while (getline(cin, line) &&
istringstream(line) >> name >> quantity)
{
auto found = find_if(begin(data), end(data), [&](entry const& a) { return a.name == name; });
if (end(data) == found)
data.push_back({name, quantity});
else
found->quantity += quantity;
}
return data;
}
int main()
{
vector<entry> const data = readData();
for (auto it = data.begin(); it != data.end(); ++it)
cout << it->name << " " << it->quantity << "\n";
}
I2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8c3N0cmVhbT4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpzdHJ1Y3QgZW50cnkgewogICAgc3RyaW5nIG5hbWU7CiAgICB1bnNpZ25lZCBxdWFudGl0eTsKfTsKCnZlY3RvcjxlbnRyeT4gcmVhZERhdGEoKQp7CiAgICB2ZWN0b3I8ZW50cnk+IGRhdGE7CgogICAgc3RyaW5nIGxpbmUsIG5hbWU7CiAgICB1bnNpZ25lZCBxdWFudGl0eTsKCiAgICB3aGlsZSAoZ2V0bGluZShjaW4sIGxpbmUpICYmIAogICAgICAgICAgICBpc3RyaW5nc3RyZWFtKGxpbmUpID4+IG5hbWUgPj4gcXVhbnRpdHkpCiAgICB7CiAgICAgICAgYXV0byBmb3VuZCA9IGZpbmRfaWYoYmVnaW4oZGF0YSksIGVuZChkYXRhKSwgWyZdKGVudHJ5IGNvbnN0JiBhKSB7IHJldHVybiBhLm5hbWUgPT0gbmFtZTsgfSk7CiAgICAgICAgaWYgKGVuZChkYXRhKSA9PSBmb3VuZCkKICAgICAgICAgICAgZGF0YS5wdXNoX2JhY2soe25hbWUsIHF1YW50aXR5fSk7CiAgICAgICAgZWxzZQogICAgICAgICAgICBmb3VuZC0+cXVhbnRpdHkgKz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