LeeFuuChang the Potato once saw a way to generate password by combining numbers from a grid in a certain pattern.

So you, as a kind and generous student, wanted to help Potato finish the program that does the transformation from grid to password.
Feel free to use the following code as a starter.
def solve(n, d, t, grid):
"""
This is the explanation of the template code
We've read the input for you.
this function will take in 4 parameters:
- n:
a integer representing the size of the grid
- d:
a integer representing the starting direction
- t:
a integer representing the rotating direction
- grid:
a 'nxn' grid filled with integers
a.k.a, for any grid[i][j] is int
you need to return a string that satisfies the problem's requirement.
Feel free to delete this explanation after reading it.
"""
ans = ""
# your
# code
# here
return ans
_n, _d, _t = map(int, input().split())
_grid = []
for _ in range(_n):
_row = []
for num in input().split():
_row.append(int(num))
_grid.append(_row)
print(solve(_n, _d, _t, _grid))
Potato judges your code by the following limitations:
n = 3, d = 0, t = 1n <= 29, d ∈ {0, 1, 2, 3}, t = 1n <= 29, d = 0, t ∈ {0, 1}n <= 59, d ∈ {0, 1, 2, 3}, t ∈ {0, 1}Potato's Whisper: If you take a closer look at the 25 grid above:
First line contains 3 integers n,d,t representing:
nxnd direction ( Up d=0 | Left d=1 | Down d=2 | Right d=3 )t=1 or counter-clockwise t=0Each of the following n lines contains n integers, forming a nxn grid.
It's guaranteed that:
n%2 == 11 <= n <= 59d ∈ {0, 1, 2, 3}t ∈ {0, 1}0 <= grid[i][j] <= n*nOutput the password formed by the order of traversing the grid, with no space between numbers, and a newline at the end.