#include <bits/stdc++.h>
using namespace std;
const int N = 150000;
const long long MOD1 = 998244353;
const long long MOD2 = (long long)1e9 + 7;
long long qpow(long long x, long long y, long long MOD) {
  long long ret = 1;
  while (y) {
    if (y & 1) ret = ret * x % MOD;
    x = x * x % MOD;
    y >>= 1;
  }
  return ret;
}
long long a[N], cnt[N], suml_1[N], suml_2[N], sumr_1[N], sumr_2[N], tmp[N],
    ans = 0;
int n;
bool check(int l, int r, int L, int R) {
  if (r < 1 || L > n) return 1;
  long long suml1 = (suml_1[r] - suml_1[l - 1] + MOD1) % MOD1;
  long long suml2 = (suml_2[r] - suml_2[l - 1] + MOD2) % MOD2;
  long long sumr1 = (sumr_1[L] - sumr_1[R + 1] + MOD1) % MOD1;
  long long sumr2 = (sumr_2[L] - sumr_2[R + 1] + MOD2) % MOD2;
  return suml1 == sumr1 && suml2 == sumr2;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    cnt[a[i]]++;
    suml_1[i] = (suml_1[i - 1] + a[i] * qpow(n, i - 1, MOD1) % MOD1) % MOD1;
    suml_2[i] = (suml_2[i - 1] + a[i] * qpow(n, i - 1, MOD2) % MOD2) % MOD2;
  }
  for (int i = n; i >= 1; i--) {
    sumr_1[i] = (sumr_1[i + 1] + a[i] * qpow(n, n - i, MOD1) % MOD1) % MOD1;
    sumr_2[i] = (sumr_2[i + 1] + a[i] * qpow(n, n - i, MOD2) % MOD2) % MOD2;
  }
  int limit_l = n, limit_r = 1;
  int bl = 0;
  for (int i = 0; i < N; i++)
    if (cnt[i] % 2 == 1) bl++;
  if (bl > 1) {
    puts("0");
    return 0;
  }
  int add = 0, mx = 0;
  for (int i = 1; i < (1 + n + 1) / 2; i++) {
    tmp[a[i]]++;
    if (tmp[a[i]] * 2 > cnt[a[i]]) {
      if (limit_l == n) limit_l = i;
      add++;
    }
  }
  mx = add;
  memset(tmp, 0, sizeof(tmp));
  add = 0;
  for (int i = n; i > (1 + n) / 2; i--) {
    tmp[a[i]]++;
    if (tmp[a[i]] * 2 > cnt[a[i]]) {
      if (limit_r == 1) limit_r = i;
      add++;
    }
  }
  mx = max(mx, add);
  int ju = 0;
  if (limit_l != n || limit_r != 1) ju = 1;
  if (ju) limit_l = min(limit_l, (n + 1) / 2 + 1 - mx);
  for (int i = 1; i <= limit_l; i++) {
    int l = max(limit_r, i), r = n, mid, best = -1;
    if (ju) l = max(l, n / 2 + mx);
    while (l <= r) {
      mid = (l + r) >> 1;
      int bl = 1;
      if (mid < n / 2 && i < n / 2) {
        int len = n / 2 - mid;
        int r_l = (n + 1) / 2 + 1;
        bl = check(mid + 1, n / 2, r_l, r_l + len - 1);
      }
      if (i > (n + 1) / 2 + 1) {
        int len = i - ((n + 1) / 2 + 1);
        int l_r = n / 2;
        bl = check(l_r - len + 1, l_r, ((n + 1) / 2 + 1), i - 1);
      }
      int L = i - 1, R = mid + 1;
      int len = min(L, n - R + 1);
      L = len;
      R = n - len + 1;
      if (check(1, L, R, n) && bl) {
        r = mid - 1;
        best = mid;
      } else
        l = mid + 1;
    }
    if (best != -1) ans += n - best + 1;
  }
  cout << ans << endl;
  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;
