aim = 0
depth = 0
forw = 0
for s in open("input.txt", 'r').read().splitlines():
split = s.split()
match split[0]:
case "forward":
i = int(split[1])
forw += i
depth += aim * i
case "down":
aim += int(split[1])
case "up":
aim -= int(split[1])
print(depth*forw)