Language: C++

#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;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:10:9: error: 'string' was not declared in this scope
   10 |         string str;
      |         ^~~~~~
a.cc:4:1: note: 'std::string' is defined in header '<string>'; this is probably fixable by adding '#include <string>'
    3 | #include <string.h>
  +++ |+#include <string>
    4 | 
a.cc:11:9: error: 'map' was not declared in this scope
   11 |         map<string, int> products;
      |         ^~~
a.cc:4:1: note: 'std::map' is defined in header '<map>'; this is probably fixable by adding '#include <map>'
    3 | #include <string.h>
  +++ |+#include <map>
    4 | 
a.cc:11:21: error: expected primary-expression before 'int'
   11 |         map<string, int> products;
      |                     ^~~
a.cc:12:21: error: expected primary-expression before 'int'
   12 |         map<string, int>::iterator it;
      |                     ^~~
a.cc:14:9: error: 'cin' was not declared in this scope
   14 |         cin >> n;
      |         ^~~
a.cc:4:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    3 | #include <string.h>
  +++ |+#include <iostream>
    4 | 
a.cc:17:24: error: 'str' was not declared in this scope; did you mean 'std'?
   17 |                 cin >> str >> total;
      |                        ^~~
      |                        std
a.cc:18:21: error: 'products' was not declared in this scope
   18 |                 if (products.find(str) != products.end()){
      |                     ^~~~~~~~
a.cc:26:13: error: 'products' was not declared in this scope
   26 |         n = products.size();
      |             ^~~~~~~~
a.cc:29:17: error: 'it' was not declared in this scope; did you mean 'int'?
   29 |                 it = products.begin();
      |                 ^~
      |                 int
a.cc:32:41: error: 'cout' was not declared in this scope
   32 |                                         cout << (*it).first << " " << (*it).second << endl;
      |                                         ^~~~
a.cc:32:41: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:32:87: error: 'endl' was not declared in this scope
   32 |                                         cout << (*it).first << " " << (*it).second << endl;
      |                                                                                       ^~~~
a.cc:4:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
    3 | #include <string.h>
  +++ |+#include <ostream>
    4 |