#include <bits/stdc++.h>
using namespace std;
int n;
int str[1000000];
int fr[1000000];
int fr_copy[1000000];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &str[i]);
    fr[str[i]]++;
  }
  int evens = 0;
  for (int i = 1; i < n + 1; i++)
    if (fr[i] % 2) evens++;
  if (evens != n % 2) {
    puts("0\n");
    return 0;
  }
  int L = 0, R = n - 1;
  while (L <= R) {
    if (str[L] != str[R]) break;
    fr[str[L]] -= 2;
    L++;
    R--;
  }
  if (L > R) {
    printf("%lld\n", (long long)n * (n + 1) / 2);
    return 0;
  }
  for (int i = 1; i < n + 1; i++) fr_copy[i] = fr[i];
  int prefix = 0;
  int suffix = 0;
  int p;
  bool ok = true;
  for (p = L; R - p >= p - L; p++) {
    if (R - p == p - L)
      fr[str[p]]--;
    else
      fr[str[p]] -= 2;
    if (fr[str[p]] < 0) {
      ok = false;
      break;
    }
    prefix++;
  }
  if (ok) {
    for (; p <= R; p++) {
      if (str[p] != str[L + R - p]) break;
      prefix++;
    }
  }
  ok = true;
  for (p = R; R - p <= p - L; p--) {
    if (R - p == p - L)
      fr_copy[str[p]]--;
    else
      fr_copy[str[p]] -= 2;
    if (fr_copy[str[p]] < 0) {
      ok = false;
      break;
    }
    suffix++;
  }
  if (ok) {
    for (; p >= L; p--) {
      if (str[p] != str[L + R - p]) break;
      suffix++;
    }
  }
  printf("%lld\n", (long long)(L + 1) * (L + 1) + (long long)(L + 1) * prefix +
                       (long long)(L + 1) * suffix);
  return 0;
}
