#include <bits/stdc++.h>
using namespace std;
namespace IO {
const int sz = 1 << 15;
char inbuf[sz], outbuf[sz];
char *pinbuf = inbuf + sz;
char *poutbuf = outbuf;
inline char _getchar() {
  if (pinbuf == inbuf + sz) fread(inbuf, 1, sz, stdin), pinbuf = inbuf;
  return *(pinbuf++);
}
inline void _putchar(char x) {
  if (poutbuf == outbuf + sz) fwrite(outbuf, 1, sz, stdout), poutbuf = outbuf;
  *(poutbuf++) = x;
}
inline void flush() {
  if (poutbuf != outbuf)
    fwrite(outbuf, 1, poutbuf - outbuf, stdout), poutbuf = outbuf;
}
}  // namespace IO
inline int read() {
  int v = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    v = v * 10 + c - '0';
    c = getchar();
  }
  return v * f;
}
const int Maxn = 100005;
int n, a[Maxn], Mxp, cnt[Maxn];
bool check(int l, int r) {
  memset(cnt, 0, sizeof(cnt));
  for (int i = l; i <= r; i++) cnt[a[i]]++;
  for (int i = 1; i <= n; i++) {
    if ((i < l || i > r)) {
      if (n + 1 - i < l || n + 1 - i > r) {
        if (a[i] != a[n + 1 - i]) return false;
      }
    }
  }
  for (int i = l; i <= r; i++) {
    if (n + 1 - i < l || n + 1 - i > r) {
      if (!cnt[a[n + 1 - i]]) return false;
      cnt[a[n + 1 - i]]--;
    }
  }
  int f = 0;
  for (int i = 1; i <= n; i++) {
    if (cnt[i] & 1) f++;
  }
  if (f > 1) return false;
  return true;
}
int main() {
  srand(time(0));
  n = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  Mxp = 0;
  bool flag = true;
  for (int i = 1; i < n + 1 - i; i++) {
    if (a[i] != a[n + 1 - i]) {
      flag = false;
      break;
    }
    Mxp = i;
  }
  if (flag) {
    printf("%lld\n", 1ll * n * (n + 1) / 2);
    return 0;
  }
  int l = Mxp + 1, r = n + 1 - l;
  if (!check(l, r)) {
    printf("0\n");
    return 0;
  }
  long long ans = 1ll * (Mxp + 1) * (Mxp + 1);
  int lo = l - 1, hi = r;
  while (hi - lo > 1) {
    int mid = lo + hi >> 1;
    if (check(l, mid))
      hi = mid;
    else
      lo = mid;
  }
  ans += 1ll * (Mxp + 1) * (r - hi);
  lo = l, hi = r + 1;
  while (hi - lo > 1) {
    int mid = lo + hi >> 1;
    if (check(mid, r))
      lo = mid;
    else
      hi = mid;
  }
  ans += 1ll * (Mxp + 1) * (lo - l);
  printf("%lld\n", ans);
}
