#!/usr/bin/perl -w

use strict;

my ($wx, $wy, $x, $y) = (10, 1);

while (<>) {
	my ($cmd, $num) = /\A(.)(\d+)/;
	print "cmd=$cmd, num=$num: ";
	if ($cmd eq 'F') {
		$x += $num*$wx;
		$y += $num*$wy;
	} elsif ($cmd eq 'R') {
		while (($num -= 90) >= 0) {
			my $tmp = $wx;
			$wx = $wy;
			$wy = -$tmp;
		}
	} elsif ($cmd eq 'L') {
		while (($num -= 90) >= 0) {
			my $tmp = $wy;
			$wy = $wx;
			$wx = -$tmp;
		}
	} elsif ($cmd eq 'N') {
		$wy += $num;
	} elsif ($cmd eq 'S') {
		$wy -= $num;
	} elsif ($cmd eq 'E') {
		$wx += $num;
	} elsif ($cmd eq 'W') {
		$wx -= $num;
	}
	print " at ($x, $y, $wx, $wy)\n";
}

print abs($x) + abs($y), "\n";
		
