#!/usr/bin/perl -w

use v5.16;

my ($x, $z, $aim) = (0, 0, 0);
while (<>) {
	my ($dir, $num) = split /\s+/;
	if ($dir eq 'forward') {
		$x += $num;
		$z += $aim*$num;
	}
	$aim+=$num if $dir eq 'down';
	$aim-=$num if $dir eq 'up';
}
say $x*$z;

