#include <bits/stdc++.h>
using namespace std;
int n, b[200010], a[200010], L[200010], R[200010], rL, lL, en, cnt[200010];
long long ans;
bool check(int len) {
  memset(cnt, 0, sizeof(cnt));
  if (len >= (n + 1) / 2) {
    for (int i = 0; i < len; i++) cnt[a[i]]++;
    for (int i = n - 1; i >= len; i--) cnt[a[i]]--;
    for (int i = n - 1; i >= len; i--)
      if (cnt[a[i]] < 0) return 0;
    bool bf = 0;
    for (int i = 1; i <= n; i++) {
      if (bf && (cnt[i] & 1)) return 0;
      if (cnt[i] & 1) bf = 1;
    }
    return 1;
  } else {
    for (int i = len; i <= n / 2; i++)
      if (a[i] != a[n - 1 - i]) return 0;
    for (int i = 0; i < len; i++) cnt[a[i]]++;
    for (int i = n - len; i < n; i++) cnt[a[i]]--;
    bool bf = 0;
    for (int i = 1; i <= n; i++)
      if (cnt[i]) return 0;
    return 1;
  }
}
void calc() {
  int l = 1, r = n + 1;
  while (l < r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  lL = l - 1;
  reverse(a, a + n);
  l = 1, r = n + 1;
  while (l < r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  rL = l - 1;
  if (lL >= n && rL >= n) {
    ans = 0;
    return;
  } else {
    ans = (n - lL + n - rL);
    ans += (1LL * ans * en);
    ans += (1LL * en * en);
    if (lL < n && rL < n) ans--;
  }
  return;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &b[i]);
  en = -1;
  for (int i = 0; i < n; i++) {
    if (b[i] != b[n - i - 1]) {
      en = i;
      break;
    }
  }
  if (en < 0) {
    printf("%I64d\n", 1LL * n * (n + 1) / 2);
    return 0;
  }
  int len = 0;
  for (int i = en; i < n - en; i++) a[len++] = b[i];
  n = len;
  calc();
  printf("%I64d\n", ans);
  return 0;
}
