// We didn't receive good response on this question during the qualifiers, so we have included this question here also.
Given a matrix of size N x M. You are currently at the top-left cell and you have to reach the bottom-right cell. Some of the cells contain treasure boxes, which contain some number of coins. When you reach a cell containing the treasure, you will automatically collect it.
From a current cell (x, y) you can move to (x+1,y),(x,y+1),(x-1,y) or (x,y-1) if its available. You can visit a cell any number of times.
You need to print the sequence of steps that you will take in the form of a string.
The length of the string should not be more than 106 and the string must consist of any of the symbols {‘N’,’E’,’W,’S’} representing North, East, West and South respectively. Print ‘E’ if you want to move to the cell in the East, i.e. (x, y+1).
Note: If you move to a cell which is not present (outside the boundary of the matrix), then you will get a wrong answer. Also the final cell reached by your sequence of moves should be the bottom-right cell only, otherwise you will get a wrong answer.
In the description, x represents row number and y represents column number.
You need to collect maximum possible treasure in minimum steps.
INPUT
First line contains N and M.
Next N lines contain M space separated integers. If its 0, that means it’s a normal cell ( no treasure), otherwise it contains treasure having the given number of coins.
OUTPUT
Print a string representing the sequence of steps. Maximum length of string 106 and it should contain only {‘N’,’E’,’W,’S’}.
CONSTRAINTS
N=M=500
0<=Ai,j<=1000
The score for the sample output will be 5/6 = 0.833