#include <bits/stdc++.h>
using namespace std;
int INT_MAX_VAL = (int)1e20;
int INT_MIN_VAL = (int)-1e20;
long long LONG_MAX_VAL = (long long)1e20;
long long LONG_MIN_VAL = (long long)-1e20;
int a[100005];
int n;
int l, r;
int l1, r1;
int res;
int cnt_l[100005];
int cnt_r[100005];
int cnt[100005];
void init() {
  memset(cnt_l, 0, sizeof(cnt_l));
  memset(cnt_r, 0, sizeof(cnt_r));
  for (int i = l; i <= l1; ++i) cnt_l[a[i]]++;
  for (int i = r1; i <= r; ++i) cnt_r[a[i]]++;
}
bool chech(int lc, int rc) {
  memset(cnt, 0, sizeof(cnt));
  for (int i = l; i <= r; ++i) {
    if ((i < lc || rc < i) && ((n - i - 1) < lc || (n - i - 1) > rc)) {
      if (a[i] != a[n - i - 1]) return false;
    } else if ((i < lc) || (i > rc)) {
      cnt[a[i]]++;
    } else {
      cnt[a[i]]--;
    }
  }
  for (long long(i) = 0LL; (i) < (n); (i)++) {
    if (cnt[a[i]] > 0) return false;
  }
  return true;
}
int main() {
  scanf("%d", &n);
  for (long long(i) = 0LL; (i) < (n); (i)++) {
    scanf("%d", &a[i]);
    cnt[a[i]]++;
  }
  l = 0, r = n - 1;
  while (l < r && a[l] == a[r]) {
    l++;
    r--;
  }
  int odd = 0;
  for (long long(i) = 0LL; (i) < (100005); (i)++) odd += cnt[i] % 2;
  if (odd > 1) {
    cout << 0 << '\n';
    return 0;
  }
  if (l >= r) {
    cout << (long long)n * (n + 1) / 2 << '\n';
    return 0;
  }
  long long lc = l, rc = n - 1;
  while (lc != rc) {
    int med = lc + (rc - lc) / 2;
    if (chech(l, med)) {
      rc = med;
    } else {
      lc = med + 1;
    }
  }
  long long ans = 0;
  ans += (l + 1) * (n - rc);
  lc = 0, rc = r;
  while (lc != rc) {
    int med = (lc + rc + 1) / 2;
    if (chech(med, r)) {
      lc = med;
    } else {
      rc = med - 1;
    }
  }
  ans += (lc - l) * (l + 1);
  cout << ans << '\n';
  return 0;
}

### 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 INT_MAX_VAL = (int)1e20;
int INT_MIN_VAL = (int)-1e20;
long long LONG_MAX_VAL = (long long)1e20;
long long LONG_MIN_VAL = (long long)-1e20;
int a[100005];
int n;
int l, r;
int l1, r1;
int res;
int cnt_l[100005];
int cnt_r[100005];
int cnt[100005];
void init() {
  memset(cnt_l, 0, sizeof(cnt_l));
  memset(cnt_r, 0, sizeof(cnt_r));
  for (int i = l; i <= l1; ++i) cnt_l[a[i]]++;
  for (int i = r1; i <= r; ++i) cnt_r[a[i]]++;
}
bool chech(int lc, int rc) {
  memset(cnt, 0, sizeof(cnt));
  for (int i = l; i <= r; ++i) {
    if ((i < lc || rc < i) && ((n - i - 1) < lc || (n - i - 1) > rc)) {
      if (a[i] != a[n - i - 1]) return false;
    } else if ((i < lc) || (i > rc)) {
      cnt[a[i]]++;
    } else {
      cnt[a[i]]--;
    }
  }
  for (long long(i) = 0LL; (i) < (n); (i)++) {
    if (cnt[a[i]] > 0) return false;
  }
  return true;
}
int main() {
  scanf("%d", &n);
  for (long long(i) = 0LL; (i) < (n); (i)++) {
    scanf("%d", &a[i]);
    cnt[a[i]]++;
  }
  l = 0, r = n - 1;
  while (l < r && a[l] == a[r]) {
    l++;
    r--;
  }
  int odd = 0;
  for (long long(i) = 0LL; (i) < (100005); (i)++) odd += cnt[i] % 2;
  if (odd > 1) {
    cout << 0 << '\n';
    return 0;
  }
  if (l >= r) {
    cout << (long long)n * (n + 1) / 2 << '\n';
    return 0;
  }
  long long lc = l, rc = n - 1;
  while (lc != rc) {
    int med = lc + (rc - lc) / 2;
    if (chech(l, med)) {
      rc = med;
    } else {
      lc = med + 1;
    }
  }
  long long ans = 0;
  ans += (l + 1) * (n - rc);
  lc = 0, rc = r;
  while (lc != rc) {
    int med = (lc + rc + 1) / 2;
    if (chech(med, r)) {
      lc = med;
    } else {
      rc = med - 1;
    }
  }
  ans += (lc - l) * (l + 1);
  cout << ans << '\n';
  return 0;
}

```