#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int N, v[MAXN];
bool outer[MAXN], inner[MAXN];
int mult[MAXN];
int neg = 0;
int odd = 0;
void add(int idx) {
  if (idx == N || idx == -1) return;
  int val = v[idx];
  int old = mult[val];
  if (old < 0) {
    if (old == -1) neg--;
  } else {
    if (old % 2 == 0)
      odd++;
    else
      odd--;
  }
  mult[val]++;
}
void rem(int idx) {
  if (idx == N || idx == -1) return;
  int val = v[idx];
  int old = mult[val];
  if (old <= 0) {
    if (old == 0) neg++;
  } else {
    if (old % 2 == 0)
      odd++;
    else
      odd--;
  }
  mult[val]--;
}
bool can_do() { return (odd <= 1) && (neg == 0); }
int mirr(int idx) { return N - 1 - idx; }
bool in(int L, int R, int i) { return L <= i && i <= R; }
void intro(int L, int R, int i) {
  int j = mirr(i);
  if (in(L, R, j)) {
    if (i != j) add(i);
  } else
    rem(j);
  add(i);
}
void excom(int L, int R, int i) {
  int j = mirr(i);
  if (in(L, R, j)) {
    if (i != j) rem(i);
  } else
    add(j);
  rem(i);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> N;
  for (int i = 0; i < N; i++) cin >> v[i];
  outer[0] = true;
  for (int o = 1; 2 * o <= N; o++) {
    outer[o] = outer[o - 1];
    outer[o] &= v[o - 1] == v[N - o];
  }
  inner[0] = true;
  for (int i = 1; 2 * i <= N; i++) {
    inner[i] = inner[i - 1];
    int j1 = (N % 2) ? (N / 2 - i) : (N / 2 - i);
    int j2 = (N % 2) ? (N / 2 + i) : (N / 2 + i - 1);
    inner[i] &= v[j1] == v[j2];
  }
  long long ans = 0;
  int R = N;
  for (int L = N - 1; L >= 0; L--) {
    intro(L, R, L);
    int in = (N % 2) ? max(0, L - (N / 2) - 1) : max(0, L - (N / 2));
    if (!inner[in]) continue;
    while (R > L) {
      R--;
      int out = min(N - 1 - R, L);
      if (!outer[out]) {
        R++;
        break;
      }
      if (R + 1 < N) excom(L, R + 1, R + 1);
      if (!can_do()) {
        if (R + 1 < N) intro(L, R + 1, R + 1);
        R++;
        break;
      }
    }
    if (R < N) {
      ans += N - R;
    }
  }
  cout << ans << endl;
  return 0;
}

### Prompt

Please provide a CPP coded solution to the problem described below:

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;
const int MAXN = 100005;
int N, v[MAXN];
bool outer[MAXN], inner[MAXN];
int mult[MAXN];
int neg = 0;
int odd = 0;
void add(int idx) {
  if (idx == N || idx == -1) return;
  int val = v[idx];
  int old = mult[val];
  if (old < 0) {
    if (old == -1) neg--;
  } else {
    if (old % 2 == 0)
      odd++;
    else
      odd--;
  }
  mult[val]++;
}
void rem(int idx) {
  if (idx == N || idx == -1) return;
  int val = v[idx];
  int old = mult[val];
  if (old <= 0) {
    if (old == 0) neg++;
  } else {
    if (old % 2 == 0)
      odd++;
    else
      odd--;
  }
  mult[val]--;
}
bool can_do() { return (odd <= 1) && (neg == 0); }
int mirr(int idx) { return N - 1 - idx; }
bool in(int L, int R, int i) { return L <= i && i <= R; }
void intro(int L, int R, int i) {
  int j = mirr(i);
  if (in(L, R, j)) {
    if (i != j) add(i);
  } else
    rem(j);
  add(i);
}
void excom(int L, int R, int i) {
  int j = mirr(i);
  if (in(L, R, j)) {
    if (i != j) rem(i);
  } else
    add(j);
  rem(i);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> N;
  for (int i = 0; i < N; i++) cin >> v[i];
  outer[0] = true;
  for (int o = 1; 2 * o <= N; o++) {
    outer[o] = outer[o - 1];
    outer[o] &= v[o - 1] == v[N - o];
  }
  inner[0] = true;
  for (int i = 1; 2 * i <= N; i++) {
    inner[i] = inner[i - 1];
    int j1 = (N % 2) ? (N / 2 - i) : (N / 2 - i);
    int j2 = (N % 2) ? (N / 2 + i) : (N / 2 + i - 1);
    inner[i] &= v[j1] == v[j2];
  }
  long long ans = 0;
  int R = N;
  for (int L = N - 1; L >= 0; L--) {
    intro(L, R, L);
    int in = (N % 2) ? max(0, L - (N / 2) - 1) : max(0, L - (N / 2));
    if (!inner[in]) continue;
    while (R > L) {
      R--;
      int out = min(N - 1 - R, L);
      if (!outer[out]) {
        R++;
        break;
      }
      if (R + 1 < N) excom(L, R + 1, R + 1);
      if (!can_do()) {
        if (R + 1 < N) intro(L, R + 1, R + 1);
        R++;
        break;
      }
    }
    if (R < N) {
      ans += N - R;
    }
  }
  cout << ans << endl;
  return 0;
}

```