#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:16777216")
const int inf = 0x3f3f3f3f;
const string debug_line = "yolo";
const double PI = 4 * atan(1);
int a[100001];
int count1[100001];
int b[100001];
bool ispalindrome(int b, int e) {
  bool poss = true;
  for (int(i) = (0); (i) < (e); ++(i)) {
    if (a[i] != a[e - 1 - i]) {
      poss = false;
    }
  }
  return poss;
}
bool check(int len, int n) {
  for (int(i) = (1); (i) < (100001); ++(i)) {
    count1[i] = 0;
  }
  if (len >= (n + 1) / 2) {
    for (int(i) = (0); (i) < (len); ++(i)) {
      count1[b[i]]++;
    }
    for (int(i) = (n - 1); (i) > (len - 1); --(i)) {
      count1[b[i]]--;
    }
    for (int(i) = (n - 1); (i) > (len - 1); --(i)) {
      if (count1[b[i]] < 0) {
        return false;
      }
    }
    bool poss = false;
    for (int(i) = (1); (i) < (n + 1); ++(i)) {
      if (poss && (count1[i] % 2 == 1)) {
        return 0;
      }
      if (count1[i] % 2 == 1) {
        poss = true;
      }
    }
    return 1;
  } else {
    for (int(i) = (len); (i) < (n / 2 + 1); ++(i)) {
      if (b[i] != b[n - 1 - i]) {
        return 0;
      }
    }
    for (int(i) = (0); (i) < (len); ++(i)) {
      count1[b[i]]++;
    }
    for (int(i) = (n - len); (i) < (n); ++(i)) {
      count1[b[i]]--;
    }
    bool poss = false;
    for (int(i) = (1); (i) < (n + 1); ++(i)) {
      if (count1[i]) {
        return 0;
      }
    }
    return true;
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int(i) = (0); (i) < (n); ++(i)) {
    int temp;
    scanf("%d", &temp);
    a[i] = temp;
    count1[temp]++;
  }
  bool num_o = 0;
  for (int(i) = (0); (i) < (n + 1); ++(i)) {
    if (count1[i] % 2 == 1) {
      num_o++;
    }
  }
  if (num_o >= 2) {
    printf("0\n");
    return 0;
  }
  if (ispalindrome(0, n)) {
    long long answer1 = 0;
    answer1 = n;
    answer1 = answer1 * (n + 1);
    answer1 = answer1 / 2;
    printf("%lld\n", answer1);
    return 0;
  }
  int m = 0;
  int prefix = 0;
  int suffix = 0;
  int lastc = 0;
  cerr << "debug_line"
       << " = " << (debug_line) << endl;
  for (int(i) = (0); (i) < (n); ++(i)) {
    if (a[i] != a[n - 1 - i]) {
      lastc = i;
      break;
    }
  }
  for (int(i) = (lastc); (i) < (n - lastc); ++(i)) {
    b[m++] = a[i];
  }
  cerr << "( "
       << "lastc"
       << " , "
       << "m"
       << " ) = ( " << (lastc) << " , " << (m) << " )\n";
  ;
  int h = m + 1;
  int l = 1;
  while (l < h) {
    int mid = (l + h) / 2;
    if (check(mid, m)) {
      h = mid;
    } else {
      l = mid + 1;
    }
  }
  prefix = l - 1;
  cerr << "prefix"
       << " = " << (prefix) << endl;
  reverse(b, b + m);
  h = m + 1;
  l = 1;
  while (l < h) {
    int mid = (l + h) / 2;
    if (check(mid, m)) {
      h = mid;
    } else {
      l = mid + 1;
    }
  }
  suffix = l - 1;
  cerr << "suffix"
       << " = " << (suffix) << endl;
  long long answer1 = 0;
  if (prefix >= m && suffix >= m) {
    answer1 = 0;
  } else {
    answer1 = (2 * m - prefix - suffix);
    answer1 += answer1 * (long long)lastc;
    answer1 = answer1 + ((long long)lastc) * ((long long)lastc);
    cerr << "answer1"
         << " = " << (answer1) << endl;
    if (prefix < m && suffix < m) {
      answer1--;
    }
  }
  printf("%lld\n", answer1);
  return 0;
}

### Prompt

