#K57887. Largest Unique Subsquare

    ID: 30520 Type: Default 1000ms 256MiB

Largest Unique Subsquare

Largest Unique Subsquare

You are given a square grid of size \(n \times n\) consisting of integers. Your task is to find the side length of the largest subsquare in which all the elements are unique (i.e. no duplicate elements exist within that subsquare).

A subsquare is defined by choosing a top-left cell (\(top, left\)) and a size \(s\) such that the block of cells spanning rows \(top\) to \(top+s-1\) and columns \(left\) to \(left+s-1\) is completely inside the grid.

If multiple subsquares satisfy the property, output the side length of the largest one.

Input/Output Specifications

Read from standard input and write to standard output.

inputFormat

The input consists of:

  • An integer \(n\) denoting the size of the grid.
  • \(n\) lines each containing \(n\) space-separated integers representing the grid.

outputFormat

Output a single integer, the side length of the largest subsquare where all the elements are unique.

## sample
4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
4