문제
Farmer John is quite reliable in all aspects of managing his farm, except one: he is terrible at mowing the grass in a timely or logical fashion.
The farm is a large 2D grid of square unit cells. FJ starts in one of these cells at time
So slow is FJ's progress that some of the grass he mows might grow back before he is finished with all his mowing. Any section of grass that is cut at time
FJ's mowing pattern might have him re-visit the same cell multiple times, but he remarks that he never encounters a cell in which the grass is already cut. That is, every time he visits a cell, his most recent visit to that same cell must have been at least
Please determine the maximum possible value of
Problem credits: Brian Dean
입력
The first line of input contains
출력
Please determine the maximum value of
예제1
6
N 10
E 2
S 3
W 4
S 5
E 8
10
In this example, FJ steps on a cell at time 17 that he stepped on earlier at time 7; therefore,