Go: package main

import (
	"fmt"
	"sort"
)

type node struct {
	Key string
	Num int
}

func main() {
	var n int
	fmt.Scan(&n)
	m := make(map[string]int)
	for i := 0; i < n; i++ {
		var s string
		var num int
		fmt.Scan(&s, &num)
		if _, ok := m[s]; !ok {
			m[s] = 0
		}
		m[s] += num
	}
	list := make([]node, 0, len(m))
	for k, v := range m {
		list = append(list, node{Key: k, Num: v})
	}
	sort.Slice(list, func(i, j int) bool {
		if len(list[i].Key) == len(list[j].Key) {
			return list[i].Key < list[j].Key
		} else {
			return len(list[i].Key) < len(list[j].Key)
		}
	})
	for _, v := range list {
		fmt.Println(v.Key, v.Num)
	}
}

C++: #include <cstdio>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;

int main() {
    auto comp = [](const string &a, const string &b) { if (a.size() == b.size()) return a < b; return a.size() < b.size(); };
    std::map<string, int, decltype (comp) > m(comp);
    int N, num;
    string str;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> str >> num;
        if (m.find(str) != m.end()) m[str] += num;
        else m.insert({str, num});
    }
    for (auto it = m.begin(); it != m.end(); it++) {
        std::cout << it->first << " " << it->second << std::endl;
    }
    return 0;
}

C++: #include<iostream>
#include<map>
using namespace std;

bool operator==(string s, string t) {
    bool same = true;
    if(s.size() == t.size())
        for(unsigned int i=0; i<s.size(); i++)
            if(s[i] != t[i]) same = false;
    return same;
}
bool operator<(string s, string t) {
    if(s.size() != t.size()) return s.size() < t.size();
    for(unsigned int i=0; i<s.size(); i++) {
        if(s[i] != t[i]) return s[i] < t[i];
    }
    return 0;
}
bool operator>(string s, string t) {
    if(s == t) return 0;
    else return !(s<t);
}

int main()
{
    map<string, int> hash;
    map<string, int>::iterator it;
    int n;
    string name;
    cin>>n;
    while(cin>>name>>n) hash[name] += n;
    for(it=hash.begin(); it!=hash.end(); it++) cout<<it->first<<" "<<it->second<<endl;
}

C++: #include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
  int n,max=0;
  cin >> n;
  int num[n],pos = 0;
  string s[n];
  for(int t=0;t<n;t++){
    cin >> s[pos] >> num[pos];
    pos++;
    for(int tt=0;t<pos;tt++){
      if(s[tt] == s[pos]){ 
	num[tt] += num[pos];
	pos--;
	break;
      }
    }

  }

  for(int i=0;i<pos;i++){
    for(int j=pos-1;j>i;j--){
      if(s[j].size()<s[j-1].size() || (s[j].size()==s[j-1].size() && s[j]<s[j-1])){
	swap(s[j],s[j-1]);
	swap(num[j],num[j-1]);
      }
    }
  }
  
  for(int i=0;i<pos;i++){
    cout << s[i] << " " << num[i] << endl;
  }

}

C++: #include <iostream>
#include <cstdio>
#include <map>
#include <string>

using namespace std;

// ??????????????§??????????????¢?´¢?????????????????????

int main(){
	
	map<string, int> m;
	map<string, int>::iterator ite;
	
	int n, num;
	
	cin >> n;
	
	string str;
	
	for(int i = 0; i < n; i++){
		
		cin >> str >> num;
		ite = m.find(str);
		if(ite != m.end()){
			ite -> second += num;
		}else{
			m.insert(make_pair(str, num));
		}
	}
	
	for(ite = m.begin(); ite != m.end(); ite++){
		cout << ite -> first << " " << ite -> second << endl;
	}
	
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<map>
#include<string>
#include<algorithm>

using namespace std;

int main() {
    int n;
    map<string, int> products;
    vector<pair<string, int> > p;
    cin>>n;
    for (int i = 0; i < n; ++i) {
        string name;
        int num;
        cin>>name>>num;

        if (products[name] > 0) {
            products[name] += num;
        }
        else {
            products[name] = num;
        }
    }

    for (auto& e : products) {
        p.push_back(make_pair(e.first, e.second));
    }

    sort(p.begin(), p.end(), [](auto& lhs, auto& rhs) -> bool {
            if (lhs.first.size() < rhs.first.size()) return true;
            else if (lhs.first < rhs.first) return true;
            else return false;
            });


    for (auto& e : p) {
        cout<<e.first<<" "<<e.second<<endl;
    }

    return 0;
}

C++: #include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

int N; vector<pair<string, long long> > R;

struct sort1 : public binary_function<pair<string, long long>, pair<string, long long>, bool>
{
	bool operator()(pair<string, long long> p1, pair<string, long long> p2)
	{
		int l1 = p1.first.size();
		int l2 = p2.first.size();

		return (l1 < l2 ? true : l1 == l2 ? p1.first < p2.first : false);
	}
};

int main()
{
	cin >> N;

	R = vector<pair<string, long long> >(N);

	for (int i = 0; i < N; i++)
	{
		cin >> R[i].first >> R[i].second;
	}

	sort(R.begin(), R.end(), sort1());

	int sum = R[0].second;

	for (int i = 1; i < N; i++)
	{
		if (R[i - 1].first != R[i].first)
		{
			cout << R[i - 1].first << ' ' << sum << endl; sum = 0;
		}
		
		sum += R[i].second;
	}

	cout << R[N - 1].first << ' ' << sum << endl;

	return 0;
}

C++: #include<iostream>
#include<vector>
#include<map>
#include<string>

using namespace std;

int main() {
    int n;
    map<string, int> products;
    cin>>n;
    for (int i = 0; i < n; ++i) {
        string name;
        int num;
        cin>>name>>num;

        if (products[name] > 0) {
            products[name] += num;
        }
        else {
            products[name] = num;
        }
    }

    for (auto& e : products) {
        cout<<e.first<<" "<<e.second<<endl;
    }

    return 0;
}

C++: #include<iostream>
#include<string>
#include<set>
#include<map>
using namespace std;
int main() {
	set<string>s;
	map<string, int>m;
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		string str, int k; cin >> str >> k;
		if (s.find(str) == s.end()) {
			s.insert(str);
			m[str] = k;
		}
		else m[str] += k;
	}
	for (auto i = s.begin(); i != s.end(); i++) {
		cout << *i << ' ' << m[*i] << endl;
	}
}

C++: #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  map<string, int> mp;
  FOR(i,0,n){
      string s;
      int x;
      cin >> s >> x;
      mp[s] += x;
  }
  FOR(i,1,6){
    for(auto m : mp){
      if(m.first.length() == i) cout << m.first <<  " " << m.second << endl;
    }
  }
}

C++: #include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<cmath>
#include<ctime>
#include<complex>

using namespace std;

#define REP(i,s,e) for(int i=int(s);i<=int(e);i++)
#define rep(i,n) for(int i=0;i<int(n);i++)

int main(){

    vector<pair<string,int> >v;
    int n,t; string s;
    cin >> n;
    rep(i,n){

    cin >> s >> t;

    bool f=true;
    rep(j,v.size()){
    if(s==v[j].first){
    v[j].second+=t; f=false; break;
    }
    }

    if(f) v.push_back(make_pair(s,t));

    }

    sort(v.begin(),v.end());

	ostringstream os;
	REP(j,1,5){
	rep(i,v.size()){
		if(v[i].first.size()==j){
		os << v[i].first << ' ' << v[i].second;
		cout << os.str() << endl;
		os.str("");
	}
	}
	}

	return 0;
}