#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 1;
int *a, *cnt[2], vt[2], sum = 0, middle, cntEqual, tmp;
bool isOdd = false;
long long n, res;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  a = new int[n + 1];
  for (int i = 0; i < 2; ++i) cnt[i] = new int[n + 1];
  memset(cnt[0], 0, (n + 1) * sizeof(int));
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    ++cnt[0][a[i]];
  }
  for (int i = 1; i <= n; ++i)
    if (cnt[0][i] & 1)
      if (isOdd) {
        cout << 0;
        return 0;
      } else
        isOdd = true;
  vt[0] = 1;
  while (vt[0] <= (n >> 1) && a[vt[0]] == a[n - vt[0] + 1]) ++vt[0];
  res = vt[0] * vt[0];
  tmp = vt[0]--;
  if (vt[0] == (n >> 1)) {
    cout << ((n * (n + 1)) >> 1);
    return 0;
  }
  n -= (vt[0] << 1);
  memset(cnt[0], 0, (n + 1) * sizeof(int));
  for (int i = 1; i <= n; ++i) {
    a[i] = a[i + vt[0]];
    if (!cnt[0][a[i]]) ++sum;
    ++cnt[0][a[i]];
  }
  vt[0] = n >> 1;
  if (n & 1) {
    vt[1] = vt[0] + 2;
    middle = 1;
  } else {
    vt[1] = vt[0] + 1;
    middle = 0;
  }
  while (vt[0] >= 1 && a[vt[0]] == a[vt[1]]) {
    --vt[0];
    ++vt[1];
    middle += 2;
  }
  for (int i = 0; i < 2; ++i) memset(cnt[i], 0, (n + 1) * sizeof(int));
  cnt[0][a[1]] = cnt[1][a[n]] = 1;
  cntEqual = (a[1] == a[n] ? sum : sum - 1);
  for (int i = 2; i < n; ++i) {
    if (i > (n + 1) >> 1) {
      --cnt[1][a[i]];
      if (cnt[0][a[i]] == cnt[1][a[i]]) ++cntEqual;
    }
    if (i > n >> 1 || a[i] != a[n - i + 1]) {
      if (cnt[0][a[i]] + 1 == cnt[1][a[i]]) ++cntEqual;
      if (i <= n >> 1)
        if (cnt[1][a[n - i + 1]] == cnt[0][a[n - i + 1]]) --cntEqual;
    }
    if ((i > n >> 1 || n - (i << 1) <= middle) && cntEqual == sum) res += tmp;
    ++cnt[0][a[i]];
    if (i <= n >> 1) ++cnt[1][a[n - i + 1]];
  }
  for (int i = 0; i < 2; ++i) memset(cnt[i], 0, (n + 1) * sizeof(int));
  cnt[0][a[n]] = cnt[1][a[1]] = 1;
  cntEqual = (a[1] == a[n] ? sum : sum - 1);
  for (int i = n - 1; i > 1; --i) {
    if (i <= n >> 1) {
      --cnt[1][a[i]];
      if (cnt[0][a[i]] == cnt[1][a[i]]) ++cntEqual;
    }
    if (i <= (n + 1) >> 1 || a[i] != a[n - i + 1]) {
      if (cnt[0][a[i]] + 1 == cnt[1][a[i]]) ++cntEqual;
      if (i > (n + 1) >> 1)
        if (cnt[1][a[n - i + 1]] == cnt[0][a[n - i + 1]]) --cntEqual;
    }
    if ((i <= (n + 1) >> 1 || n - ((n - i + 1) << 1) <= middle) &&
        cntEqual == sum)
      res += tmp;
    ++cnt[0][a[i]];
    if (i > (n + 1) >> 1) ++cnt[1][a[n - i + 1]];
  }
  cout << res;
  delete[] a;
  for (int i = 0; i < 2; ++i) delete[] cnt[i];
  return 0;
}
