#P12212. Maximum Monochrome Staircase
Maximum Monochrome Staircase
Maximum Monochrome Staircase
Small Blue loves staircase patterns. A staircase pattern of size is defined as an arrangement of columns placed side‐by‐side, where the -th column contains exactly identical squares (i.e. same size and color) for . When the bottoms of the columns are aligned, a staircase pattern is formed. Furthermore, any pattern obtained by rotating a staircase pattern by a multiple of is still considered a staircase pattern. For example, the following four orientations are valid for a staircase pattern of size :
1., 0° rotation (original): In an box with rows indexed to from top to bottom and columns to , the cell at position is included if [ i \ge N - j - 1. ]
2., 90° rotation: In an box, the cell at position is included if [ i \ge j. ]
3., 180° rotation: In an box, the cell at position is included if [ i \le N - j - 1. ]
4., 270° rotation: In an box, the cell at position is included if [ i \le j. ]
Small Blue has a cloth divided into an grid. Each cell of the grid has its own color (represented by an integer). He can cut the cloth along the cell boundaries to obtain a piece exactly in the shape of a staircase pattern (in any one of the four allowed rotations). What is the maximum staircase size such that there exists a staircase pattern formed by cells of a single color that can be cut out from the cloth?
inputFormat
The first line of input contains a single integer (), the size of the cloth. Each of the next lines contains integers separated by spaces, where each integer represents the color of that cell.
outputFormat
Output a single integer, the maximum size of a monochrome staircase pattern that can be obtained from the cloth. If no staircase pattern (even of size 1) exists, output 0.
sample
3
1 1 1
1 1 1
1 1 1
3