#include <bits/stdc++.h>
int static const N = 100000;
using namespace std;
int a[N], n, l, d, broj[N], broj2[N];
bool ql[N], qd[N];
bool valja(int i, int j) {
  if (i >= l && j >= d && ql[i] == true) return true;
  if (i <= l && j >= d) return true;
  if (i <= l && j <= d && qd[j] == true) return true;
  return false;
}
void rad() {
  long long int rez = 0;
  for (int i = 1; i <= n; i++) {
    int j = n;
    if (ql[i] == false) break;
    int kl, kd;
    if (valja(i, j) == true) {
      kl = i;
      kd = j - 1;
      if (kl < kd) {
        while (kl != kd) {
          if (valja(i, (kl + kd) / 2) == true)
            kd = (kl + kd) / 2;
          else
            kl = (kl + kd) / 2 + 1;
        }
      }
    } else
      break;
    if (valja(i, kl) == false && valja(i, j) == false) break;
    if (valja(i, kl) == false) kl = j;
    rez += n - kl + 1;
  }
  cout << rez << endl;
}
void nam() {
  long long int suma = 0, sump = 0;
  l = 1;
  d = n;
  while (a[l] == a[d] && l + 2 <= d) {
    l++;
    d--;
  }
  int kk = 0;
  for (int i = 1; i <= n; i++) {
    suma += a[i];
    if (i <= n / 2) sump += a[i];
    broj[a[i]]++;
    if (broj[a[i]] == 1 && i <= n / 2) kk++;
    ql[i] = true;
  }
  if (n % 2 == 0) {
    if (sump < suma - sump) {
      for (int i = n / 2 + 1; i <= n; i++) ql[i] = false;
    }
  } else {
    if (sump < suma - sump - a[n / 2 + 1])
      for (int i = n / 2 + 1; i <= n; i++) ql[i] = false;
  }
  sump = 0;
  for (int i = 1; i <= n; i++)
    if ((n % 2 == 0 && i > n / 2) || (n % 2 == 1 && i > n / 2 + 1))
      sump += a[i];
  for (int i = 1; i <= n; i++) {
    broj2[a[i]]++;
    if (broj2[a[i]] >= broj[a[i]] / 2 && i <= n / 2 &&
        broj2[a[i]] - 1 <= broj[a[i]] / 2)
      kk--;
    if ((broj2[a[i]] > broj[a[i]] / 2 && i <= n / 2) || (i > n / 2 && kk > 0)) {
      for (int j = i + 1; j <= n; j++) ql[j] = false;
      break;
    }
  }
  for (int i = n; i > 0; i--) broj[a[i]] = 0;
  kk = 0;
  for (int i = n; i > 0; i--) {
    broj[a[i]]++;
    if (broj[a[i]] == 1 && i >= n / 2) kk++;
    broj2[i] = 0;
    qd[i] = true;
  }
  for (int i = n; i >= 0; i--) {
    broj2[a[i]]++;
    if (broj2[a[i]] >= broj[a[i]] / 2 && i >= n / 2 &&
        broj2[a[i]] - 1 <= broj[a[i]] / 2)
      kk--;
    if ((broj2[a[i]] > broj[a[i]] / 2 &&
         ((n % 2 == 0 && i >= n / 2 + 1) || (n % 2 == 1 && i > n / 2 + 1))) ||
        (i < n / 2 && kk > 0)) {
      for (int j = i - 1; j >= 0; j--) qd[j] = false;
      break;
    }
  }
  if (n % 2 == 1) {
    if (sump < suma - sump - a[n / 2 + 1])
      for (int i = n / 2; i > 0; i--) qd[i] = false;
  } else {
    if (sump < suma - sump)
      for (int i = n / 2; i > 0; i--) qd[i] = false;
  }
  if (n % 2 == 0) {
    int y = n / 2;
    for (int i = 1; i < n / 2; i++) {
      if (a[y - i + 1] != a[y + i]) {
        for (int j = y + i + 1; j <= n; j++) ql[j] = false;
        for (int j = y - i; j > 0; j--) qd[j] = false;
        break;
      }
    }
  } else {
    int y = n / 2 + 1;
    for (int i = 1; i < n / 2; i++) {
      if (a[y - i] != a[y + i]) {
        for (int j = y + i + 1; j <= n; j++) ql[j] = false;
        for (int j = y - i - 1; j > 0; j--) qd[j] = false;
        break;
      }
    }
  }
  int bn = 0;
  for (int i = 1; i < N; i++)
    if (broj[i] % 2 == 1) bn++;
  if (bn > 1)
    printf("0\n");
  else
    rad();
}
int main() {
  scanf("%i", &n);
  for (int i = 1; i <= n; i++) scanf("%i", &a[i]);
  nam();
  return 0;
}
