#include <bits/stdc++.h>
using namespace std;
int n, a[200005], num[200005], l, sum;
long long ans;
bool flag;
inline bool inside(int x, int l, int r) {
  if ((l <= x) && (r >= x))
    return true;
  else
    return false;
}
inline bool check(int l, int r) {
  for (int i = 1; i <= n; i++)
    if ((!inside(i, l, r)) && (!inside(n - i + 1, l, r)) &&
        (a[i] != a[n - i + 1]))
      return false;
  memset(num, 0, sizeof(num));
  for (int i = l; i <= r; i++) num[a[i]]++;
  for (int i = 1; i <= n; i++)
    if ((!inside(i, l, r)) && inside(n - i + 1, l, r)) {
      num[a[i]]--;
      if (num[a[i]] < 0) return false;
    }
  return true;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    num[a[i]]++;
  }
  for (int i = 1; i <= n; i++) sum += num[i] % 2;
  if (sum >= 2) {
    printf("0\n");
    return 0;
  }
  flag = true;
  for (int i = 1; i <= n; i++)
    if (a[i] != a[n - i + 1]) flag = false;
  if (flag) {
    printf("%I64d\n", (long long)n * (n + 1) / 2);
    return 0;
  }
  l = 1;
  while (a[l] == a[n - l + 1]) l++;
  int ll = l, rr = n;
  while (ll + 1 < rr) {
    int mid = (ll + rr) >> 1;
    if (check(l, mid))
      rr = mid;
    else
      ll = mid;
  }
  ans += (long long)l * (n - rr + 1);
  for (int i = 1; i <= (n >> 1); i++) swap(a[i], a[n - i + 1]);
  ll = l;
  rr = n;
  while (ll + 1 < rr) {
    int mid = (ll + rr) >> 1;
    if (check(l, mid))
      rr = mid;
    else
      ll = mid;
  }
  ans += (long long)l * (n - l + 1 - rr);
  printf("%I64d\n", ans);
  return 0;
}
