#include <bits/stdc++.h>
using namespace std;
const int maxn = 100001;
int a[maxn];
int b[maxn];
long long int n;
bool is(int r) {
  memset(b, 0, sizeof b);
  for (int i = 0; i < r; i++) {
    ++b[a[i]];
  }
  for (int i = 0; i < r; i++) {
    if (n - i - 1 >= r) {
      --b[a[n - i - 1]];
      if (b[a[n - i - 1]] < 0) return false;
    }
  }
  for (int i = r; i < n; i++) {
    if (n - i - 1 < r)
      break;
    else {
      if (a[i] != a[n - i - 1]) return false;
    }
  }
  int odd = 0;
  for (int i = 0; i < n; i++) {
    odd += b[i] % 2;
  }
  if (n % 2 == 1 && odd <= 1)
    return true;
  else if (odd == 0)
    return true;
  else
    return false;
}
int main() {
  scanf("%lld", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  int l = 0;
  while (l < n && a[l] == a[n - l - 1]) ++l;
  if (l * 2 >= n)
    printf("%lld\n", (n * (n + 1)) / 2);
  else {
    int ri = n + 1;
    int le = l;
    while (le + 1 < ri) {
      int mid = (le + ri) >> 1;
      if (is(mid)) {
        ri = mid;
      } else
        le = mid;
    }
    if (ri == n + 1) {
      printf("0\n");
      return 0;
    }
    int z1 = ri;
    reverse(a, a + n);
    le = l;
    ri = n + 1;
    while (le + 1 < ri) {
      int mid = (le + ri) >> 1;
      if (is(mid)) {
        ri = mid;
      } else
        le = mid;
    }
    int z2 = ri;
    long long ans = ((long long)l + 1) * ((long long)l + 1);
    if (z1 + l < n) ans += ((long long)l + 1) * ((long long)n - z1 - l);
    if (z2 + l < n) ans += ((long long)l + 1) * ((long long)n - z2 - l);
    printf("%lld\n", ans);
  }
  return 0;
}
