import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.regex.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
{
SortedMap
<String, String
> map
= new TreeMap
<String, String
>(); map.put("test", "REPLACE");
String update
= "$(test) (test) (test2)"; Matcher m = Pattern.compile("\\$\\(([^)]*)\\)").matcher(update);
while (m.find()) {
String t
= map.
getOrDefault(m.
group(1), m.
group(1)); m.appendReplacement(sb, t);
}
m.appendTail(sb); // append the rest of the contents
}
}
aW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CmltcG9ydCBqYXZhLnV0aWwucmVnZXguKjsKLyogTmFtZSBvZiB0aGUgY2xhc3MgaGFzIHRvIGJlICJNYWluIiBvbmx5IGlmIHRoZSBjbGFzcyBpcyBwdWJsaWMuICovCmNsYXNzIElkZW9uZQp7CglwdWJsaWMgc3RhdGljIHZvaWQgbWFpbiAoU3RyaW5nW10gYXJncykgdGhyb3dzIGphdmEubGFuZy5FeGNlcHRpb24KCXsKCQlTb3J0ZWRNYXA8U3RyaW5nLCBTdHJpbmc+IG1hcCA9IG5ldyBUcmVlTWFwPFN0cmluZywgU3RyaW5nPigpOwoJCW1hcC5wdXQoInRlc3QiLCAiUkVQTEFDRSIpOwoJCVN0cmluZyB1cGRhdGUgPSAiJCh0ZXN0KSAodGVzdCkgICAgICAodGVzdDIpIjsKICAgICAgICBNYXRjaGVyIG0gPSBQYXR0ZXJuLmNvbXBpbGUoIlxcJFxcKChbXildKilcXCkiKS5tYXRjaGVyKHVwZGF0ZSk7CgogICAgICAgIFN0cmluZ0J1ZmZlciBzYiA9IG5ldyBTdHJpbmdCdWZmZXIoKTsKICAgICAgICB3aGlsZSAobS5maW5kKCkpIHsKICAgICAgICAJU3RyaW5nIHQgPSBtYXAuZ2V0T3JEZWZhdWx0KG0uZ3JvdXAoMSksIG0uZ3JvdXAoMSkpOwogICAgICAgICAgICBtLmFwcGVuZFJlcGxhY2VtZW50KHNiLCB0KTsKICAgICAgICB9CiAgICAgICAgbS5hcHBlbmRUYWlsKHNiKTsgLy8gYXBwZW5kIHRoZSByZXN0IG9mIHRoZSBjb250ZW50cwogICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbihzYik7Cgl9CgkKfQ==