Rail Station Recovery
Time limit3sMemory limit512 MB
Recover every station's block number and C or D type from the all-pairs shortest-route distances and station 0's block.
Problem
A railway line runs from the western end of the island to the eastern end and consists of blocks. The blocks are numbered , , ..., from the west. Each block has a one way westbound track on its north side, a one way eastbound track on its south side, and possibly one station between the two tracks.
A block has one of three types. A type C block holds a station that you enter from the northern track and leave onto the southern track. A type D block holds a station that you enter from the southern track and leave onto the northern track. An empty block has no station. The tracks of two neighboring blocks are joined by a connector. In the figure below the connectors are the gray rectangles.

The line in the figure has 7 blocks. Blocks , and are type C, block is type D, and the other blocks are empty. It has 4 stations: station sits in block , station in block , station in block , and station in block .
The line has stations, numbered to . From every station you can reach every other station along the tracks. Several routes join one station to another, so the distance between two stations is the smallest number of connectors a route passes. In the figure the shortest route from station 0 to station 2 runs through blocks 2, 3, 4, 5, 4, 3 and passes 5 connectors, so the distance between those two stations is .
After a power outage the computer that manages the line lost the block number and the block type of every station. The only clue left is the block number of station , and that block is always type C. The computer can still measure the distance between every pair of stations. Recover the block number and the block type of every station from the distance table and the block number of station .
Input
The first line has the number of stations and the block number of station , separated by a space. Each of the next lines holds one row of the distance table. The -th number on the -th of those lines is the distance between station and station .
- Every station has a block number that is at least and less than , and a block holds at most one station.
- The distance table is symmetric and every diagonal entry is .
- The input comes from a line that meets all of the conditions above, and only one arrangement of stations produces it.
Output
Print lines. The -th line holds the block number of station and the type of that block, separated by a single space. Write C for a type C block and D for a type D block.