const int N = 150000;
const long long MOD1 = 998244353;
const long long MOD2 = (long long)1e9 + 7;
long long qpow(long long x, long long y, long long MOD) {
  long long ret = 1;
  while (y) {
    if (y & 1) ret = ret * x % MOD;
    x = x * x % MOD;
    y >>= 1;
  }
  return ret;
}
long long a[N], cnt[N], suml_1[N], suml_2[N], sumr_1[N], sumr_2[N], tmp[N],
    ans = 0;
int n;
bool check(int l, int r, int L, int R) {
  if (r < 1 || L > n) return 1;
  long long suml1 = (suml_1[r] - suml_1[l - 1] + MOD1) % MOD1;
  long long suml2 = (suml_2[r] - suml_2[l - 1] + MOD2) % MOD2;
  long long sumr1 = (sumr_1[L] - sumr_1[R + 1] + MOD1) % MOD1;
  long long sumr2 = (sumr_2[L] - sumr_2[R + 1] + MOD2) % MOD2;
  return suml1 == sumr1 && suml2 == sumr2;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    cnt[a[i]]++;
    suml_1[i] = (suml_1[i - 1] + a[i] * qpow(n, i - 1, MOD1) % MOD1) % MOD1;
    suml_2[i] = (suml_2[i - 1] + a[i] * qpow(n, i - 1, MOD2) % MOD2) % MOD2;
  }
  for (int i = n; i >= 1; i--) {
    sumr_1[i] = (sumr_1[i + 1] + a[i] * qpow(n, n - i, MOD1) % MOD1) % MOD1;
    sumr_2[i] = (sumr_2[i + 1] + a[i] * qpow(n, n - i, MOD2) % MOD2) % MOD2;
  }
  int limit_l = n, limit_r = 1;
  int bl = 0;
  for (int i = 0; i < N; i++)
    if (cnt[i] % 2 == 1) bl++;
  if (bl > 1) {
    puts("0");
    return 0;
  }
  int add = 0, mx = 0;
  for (int i = 1; i < (1 + n + 1) / 2; i++) {
    tmp[a[i]]++;
    if (tmp[a[i]] * 2 > cnt[a[i]]) {
      if (limit_l == n) limit_l = i;
      add++;
    }
  }
  mx = add;
  memset(tmp, 0, sizeof(tmp));
  add = 0;
  for (int i = n; i > (1 + n) / 2; i--) {
    tmp[a[i]]++;
    if (tmp[a[i]] * 2 > cnt[a[i]]) {
      if (limit_r == 1) limit_r = i;
      add++;
    }
  }
  mx = max(mx, add);
  int ju = 0;
  if (limit_l != n || limit_r != 1) ju = 1;
  if (ju) limit_l = min(limit_l, (n + 1) / 2 + 1 - mx);
  for (int i = 1; i <= limit_l; i++) {
    int l = max(limit_r, i), r = n, mid, best = -1;
    if (ju) l = max(l, n / 2 + mx);
    while (l <= r) {
      mid = (l + r) >> 1;
      int bl = 1;
      if (mid < n / 2 && i < n / 2) {
        int len = n / 2 - mid;
        int r_l = (n + 1) / 2 + 1;
        bl = check(mid + 1, n / 2, r_l, r_l + len - 1);
      }
      if (i > (n + 1) / 2 + 1) {
        int len = i - ((n + 1) / 2 + 1);
        int l_r = n / 2;
        bl = check(l_r - len + 1, l_r, ((n + 1) / 2 + 1), i - 1);
      }
      int L = i - 1, R = mid + 1;
      int len = min(L, n - R + 1);
      L = len;
      R = n - len + 1;
      if (check(1, L, R, n) && bl) {
        r = mid - 1;
        best = mid;
      } else
        l = mid + 1;
    }
    if (best != -1) ans += n - best + 1;
  }
  cout << ans << endl;
  return 0;
}

```