#abc290e. [abc290_e]Make it Palindrome

[abc290_e]Make it Palindrome

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 1leilem1 \\le i \\le m.

Constraints

  • All values in the input are integers.
  • 1leNle2times1051 \\le N \\le 2 \\times 10^5
  • 1leAileN1 \\le A_i \\le N

Input

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

NN A1A_1 A2A_2 dots\\dots ANA_N

Output

Print the answer as an integer.


Sample Input 1

5
5 2 1 2 2

Sample Output 1

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.