#include <bits/stdc++.h>
using namespace std;
int n;
int a[100001];
int pmid;
int pfromside;
char sideequal[50001];
int leftplenty, rightplenty;
int ln[100001] = {0}, rn[100001] = {0};
int wn1[100001] = {0}, wn2[100001] = {0};
int possible(int l, int r) {
  int includemid;
  int left = l - 1;
  int right = n - r;
  int width = r - l + 1;
  if (n & 1)
    includemid = (l <= (n / 2 + 1) && r >= (n / 2 + 1));
  else
    includemid = (l <= (n / 2) && r > (n / 2));
  if (includemid) {
    if (left < right)
      return (left <= pfromside) && (right <= rightplenty);
    else
      return (right <= pfromside) && (left <= leftplenty);
  } else {
    int side;
    if (left < right)
      side = left;
    else
      side = right;
    return (side <= pfromside) && ((n - side - side - width - width) <= pmid) &&
           (sideequal[side + width]);
  }
}
int findminr(int l) {
  int no, yes;
  if (!possible(l, n)) return 0;
  yes = n;
  if (possible(l, l)) return l;
  no = l;
  while (no != yes - 1) {
    int newmid = (yes + no) / 2;
    if (possible(l, newmid))
      yes = newmid;
    else
      no = newmid;
  }
  return yes;
}
int main() {
  int i;
  int minr;
  long long total = 0;
  int lj, rj;
  cin >> n;
  for (i = 1; i <= n; i++) cin >> a[i];
  for (i = 1; i <= n / 2; i++) {
    if (a[i] != a[n - i + 1]) break;
  }
  pfromside = i - 1;
  pmid = n & 1;
  lj = n / 2;
  rj = n / 2 + 1 + (n & 1);
  for (i = 0; i < n / 2; i++) {
    if (a[lj] != a[rj]) break;
    lj--;
    rj++;
  }
  pmid += i * 2;
  int wasequal, diffn = 0;
  lj = 1;
  rj = n;
  sideequal[0] = 1;
  for (i = 1; i <= n / 2; i++) {
    wasequal = (ln[a[lj]] == rn[a[lj]]);
    ln[a[lj]]++;
    if (ln[a[lj]] == rn[a[lj]])
      diffn--;
    else if (wasequal)
      diffn++;
    wasequal = (ln[a[rj]] == rn[a[rj]]);
    rn[a[rj]]++;
    if (ln[a[rj]] == rn[a[rj]])
      diffn--;
    else if (wasequal)
      diffn++;
    if (diffn == 0)
      sideequal[i] = 1;
    else
      sideequal[i] = 0;
    lj++;
    rj--;
  }
  int odds = 0;
  for (i = 1; i <= n; i++) {
    wn1[a[i]]++;
    wn2[a[i]]++;
    if (wn1[a[i]] & 1)
      odds++;
    else
      odds--;
  }
  if (odds > 1) {
    cout << 0;
    return 0;
  }
  lj = 1;
  for (i = 0; i < n / 2; i++) {
    wn1[a[lj]] -= 2;
    if (wn1[a[lj]] < 0) break;
    lj++;
  }
  leftplenty = i;
  rj = n;
  for (i = 0; i < n / 2; i++) {
    wn2[a[rj]] -= 2;
    if (wn2[a[rj]] < 0) break;
    rj--;
  }
  rightplenty = i;
  for (i = 1; i <= n; i++) {
    minr = findminr(i);
    if (minr) total = total + (long long)(n - minr + 1);
  }
  cout << total;
  return 0;
}
