atcoder#ABC258B. [ABC258B] Number Box
[ABC258B] Number Box
Score : points
Problem Statement
You are given a positive integer .
We have a grid with rows and columns, where the square at the -th row from the top and -th column from the left has a digit written on it.
Assume that the upper and lower edges of this grid are connected, as well as the left and right edges. In other words, all of the following holds.
- is just above , and is just below . .
- is just to the left of , and is just to the right of . .
Takahashi will first choose one of the following eight directions: up, down, left, right, and the four diagonal directions. Then, he will start on a square of his choice and repeat moving one square in the chosen direction times.
In this process, Takahashi visits squares. Find the greatest possible value of the integer that is obtained by arranging the digits written on the squares visited by Takahashi from left to right in the order visited by him.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
4
1161
1119
7111
1811
9786
If Takahashi starts on the square at the -nd row from the top and -th column from the left and goes down and to the right, the integer obtained by arranging the digits written on the visited squares will be . It is impossible to make a value greater than , so the answer is .
10
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
Note that the answer may not fit into a 32-bit integer.