BEGIN { h = 0; d = 0; a = 0; } $1 == "forward" { h+=+$2; d+=+$2*a; } $1 == "up" { a-=+$2 } $1 == "down" { a+=+$2 } END { print h*d }