#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 9;
int n, a[N], cnt[N], cnt2[N], b1, b2;
void Add(int x, int y) {
  if (cnt[x] & 1) --b2;
  if (cnt[x] < 0) --b1;
  cnt[x] += y;
  if (cnt[x] < 0) ++b1;
  if (cnt[x] & 1) ++b2;
}
int main() {
  while (scanf("%d", &n) == 1) {
    long long ret = 0;
    b1 = b2 = 0;
    for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
    int l = 1, r = n;
    int mid = (l + r) / 2;
    for (; l + 1 < r && a[l] == a[r]; ++l, --r)
      ;
    if (l + 1 >= r) {
      printf("%I64d\n", 1ll * n * (n + 1) / 2);
      continue;
    }
    for (int i = l; i <= r; ++i) Add(a[i], 1);
    int qr = r;
    for (; b1 == 0 && b2 == (n & 1) && qr >= l; --qr) {
      if (qr <= mid) {
        if (a[qr] != a[1 + n - qr]) {
          --qr;
          break;
        }
        if ((n & 1) && qr == mid && !(cnt[a[qr]] & 1)) {
          --qr;
          break;
        }
      }
      if (qr > mid) Add(a[qr], -1), Add(a[qr], -1);
    }
    ret += 1ll * (n - qr) * l;
    for (int i = 0; i <= n; ++i) cnt[i] = cnt2[i] = 0;
    b1 = b2 = 0;
    for (int i = l; i <= r; ++i) Add(a[i], 1);
    int ql = l;
    mid = (l + r - 1) / 2;
    for (; b1 == 0 && b2 == (n & 1) && ql <= r; ++ql) {
      if (ql <= mid)
        Add(a[ql], -1), Add(a[ql], -1);
      else {
        if (a[ql] != a[1 + n - ql]) break;
        if ((n & 1) && ql == mid && !(cnt[a[ql]] & 1)) break;
      }
      if (!(b1 == 0 && b2 == (n & 1))) break;
      ret += n - r + 1;
    }
    for (int i = 0; i <= n; ++i) cnt[i] = cnt2[i] = 0;
    printf("%I64d\n", ret);
  }
  return 0;
}
