#!/usr/bin/env python3 import sys depth = 0 horiz = 0 aim = 0 for l in sys.stdin: comm, val = l.split() if comm == "down": aim += int(val) elif comm == "up": aim -= int(val) elif comm == "forward": horiz += int(val) depth += aim * int(val) else: raise Exception(f"bad comm: {comm}") print(horiz * depth)