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<iostream>
#include<map>
#include<algorithm>
#include<vector>

using namespace std;

bool cmp(const string& a,const string& b)
{
  
  if(a.size() != b.size())
    return a.size() < b.size(); 
    
  for(int i=0;i<a.size();i++)
    {
      if(a[i] == b[i])
	continue;
      return a[i] < b[i];
    }
  return false;
}

int main()
{
  map<string,int> ans;
  vector<string> vec;
  int n;
  cin >> n;
  for(int i=0;i<n;i++)
    {
      string name;
      int val;
      cin >> name >> val;
      ans[name] += val;
      vec.push_back(name);
    }
  sort(vec.begin(),vec.end());
  vec.erase(unique(vec.begin(),vec.end()),vec.end());
  sort(vec.begin(),vec.end(),cmp);

  for(int i=0;i<vec.size();i++)
    cout << vec[i] << ans[vec[i]] << endl;

  return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	
	scanf("%d", &n);
	
	vector<pair<int, pair<string, int> > > v;
	for (int i = 0; i < n; i++){
		char pName[8];
		int num;
		scanf("%s %d", pName, &num);
		v.push_back(make_pair(strlen(pName), make_pair((string)pName, num)));
	}
	
	sort(v.begin(), v.end());
	
	string lead = "$";
	int cnt = 0;
	for (int i = 0; i < n; i++){
		if (lead != v[i].second.first){
			if (lead != "$") printf("%s %d\n", lead.c_str(), cnt);
			lead = v[i].second.first;
			cnt = v[i].second.second;
		}
		else cnt += v[i].second.second;
	}
	return (!printf("%s %d\n", lead.c_str(), cnt));
}

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

struct cmp{
	bool operator() (const string &s, const string &t){
		return s.size() != t.size() ? s.size() < t.size() : s < t;
	}
};

int main(){
	map<string,int,cmp> mp;
	int n, x;
	string s;
	
	cin >> n;
	for(int i = 0; i < n; ++i){
		cin >> s >> x;
		mp[s] += x;
	}
	
	for(map<string,int,cmp>::iterator it = mp.begin(); it != mp.end(); ++it){
		cout << it->first << ' ' << it->second << '\n';
	}
}

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

int main(){
  int i;
  int n;
  map<string, int> p;
  cin >> n;
  int num;
  string name;
  map<string, int>::iterator it;
  for(i = 0; i < n; i++){
    cin >> name >> num;
    if(p.find(name) != p.end()) p[name] += num;
    else p[name] = num;
  }

  for(i=1; i<=5; i++){
    it = p.begin;
    while( it != p.end()){
      if(p->first.size() = i){
	count << p->first << " " << p->second << endl;
      }
      it++;
    }
  }
  return 0;
}

C++: #include<iostream>
#include<string>
#include<map>
using namespace std;
int main(){
  int n,ss,max=0;
  cin >> n;
  string s;
  map<string,int> m;
  map<string,int>::iterator p;
  for(int i=0;i<n;i++){
    cin >> s >> ss;
    m[s] += ss;
    if(s.size()>max) max = s.size();
  }
  for(int i=1;i<=max;i++){
    for(p=m.begin();p!=m.end();p++){
      if(p->first.size()==i) cout << p->first << ' ' << p->second << endl; 
    }
  }
  return 0;
}

C++: #include <iostream>
#include <map>
#include <string>
#include <algorithm>
using namespace std;
typedef pair<int,string> P;

int main(){
    int n,num;
    string str;
    map<P,int> m;
    
    cin >> n;
    for(int i = 0 ; i < n ; i++){
        cin >> str >> num;
        m[P(str.size(),str)] += num;
    }
    
    map<P,int>::iterator it;
    for(it = m.begin() ; it != m.end() ; it++){
        cout << it->first.second << ' ' << it->second << endl;
    }

    return 0;
}

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

using namespace std;

int main()
{
    int n;
    map<string, int> m;

    cin >> n;
    for (int i = 0; i < n; i++) {
        string str;
        int num;

        cin >> str >> num;
        if (m.count(str) == 0) 
            m[str] = num;
        else
            m[str] += num;
    }
    
    for (int i = 0; i < n; i++) 
        cout << m[i].first << " " << m[i].second << endl;

    return 0;
}