#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n;
int cnt[N], a[N];
bool ok(int x, int y) {
  memset(cnt, 0, sizeof cnt);
  for (int i = x; i <= y; i++) cnt[a[i]]++;
  while (x <= y && n - x - 1 > y) {
    if (cnt[a[n - x - 1]] == 0) return 0;
    cnt[a[n - x - 1]]--;
    x++;
  }
  while (x <= y && x > n - y - 1) {
    if (cnt[a[n - y - 1]] == 0) return 0;
    cnt[a[n - y - 1]]--;
    y--;
  }
  y++;
  while (y < n - y - 1) {
    if (a[y] != a[n - y - 1]) return 0;
    y++;
  }
  x--;
  while (x > n - x - 1) {
    if (a[x] != a[n - x - 1]) return 0;
    x--;
  }
  return 1;
}
int main() {
  scanf("%d", &n);
  memset(cnt, 0, sizeof cnt);
  for (int i = 0; i < n; i++) scanf("%d", a + i), cnt[a[i]] ^= 1;
  int sum = 0;
  for (int i = 0; i <= n; i++) sum += cnt[i];
  if (sum > 1) {
    puts("0");
    return 0;
  }
  int le, ri;
  le = 0;
  ri = n - 1;
  while (le < ri && a[le] == a[ri]) le++, ri--;
  if (le >= ri) {
    cout << (long long)n * (n + 1) / 2LL << "\n";
    return 0;
  }
  int p, q;
  {
    int l = le, r = ri;
    while (l < r) {
      int mid = (l + r) >> 1;
      if (ok(le, mid))
        r = mid;
      else
        l = mid + 1;
    }
    q = r;
  }
  {
    int l = le, r = ri;
    while (l < r) {
      int mid = (l + r + 1) >> 1;
      if (ok(mid, ri))
        l = mid;
      else
        r = mid - 1;
    }
    p = l;
  }
  cout << (long long)(le + 1) * (n - q) + (long long)(p + 1) * (n - ri) -
              (long long)(le + 1) * (n - ri)
       << "\n";
  return 0;
}
