#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 100007;
int n;
int a[MAXN], ra[MAXN];
int cc[MAXN];
void init();
void input();
void work();
int getok(int b[], int pos);
bool check(int b[], int tst);
int main() {
  init();
  input();
  work();
}
void init() { ios::sync_with_stdio(false); }
void input() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
}
void work() {
  memset(cc, 0, sizeof(cc));
  for (int i = 1; i <= n; ++i) ++cc[a[i]];
  bool flag = false;
  for (int i = 1; i <= n; ++i) {
    if (cc[i] & 1) {
      if (flag) {
        printf("0\n");
        return;
      } else
        flag = true;
    }
  }
  flag = true;
  for (int i = 1; i <= n >> 1; ++i) {
    if (a[i] ^ a[n - i + 1]) {
      flag = false;
      break;
    }
  }
  if (flag) {
    printf("%I64d\n", static_cast<long long>(n) * (n + 1) >> 1);
    return;
  }
  int ml = 1, mr = n;
  while (a[ml] == a[mr]) ++ml, --mr;
  long long ans = -static_cast<long long>(ml) * ml;
  ans += static_cast<long long>(ml) * getok(a, ml);
  for (int i = 1; i <= n; ++i) ra[i] = a[n - i + 1];
  ans += static_cast<long long>(ml) * getok(ra, ml);
  printf("%I64d\n", ans);
}
int getok(int b[], int pos) {
  int l = pos + 1, r = n, mid;
  while (l < r) {
    mid = (l + r) >> 1;
    if (check(b, mid))
      r = mid;
    else
      l = mid + 1;
  }
  return (n - l + 1);
}
bool check(int b[], int tst) {
  if (tst <= (n >> 1)) {
    int nl = tst + 1, nr = (n - tst);
    while (nl < nr) {
      if (b[nl] ^ b[nr]) return false;
      ++nl, --nr;
    }
  }
  memset(cc, 0, sizeof(cc));
  for (int i = 1; i <= tst; ++i) ++cc[b[i]];
  if (tst > (n >> 1)) tst = n - tst;
  for (int i = 1; i <= tst; ++i) {
    --cc[b[n - i + 1]];
    if (cc[b[n - i + 1]] < 0) return false;
  }
  return true;
}

### Prompt

Create a solution in Cpp for 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;
const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 100007;
int n;
int a[MAXN], ra[MAXN];
int cc[MAXN];
void init();
void input();
void work();
int getok(int b[], int pos);
bool check(int b[], int tst);
int main() {
  init();
  input();
  work();
}
void init() { ios::sync_with_stdio(false); }
void input() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
}
void work() {
  memset(cc, 0, sizeof(cc));
  for (int i = 1; i <= n; ++i) ++cc[a[i]];
  bool flag = false;
  for (int i = 1; i <= n; ++i) {
    if (cc[i] & 1) {
      if (flag) {
        printf("0\n");
        return;
      } else
        flag = true;
    }
  }
  flag = true;
  for (int i = 1; i <= n >> 1; ++i) {
    if (a[i] ^ a[n - i + 1]) {
      flag = false;
      break;
    }
  }
  if (flag) {
    printf("%I64d\n", static_cast<long long>(n) * (n + 1) >> 1);
    return;
  }
  int ml = 1, mr = n;
  while (a[ml] == a[mr]) ++ml, --mr;
  long long ans = -static_cast<long long>(ml) * ml;
  ans += static_cast<long long>(ml) * getok(a, ml);
  for (int i = 1; i <= n; ++i) ra[i] = a[n - i + 1];
  ans += static_cast<long long>(ml) * getok(ra, ml);
  printf("%I64d\n", ans);
}
int getok(int b[], int pos) {
  int l = pos + 1, r = n, mid;
  while (l < r) {
    mid = (l + r) >> 1;
    if (check(b, mid))
      r = mid;
    else
      l = mid + 1;
  }
  return (n - l + 1);
}
bool check(int b[], int tst) {
  if (tst <= (n >> 1)) {
    int nl = tst + 1, nr = (n - tst);
    while (nl < nr) {
      if (b[nl] ^ b[nr]) return false;
      ++nl, --nr;
    }
  }
  memset(cc, 0, sizeof(cc));
  for (int i = 1; i <= tst; ++i) ++cc[b[i]];
  if (tst > (n >> 1)) tst = n - tst;
  for (int i = 1; i <= tst; ++i) {
    --cc[b[n - i + 1]];
    if (cc[b[n - i + 1]] < 0) return false;
  }
  return true;
}

```