#include <bits/stdc++.h>
using namespace std;
int _pow(int a, int b, int mo) {
  int tmp = 1;
  a %= mo;
  for (; b; b >>= 1) {
    if (b & 1) tmp = (long long)tmp * a % mo;
    a = (long long)a * a % mo;
  }
  return tmp;
}
template <class T>
inline void R(T &xx) {
  xx = 0;
  char ch = getchar();
  bool F = 0;
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') F = 1, ch = getchar();
  while (ch >= '0' && ch <= '9')
    xx = xx + xx + (xx << 3) + ch - 48, ch = getchar();
  if (F) xx = -xx;
}
int tt, cnt[200011], a[200011], s1, s2, le, ri, n;
long long ans;
inline void modi(int x, int f) {
  tt -= cnt[x] <= 0;
  cnt[x] += f;
  tt += cnt[x] <= 0;
}
bool che(int l, int r) {
  if (min(l - 1, n - r) > s1 - 1) return 0;
  if (r < s2 || l > n - s2 + 1) return 0;
  pair<int, int> p = (n - l + 1 > r)
                         ? make_pair(max(n - r + 1, r + 1), n - l + 1)
                         : make_pair(n - r + 1, min(n - l + 1, l - 1));
  while (le < p.first) modi(a[le++], -1);
  while (le > p.first) modi(a[--le], 1);
  while (ri > p.second) modi(a[ri--], -1);
  while (ri < p.second) modi(a[++ri], 1);
  return tt == n;
}
int main() {
  R(n);
  tt = n;
  for (int i = 1; i <= n; i++) R(a[i]), modi(a[i], 1);
  int l1 = 0;
  for (int i = 1; i <= n; i++)
    if (cnt[i] & 1) l1++;
  if (l1 >= 2) return puts("0"), 0;
  s1 = 1;
  s2 = n + 1 >> 1;
  while (s1 <= n && a[s1] == a[n - s1 + 1]) s1++;
  while (s2 >= 1 && a[s2] == a[n - s2 + 1]) s2--;
  le = 1;
  ri = n;
  int l = 1;
  for (int r = 1; r <= n; r++) {
    modi(a[r], -1);
    while (l <= r && che(l, r)) modi(a[l], 1), l++;
    ans += l - 1;
  }
  cout << ans << endl;
  return 0;
}

### Prompt

Your challenge is to write a cpp solution 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 _pow(int a, int b, int mo) {
  int tmp = 1;
  a %= mo;
  for (; b; b >>= 1) {
    if (b & 1) tmp = (long long)tmp * a % mo;
    a = (long long)a * a % mo;
  }
  return tmp;
}
template <class T>
inline void R(T &xx) {
  xx = 0;
  char ch = getchar();
  bool F = 0;
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') F = 1, ch = getchar();
  while (ch >= '0' && ch <= '9')
    xx = xx + xx + (xx << 3) + ch - 48, ch = getchar();
  if (F) xx = -xx;
}
int tt, cnt[200011], a[200011], s1, s2, le, ri, n;
long long ans;
inline void modi(int x, int f) {
  tt -= cnt[x] <= 0;
  cnt[x] += f;
  tt += cnt[x] <= 0;
}
bool che(int l, int r) {
  if (min(l - 1, n - r) > s1 - 1) return 0;
  if (r < s2 || l > n - s2 + 1) return 0;
  pair<int, int> p = (n - l + 1 > r)
                         ? make_pair(max(n - r + 1, r + 1), n - l + 1)
                         : make_pair(n - r + 1, min(n - l + 1, l - 1));
  while (le < p.first) modi(a[le++], -1);
  while (le > p.first) modi(a[--le], 1);
  while (ri > p.second) modi(a[ri--], -1);
  while (ri < p.second) modi(a[++ri], 1);
  return tt == n;
}
int main() {
  R(n);
  tt = n;
  for (int i = 1; i <= n; i++) R(a[i]), modi(a[i], 1);
  int l1 = 0;
  for (int i = 1; i <= n; i++)
    if (cnt[i] & 1) l1++;
  if (l1 >= 2) return puts("0"), 0;
  s1 = 1;
  s2 = n + 1 >> 1;
  while (s1 <= n && a[s1] == a[n - s1 + 1]) s1++;
  while (s2 >= 1 && a[s2] == a[n - s2 + 1]) s2--;
  le = 1;
  ri = n;
  int l = 1;
  for (int r = 1; r <= n; r++) {
    modi(a[r], -1);
    while (l <= r && che(l, r)) modi(a[l], 1), l++;
    ans += l - 1;
  }
  cout << ans << endl;
  return 0;
}

```