def calmul(a,b,c,d):
return a*b*d
num = int(input())
matrixs = []
for i in range(num):
matrixs.append(input().split())
commands = input()
order = []
res = 0
for command in commands:
if command != ')':
if command == '(':
order.append(command)
else:
order.append(matrixs[ord(command)-ord('A')])
else:
a = order.pop()
b = order.pop()
order.pop()
order.append([b[0],a[1]])
res = res + calmul(int(b[0]),int(b[1]),int(a[0]),int(a[1]))
print(res)

京公网安备 11010502036488号