atcoder#ABC290E. [ABC290E] Make it Palindrome

[ABC290E] Make it Palindrome

Score : 500500 points

Problem Statement

For a sequence XX, let f(X)=f(X) = (the minimum number of elements one must modify to make XX a palindrome).

Given a sequence AA of length NN, find the sum of f(X)f(X) over all contiguous subarrays of AA.

Here, a sequence XX of length mm is said to be a palindrome if and only if the ii-th and the (m+1i)(m+1-i)-th elements of XX are equal for all 1im1 \le i \le m.

Constraints

  • All values in the input are integers.
  • 1N2×1051 \le N \le 2 \times 10^5
  • 1AiN1 \le A_i \le N

Input

The input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 \dots ANA_N

Output

Print the answer as an integer.

5
5 2 1 2 2
9
  • f(5)=0f(5) = 0
  • f(2)=0f(2) = 0
  • f(1)=0f(1) = 0
  • f(2)=0f(2) = 0
  • f(2)=0f(2) = 0
  • f(5,2)=1f(5,2) = 1
  • f(2,1)=1f(2,1) = 1
  • f(1,2)=1f(1,2) = 1
  • f(2,2)=0f(2,2) = 0
  • f(5,2,1)=1f(5,2,1) = 1
  • f(2,1,2)=0f(2,1,2) = 0
  • f(1,2,2)=1f(1,2,2) = 1
  • f(5,2,1,2)=2f(5,2,1,2) = 2
  • f(2,1,2,2)=1f(2,1,2,2) = 1
  • f(5,2,1,2,2)=1f(5,2,1,2,2) = 1

Therefore, the sought answer is 99.