#K33647. Find the Largest Mirror Section

    ID: 25134 Type: Default 1000ms 256MiB

Find the Largest Mirror Section

Find the Largest Mirror Section

You are given an array of integers. Your task is to determine the length of the largest mirror section in this array.

A mirror section in an array is a contiguous subsequence that appears in reverse order somewhere else in the array. Formally, if the array is denoted as \(a_0, a_1, \ldots, a_{n-1}\), then a mirror section of length \(L\) exists if there are indices \(i\) and \(j\) (with appropriate bounds) such that:

[ a_i = a_{j},\quad a_{i+1} = a_{j-1},\quad \ldots,\quad a_{i+L-1} = a_{j-L+1} ]

Your program should read the input from stdin and output the result to stdout.

Examples:

  • For the input array [1, 2, 3, 8, 9, 3, 2, 1], the largest mirror section has length 3.
  • For the input array [1, 4, 5, 3, 5, 4, 1], the largest mirror section has length 7.

inputFormat

The first line of input contains a single integer \(n\) representing the number of elements in the array. The second line contains \(n\) space-separated integers.

For example:

8
1 2 3 8 9 3 2 1

outputFormat

Output a single integer which is the length of the largest mirror section found in the array.

## sample
8
1 2 3 8 9 3 2 1
3