#include <bits/stdc++.h>
using namespace std;
int n;
int a[100001];
int pmid;
int pfromside;
char sideequal[50001];
int leftplenty, rightplenty;
int ln[100001] = {0}, rn[100001] = {0};
int wn1[100001] = {0}, wn2[100001] = {0};
int possible(int l, int r) {
  int includemid;
  int left = l - 1;
  int right = n - r;
  int width = r - l + 1;
  if (n & 1)
    includemid = (l <= (n / 2 + 1) && r >= (n / 2 + 1));
  else
    includemid = (l <= (n / 2) && r > (n / 2));
  if (includemid) {
    if (left < right)
      return (left <= pfromside) && (right <= rightplenty);
    else
      return (right <= pfromside) && (left <= leftplenty);
  } else {
    int side;
    if (left < right)
      side = left;
    else
      side = right;
    return (side <= pfromside) && ((n - side - side - width - width) <= pmid) &&
           (sideequal[side + width]);
  }
}
int findminr(int l) {
  int no, yes;
  if (!possible(l, n)) return 0;
  yes = n;
  if (possible(l, l)) return l;
  no = l;
  while (no != yes - 1) {
    int newmid = (yes + no) / 2;
    if (possible(l, newmid))
      yes = newmid;
    else
      no = newmid;
  }
  return yes;
}
int main() {
  int i;
  int minr;
  long long total = 0;
  int lj, rj;
  cin >> n;
  for (i = 1; i <= n; i++) cin >> a[i];
  for (i = 1; i <= n / 2; i++) {
    if (a[i] != a[n - i + 1]) break;
  }
  pfromside = i - 1;
  pmid = n & 1;
  lj = n / 2;
  rj = n / 2 + 1 + (n & 1);
  for (i = 0; i < n / 2; i++) {
    if (a[lj] != a[rj]) break;
    lj--;
    rj++;
  }
  pmid += i * 2;
  int wasequal, diffn = 0;
  lj = 1;
  rj = n;
  sideequal[0] = 1;
  for (i = 1; i <= n / 2; i++) {
    wasequal = (ln[a[lj]] == rn[a[lj]]);
    ln[a[lj]]++;
    if (ln[a[lj]] == rn[a[lj]])
      diffn--;
    else if (wasequal)
      diffn++;
    wasequal = (ln[a[rj]] == rn[a[rj]]);
    rn[a[rj]]++;
    if (ln[a[rj]] == rn[a[rj]])
      diffn--;
    else if (wasequal)
      diffn++;
    if (diffn == 0)
      sideequal[i] = 1;
    else
      sideequal[i] = 0;
    lj++;
    rj--;
  }
  int odds = 0;
  for (i = 1; i <= n; i++) {
    wn1[a[i]]++;
    wn2[a[i]]++;
    if (wn1[a[i]] & 1)
      odds++;
    else
      odds--;
  }
  if (odds > 1) {
    cout << 0;
    return 0;
  }
  lj = 1;
  for (i = 0; i < n / 2; i++) {
    wn1[a[lj]] -= 2;
    if (wn1[a[lj]] < 0) break;
    lj++;
  }
  leftplenty = i;
  rj = n;
  for (i = 0; i < n / 2; i++) {
    wn2[a[rj]] -= 2;
    if (wn2[a[rj]] < 0) break;
    rj--;
  }
  rightplenty = i;
  for (i = 1; i <= n; i++) {
    minr = findminr(i);
    if (minr) total = total + (long long)(n - minr + 1);
  }
  cout << total;
  return 0;
}

### Prompt

Generate 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 n;
int a[100001];
int pmid;
int pfromside;
char sideequal[50001];
int leftplenty, rightplenty;
int ln[100001] = {0}, rn[100001] = {0};
int wn1[100001] = {0}, wn2[100001] = {0};
int possible(int l, int r) {
  int includemid;
  int left = l - 1;
  int right = n - r;
  int width = r - l + 1;
  if (n & 1)
    includemid = (l <= (n / 2 + 1) && r >= (n / 2 + 1));
  else
    includemid = (l <= (n / 2) && r > (n / 2));
  if (includemid) {
    if (left < right)
      return (left <= pfromside) && (right <= rightplenty);
    else
      return (right <= pfromside) && (left <= leftplenty);
  } else {
    int side;
    if (left < right)
      side = left;
    else
      side = right;
    return (side <= pfromside) && ((n - side - side - width - width) <= pmid) &&
           (sideequal[side + width]);
  }
}
int findminr(int l) {
  int no, yes;
  if (!possible(l, n)) return 0;
  yes = n;
  if (possible(l, l)) return l;
  no = l;
  while (no != yes - 1) {
    int newmid = (yes + no) / 2;
    if (possible(l, newmid))
      yes = newmid;
    else
      no = newmid;
  }
  return yes;
}
int main() {
  int i;
  int minr;
  long long total = 0;
  int lj, rj;
  cin >> n;
  for (i = 1; i <= n; i++) cin >> a[i];
  for (i = 1; i <= n / 2; i++) {
    if (a[i] != a[n - i + 1]) break;
  }
  pfromside = i - 1;
  pmid = n & 1;
  lj = n / 2;
  rj = n / 2 + 1 + (n & 1);
  for (i = 0; i < n / 2; i++) {
    if (a[lj] != a[rj]) break;
    lj--;
    rj++;
  }
  pmid += i * 2;
  int wasequal, diffn = 0;
  lj = 1;
  rj = n;
  sideequal[0] = 1;
  for (i = 1; i <= n / 2; i++) {
    wasequal = (ln[a[lj]] == rn[a[lj]]);
    ln[a[lj]]++;
    if (ln[a[lj]] == rn[a[lj]])
      diffn--;
    else if (wasequal)
      diffn++;
    wasequal = (ln[a[rj]] == rn[a[rj]]);
    rn[a[rj]]++;
    if (ln[a[rj]] == rn[a[rj]])
      diffn--;
    else if (wasequal)
      diffn++;
    if (diffn == 0)
      sideequal[i] = 1;
    else
      sideequal[i] = 0;
    lj++;
    rj--;
  }
  int odds = 0;
  for (i = 1; i <= n; i++) {
    wn1[a[i]]++;
    wn2[a[i]]++;
    if (wn1[a[i]] & 1)
      odds++;
    else
      odds--;
  }
  if (odds > 1) {
    cout << 0;
    return 0;
  }
  lj = 1;
  for (i = 0; i < n / 2; i++) {
    wn1[a[lj]] -= 2;
    if (wn1[a[lj]] < 0) break;
    lj++;
  }
  leftplenty = i;
  rj = n;
  for (i = 0; i < n / 2; i++) {
    wn2[a[rj]] -= 2;
    if (wn2[a[rj]] < 0) break;
    rj--;
  }
  rightplenty = i;
  for (i = 1; i <= n; i++) {
    minr = findminr(i);
    if (minr) total = total + (long long)(n - minr + 1);
  }
  cout << total;
  return 0;
}

```