#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 100007;
int n;
int a[MAXN], ra[MAXN];
int cc[MAXN];
void init();
void input();
void work();
int getok(int b[], int pos);
bool check(int b[], int tst);
int main() {
  init();
  input();
  work();
}
void init() { ios::sync_with_stdio(false); }
void input() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
}
void work() {
  memset(cc, 0, sizeof(cc));
  for (int i = 1; i <= n; ++i) ++cc[a[i]];
  bool flag = false;
  for (int i = 1; i <= n; ++i) {
    if (cc[i] & 1) {
      if (flag) {
        printf("0\n");
        return;
      } else
        flag = true;
    }
  }
  flag = true;
  for (int i = 1; i <= n >> 1; ++i) {
    if (a[i] ^ a[n - i + 1]) {
      flag = false;
      break;
    }
  }
  if (flag) {
    printf("%I64d\n", static_cast<long long>(n) * (n + 1) >> 1);
    return;
  }
  int ml = 1, mr = n;
  while (a[ml] == a[mr]) ++ml, --mr;
  long long ans = -static_cast<long long>(ml) * ml;
  ans += static_cast<long long>(ml) * getok(a, ml);
  for (int i = 1; i <= n; ++i) ra[i] = a[n - i + 1];
  ans += static_cast<long long>(ml) * getok(ra, ml);
  printf("%I64d\n", ans);
}
int getok(int b[], int pos) {
  int l = pos + 1, r = n, mid;
  while (l < r) {
    mid = (l + r) >> 1;
    if (check(b, mid))
      r = mid;
    else
      l = mid + 1;
  }
  return (n - l + 1);
}
bool check(int b[], int tst) {
  if (tst <= (n >> 1)) {
    int nl = tst + 1, nr = (n - tst);
    while (nl < nr) {
      if (b[nl] ^ b[nr]) return false;
      ++nl, --nr;
    }
  }
  memset(cc, 0, sizeof(cc));
  for (int i = 1; i <= tst; ++i) ++cc[b[i]];
  if (tst > (n >> 1)) tst = n - tst;
  for (int i = 1; i <= tst; ++i) {
    --cc[b[n - i + 1]];
    if (cc[b[n - i + 1]] < 0) return false;
  }
  return true;
}
