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 <cmath>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <utility>
#include <cstring>
using namespace std;
typedef long long ll;

struct Order {
	string name;
	int c;
};

bool operator<(const Order& l, const Order& r) {
	if (l.name.size() != r.name.size()) return l.name.size() < r.name.size();
	return l.name < r.name;
}

int main() {
	int N;
	scanf("%d", &N);
	char name[9];
	int c;
	vector<Order> ords;
	for (int i = 0; i < N; ++i) {
		scanf("%s %d", name, &c);
		ords.push_back({string(name), c});
	}
	sort(ords.begin(), ords.end());
	int sum = 0;
	for (int i = 0; i < N; ++i) {
		if (i > 0 && ords[i].name != ords[i-1].name) {
			printf("%s %d\n", ords[i-1].name.c_str(), sum);
			sum = 0;
		}
		sum += ords[i].c;
	}
	printf("%s %d\n", ords.back().name.c_str(), sum);
}

C++: #include <iostream>
#include <map>
#include <cstring>
#include <vector>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<string,int> P;

map<string, int> m;
map<string, int>::iterator it;
vector<P> ans;
int n;

int main(){
	cin >> n;
	rep(i,n){
		string str;
		int cnt;
		cin >> str >> cnt;
		m[str] += cnt;
	}
	for(int i = 1; i <= 5; i++){
		for(it = m.begin(); it != m.end(); it++){
			if((*it).first.size() == i) ans.push_back(P((*it).first,(*it).second));
		}
	}
	rep(i,ans.size()){
		cout << ans[i].first << " " << ans[i].second << endl;
	}
}

C++: #include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;




const int INF = 1000000;
const int mod = 1e9 + 7;




struct MyString
{
	string str;

	MyString(){}
	MyString(string t) :str(t){}

	void in() { cin >> str; }

	bool operator < (const MyString& S) {
		if (this->str.size() != S.str.size()) return this->str.size() < S.str.size();
		return this->str < S.str;
	}

	bool operator > (const MyString& S) {
		if (this->str.size() != S.str.size()) return this->str.size() > S.str.size();
		return this->str > S.str;
	}
};


bool cmp(MyString s1, MyString s2) {
	return s1 < s2;
}


int main() {
	MyString s;
	int n, t;
	map<MyString, int> m;

	cin >> n;
	for (int i = 0; i < n; i++) {
		s.in();
		cin >> t;
		m[s] += t;
	}

	for (map<MyString, int>::iterator it = m.begin(); it != m.end(); it++) {
		cout << it->first.str << " " << it->second << endl;
	}
}

C++: #include <bits/stdc++.h>

using namespace std;

struct CmpSort {
	bool operator ()(const string &s1, const string &s2) {
		if (s1.size() == s2.size()) {
			return s1 < s2;
		}
		return s1.size() < s2.size();
	}
};

int main() {
	int n, num;
	string name;
	map<string, int, CmpSort> productionInfo;
	map<string, int>::iterator pos;

	productionInfo.clear();
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> name >> num;
		productionInfo[name] += num;
	}
	for (pos = productionInfo.begin(); pos != productionInfo.end(); ++pos) {
		cout << pos->first << " " << pos->second << endl;
	}

	return 0;
}

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

using namespace std;

map<string,int> mp[5];
int main(){
    int n,m,sz;
    string s;
    cin>>n;
    for(int i=0;i<n;++i){
        cin>>s>>m;
        sz=s.size();
        if(mp[sz-1].find(s)==mp[sz-1].end()) mp[sz-1][s]=m;
        else mp[sz-1][s] +=m;
    }
    for(int i=0;i<5;++i){
        for(map<string,int>::iterator it=mp[i].begin();it!=mp[i].end();++it) cout<<it->first<<" "<<it->second<<endl;
    }
    return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <string>
#include <map>

using namespace std;

char s[10];

int main()
{
	map<pair<int,string>,int> m;
	int n;
	scanf("%d",&n);
	for(int i = 0; i < n; i++)
	{
		int w;
		scanf("%s %d",s,&w);
		int l = strlen(s);
		if(m.end() != m.find(make_pair(l,s)))
		{
			m[make_pair(l,s)] += w;
		}
		else
		{
			m[make_pair(l,s)] = w;
		}
	}
	map<pair<int,string>,int>::iterator it = m.begin();
	while(it != m.end())
	{
		printf("%s %d\n",(*it).first.second.c_str(),(*it).second);
		it++;
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<stack>
#include<queue>

using namespace std;
typedef pair<int,string> P;
string s;
int n,m;
vector<P> p;
map<string,int> q;

int main(){
	scanf("%d",&n);
	p.resize(n);
	for(int i=0;i<n;i++){
		cin>>p[i].second>>m;
		p[i].first=p[i].second.size();
		q[p[i].second]+=m;
	}
	sort(p.begin(),p.end());
	for(int i=0;i<n;i++){
		if(i&&p[i]==p[i-1]) continue;
		printf("%s %d\n",p[i].second.c_str(),q[p[i].second]);
	}
}

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

using namespace std;

struct P {
	string a;
	int b;
};

int main() {
	int n;
	cin >> n;
	vector<P> p;
	string name;
	int number;
	cin >> name >> number; 
	P ab;
	ab.a = name;
	ab.b = number;
	p.push_back(ab);
	for (int i = 1; i < n; i++) {
		cin >> name >> number;
		bool hantei = true;
		for (int j = 0; j < p.size(); j++) {
			if (p[j].a == name) {
				p[j].b += number;
				hantei = false;
			}
		}
		if (hantei) {
			ab.a = name;
			ab.b = number;
			p.push_back(ab);
		}
	}
	for (int i = p.size()-1; i > 0; i--) {
		for (int j = 0; j < i; j++) {
			if ((p[j].a).size() > (p[j+1].a).size()) {
				swap(p[j], p[j+1]);
			} else if ((p[j].a).size() == (p[j+1].a).size()) {
				for (int k = 0; k < (p[j].a).size(); k++) {
					if ((p[j].a)[k] > (p[j+1].a)[k]) {
						swap(p[j], p[j+1]);
						break;
					}
				}
			}
		}
	}
	for (int i = 0; i < p.size(); i++) {
		cout << p[i].a << " " << p[i].b << endl;
	}
	return 0;
}