/* package whatever; // don't place package name! */
import java.util.*;
import java.util.regex.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
{
Pattern p = Pattern.compile("^(dog)(?:[^c]|c[^a]|ca[^t])+(cat)?");
for (String s
: new String[] {"dog, cat",
"dog, dog, cat",
"dog, dog, dog",
"dog, cut, cab, cat, meow"}) { Matcher m = p.matcher(s);
if (m.find()) {
System.
out.
println(m.
group(1)+" "+m.
group(2)); }
}
}
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS51dGlsLnJlZ2V4Lio7CmltcG9ydCBqYXZhLmxhbmcuKjsKaW1wb3J0IGphdmEuaW8uKjsKCi8qIE5hbWUgb2YgdGhlIGNsYXNzIGhhcyB0byBiZSAiTWFpbiIgb25seSBpZiB0aGUgY2xhc3MgaXMgcHVibGljLiAqLwpjbGFzcyBJZGVvbmUKewoJcHVibGljIHN0YXRpYyB2b2lkIG1haW4gKFN0cmluZ1tdIGFyZ3MpIHRocm93cyBqYXZhLmxhbmcuRXhjZXB0aW9uCgl7CgkJUGF0dGVybiBwID0gUGF0dGVybi5jb21waWxlKCJeKGRvZykoPzpbXmNdfGNbXmFdfGNhW150XSkrKGNhdCk/Iik7CgkJZm9yIChTdHJpbmcgcyA6IG5ldyBTdHJpbmdbXSB7ImRvZywgY2F0IiwgImRvZywgZG9nLCBjYXQiLCAiZG9nLCBkb2csIGRvZyIsICJkb2csIGN1dCwgY2FiLCBjYXQsIG1lb3cifSkgewoJCQlNYXRjaGVyIG0gPSBwLm1hdGNoZXIocyk7CgkJCWlmIChtLmZpbmQoKSkgewoJCQkJU3lzdGVtLm91dC5wcmludGxuKG0uZ3JvdXAoMSkrIiAiK20uZ3JvdXAoMikpOwoJCQl9CgkJfQoJfQp9