#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
int main() {
  int nn, m;
  long long n;
  scanf("%d", &nn);
  n = nn;
  std::vector<int> a(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  int k = n / 2;
  std::vector<int> cnt(n + 1, 0);
  std::vector<int> cnthalf(n + 1, 0);
  int mine = n + 1;
  int maxe = -1;
  for (int i = 0; i < k; i++) {
    if (a[i] != a[n - 1 - i]) {
      maxe = max(maxe, i);
      mine = min(mine, i);
    }
    cnthalf[a[i]]++;
    cnt[a[i]]++;
  }
  if (maxe == -1) {
    long long nn = n;
    cout << n * (n + 1) / 2;
    return 0;
  }
  for (int i = k; i < n; i++) {
    cnt[a[i]]++;
  }
  bool halfcool = true;
  if (n & 1) cnt[a[k]]--;
  for (int i = 0; i < n + 1; i++)
    if (cnt[i] != 2 * cnthalf[i]) halfcool = false;
  if (n & 1) cnt[a[k]]++;
  int oddcnt = 0;
  for (int i = 0; i < n + 1; i++)
    if (cnt[i] & 1) oddcnt++;
  if (oddcnt > 1) {
    cout << 0;
    return 0;
  }
  if (n % 2 == 0)
    if (oddcnt > 0) {
      cout << 0;
      return 0;
    }
  if (halfcool) {
    long long l = mine;
    long long l1 = maxe;
    long long r1 = n - 1 - l1;
    long long r = n - 1 - l;
    cout << (l + 1) * (n - l1) + (r1 + 1) * (n - r) - (l + 1) * (n - r);
    return 0;
  } else {
    long long l = mine;
    long long r = n - 1 - l;
    for (int i = 0; i < l; i++) cnt[a[i]] -= 2;
    std::vector<int> cntl(n + 1, 0);
    std::vector<int> cntr(n + 1, 0);
    for (int i = 0; i < n + 1; i++) cntl[i] = cnt[i];
    for (int i = 0; i < n + 1; i++) cntr[i] = cnt[i];
    std::vector<bool>(n + 1, false);
    int bl = 0;
    for (int i = 0; i < n + 1; i++) {
      if (cnt[i]) bl++;
    }
    int br = bl;
    long long lto = l - 1;
    while (bl > 0) {
      lto++;
      if (2 * cntl[a[lto]] - 2 <= cnt[a[lto]])
        if (2 * cntl[a[lto]] > cnt[a[lto]]) bl--;
      cntl[a[lto]]--;
    }
    long long rto = r + 1;
    while (br > 0) {
      rto--;
      if (2 * cntr[a[rto]] - 2 <= cnt[a[rto]])
        if (2 * cntr[a[rto]] > cnt[a[rto]]) br--;
      cntr[a[rto]]--;
    }
    cout << (l + 1) * (n - lto) + (rto + 1) * (n - r) - (l + 1) * (n - r);
  }
}
