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)
	}
}

Python: n = int(input())
a = {}
for _ in range(n):
    x,y = input().split()
    y = int(y)
    if x in a:
        a[x] += y
    else:
        a[x] = y
a_s = sorted(a.items(), key=lambda p:(len(p[0]), p[0]))
for i in a_s:
    print(i[0], i[1])

Python: from collections import Counter
order = Counter()
N = int(input())
for i in range(N):
    A = input().split()
    name,quantity = A[0],int(A[1])
    order[name] += quantity
po = sorted(order.items(),key=lambda x:x[0])
pu = sorted(po,key=lambda x:len(x[0]))
for j,k in pu:
    print(j,k)

Python: n = int(input())
o = {}
for i in range(n):
    p, m = input().split()
    o[p] = o.get(p, 0) + int(m)
k = list(o.keys())
k = [(len(x), x) for x in k]
k.sort()
for i in k:
    print(i[1], o[i[1]])

Python: n = int(input())
s = []
for i in range(n):
    dat = input().split(" ")
    if dat[0] in s:
        s[s.index(dat[0])+1] += int(dat[1])
    else:
        s.append(dat[0])
        s.append(int(dat[1]))
for i in range(len(s)//2):
    s[i] = [s[i],s[i+1]]
    del s[i+1]
s.sort(key = lambda x: x[0])
s.sort(key = lambda x: len(x[0]))
for i in range(len(s)):
    print(s[i][0],s[i][1])

Python: n = int(input())
product = {}
for i in range(n) :
    p, m = input().split()
    if p not in product :
        product[p] = int(m)
    else :
        product[p] += int(m)
sorted_product = dict(sorted(product.items(), key = lambda x: x[0]))
sorted_product = sorted(sorted_product.items(), key = lambda x: len(x[0]))
for i in range(len(sorted_product)) :
    print(*sorted_product[i])

Python: d={}
for _ in[0]*int(input()):
 k,v=input().split()
 d[k]=d.get(k,0)+int(v)
for k in sorted(d,key=lambda x:(sum(26**i+ord(k)for i,k in enumerate(x[::-1])),x)):
 print(k,d[k])

Python: import copy
def main():
    n = int(input())
    a = []
    b = []
    for x in range(n):
        a.append(input().split())
        a[x][1] = int(a[x][1])
        b.append(a[x][0])

    b = list(set(b))
    c = [0] * len(b)
    for x in range(n):
        c[b.index(a[x][0])] += a[x][1]

    alp = [chr(i) for i in range(64, 65 + 26)]
    bb = copy.deepcopy(b)
    bb_num = []
    for x in range(len(bb)):
        bb[x] = list(bb[x])
        hoge = 0
        for y in range(len(bb[x])):
            hoge += alp.index(bb[x][y]) * 10 ** (len(bb[x]) - y - 1)
        bb_num.append(hoge)

    bb_num_copy = copy.deepcopy(bb_num)
    bb_num_copy.sort()

    for x in range(len(bb_num_copy)):
        hoge = b[bb_num.index(bb_num_copy[x])]
        fuga = c[bb_num.index(bb_num_copy[x])]
        print(hoge, fuga)

    #print("a           :", a)
    #print("b           :", b)
    #print("c           :", c)
    #print("bb          :", bb)
    #print("bb_num      :", bb_num)
    #print("bb_num_copy :", bb_num_copy)


if __name__ == "__main__":
    main()

Python: N = int(input())
dic = {}
for i in range(N):
    a, b = input().split()
    b = int(b)
    if a in dic:
        dic[a] += b
    else:
        dic[a] = b
L = [(x, y, len(x)) for x, y in dic.items()]
L.sort(key=lambda x: (x[2], x[0]))

for l in L:
    print(l[0], l[1])

Python: n = int(input())
o = {}
for i in range(n):
    name, value = input().split()
    if name in o:
        o[name] += int(value)
    else:
        o[name] = int(value)
o = sorted(o.items(), key=lambda x: x[0])
o.sort(key = lambda x: len(x[0]))
for i in o:
    print("{0} {1}".format(i[0], i[1]))

Python: d={}
for _ in[0]*int(input()):
 k,v=input().split()
 d[k]=d.get(k,0)+int(v)
for l,k in sorted([len(x),x]for x in d):
 print(k,d[k])

Python: n = int(input())
d = {}
for i in range(n):
    order, num = input().split()
    num = int(num)
    if order not in d:
        d[order] = num
    else:
        d[order] += num
# tupleにして、keyの長さでソートできるようにする。
d = sorted(d.items())
d = sorted(d, key=lambda x: len(x[0]))

for line in d:
    print(line[0], line[1])

Python: from collections import Counter
order = Counter()
N = int(input())
for i in range(N):
    A = input().split()
    name,quantity = A[0],int(A[1])
    order[name] += quantity
po = sorted(order.items(),key=lambda x:len(x[0]))
pu = sorted(po,key=lambda x:x[0])
for j,k in pu:
    print(j,k)

C++: #include <bits/stdc++.h>
using namespace std;

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<string,int> P;
typedef pair<int,P> PP;

//-----------------------------------------------------------------------------

bool f(const P& a,const P& b) {
	if(a.fi.size()<b.fi.size()) return a.fi.size()<b.fi.size();
	REP(i,(int)a.fi.size()) {
		if(a.fi[i]==b.fi[i]) continue;
		return a.fi[i]<b.fi[i];
	}
	return false;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n;
	cin>>n;
	map<string,int> mp;
	string s;int m;
	REP(i,n) {
		cin>>s>>m;
		mp[s]+=m;
	}
	vector<P> vec;
	for(auto x:mp) vec.pb(P(x.fi,x.se));
	sort(vec.begin(),vec.end(),f);
	for(auto x:vec) cout<<x.fi<<' '<<x.se<<endl;

	return 0;
}

C++: #include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
  int n;
  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;tt<pos-1;tt++){
      //cout << s[tt] << " " << s[pos-1] << endl;
      if(s[tt] == s[pos-1]){ 
	num[tt] += num[pos-1];
	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 <map>
#include<math.h>
#include<vector>           
#include<algorithm>
#include <string.h>


using namespace std;

int main(){
	int n,total,min_size=1;
	string str;
	map<string, int> products;
	map<string, int>::iterator it;

	cin >> n;

	for (int i = 0; i<n; i++){
		cin >> str >> total;
		if (products.find(str) != products.end()){
			products[str] =  products[str] + total;
		}
		else{
			products[str] = total;
		}
	}

	n = products.size();

	while (n != 0){
		it = products.begin();
			while (it != products.end()){
				if ((*it).first.size() == min_size){
					cout << (*it).first << " " << (*it).second << endl;
					n--;
				}
				it++;
			}
		min_size++;
	}

	return 0;
}

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

int main(){
	int n,num;
	map<string,int> MAP;
	string tmp;
	for(cin>>n;n>0;n--){
		cin>>tmp>>num;
		while(tmp.size()<5)tmp=" "+tmp;
		MAP[tmp]+=num;
	}
	map<string, int>::iterator it = MAP.begin();
	while( it != MAP.end() ){
		tmp=(*it).first ;
		for(int i=0;i<5;i++)if(tmp[i]!=' ')cout<<tmp[i];
		cout <<" " << (*it).second << endl;
		++it;
	}
	
	
	return 0;
}