#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
map<int, int> bal;
long long ans;
int b[N], a[N];
int n, sdfadf, asdf, mxSuf, cntNeg;
void read() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
}
void add(int x) {
  if (bal[-x] > 0) {
    bal[-x]--;
    cntNeg--;
  } else {
    bal[x]++;
  }
}
void erase(int x) {
  if (bal[x] > 0) {
    bal[x]--;
  } else {
    bal[-x]++;
    cntNeg++;
  }
}
int mirror(int x) { return n - x - 1; }
void nextStep1() {
  if (sdfadf <= mirror(asdf)) {
    add(a[asdf]);
    add(a[asdf]);
  } else {
    add(a[asdf]);
    erase(a[mirror(asdf)]);
  }
  asdf++;
}
void nextStep2() {
  add(a[asdf]);
  erase(a[mirror(asdf)]);
  asdf++;
}
void solve() {
  int lastLeft = n / 2;
  int firstRight = (n + 1) / 2;
  for (int i = 0; i < n; i++) b[a[i]]++;
  int cntOdd = 0;
  for (int i = 1; i <= n; i++) cntOdd += b[i] % 2;
  if (cntOdd != n % 2) {
    printf("0\n");
    exit(0);
  }
  mxSuf = 0;
  ans = 0;
  for (; mxSuf < lastLeft && a[mxSuf] == a[n - mxSuf - 1]; mxSuf++)
    ;
  cntNeg = 0;
  bal.clear();
  for (int i = 0; i < lastLeft + 1; i++) add(a[i]);
  for (int i = lastLeft + 1; i < n; i++) erase(a[i]);
  asdf = lastLeft + 1;
  for (sdfadf = 0; sdfadf < firstRight; sdfadf++) {
    while (asdf <= n) {
      int mnSuf = min(sdfadf, n - asdf);
      if (mnSuf > mxSuf || cntNeg > 0) {
        nextStep1();
        continue;
      }
      break;
    }
    ans += n - asdf + 1;
    if (sdfadf <= mirror(asdf)) {
      erase(a[sdfadf]);
      add(a[mirror(sdfadf)]);
    } else {
      erase(a[sdfadf]);
      erase(a[sdfadf]);
    }
  }
  int mxC = 0;
  for (; firstRight + mxC < n &&
         a[firstRight + mxC] == a[mirror(firstRight + mxC)];
       mxC++)
    ;
  int tmp = mirror(firstRight + mxC) + 1;
  long long ans2 = 0;
  bal.clear();
  cntNeg = 0;
  asdf = 0;
  for (sdfadf = 0; sdfadf <= mxSuf; sdfadf++) {
    while (asdf <= lastLeft) {
      if (asdf < tmp || cntNeg > 0 || sdfadf >= asdf) {
        nextStep2();
        continue;
      }
      break;
    }
    ans2 += lastLeft - asdf + 1;
    erase(a[sdfadf]);
    add(a[mirror(sdfadf)]);
  }
  ans += ans2 * 2;
}
int main() {
  read();
  solve();
  printf("%lld\n", ans);
  return 0;
}
