Santi is playing a game with a grid of R rows (from top to bottom) and C columns (from left to right). The cell at the ith row and the jth column is denoted by cell (i,j). There are A_i,j apples on the (i,j) cell.
Santi’s character, Nano, is initially on the (1,1) cell and would like to move to the (R,C) cell. On each turn, Nano can only move one cell to the bottom or one cell to the right so that it is closer to the goal. Nano’s path to the goal can be represented as a string containing R+C−2 characters, where R−1 of those characters are ‘D’ and C−1 of those characters are ‘R’. This means that Nano moves one cell to the bottom on the ith turn if the ith character is ‘D’ and Nano moves one cell to the right on the ith turn if the ith character is ‘R’.
Two paths are different if the string representation is different. We know that there are (R−1R+C−2) different paths. A path X is better than path Y if either the following is true:
Finding the best path is too boring for Santi, so she would like to find the Kth best path instead. In other words, she would like to find a path X such that there are K−1 paths that are better than X, and there are (R−1R+C−2)−K paths that are worse than X.
For example, let R=2, C=3, K=3, A_1,1..3=1,2,3, and A_2,1..3=2,2,3. Therefore, there are three different paths to the goal, sorted in the decreasing wellness order.
RRD. This path collects 1+2+3+3=9 apples.DRR. This path collects 1+2+2+3=8 apples.RDR. This path collects 1+2+2+3=8 apples.Therefore, the 3rd best path is the path represented by string RDR.
Input begins with a line containing three integers: R C K (2 ≤R,C≤30;1≤ K≤(R−1R+C−2)) representing the number of rows, the number of columns, and the index of the path that Santi would like to find, respectively. The next R lines, each contains C integers representing the number of apples on each cell. The jth integer on the ith line is A_i,j (0≤A_i,j≤200).
Output in a line a string representing the Kth best path to the goal.