cho.sh
Notes
Loading...

Making a Palindrome

Time limit

2s

Memory limit

128 MB

Problem

A sequence is a palindrome if it reads the same from left to right and from right to left. For example, {1}, {1, 2, 1}, and {1, 2, 2, 1} are palindromes, while {1, 2, 3} and {1, 2, 3, 2} are not.

You are given one sequence. You may insert any numbers at any positions in the sequence. Find the minimum number of inserted numbers needed to make the sequence a palindrome.

Input

The first line contains the length N of the sequence. (1 <= N <= 5,000)

The second line contains the N integers in the sequence. Each integer is within the int range.

Output

Print the minimum number of numbers that must be inserted to make the sequence a palindrome.