#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T qmin(const T a, const T b) {
  return a < b ? a : b;
}
template <typename T>
inline T qmax(const T a, const T b) {
  return a > b ? a : b;
}
template <typename T>
inline void getmin(T &a, const T b) {
  if (a > b) a = b;
}
template <typename T>
inline void getmax(T &a, const T b) {
  if (a < b) a = b;
}
inline void fileio(string s) {
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
}
const int inf = 1e9 + 7;
const long long linf = 1e17 + 7;
const int N = 2e5 + 7;
int a[N], n, pos;
long long ans = 0;
bool ispal() {
  for (int i = 1; i + i <= n; ++i)
    if (a[i] != a[n + 1 - i]) return 0;
  return 1;
}
int num[N];
bool checkodd() {
  memset(num, 0, sizeof(num));
  for (int i = 1; i <= n; ++i) ++num[a[i]];
  int times = 0;
  for (int i = 1; i <= n; ++i)
    if (num[i] & 1) ++times;
  return times < 2;
}
int need[N];
bool check1(int p) {
  memset(need, 0, sizeof(need));
  memset(num, 0, sizeof(num));
  for (int i = p + 1; i <= n - pos + 1; ++i) {
    if (n - i + 1 <= p)
      ++need[a[i]];
    else if (a[n - i + 1] != a[i])
      return false;
  }
  for (int i = pos; i <= p; ++i) {
    ++num[a[i]];
  }
  for (int i = 1; i <= n; ++i)
    if (need[i] > num[i]) return false;
  return true;
}
bool check2(int p) {
  memset(need, 0, sizeof(need));
  memset(num, 0, sizeof(num));
  for (int i = pos; i < p; ++i) {
    if (n - i + 1 >= p)
      ++need[a[i]];
    else if (a[n - i + 1] != a[i])
      return false;
  }
  for (int i = p; i <= n - pos + 1; ++i) {
    ++num[a[i]];
  }
  for (int i = 1; i <= n; ++i)
    if (need[i] > num[i]) return false;
  return true;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
  }
  if (ispal()) {
    printf("%I64d\n", (long long)n + (long long)n * (n - 1) / 2ll);
    return 0;
  } else if (!checkodd()) {
    puts("0");
    return 0;
  }
  int pos = 1;
  while (a[pos] == a[n + 1 - pos]) ++pos;
  ans += (long long)(pos - 1) * (pos - 1);
  {
    int ul = pos - 1, ur = n - pos + 1;
    while (ur - ul > 1) {
      int mid = ul + ur >> 1;
      if (check1(mid))
        ur = mid;
      else
        ul = mid;
    }
    ans += (long long)(n - pos - ur + 2) * (long long)pos;
  }
  {
    int ul = pos, ur = n - pos + 2;
    while (ur - ul > 1) {
      int mid = ul + ur >> 1;
      if (check2(mid))
        ul = mid;
      else
        ur = mid;
    }
    ans += (long long)(ul - pos + 1) * (long long)pos;
  }
  printf("%I64d\n", ans - 1);
  return 0;
}

### 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;
template <typename T>
inline T qmin(const T a, const T b) {
  return a < b ? a : b;
}
template <typename T>
inline T qmax(const T a, const T b) {
  return a > b ? a : b;
}
template <typename T>
inline void getmin(T &a, const T b) {
  if (a > b) a = b;
}
template <typename T>
inline void getmax(T &a, const T b) {
  if (a < b) a = b;
}
inline void fileio(string s) {
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
}
const int inf = 1e9 + 7;
const long long linf = 1e17 + 7;
const int N = 2e5 + 7;
int a[N], n, pos;
long long ans = 0;
bool ispal() {
  for (int i = 1; i + i <= n; ++i)
    if (a[i] != a[n + 1 - i]) return 0;
  return 1;
}
int num[N];
bool checkodd() {
  memset(num, 0, sizeof(num));
  for (int i = 1; i <= n; ++i) ++num[a[i]];
  int times = 0;
  for (int i = 1; i <= n; ++i)
    if (num[i] & 1) ++times;
  return times < 2;
}
int need[N];
bool check1(int p) {
  memset(need, 0, sizeof(need));
  memset(num, 0, sizeof(num));
  for (int i = p + 1; i <= n - pos + 1; ++i) {
    if (n - i + 1 <= p)
      ++need[a[i]];
    else if (a[n - i + 1] != a[i])
      return false;
  }
  for (int i = pos; i <= p; ++i) {
    ++num[a[i]];
  }
  for (int i = 1; i <= n; ++i)
    if (need[i] > num[i]) return false;
  return true;
}
bool check2(int p) {
  memset(need, 0, sizeof(need));
  memset(num, 0, sizeof(num));
  for (int i = pos; i < p; ++i) {
    if (n - i + 1 >= p)
      ++need[a[i]];
    else if (a[n - i + 1] != a[i])
      return false;
  }
  for (int i = p; i <= n - pos + 1; ++i) {
    ++num[a[i]];
  }
  for (int i = 1; i <= n; ++i)
    if (need[i] > num[i]) return false;
  return true;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
  }
  if (ispal()) {
    printf("%I64d\n", (long long)n + (long long)n * (n - 1) / 2ll);
    return 0;
  } else if (!checkodd()) {
    puts("0");
    return 0;
  }
  int pos = 1;
  while (a[pos] == a[n + 1 - pos]) ++pos;
  ans += (long long)(pos - 1) * (pos - 1);
  {
    int ul = pos - 1, ur = n - pos + 1;
    while (ur - ul > 1) {
      int mid = ul + ur >> 1;
      if (check1(mid))
        ur = mid;
      else
        ul = mid;
    }
    ans += (long long)(n - pos - ur + 2) * (long long)pos;
  }
  {
    int ul = pos, ur = n - pos + 2;
    while (ur - ul > 1) {
      int mid = ul + ur >> 1;
      if (check2(mid))
        ul = mid;
      else
        ur = mid;
    }
    ans += (long long)(ul - pos + 1) * (long long)pos;
  }
  printf("%I64d\n", ans - 1);
  return 0;
}

```