def calculate(s: str) -> int:
# 统一括号为小括号
s = s.replace('{', '(').replace('}', ')')
s = s.replace('[', '(').replace(']', ')')
# 运算符优先级
priority = {'+':1, '-':1, '*':2, '/':2}
output = [] # 后缀表达式列表
op_stack = [] # 运算符栈
i = 0
n = len(s)
while i < n:
c = s[i]
# 1. 数字(多位数)
if c.isdigit():
num = 0
while i < n and s[i].isdigit():
num = num * 10 + int(s[i])
i += 1
output.append(num)
continue
# 2. 左括号
if c == '(':
op_stack.append(c)
i += 1
# 3. 右括号
elif c == ')':
while op_stack and op_stack[-1] != '(':
output.append(op_stack.pop())
op_stack.pop() # 弹出左括号
i += 1
# 4. 运算符(+ - * /),处理一元负号
elif c in '+-*/':
# 判断是否为一元负号:开头、或前面是运算符/左括号
if c == '-' and (i == 0 or s[i-1] in '+-*/('):
output.append(0) # 补一个0,把一元负号变成 0 - x
# 弹出栈中优先级 >= 当前运算符的运算符
while op_stack and op_stack[-1] != '(' and priority[op_stack[-1]] >= priority[c]:
output.append(op_stack.pop())
op_stack.append(c)
i += 1
else:
i += 1
# 弹出剩余运算符
while op_stack:
output.append(op_stack.pop())
# 计算后缀表达式
calc_stack = []
for token in output:
if isinstance(token, int):
calc_stack.append(token)
else:
b = calc_stack.pop()
a = calc_stack.pop()
if token == '+':
res = a + b
elif token == '-':
res = a - b
elif token == '*':
res = a * b
elif token == '/':
# 题目保证整除,且结果为整数,向0取整
res = int(a / b)
calc_stack.append(res)
return calc_stack[0]
if __name__ == "__main__":
s = input().strip()
print(calculate(s))
# 评论区看到的不讲武德的解法
# while True:
# try:
# exp = input()
# exp = exp.replace("[", "(").replace("]", ")")
# exp = exp.replace("{", "(").replace("}", ")")
# print(int(eval(exp)))
# except:
# break