#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 28;
const int mod = (int)1e9 + 7;
const double eps = 1e-8;
int n, m;
int a[100010];
int cnt[100010];
bool in(int k, int l, int r) { return k <= r && l <= k; }
int check(int l, int r) {
  memset(cnt, 0, sizeof cnt);
  for (int i = 1; i <= n; i++)
    if (!in(i, l, r) && !in(n - i + 1, l, r) && a[i] != a[n - i + 1])
      return false;
  for (int i = l; i <= r; i++) cnt[a[i]]++;
  for (int i = 1; i <= n; i++) {
    if (!in(i, l, r) && in(n - i + 1, l, r)) {
      cnt[a[i]]--;
    }
  }
  for (int i = 1; i <= n; i++)
    if (cnt[i] < 0) return false;
  return true;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    cnt[a[i]]++;
  }
  bool yes = true;
  int sum = 0;
  for (int i = 1; i <= n; i++)
    if (cnt[i] & 1) sum++;
  if (sum > 1) {
    cout << 0;
    return 0;
  }
  for (int i = 1; i <= n; i++)
    if (a[i] != a[n - i + 1]) yes = false;
  if (yes) {
    cout << n * 1ll * (n + 1) / 2;
    return 0;
  }
  int s = 1;
  while (a[s] == a[n - s + 1]) s++;
  long long ans = -s * 1ll * s;
  int l = s, r = n + 1;
  while (l < r) {
    int mid = (l + r) / 2;
    if (check(s, mid))
      r = mid;
    else
      l = mid + 1;
  }
  ans += s * 1ll * (n - r + 1);
  reverse(a + 1, a + n + 1);
  l = s, r = n + 1;
  while (l < r) {
    int mid = (l + r) / 2;
    if (check(s, mid))
      r = mid;
    else
      l = mid + 1;
  }
  ans += s * 1ll * (n - r + 1);
  cout << ans << endl;
  return 0;
}
