import java.util.*;
import java.util.regex.*;
class Ideone
{
static Pattern pattern = Pattern.compile("[a-zA-Z0-9]{0,100}<(/?)([ab])>");
{
LinkedList<String> elements = new LinkedList<String>();
elements.add("");
Matcher matcher = pattern.matcher(str);
while (matcher.find())
{
if ("".equals(matcher.group(1)))
{
switch (elements.getLast())
{
case "a": if ("b".equals(matcher.group(2))) break;
case "b": System.
out.
println(0); return; }
elements.add(matcher.group(2));
}
else if (!elements.removeLast().equals(matcher.group(2)))
{
return;
}
}
System.
out.
println(elements.
size() == 1 ? 1 : 0); }
public static void main
(String[] args
) {
test("<a>ruby<b>php</b>python</a><a><b></b></a><a></a>");
test("<a>ruby<b>php</b>python</a><a></b></a><a></a>");
test("<a>ruby<b>php</b>python</a><a><b></a><a></a>");
test("<a>ruby<b>php</b>python</a><a><b></b></a><a>");
test("vvvc<a>ruby<b>php</b>python</a><a><b></b></a><a></a>");
}
}
aW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS51dGlsLnJlZ2V4Lio7CgpjbGFzcyBJZGVvbmUKewogICAgc3RhdGljIFBhdHRlcm4gcGF0dGVybiA9IFBhdHRlcm4uY29tcGlsZSgiW2EtekEtWjAtOV17MCwxMDB9PCgvPykoW2FiXSk+Iik7CgogICAgc3RhdGljIHZvaWQgdGVzdChTdHJpbmcgc3RyKQogICAgewogICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbihzdHIpOwogICAgICAgIExpbmtlZExpc3Q8U3RyaW5nPiBlbGVtZW50cyA9IG5ldyBMaW5rZWRMaXN0PFN0cmluZz4oKTsKICAgICAgICBlbGVtZW50cy5hZGQoIiIpOwoKICAgICAgICBNYXRjaGVyIG1hdGNoZXIgPSBwYXR0ZXJuLm1hdGNoZXIoc3RyKTsKICAgICAgICB3aGlsZSAobWF0Y2hlci5maW5kKCkpCiAgICAgICAgewogICAgICAgICAgICBpZiAoIiIuZXF1YWxzKG1hdGNoZXIuZ3JvdXAoMSkpKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBzd2l0Y2ggKGVsZW1lbnRzLmdldExhc3QoKSkKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGNhc2UgImEiOiBpZiAoImIiLmVxdWFscyhtYXRjaGVyLmdyb3VwKDIpKSkgYnJlYWs7CiAgICAgICAgICAgICAgICBjYXNlICJiIjogU3lzdGVtLm91dC5wcmludGxuKDApOyByZXR1cm47CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBlbGVtZW50cy5hZGQobWF0Y2hlci5ncm91cCgyKSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZSBpZiAoIWVsZW1lbnRzLnJlbW92ZUxhc3QoKS5lcXVhbHMobWF0Y2hlci5ncm91cCgyKSkpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigwKTsKICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oZWxlbWVudHMuc2l6ZSgpID09IDEgPyAxIDogMCk7CiAgICB9CgogICAgcHVibGljIHN0YXRpYyB2b2lkIG1haW4oU3RyaW5nW10gYXJncykKICAgIHsKICAgICAgICB0ZXN0KCI8YT5ydWJ5PGI+cGhwPC9iPnB5dGhvbjwvYT48YT48Yj48L2I+PC9hPjxhPjwvYT4iKTsKCiAgICAgICAgdGVzdCgiPGE+cnVieTxiPnBocDwvYj5weXRob248L2E+PGE+PC9iPjwvYT48YT48L2E+Iik7CiAgICAgICAgdGVzdCgiPGE+cnVieTxiPnBocDwvYj5weXRob248L2E+PGE+PGI+PC9hPjxhPjwvYT4iKTsKICAgICAgICB0ZXN0KCI8YT5ydWJ5PGI+cGhwPC9iPnB5dGhvbjwvYT48YT48Yj48L2I+PC9hPjxhPiIpOwogICAgICAgIHRlc3QoInZ2dmM8YT5ydWJ5PGI+cGhwPC9iPnB5dGhvbjwvYT48YT48Yj48L2I+PC9hPjxhPjwvYT4iKTsKICAgIH0KfQ==