import java.util.regex.*;
class Ideone
{
public static void main
(String[] args
) { System.
out.
println(extractInt
("")); System.
out.
println(extractInt
("heyhow$98765$you")); System.
out.
println(extractInt
("heyhow$$areyou")); System.
out.
println(extractInt
("heyhow$xyz$areyou")); System.
out.
println(extractInt
("heyhow$42x$areyou")); }
private static int extractInt
(String input
) { Matcher m = Pattern.compile("\\$([0-9]+)\\$").matcher(input);
if (! m.find())
return 0;
return Integer.
parseInt(m.
group(1)); }
}
aW1wb3J0IGphdmEudXRpbC5yZWdleC4qOwoKY2xhc3MgSWRlb25lCnsKCXB1YmxpYyBzdGF0aWMgdm9pZCBtYWluIChTdHJpbmdbXSBhcmdzKSB7CgkJU3lzdGVtLm91dC5wcmludGxuKGV4dHJhY3RJbnQoIiIpKTsKCQlTeXN0ZW0ub3V0LnByaW50bG4oZXh0cmFjdEludCgiaGV5aG93JDk4NzY1JHlvdSIpKTsKCQlTeXN0ZW0ub3V0LnByaW50bG4oZXh0cmFjdEludCgiaGV5aG93JCRhcmV5b3UiKSk7CgkJU3lzdGVtLm91dC5wcmludGxuKGV4dHJhY3RJbnQoImhleWhvdyR4eXokYXJleW91IikpOwoJCVN5c3RlbS5vdXQucHJpbnRsbihleHRyYWN0SW50KCJoZXlob3ckNDJ4JGFyZXlvdSIpKTsKCX0KCXByaXZhdGUgc3RhdGljIGludCBleHRyYWN0SW50KFN0cmluZyBpbnB1dCkgewoJCU1hdGNoZXIgbSA9IFBhdHRlcm4uY29tcGlsZSgiXFwkKFswLTldKylcXCQiKS5tYXRjaGVyKGlucHV0KTsKCQlpZiAoISBtLmZpbmQoKSkKCQkJcmV0dXJuIDA7CgkJcmV0dXJuIEludGVnZXIucGFyc2VJbnQobS5ncm91cCgxKSk7Cgl9Cn0=