BRACES = { '(': ')', '[': ']', '{': '}' }
def group_check(s):
stack = []
for b in s:
c = BRACES.get(b)
if c:
stack.append(c)
elif not stack or stack.pop() != b:
return False
return not stack
print(group_check("()"))
print(group_check("({"))
print(group_check("({}{}[])"))
QlJBQ0VTID0geyAnKCc6ICcpJywgJ1snOiAnXScsICd7JzogJ30nIH0KCmRlZiBncm91cF9jaGVjayhzKToKICAgIHN0YWNrID0gW10KICAgIGZvciBiIGluIHM6CiAgICAgICAgYyA9IEJSQUNFUy5nZXQoYikKICAgICAgICBpZiBjOgogICAgICAgICAgICBzdGFjay5hcHBlbmQoYykKICAgICAgICBlbGlmIG5vdCBzdGFjayBvciBzdGFjay5wb3AoKSAhPSBiOgogICAgICAgICAgICByZXR1cm4gRmFsc2UKICAgIHJldHVybiBub3Qgc3RhY2sKICAgIAogICAgCiAgICAKcHJpbnQoZ3JvdXBfY2hlY2soIigpIikpCnByaW50KGdyb3VwX2NoZWNrKCIoeyIpKQpwcmludChncm91cF9jaGVjaygiKHt9e31bXSkiKSk=