#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1E9;
int N, M;
int a[100005], bi[100005], b[100005];
int cntl[100005], cntr[100005], cntall[100005];
bool ok[100005];
int main() {
  cin >> N;
  for (int i = (0); i < (N); i++) scanf("%d", a + i);
  int st = -1;
  for (int i = (0); i < (N / 2); i++) {
    int ri = N - 1 - i;
    if (a[i] != ri[a]) {
      st = i;
      break;
    }
  }
  if (st == -1) {
    long long x = N;
    cout << x * (x + 1) / 2 << endl;
    return 0;
  }
  for (int i = N / 2; i >= 0; i--) {
    if (a[i] != a[N - 1 - i]) {
      break;
    }
    ok[i] = ok[N - 1 - i] = 1;
  }
  bool odd = N % 2;
  for (int i = (st); i < (N - st); i++) {
    b[M] = a[i];
    bi[M++] = i;
  }
  M /= 2;
  int L = 2 * M + odd;
  for (int i = (0); i < (L); i++) cntall[b[i]]++;
  int oddneed = 0;
  for (int v = (1); v < (N + 1); v++)
    if (cntall[v] % 2 == 1) oddneed++;
  if (oddneed > 1) {
    puts("0");
    return 0;
  }
  memset(cntl, 0, sizeof(cntl));
  memset(cntr, 0, sizeof(cntr));
  int need = 0;
  bool hit = 0;
  long long ans = 0;
  for (int i = (0); i < (L); i++) {
    if (i < M) {
      int vl = b[i], vr = b[L - 1 - i];
      if (vl == vr) {
        cntl[vl]++;
        cntr[vl]++;
      } else {
        if (cntl[vl] == cntr[vl] - 1) need--;
        cntl[vl]++;
        if (cntr[vr] == cntl[vr]) need++;
        cntr[vr]++;
      }
    } else {
      int v = b[i];
      if (odd && i == M) {
        if (cntl[v] == cntr[v] - 1) need--;
        cntl[v]++;
      } else {
        if (cntl[v] < cntr[v] && cntl[v] + 1 >= cntr[v] - 1) need--;
        cntl[v]++;
        cntr[v]--;
      }
    }
    if (need == 0) {
      bool valid = 0;
      if (i < M - 1) {
        if (ok[bi[i] + 1]) valid = 1;
      } else
        valid = 1;
      if (valid) {
        long long l = bi[0], r = bi[i];
        hit = 1;
        ans += (l + 1) * (N - r);
        break;
      }
    }
  }
  memset(cntl, 0, sizeof(cntl));
  memset(cntr, 0, sizeof(cntr));
  need = 0;
  for (int i = L - 1; i >= 0; i--) {
    if (i >= L - M) {
      int vr = b[i], vl = b[L - 1 - i];
      if (vl == vr) {
        cntl[vl]++;
        cntr[vl]++;
      } else {
        if (cntr[vr] == cntl[vr] - 1) need--;
        cntr[vr]++;
        if (cntl[vl] == cntr[vl]) need++;
        cntl[vl]++;
      }
    } else {
      int v = b[i];
      if (odd && i == M) {
        if (cntr[v] == cntl[v] - 1) need--;
        cntr[v]++;
      } else {
        if (cntr[v] < cntl[v] && cntr[v] + 1 >= cntl[v] - 1) need--;
        cntr[v]++;
        cntl[v]--;
      }
    }
    if (need == 0) {
      bool valid = 0;
      if (i >= L - M + 1) {
        if (ok[bi[i] - 1]) valid = 1;
      } else
        valid = 1;
      if (valid) {
        long long l = bi[i], r = bi[L - 1];
        ans += (l + 1) * (N - r);
        break;
      }
    }
  }
  if (hit) {
    long long l = bi[0], r = bi[L - 1];
    ans -= (l + 1) * (N - r);
  }
  cout << ans << endl;
  return 0;
}
