Suki Sniffs the Garden in a Spiral
Suki, the curly black dog with the grey beard, inspects the vegetable garden every morning, and she always does it in the same order. The garden is a grid of R rows and C columns of beds, and each bed holds one plant, written as a lowercase letter.
Suki starts at the top-left bed. She walks right along the top row, then down the rightmost column, then left along the bottom row, then up the leftmost column. That is the outer ring of the garden. Then she steps inside and sniffs the next ring the same way: right, down, left, up. She keeps spiralling inward until she has sniffed every bed exactly once. If what's left is a single row or a single column, she just walks along it (right for a row, down for a column).
Print the letters of the beds in the order Suki sniffs them.
Input
The first line contains two integers R and C (1 ≤ R, C ≤ 1000): the number of rows and columns.
Each of the next R lines contains a string of exactly C lowercase English letters: one row of the garden, from top to bottom.
Output
Print one line with a string of R·C letters: the plants in the order Suki visits their beds.
Notes
In the first example the garden is
abc
def
ghi
Suki sniffs abc along the top, fi down the right side, hg back along the bottom, d going up, and finally e in the middle: abcfihgde.
In the second example the garden has 3 rows and 4 columns. After the outer ring (abcd, hl, kji, e), only the middle row fg is left, which she walks from left to right. Each bed is sniffed exactly once, so the answer has 12 letters.