#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 1e6 + 10;
const long long INF = 1e18;
const long double EPS = 1e-12;
int n, m, a[100005], b[100005];
int freq[100005];
void init() {
  cin >> n;
  for (int i = 0; i < (int)n; i++) {
    cin >> a[i];
  }
  int l = 0, r = n - 1;
  while (l <= r && a[l] == a[r]) m++, l++, r--;
  if (l > r) {
    cout << (long long)(n) * (n + 1) / 2LL << endl;
    exit(0);
  }
  n = 0;
  for (int i = (int)l; i < (int)r + 1; i++) {
    b[n++] = a[i];
  }
}
int main() {
  init();
  long long ans = 0;
  auto go = [&](int l) {
    memset(freq, 0, sizeof(freq));
    for (int i = 0; i < (int)l + 1; i++) freq[b[i]]++;
    for (int i = 0; i < n - 1 - i; i++) {
      if (i <= l && n - 1 - i > l) {
        if (not freq[b[n - 1 - i]]) return false;
        freq[b[n - 1 - i]]--;
      } else if (i > l) {
        if (b[i] != b[n - 1 - i]) return false;
      }
    }
    int tmp = 0;
    for (int i = (int)1; i < (int)n + 1; i++) {
      tmp += (freq[i] % 2);
    }
    return tmp <= 1;
  };
  auto binSearch = [&]() {
    int lo = 0, hi = n;
    while (lo < hi) {
      int mid = (lo + hi) / 2;
      if (go(mid))
        hi = mid;
      else
        lo = mid + 1;
    }
    ans += n - lo;
  };
  binSearch();
  reverse(b, b + n);
  binSearch();
  if (ans == 0)
    cout << "0" << endl;
  else
    cout << (long long)(m + 1) * (ans + m - 1) << endl;
  return 0;
}

### Prompt

Develop a solution in CPP 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 mod = 1e9 + 7;
const int N = 1e6 + 10;
const long long INF = 1e18;
const long double EPS = 1e-12;
int n, m, a[100005], b[100005];
int freq[100005];
void init() {
  cin >> n;
  for (int i = 0; i < (int)n; i++) {
    cin >> a[i];
  }
  int l = 0, r = n - 1;
  while (l <= r && a[l] == a[r]) m++, l++, r--;
  if (l > r) {
    cout << (long long)(n) * (n + 1) / 2LL << endl;
    exit(0);
  }
  n = 0;
  for (int i = (int)l; i < (int)r + 1; i++) {
    b[n++] = a[i];
  }
}
int main() {
  init();
  long long ans = 0;
  auto go = [&](int l) {
    memset(freq, 0, sizeof(freq));
    for (int i = 0; i < (int)l + 1; i++) freq[b[i]]++;
    for (int i = 0; i < n - 1 - i; i++) {
      if (i <= l && n - 1 - i > l) {
        if (not freq[b[n - 1 - i]]) return false;
        freq[b[n - 1 - i]]--;
      } else if (i > l) {
        if (b[i] != b[n - 1 - i]) return false;
      }
    }
    int tmp = 0;
    for (int i = (int)1; i < (int)n + 1; i++) {
      tmp += (freq[i] % 2);
    }
    return tmp <= 1;
  };
  auto binSearch = [&]() {
    int lo = 0, hi = n;
    while (lo < hi) {
      int mid = (lo + hi) / 2;
      if (go(mid))
        hi = mid;
      else
        lo = mid + 1;
    }
    ans += n - lo;
  };
  binSearch();
  reverse(b, b + n);
  binSearch();
  if (ans == 0)
    cout << "0" << endl;
  else
    cout << (long long)(m + 1) * (ans + m - 1) << endl;
  return 0;
}

```