#include <bits/stdc++.h>
using namespace std;
int a[101010], total[101010], cnt1[101010], cnt2[101010];
int main() {
  int n, begin, end, e = 0, pref, suf, mid;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", a + i), total[a[i]]++;
  for (int i = 1; i <= n; i++)
    if (total[i] % 2 == 1) {
      if (n % 2 == 0 || e) {
        puts("0");
        return 0;
      } else
        e = i;
    }
  for (begin = 1, end = n; a[begin] == a[end] && begin <= end;
       total[a[begin++]] -= 2, end--)
    ;
  if (begin >= end) {
    printf("%I64d\n", 1ll * n * (n + 1) / 2);
    return 0;
  }
  mid = (1 + n) >> 1;
  for (pref = end;; pref--) {
    cnt1[a[pref]]++;
    if ((n % 2 == 1 && pref == mid && a[pref] != e) ||
        (pref > mid && cnt1[a[pref]] * 2 > total[a[pref]]) ||
        (pref <= mid && a[pref] != a[n + 1 - pref]))
      break;
  }
  if (n % 2 == 0) mid++;
  for (suf = begin;; suf++) {
    cnt2[a[suf]]++;
    if ((n % 2 == 1 && suf == mid && a[suf] != e) ||
        (suf < mid && cnt2[a[suf]] * 2 > total[a[suf]]) ||
        (suf >= mid && a[suf] != a[n + 1 - suf]))
      break;
  }
  printf("%I64d\n",
         1ll * begin * (n + 1 - pref) + 1ll * (suf - begin) * (n + 1 - end));
  return 0;
}
