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<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<iostream>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;

int k[15000000];
int n, a, z, cnt;
string S;

pair<int, int>x[500000];

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> S;
		z = 0;
		for (int j = 0; j < S.size(); j++) {
			z += (int)(S[j] - 'A' + 1)*pow(27, S.size() - j - 1);
		}
		cin >> a;
		k[z] += a;
	}
	for (int i = 0; i < 15000000; i++) {
		if (k[i] > 0) {
			x[cnt].first = 200000000 - k[i];
			x[cnt].second = i;
			cnt++;
		}
	}
	sort(x, x + cnt);
	for (int i = 0; i < cnt; i++) {
		for (int j = 4; j >= 0; j--) {
			z = (x[i].second / (int)pow(27, j)) % 27;
			if (z >= 1) { cout << (char)('A' + z - 1); }
		}
		cout << ' ' << 200000000 - x[i].first << endl;
	}
	return 0;
}

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

typedef pair<int,string> P;
map<P,int>ans;


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

}

C++: #include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()
 
#define REP(i,s,e)	for(ll i=(s); i<(e); i++)
#define rep(i,n)	REP(i,0,n)
#define REPE(i,s,e)	for(ll i=s; i>e; i--)
#define repe(i,n)	REPE(i,n,-1)


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<vi> vvi;
 
const int IMAX=((1<<30)-1)*2+1;
const int INF=100000000;
const double EPS=1e-10;
//int mod=1000000007


int main(){
	string s;
	int n, t;
	map<string,int> m;
	cin>>n;
	for(int i = 0; i < n; i++){
		cin>>s>>t;
		m[s] += t;
	}
	for(map<string,int>::iterator it = m.begin(); it != m.end(); it++){
		cout<<it->fi<<" "<<it->se<<endl;
	}
}

C++: #include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define rep(a,t) for(int a=0;a<t;a++) 
#define forever while(true)
#define Sort(a) sort(a.begin(),a.end())
#define Reverse(a) reverse(a.begin(),a.end())
#define pb push_back
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	map<string, int>a;
	int n;
	cin >> n;
	vector<string>find_;
	while (n--) {
		string p;
		int q;
		cin >> p >> q;
		a[p] += q;
		find_.pb(p);
	}
	Sort(find_);
	for (int i = 0; i < a.count; i++) {
		cout << find_[i] << " " << a[find_[i]] << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
 
typedef pair<string, int> P;
 
bool compare(P s1, P s2){
  if(s1.first.size() < s2.first.size()) return true;
  else if(s1.first.size() > s2.first.size()) return false;
  else{
    if(s1.first < s2.first) return true;
    else return false;
  }
}

int main(){
  map<string, int> data;
  vector<P> ans;
  
  int n;
  cin >> n;
  string s;
  int t;
  for(int i = 0 ; i < n ; i++){
    cin >> s >> t;
    data[s] += t;
  }
   
  for(map<string, int>::iterator it = data.begin() ; it != data.end() ; it++){
    ans.push_back(*it);
  }
   
  sort(ans.begin(), ans.end(), compare);
   
  for(int i = 0 ; i < ans.size() ; i++){
    cout << ans[i].first << ' ' << ans[i].second << endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<string,int> P;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
bool comp(P a,P b)
{
	if(a.fi.size()!=b.fi.size())return a.fi.size()<b.fi.size();
	else return a.fi<b.fi;
}
int main()
{
	int n;
	map<string,int> m;
	cin >> n;
	string name;
	int order;
	for(int i=0;i<n;i++)
	{
		cin >> name >> order;
		if(m.find(name)==m.end())m[name]=order;
		else m[name]+=order;
	}
	map<string,int>::iterator it;
	vector<P> vec;
	for(it=m.begin();it!=m.end();it++)
	{
		P in;
		in.fi=it->fi;
		in.sec=it->sec;
		vec.pb(in);
	}
	sort(vec.begin(),vec.end(),comp);
	for(int i=0;i<vec.size();i++)
	{
		cout << vec[i].fi << ' ' << vec[i].sec << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef pair<int,string> P;
typedef long long int lld;
#define INF (1<<20)

int main(){
  int n;
  cin >> n;
  vector<P> product;
  map<string,int> count;
  for(int i=0;i<n;i++){
    string name; int num;
    cin >> name >> num;
    if(count[name] == 0) product.push_back(P(name.size(),name));
    count[name] += num;
  }
  sort(product.begin(),product.end());
  for(int i=0;i<product.size();i++){
    cout << product[i].second << " " << count[product[i].second] << endl;
  }
}