In Cpp, your task is to solve 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;
#pragma comment(linker, "/STACK:16777216")
const int inf = 0x3f3f3f3f;
const string debug_line = "yolo";
const double PI = 4 * atan(1);
int a[100001];
int count1[100001];
int b[100001];
bool ispalindrome(int b, int e) {
  bool poss = true;
  for (int(i) = (0); (i) < (e); ++(i)) {
    if (a[i] != a[e - 1 - i]) {
      poss = false;
    }
  }
  return poss;
}
bool check(int len, int n) {
  for (int(i) = (1); (i) < (100001); ++(i)) {
    count1[i] = 0;
  }
  if (len >= (n + 1) / 2) {
    for (int(i) = (0); (i) < (len); ++(i)) {
      count1[b[i]]++;
    }
    for (int(i) = (n - 1); (i) > (len - 1); --(i)) {
      count1[b[i]]--;
    }
    for (int(i) = (n - 1); (i) > (len - 1); --(i)) {
      if (count1[b[i]] < 0) {
        return false;
      }
    }
    bool poss = false;
    for (int(i) = (1); (i) < (n + 1); ++(i)) {
      if (poss && (count1[i] % 2 == 1)) {
        return 0;
      }
      if (count1[i] % 2 == 1) {
        poss = true;
      }
    }
    return 1;
  } else {
    for (int(i) = (len); (i) < (n / 2 + 1); ++(i)) {
      if (b[i] != b[n - 1 - i]) {
        return 0;
      }
    }
    for (int(i) = (0); (i) < (len); ++(i)) {
      count1[b[i]]++;
    }
    for (int(i) = (n - len); (i) < (n); ++(i)) {
      count1[b[i]]--;
    }
    bool poss = false;
    for (int(i) = (1); (i) < (n + 1); ++(i)) {
      if (count1[i]) {
        return 0;
      }
    }
    return true;
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int(i) = (0); (i) < (n); ++(i)) {
    int temp;
    scanf("%d", &temp);
    a[i] = temp;
    count1[temp]++;
  }
  bool num_o = 0;
  for (int(i) = (0); (i) < (n + 1); ++(i)) {
    if (count1[i] % 2 == 1) {
      num_o++;
    }
  }
  if (num_o >= 2) {
    printf("0\n");
    return 0;
  }
  if (ispalindrome(0, n)) {
    long long answer1 = 0;
    answer1 = n;
    answer1 = answer1 * (n + 1);
    answer1 = answer1 / 2;
    printf("%lld\n", answer1);
    return 0;
  }
  int m = 0;
  int prefix = 0;
  int suffix = 0;
  int lastc = 0;
  cerr << "debug_line"
       << " = " << (debug_line) << endl;
  for (int(i) = (0); (i) < (n); ++(i)) {
    if (a[i] != a[n - 1 - i]) {
      lastc = i;
      break;
    }
  }
  for (int(i) = (lastc); (i) < (n - lastc); ++(i)) {
    b[m++] = a[i];
  }
  cerr << "( "
       << "lastc"
       << " , "
       << "m"
       << " ) = ( " << (lastc) << " , " << (m) << " )\n";
  ;
  int h = m + 1;
  int l = 1;
  while (l < h) {
    int mid = (l + h) / 2;
    if (check(mid, m)) {
      h = mid;
    } else {
      l = mid + 1;
    }
  }
  prefix = l - 1;
  cerr << "prefix"
       << " = " << (prefix) << endl;
  reverse(b, b + m);
  h = m + 1;
  l = 1;
  while (l < h) {
    int mid = (l + h) / 2;
    if (check(mid, m)) {
      h = mid;
    } else {
      l = mid + 1;
    }
  }
  suffix = l - 1;
  cerr << "suffix"
       << " = " << (suffix) << endl;
  long long answer1 = 0;
  if (prefix >= m && suffix >= m) {
    answer1 = 0;
  } else {
    answer1 = (2 * m - prefix - suffix);
    answer1 += answer1 * (long long)lastc;
    answer1 = answer1 + ((long long)lastc) * ((long long)lastc);
    cerr << "answer1"
         << " = " << (answer1) << endl;
    if (prefix < m && suffix < m) {
      answer1--;
    }
  }
  printf("%lld\n", answer1);
  return 0;
}

```