inp = "input.txt"

# Part 1

d, h = 0, 0                        
with open(inp) as f:
    for c in f.readlines():
        cmd, val = c.split()
        if cmd == "forward": h   += int(val)
        elif cmd == "down":  d += int(val)
        elif cmd == "up":    d -= int(val)
print(d * h)

# Part 2

d, h, a = 0, 0, 0                 
with open(inp) as f:
    for c in f.readlines():
        cmd, val = c.split()
        if cmd == "forward":
                             d += a * int(val)
                             h   += int(val)
        elif cmd == "down":  a   += int(val)
        elif cmd == "up":    a   -= int(val)
print(d * h)
