#include <bits/stdc++.h>
using namespace std;
int n;
int a[100514];
int c[100514];
long long int c2(long long int k) { return k * (k + 1) / 2; }
long long int f(long long int a, long long int b, long long int c,
                long long int d) {
  return (a + 1) * (n - b) + (c - a) * (n - d);
}
long long int sol() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  int fff = 1;
  for (int i = 0; i < n; i++) {
    if (a[i] != a[n - 1 - i]) fff = 0;
  }
  if (fff) {
    return c2(n);
  }
  for (int i = 1; i <= n; i++) c[i] = 0;
  for (int i = 0; i < n; i++) {
    c[a[i]] ^= 1;
  }
  fff = 0;
  int odd = 0;
  for (int i = 1; i <= n; i++) {
    fff += c[i];
    if (c[i]) odd = i;
  }
  if (n % 2 == 0 && fff != 0) return 0;
  if (n % 2 == 1 && fff != 1) return 0;
  if (n % 2) c[odd] ^= 1;
  int x = 0;
  for (; x < n; x++) {
    if (a[x] != a[n - 1 - x]) break;
  }
  int l = 0;
  if (n % 2 == 0) {
    for (; l < n / 2 + 0 && a[n / 2 - 1 - l] == a[n / 2 + l]; l++)
      ;
  } else {
    for (; l < n / 2 + 1 && a[n / 2 - l] == a[n / 2 + l]; l++)
      ;
  }
  int y = x;
  fff = 0;
  for (; y < n / 2; y++) {
    c[a[y]]++;
    if (c[a[y]] == 0)
      fff--;
    else if (c[a[y]] == +1)
      fff++;
    c[a[n - 1 - y]]--;
    if (c[a[n - 1 - y]] == 0)
      fff--;
    else if (c[a[n - 1 - y]] == -1)
      fff++;
    if (fff == 0 && y + l >= (n - 1) / 2) {
      return f(x, y, (n - 1) - y, n - 1 - x);
    }
  }
  for (int k = 0, la, lb; k < 2; k++) {
    for (int i = 1; i <= n; i++) c[i] = 0;
    for (int i = x; i < n / 2; i++) c[a[i]]++;
    fff = 0;
    if (odd) {
      c[odd]--;
      if (c[odd] == -1) fff--;
    }
    for (int i = n / 2; i <= n - 1 - x; i++) {
      c[a[i]]--;
      if (c[a[i]] == -1) fff--;
    }
    for (y = n / 2; y <= n - 1 - x; y++) {
      c[a[y]] += 2;
      if (c[a[y]] == 0) fff++;
      if (fff == 0) {
        if (k == 0) {
          la = x;
          lb = y;
        } else {
          return f(la, lb, (n - 1) - y, n - 1 - x);
        }
        break;
      }
    }
    for (int i = 0; i + i < n; i++) swap(a[i], a[n - 1 - i]);
  }
  return 7122;
}
int main() {
  while (1) {
    long long int ans = sol();
    printf("%I64d\n", ans);
    break;
  }
  return 0;
}
