#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <cassert>
using namespace std;

typedef pair<char, uint8_t> RunLength;

vector<RunLength> runLengthEncode(const string& s) {
	if(s == "") return {};
	vector<RunLength> res;

	size_t i = 0, nextPos;
	while(s.npos != (nextPos = s.find_first_not_of(s[i], i + 1)) ) {
		auto diff = nextPos - i;
		assert(diff <= 255);
		res.push_back( {s[i], diff} );
		i = nextPos;
	}
	res.push_back( {s[i], s.size() - i} ); 
	return res;
}

string runLengthDecode(const vector<RunLength>& encoding) {
	string res;
	auto addFun = [&res](const RunLength& rl) { 
		res += string(rl.second, rl.first);
	};
	for_each(encoding.begin(), encoding.end(), addFun);
	return res;
}

int main() {
	cout << runLengthDecode(runLengthEncode("All your base are belong to us!")) << "\n";
}