https://www.codechef.com/problems/DRGRAC

https://www.codechef.com/problems/DRGRAC

can someone please explain how to solve this question

Exactly, I also didn’t get the concept of directions in it.