import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.regex.*;
class Ideone
{
{
String s
= "wo'rd w'ord wo'r'd"; Matcher m = Pattern.compile("\\b(\\w)(\\w*)'(\\w(?:'\\w)*)").matcher(s);
while (m.find()) {
m.appendReplacement(result,
m.group(1).toUpperCase()+m.group(2) + "'" + m.group(3).toUpperCase());
}
m.appendTail(result);
System.
out.
println(result.
toString());
}
}
aW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CmltcG9ydCBqYXZhLnV0aWwucmVnZXguKjsKCmNsYXNzIElkZW9uZQp7CglwdWJsaWMgc3RhdGljIHZvaWQgbWFpbiAoU3RyaW5nW10gYXJncykgdGhyb3dzIGphdmEubGFuZy5FeGNlcHRpb24KCXsKCQlTdHJpbmcgcyA9ICJ3bydyZCB3J29yZCB3bydyJ2QiOwoJCVN0cmluZ0J1ZmZlciByZXN1bHQgPSBuZXcgU3RyaW5nQnVmZmVyKCk7CgkJTWF0Y2hlciBtID0gUGF0dGVybi5jb21waWxlKCJcXGIoXFx3KShcXHcqKScoXFx3KD86J1xcdykqKSIpLm1hdGNoZXIocyk7CgkJd2hpbGUgKG0uZmluZCgpKSB7CgkJICAgIG0uYXBwZW5kUmVwbGFjZW1lbnQocmVzdWx0LCAKCQkgICAgCW0uZ3JvdXAoMSkudG9VcHBlckNhc2UoKSttLmdyb3VwKDIpICsgIiciICsgbS5ncm91cCgzKS50b1VwcGVyQ2FzZSgpKTsKCQl9CgkJbS5hcHBlbmRUYWlsKHJlc3VsdCk7CgkJU3lzdGVtLm91dC5wcmludGxuKHJlc3VsdC50b1N0cmluZygpKTsKCgl9Cn0=