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