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<cstdio>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

int n,x;
string str;

class data{
	public:
	string str;
	int x;
};

bool comp(const data &left,const data &right){
	return left.str<right.str;
}
bool comp2(const data &left,const data &right){
	if(left.str.size()==right.str.size())return left.str<right.str;
	return left.str.size()<right.str.size();
	//return left.x>right.x;
}

vector<data> que;
vector<data> que2;

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		cin >> str >> x;
		data q;
		q.str=str;
		q.x=x;
		que.push_back(q);
	}
	sort(que.begin(),que.end(),comp);
	string str2=que[0].str;
	int x=que[0].x;
	for(int i=1;i<que.size();i++){
		if(que[i].str==str2)x+=que[i].x;
		else{
			data q;
			q.str=str2;
			q.x=x;
			que2.push_back(q);
			str2=que[i].str;
			x=que[i].x;
		}
	}
	data q;
	q.str=str2;
	q.x=x;
	que2.push_back(q);
	sort(que2.begin(),que2.end(),comp2);
	for(int i=0;i<que2.size();i++)cout << que2[i].str << " " << que2[i].x << endl;
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  map<string,int> a;
  int k=1;
  vector<int> co(n,0);
  vector<string> rema;
  for(int i=0;i<n;i++){
    string x;
    int y;
    cin >> x >> y;
    if(a[x]==0){
      a[x]=k;
      k++;
      rema.push_back(x);
    }
    co[a[x]-1]+=y;
  }
  sort(rema.begin(),rema.end());
  for(int j=1;j<=5;j++){
    for(int i=0;i<rema.size();i++){
      if(rema[i].size()==j)cout << rema[i] << " " <<co[a[rema[i]]-1] << endl;
    }
  }
  return 0;
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vi vector<int>
#define VS vector<string>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back

using namespace std;

bool pairCompare(const std::pair<string, int>& firstElem, const std::pair<string, int>& secondElem) {
    if(firstElem.second != secondElem.second){
        return firstElem.second > secondElem.second;
    }else{
        if(firstElem.first.size() != secondElem.first.size()){
            return firstElem.first.size() < secondElem.first.size();
        }
        else
            return firstElem.first < secondElem.first;
    }
}

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

    cin >> n;
    for(int i=0; i < n; i++){
        string s; int p;
        cin >> s >> p;
        st.insert(s);
        m[s] += p;
    }

    set<string>::iterator it = st.begin();
    vector<pair<string, int> > ans;
    while(it != st.end()){
        ans.push_back(mp(*it, m[*it]));
        ++it;
    }
    sort(all(ans), pairCompare);

    for(int i=0; i < ans.size(); i++){
        cout << ans[i].first << " " << ans[i].second << endl;
    }
}

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

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

int main() {
	memset(k, 0, sizeof(k));
	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 < 16500000; i++) {
		if (k[i] >= 1) {
			for (int j = 4; j >= 0; j--) {
				z = (int)(i / (int)pow(27, j)) % 27;
			}
			if (z >= 1) {
				cout << (char)(z + 'A' - 1) << endl;
			}
			cout << ' ';
			cout << k[i] << endl;
		}
	}
	return 0;
}

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

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

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

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

struct name{
  string s;
  name(string x):s(x){}

  bool operator<(const name a)const{
    if(s.size()==a.s.size())return s<a.s;
    return s.size()<a.s.size();
  }
};

int main(){
  int n,num;
  string s;

  std::ios::sync_with_stdio(false);

  cin >> n;
  map<name,int> m;
  for(int i=0;i<n;i++){
    cin >> s >> num;
    m[name(s)] += num;
  }

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

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

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

int main() {
  
  map<string, int, grtr> mp;
  int n; cin>>n;
  string s; int a;
  
  for(int i=0;i<n;i++) {
    cin>>s>>a;
    mp[s]=a;
  }

  for(map<string,int,grtr>::iterator it=mp.begin();it!=mp.end();it++)
    cout << it->first << " " << it->second << endl;
  
  return 0;
}

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

using namespace std;

typedef map< string, set<int>> Dic;
Dic dic;

int main(){
  //map<string, int> dic;
  int num;
  string s;
  while(cin >> s >> num)
  {
    dic[s].insert(num);
  }
  
  for(Dic::iterator it = dic.begin() ; it != dic.end() ; it++)
  {
  	cout << it->first;
  	int total=0;
  	for(set<int>::iterator set_it = it->second.begin() ; set_it != it->second.end() ; set_it++)
  	{
  		total += *set_it;
  	}
  	cout <<" " << total << endl;
  }

  return 0;
}

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

using namespace std;
  
typedef pair<string, int> P;
  
bool compare(const string& s1, const string& s2){
  if(s1.size() < s2.size()) return true;
  else if(s1.size() > s2.size()) return false;
  else{
    if(s1 < s2) return true;
    else return false;
  }
}
 
int main(){
  map<string, int, bool(*)(const string&, const string&)> data(compare);
  vector<string> 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++){
    cout << it->first << ' ' << it->second << endl;
  }
  return 0;
}