s = input()

stack = []
ok = True

for c in s:
    if c == '(' or c == '[':
        stack.append(c)

    elif c == ')':
        n = 0

        
        while stack:
            x = stack.pop()

            if x == '(':
                if n == 0:
                    stack.append(2)
                else:
                    stack.append(n * 2)
                break

            elif x == '[':
                ok = False
                break

            else:
                n += x

        else:
            ok = False

    elif c == ']':
        n = 0

        while stack:
            x = stack.pop()

            if x == '[':
                if n == 0:
                    stack.append(3)
                else:
                    stack.append(n * 3)
                break

            elif x == '(':
                ok = False
                break

            else:
                n += x

        else:
            ok = False

answer = 0

if ok == True:
    for x in stack:
        if x == '(' or x == '[':
            ok = False
            break
        answer += x

if ok == True:
    print(answer)
else:
    print(0)

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: