스택을 이용한 풀이
data = input() def solution(data): stack = [] answer = 0 temp = 1 for index, char in enumerate(data): if char == "(": stack.append(char) temp *= 2 elif char == "[": stack.append(char) temp *= 3 elif char == ")": if not stack or stack[-1] == "[": return 0 if data[index-1] == "(": answer += temp temp //= 2 stack.pop() elif char == "]": if not stack or stack[-1] == "(": return 0 if data[index - 1] == "[": answer += temp temp //= 3 stack.pop() return answer if not stack else 0 print(solution(data))