#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int n;
int a[200000];
int cnt[200000];
int check(int l, int r) {
  int i, j;
  fill(cnt + 1, cnt + n + 1, 0);
  if (r >= n / 2) {
    for (i = l; i <= r; i++) cnt[a[i]]++;
    for (i = r + 1; i <= n - 1 - l; i++) {
      if (!cnt[a[i]]) return 0;
      cnt[a[i]]--;
    }
    int even = 0, odd = 0;
    for (i = 1; i <= n; i++) {
      if (cnt[i] % 2)
        odd++;
      else
        even++;
    }
    if (odd == 1 || odd == 0) return 1;
    return 0;
  } else {
    for (i = l; i <= r; i++) cnt[a[i]]++;
    for (i = n - 1 - l; i >= n - 1 - r; i--) {
      if (!cnt[a[i]]) return 0;
      cnt[a[i]]--;
    }
    for (i = r + 1; i < n / 2; i++) {
      if (a[i] != a[n - 1 - i]) return 0;
    }
    return 1;
  }
}
int main() {
  int i, j, k;
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", &a[i]);
  int u = n;
  for (i = 0; i < n; i++) {
    if (a[i] != a[n - 1 - i]) {
      u = i;
      break;
    }
  }
  if (u == n) {
    return printf("%I64d", (long long)n * (n + 1) / 2), 0;
  }
  if (!check(0, n - 1)) return printf("0"), 0;
  int low = u, high = n - 1 - u, mid;
  while (low <= high) {
    mid = (low + high) / 2;
    if (check(u, mid))
      high = mid - 1;
    else
      low = mid + 1;
  }
  long long u1 = low;
  reverse(a, a + n);
  low = u, high = n - 1 - u, mid;
  while (low <= high) {
    mid = (low + high) / 2;
    if (check(u, mid))
      high = mid - 1;
    else
      low = mid + 1;
  }
  long long u2 = low;
  long long dab = (long long)(u + 1) * (u + 1) +
                  (u + 1) * ((long long)n - 1 - u - u1 + n - 1 - u - u2);
  printf("%I64d", dab);
  return 0;
}
