#!/usr/bin/perl -w

use strict;

my ($x, $y, $dir) = (0, 0, 'E');

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

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