Texture Tile

No attempts yetTime limit2sMemory limit256 MB

Problem

A square raster image is represented by an N×NN \times N array of pixels. A texture tile is a square (sub)image whose first row is identical to its last row and whose first column is identical to its last column. This property is useful when covering the surface of a graphics object with repeated copies of a texture, because it lets adjacent copies join together "seamlessly".

Given an image, find the side length of the largest square subimage that is a texture tile.

Input

The first token is the integer NN. It is followed by N2N^2 integers ci,jc_{i,j}, the pixel values, given row by row (row 11 first, then row 22, and so on).

Output

Print a single integer mm: the side length of the largest texture tile contained in the image. (Since a single pixel is always a texture tile, m1m \ge 1 always holds.)

Constraints

  • 1N3701 \le N \le 370
  • 0ci,j2550 \le c_{i,j} \le 255