with open("input.txt", 'r') as f:
    data = [l.split(' ') for l in f.read().strip().split('\n')]

    x = 0
    dep = 0
    aim = 0

    for c in data:
        if c[0] == "forward":
            x += int(c[1])
            dep += (aim*int(c[1]))
        elif c[0] == "up":
            aim -= int(c[1])
        elif c[0] == "down":
            aim += int(c[1])

    print(x*dep)