#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000;
int n, a[maxn], cnt[maxn], now[maxn];
inline long long getnum(int l1, int r1, int l2, int r2) {
  return (long long)(l1 + 1) * (n - r1) + (long long)(l2 + 1) * (n - r2) -
         (long long)(l1 + 1) * (n - r2);
}
int main(void) {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
    --a[i];
  }
  int leftmost = 0, rightmost = n - 1;
  while (leftmost <= rightmost && a[leftmost] == a[rightmost]) {
    ++leftmost;
    --rightmost;
  }
  if (leftmost > rightmost) {
    printf("%I64d\n", (long long)n * (n + 1) / 2);
    return 0;
  }
  for (int i = leftmost; i <= rightmost; ++i) {
    ++cnt[a[i]];
  }
  int odd = 0;
  for (int i = 0; i < n; ++i) {
    odd += cnt[i] & 1;
  }
  if (odd != (n & 1)) {
    puts("0");
    return 0;
  }
  for (int i = leftmost; i < n / 2; ++i) {
    ++now[a[i]];
  }
  for (int i = (n + 1) / 2; i <= rightmost; ++i) {
    --now[a[i]];
  }
  bool is_good = true;
  for (int i = 0; i < n; ++i) {
    if (now[i]) {
      is_good = false;
      break;
    }
  }
  long long ans;
  if (is_good) {
    int leftmid = n / 2 - 1, rightmid = (n + 1) / 2;
    while (leftmid >= leftmost && a[leftmid] == a[rightmid]) {
      --leftmid;
      ++rightmid;
    }
    ans = getnum(leftmost, leftmid, rightmid, rightmost);
  } else {
    int rightmid, leftmid;
    memset(now, 0, sizeof now);
    for (int i = rightmost; i >= leftmost; --i) {
      if (++now[a[i]] > cnt[a[i]] / 2) {
        rightmid = i;
        break;
      }
    }
    memset(now, 0, sizeof now);
    for (int i = leftmost; i <= rightmost; ++i) {
      if (++now[a[i]] > cnt[a[i]] / 2) {
        leftmid = i;
        break;
      }
    }
    ans = getnum(leftmost, rightmid, leftmid, rightmost);
  }
  printf("%I64d\n", ans);
  return 0;
}
