#include <iostream>
#include <map>
#include <string>
using namespace std;
int main() {
map<string, string> interpolate = { { "F", "a && b && c" }, { "H", "p ^ 2 + w" }, { "K", "H > 10 || e < 5" }, { "J", "F && !K" } };
for(map<string, string>::iterator i = interpolate.begin(); i != interpolate.end(); ++i) {
for(map<string, string>::iterator it = interpolate.begin(); it != interpolate.end(); ++it) {
for(string::size_type pos = it->second.find(i->first); pos != string::npos; pos = it->second.find(i->first, pos)) {
it->second.replace(pos, i->first.size(), '(' + i->second + ')');
}
}
}
for(map<string, string>::iterator i = interpolate.begin(); i != interpolate.end(); ++i) {
cout << i->first << " : " << i->second << endl;
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bWFwPgojaW5jbHVkZSA8c3RyaW5nPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKCkgewogICAgbWFwPHN0cmluZywgc3RyaW5nPiBpbnRlcnBvbGF0ZSA9IHsgeyAiRiIsICJhICYmIGIgJiYgYyIgfSwgeyAiSCIsICJwIF4gMiArIHciIH0sIHsgIksiLCAiSCA+IDEwIHx8IGUgPCA1IiB9LCB7ICJKIiwgIkYgJiYgIUsiIH0gfTsKCiAgICBmb3IobWFwPHN0cmluZywgc3RyaW5nPjo6aXRlcmF0b3IgaSA9IGludGVycG9sYXRlLmJlZ2luKCk7IGkgIT0gaW50ZXJwb2xhdGUuZW5kKCk7ICsraSkgewogICAgICAgIGZvcihtYXA8c3RyaW5nLCBzdHJpbmc+OjppdGVyYXRvciBpdCA9IGludGVycG9sYXRlLmJlZ2luKCk7IGl0ICE9IGludGVycG9sYXRlLmVuZCgpOyArK2l0KSB7CiAgICAgICAgICAgIGZvcihzdHJpbmc6OnNpemVfdHlwZSBwb3MgPSBpdC0+c2Vjb25kLmZpbmQoaS0+Zmlyc3QpOyBwb3MgIT0gc3RyaW5nOjpucG9zOyBwb3MgPSBpdC0+c2Vjb25kLmZpbmQoaS0+Zmlyc3QsIHBvcykpIHsKICAgICAg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