#include <bits/stdc++.h>
using namespace std;
long long n, a[(1 << 20)], cnt[(1 << 20)];
bool palin[(1 << 20)], okTo[(1 << 20)];
long long c1, oddNum, cntAv[(1 << 20)], ans;
int cntL[(1 << 20)], cntR[(1 << 20)];
bool pos(int l, int r) {
  for (int i = 0; i <= n; i++) {
    cntAv[i] = 0;
  }
  if (r < n / 2) {
    if (n % 2 && a[n / 2] != oddNum) {
      return 0;
    }
    for (int i = r + 1; i < n - r - 1; i++) {
      if (a[i] != a[n - 1 - i]) {
        return 0;
      }
    }
    for (int i = l; i <= r; i++) {
      cntAv[a[i]]++;
    }
    for (int i = n - r - 1; i < n - l; i++) {
      cntAv[a[i]]--;
    }
    for (int i = 0; i <= n; i++) {
      if (cntAv[i] < 0) {
        return 0;
      }
      if (n % 2 && i == oddNum) {
      } else {
        if (cntAv[i] % 2) {
          return 0;
        }
      }
    }
    return 1;
  }
  for (int i = l; i <= r; i++) {
    cntAv[a[i]]++;
  }
  for (int i = r + 1; i < n - l; i++) {
    cntAv[a[i]]--;
  }
  for (int i = 0; i <= n; i++) {
    if (cntAv[i] < 0) {
      return 0;
    }
    if (n % 2 && i == oddNum) {
      if (cntAv[i] % 2 == 0) {
        return 0;
      }
    } else {
      if (cntAv[i] % 2) {
        return 0;
      }
    }
  }
  return 1;
}
int lf;
void getC(bool b) {
  int sInd = 0;
  for (; palin[sInd]; sInd++) {
  }
  int l = sInd, r = n - sInd, m = (l + r) / 2;
  for (; l + 1 < r; m = (l + r) / 2) {
    if (pos(sInd, m)) {
      r = m;
    } else {
      l = m;
    }
  }
  int crr = (n - sInd - 1) - r + 1;
  if (!b) {
    lf = crr;
  }
  if (b) {
    cntL[sInd] = crr;
    for (int i = sInd - 1; i >= 0; i--) {
      cntL[i] = cntL[i + 1] + 2;
    }
  } else {
    r = max(1LL * r, n - crr);
    crr = (n - sInd - 1) - r + 1;
    cntR[n - 1 - sInd] = crr;
    for (int i = sInd - 1; i >= 0; i--) {
      cntR[n - 1 - i] = cntR[n - 1 - i - 1] + 2;
    }
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    oddNum ^= a[i];
  }
  for (int i = 0; i < n; i++) {
    cnt[a[i]]++;
    if (cnt[a[i]] % 2) {
      c1++;
    } else {
      c1--;
    }
  }
  if (n % 2) {
    if (c1 != 1 || cnt[oddNum] % 2 != 1) {
      cout << "0\n";
      return 0;
    }
  } else {
    if (c1) {
      cout << "0\n";
      return 0;
    }
  }
  for (int i = 0; i <= n / 2; i++) {
    if (a[i] == a[n - 1 - i]) {
      palin[i] = 1;
      palin[n - 1 - i] = 1;
    } else {
      break;
    }
  }
  if (palin[n / 2]) {
    cout << n * (n + 1) / 2 << "\n";
    return 0;
  }
  getC(0);
  reverse(a, a + n);
  getC(1);
  reverse(a, a + n);
  int l = 0, r = n - 1;
  for (; l < r;) {
    ans += cntL[l] + cntR[r] - 1;
    if (!palin[l]) {
      break;
    }
    l++;
    r--;
  }
  cout << ans << "\n";
  return 0;
}
