def p(s):
n9 = s.count("(")
n0 = s.count(")")
if n9 == n0:
nn = s.rfind("(")
left = s[0:nn+1]
right = s[nn+1:]
if left.count("(") == right.count(")"):
print "yes"
else:
print "no"
else:
print "no"
if __name__ == "__main__":
str = "(((())))"
p(str)
str2 = "zx(4er(1(er(Yy)ol)ol)ik"
p(str2)
str3 = "zx(4er(1(er(Yy)o)l)ol)ik)"
p(str3)
|