#include <bits/stdc++.h>
using namespace std;
long long ans;
int n, i, j, k, l, r, res, mid, a[100005], b[100005];
bool check1(int l, int r) {
  memset(b, 0, sizeof(b));
  for (int j = l; j <= r; j++)
    if (j <= k || j >= n - k + 1) b[a[j]]++;
  bool pd = 1;
  for (int j = r + 1; j <= n - i + 1; j++) {
    if (j > k && j < n - k + 1) continue;
    b[a[j]]--;
    if (b[a[j]] < 0) {
      pd = 0;
      break;
    }
  }
  if (pd) return 1;
  memset(b, 0, sizeof(b));
  for (int j = l; j <= r; j++) b[a[j]]++;
  for (int j = r + 1; j <= n - i + 1; j++) {
    b[a[j]]--;
    if (b[a[j]] < 0) return 0;
  }
  return 1;
}
bool check2(int l, int r) {
  memset(b, 0, sizeof(b));
  for (int j = l; j <= r; j++)
    if (j <= k || j >= n - k + 1) b[a[j]]++;
  bool pd = 1;
  for (int j = i; j < l; j++) {
    if (j > k && j < n - k + 1) continue;
    b[a[j]]--;
    if (b[a[j]] < 0) {
      pd = 0;
      break;
    }
  }
  if (pd) return 1;
  memset(b, 0, sizeof(b));
  for (int j = l; j <= r; j++) b[a[j]]++;
  for (int j = i; j < l; j++) {
    b[a[j]]--;
    if (b[a[j]] < 0) return 0;
  }
  return 1;
}
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]), b[a[i]]++;
  for (i = 0; i <= n; i++)
    if (b[i] & 1) j++;
  if (n % 2 == 0 && j) {
    puts("0");
    return 0;
  }
  if (n % 2 == 1 && j > 1) {
    puts("0");
    return 0;
  }
  for (i = 1; i <= n / 2 && a[i] == a[n - i + 1]; i++)
    ;
  if (i > n / 2) {
    printf("%lld\n", 1ll * n * (n + 1) / 2);
    return 0;
  }
  for (k = n / 2; a[k] == a[n - k + 1]; k--)
    ;
  ans = -(long long)i * i;
  l = i, r = n, res = 0;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (check1(i, mid))
      res = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  if (res) ans += 1ll * i * (n - res + 1);
  l = 1, r = n - i + 1, res = 0;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (check2(mid, n - i + 1))
      res = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  if (res) ans += 1ll * res * i;
  printf("%lld\n", ans);
  return 0;
}
