/* 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).+?(cat)?$");
for (String s
: new String[] {"dog, cat",
"dog, dog, cat",
"dog, dog, dog"}) { Matcher m = p.matcher(s);
if (m.find()) {
System.
out.
println(m.
group(1)+" "+m.
group(2)); }
}
}
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS51dGlsLnJlZ2V4Lio7CmltcG9ydCBqYXZhLmxhbmcuKjsKaW1wb3J0IGphdmEuaW8uKjsKCi8qIE5hbWUgb2YgdGhlIGNsYXNzIGhhcyB0byBiZSAiTWFpbiIgb25seSBpZiB0aGUgY2xhc3MgaXMgcHVibGljLiAqLwpjbGFzcyBJZGVvbmUKewoJcHVibGljIHN0YXRpYyB2b2lkIG1haW4gKFN0cmluZ1tdIGFyZ3MpIHRocm93cyBqYXZhLmxhbmcuRXhjZXB0aW9uCgl7CgkJUGF0dGVybiBwID0gUGF0dGVybi5jb21waWxlKCJeKGRvZykuKz8oY2F0KT8kIik7CgkJZm9yIChTdHJpbmcgcyA6IG5ldyBTdHJpbmdbXSB7ImRvZywgY2F0IiwgImRvZywgZG9nLCBjYXQiLCAiZG9nLCBkb2csIGRvZyJ9KSB7CgkJCU1hdGNoZXIgbSA9IHAubWF0Y2hlcihzKTsKCQkJaWYgKG0uZmluZCgpKSB7CgkJCQlTeXN0ZW0ub3V0LnByaW50bG4obS5ncm91cCgxKSsiICIrbS5ncm91cCgyKSk7CgkJCX0KCQl9Cgl9Cn0=