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.
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 5;
int arr[MAX_N];
int cnt[MAX_N];
int cntl[MAX_N];
int cntr[MAX_N];
int main() {
  long long n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    cnt[arr[i]]++;
  }
  int cntodd = 0;
  for (int i = 1; i <= n; i++) {
    if (cnt[i] % 2 == 1) {
      cntodd++;
    }
  }
  if (cntodd > 1) {
    cout << 0 << endl;
    return 0;
  }
  bool palin = true;
  for (int i = 0; i < n / 2; i++) {
    if (arr[i] != arr[n - i - 1]) {
      palin = false;
    }
  }
  if (palin) {
    cout << (long long)n * (long long)(n + 1) / 2 << endl;
    return 0;
  }
  long long lfa = n / 2;
  for (int i = 0; i < n / 2; i++) {
    cntl[arr[i]]++;
    if (cntl[arr[i]] > cnt[arr[i]] / 2) {
      lfa = i;
      break;
    }
  }
  long long rga = n - n / 2 - 1;
  for (int i = 0; i < n / 2; i++) {
    cntr[arr[n - i - 1]]++;
    if (cntr[arr[n - i - 1]] > cnt[arr[n - i - 1]] / 2) {
      rga = n - i - 1;
      break;
    }
  }
  long long lfb = n + 5;
  long long rgb = -5;
  for (int i = 0; i < n / 2; i++) {
    if (arr[i] != arr[n - i - 1]) {
      lfb = min(lfb, (long long)i);
      rgb = max(rgb, (long long)i);
    }
  }
  long long lfc = n - rgb - 1;
  long long rgc = n - lfb - 1;
  cerr << lfa << " " << rga << " " << lfb << " " << rgb << " " << lfc << " "
       << rgc << endl;
  if (rga - lfa <= 0) {
    long long ans =
        (1 + lfb) * (n - rgb) + (1 + lfc) * (n - rgc) - (1 + lfb) * (n - rgc);
    cout << ans << endl;
    return 0;
  } else {
    long long ans = min(1 + lfa, 1 + lfb) * (n - rga) +
                    (1 + lfa) * (n - max(rgb, rgc)) -
                    min(1 + lfa, 1 + lfb) * (n - max(rgb, rgc));
    cout << ans << endl;
    return 0;
  }
}
