#include <bits/stdc++.h>
using namespace std;
int N, M;
int A[100002], B[100002];
int F1[100002], F2[100002];
int nimp, wh;
bool pluss;
int get_res() {
  memset(F1, 0, sizeof(F1));
  memset(F2, 0, sizeof(F2));
  for (int i = 1; i <= (M + 1) / 2; ++i) ++F1[B[i]];
  for (int i = (M + 1) / 2 + 1; i <= M; ++i) ++F2[B[i]];
  int nok = 0;
  for (int i = 1; i <= N; ++i)
    if (F2[i] > F1[i]) ++nok;
  if (!nok) {
    int lim = (M + 1) / 2;
    while (lim > 0 && B[lim] == B[M - lim + 1] &&
           !(lim == (M + 1) / 2 && nimp == 1 && B[lim] != wh))
      --lim;
    return lim;
  }
  int go = (M + 1) / 2;
  for (int i = (M + 1) / 2 + 1; i <= M && nok; ++i) {
    if (F2[B[i]] > F1[B[i]] && F2[B[i]] - 1 <= F1[B[i]] + 1) --nok;
    ++F1[B[i]];
    --F2[B[i]];
    go = i;
  }
  return go;
}
int main() {
  cin.sync_with_stdio(false);
  cin >> N;
  for (int i = 1; i <= N; ++i) {
    cin >> A[i];
    ++F1[A[i]];
  }
  nimp = 0;
  for (int i = 1; i <= N; ++i) {
    nimp += F1[i] % 2;
    if (F1[i] % 2 == 1) wh = i;
  }
  if (nimp > 1) {
    cout << 0 << '\n';
    return 0;
  }
  int fw = N, lw = 1;
  for (int i = 1; i <= N; ++i)
    if (A[i] != A[N - i + 1] || (nimp == 1 && i == N / 2 + 1 && A[i] != wh)) {
      B[++M] = A[i];
      fw = min(fw, i);
      lw = max(lw, i);
    }
  if (M == 0) {
    cout << 1LL * N * (N + 1) / 2 << '\n';
    return 0;
  }
  M = N;
  for (int i = 1; i <= N; ++i) B[i] = A[i];
  int p1 = get_res();
  if (p1 == -1) {
    cout << 0 << '\n';
    return 0;
  }
  reverse(B + 1, B + M + 1);
  int p2 = get_res();
  int bg1 = fw, en1 = p1;
  int bg2 = N - lw + 1, en2 = p2;
  bg2 = N - bg2 + 1;
  en2 = N - en2 + 1;
  swap(bg2, en2);
  long long result = 1LL * bg1 * (N - en1 + 1) + 1LL * bg2 * (N - en2 + 1);
  int bg3 = min(bg1, bg2), en3 = max(en1, en2);
  result -= 1LL * bg3 * (N - en3 + 1);
  cout << result << '\n';
}

### Prompt

Please create a solution in cpp to the following problem:

Misha has an array of n integers indexed by integers from 1 to n. Let's define palindrome degree of array a as the number of such index pairs (l, r)(1 ≤ l ≤ r ≤ n), that the elements from the l-th to the r-th one inclusive can be rearranged in such a way that the whole array will be a palindrome. In other words, pair (l, r) should meet the condition that after some rearranging of numbers on positions from l to r, inclusive (it is allowed not to rearrange the numbers at all), for any 1 ≤ i ≤ n following condition holds: a[i] = a[n - i + 1]. 

Your task is to find the palindrome degree of Misha's array.

Input

The first line contains integer n (1 ≤ n ≤ 105).

The second line contains n positive integers a[i] (1 ≤ a[i] ≤ n), separated by spaces — the elements of Misha's array.

Output

In a single line print the answer to the problem.

Examples

Input

3
2 2 2


Output

6


Input

6
3 6 5 3 3 5


Output

0


Input

5
5 5 2 5 2


Output

4

Note

In the first sample test any possible pair (l, r) meets the condition.

In the third sample test following pairs (1, 3), (1, 4), (1, 5), (2, 5) meet the condition.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int N, M;
int A[100002], B[100002];
int F1[100002], F2[100002];
int nimp, wh;
bool pluss;
int get_res() {
  memset(F1, 0, sizeof(F1));
  memset(F2, 0, sizeof(F2));
  for (int i = 1; i <= (M + 1) / 2; ++i) ++F1[B[i]];
  for (int i = (M + 1) / 2 + 1; i <= M; ++i) ++F2[B[i]];
  int nok = 0;
  for (int i = 1; i <= N; ++i)
    if (F2[i] > F1[i]) ++nok;
  if (!nok) {
    int lim = (M + 1) / 2;
    while (lim > 0 && B[lim] == B[M - lim + 1] &&
           !(lim == (M + 1) / 2 && nimp == 1 && B[lim] != wh))
      --lim;
    return lim;
  }
  int go = (M + 1) / 2;
  for (int i = (M + 1) / 2 + 1; i <= M && nok; ++i) {
    if (F2[B[i]] > F1[B[i]] && F2[B[i]] - 1 <= F1[B[i]] + 1) --nok;
    ++F1[B[i]];
    --F2[B[i]];
    go = i;
  }
  return go;
}
int main() {
  cin.sync_with_stdio(false);
  cin >> N;
  for (int i = 1; i <= N; ++i) {
    cin >> A[i];
    ++F1[A[i]];
  }
  nimp = 0;
  for (int i = 1; i <= N; ++i) {
    nimp += F1[i] % 2;
    if (F1[i] % 2 == 1) wh = i;
  }
  if (nimp > 1) {
    cout << 0 << '\n';
    return 0;
  }
  int fw = N, lw = 1;
  for (int i = 1; i <= N; ++i)
    if (A[i] != A[N - i + 1] || (nimp == 1 && i == N / 2 + 1 && A[i] != wh)) {
      B[++M] = A[i];
      fw = min(fw, i);
      lw = max(lw, i);
    }
  if (M == 0) {
    cout << 1LL * N * (N + 1) / 2 << '\n';
    return 0;
  }
  M = N;
  for (int i = 1; i <= N; ++i) B[i] = A[i];
  int p1 = get_res();
  if (p1 == -1) {
    cout << 0 << '\n';
    return 0;
  }
  reverse(B + 1, B + M + 1);
  int p2 = get_res();
  int bg1 = fw, en1 = p1;
  int bg2 = N - lw + 1, en2 = p2;
  bg2 = N - bg2 + 1;
  en2 = N - en2 + 1;
  swap(bg2, en2);
  long long result = 1LL * bg1 * (N - en1 + 1) + 1LL * bg2 * (N - en2 + 1);
  int bg3 = min(bg1, bg2), en3 = max(en1, en2);
  result -= 1LL * bg3 * (N - en3 + 1);
  cout << result << '\n';
}

```