USACO 2016 January Contest, Bronze Problem 3. Mowing the Field

Hello. i was coding the USACO 2016 January Contest, Bronze Problem 3. Mowing the Field:
url to task
And i solved it with the given code: link to code
However it is failing on the last three cases and i cannot find the issue. I even downloaded the files and it is correct to my calculation. If anyone could help me i would be very thankful. Here is a sample case that my code fails to:
50
N 7
E 2
S 6
W 9
N 9
E 3
S 7
W 9
N 6
E 4
S 6
W 5
N 7
E 9
S 3
W 5
N 7
E 9
S 4
W 10
N 1
E 1
S 6
W 3
N 10
E 9
S 6
W 10
N 8
E 5
S 1
W 6
N 8
E 9
S 6
W 6
N 3
E 2
S 6
W 8
N 7
E 1
S 2
W 5
N 1
E 6
S 10
W 8
N 7
E 5
And this is the following output according to the files i downloaded: 4
However when i do the math i get 16 which is also what my code prints.

\quad

ISSUES

  • A greedy solution won’t work here, as it’s possible for the farmer to revisit a location in a smaller time interval later on. For example, in the test case provided above, (10, -10) is revisited within 4 seconds.
  • The constraints state that the maximum distance that can be visited is 1000, so for larger test cases, an out-of-bounds error could occur.
  • If you’re stuck, take a look at the provided solution. If you’re sure your logic is correct and the given test cases passed, try using a generator function to find test cases that don’t match and figure out why that’s the case. Benq’s link above provides more information on how to do this.

That’s all. Happy coding!