#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
int n, cnt[maxn], a[maxn], str[maxn];
bool ok[maxn];
int t1 = 0, t2 = 0;
int get1(int m) {
  memset(cnt, 0, sizeof(cnt));
  int not0 = 0, ret = 0;
  for (int l = 1; l <= m / 2; l++) {
    int x = a[l], y = a[m - l + 1];
    if (cnt[x] != 0) not0--;
    cnt[x]--;
    if (cnt[x] != 0) not0++;
    if (cnt[y] != 0) not0--;
    cnt[y]++;
    if (cnt[y] != 0) not0++;
    if (not0 == 0 && (ok[l + 1] || l == m / 2)) {
      ret++;
    }
  }
  t1++;
  return ret;
}
int get2(int m) {
  memset(cnt, 0, sizeof(cnt));
  for (int i = 1; i <= m; i++) cnt[a[i]]++;
  int ret = 0;
  for (int l = 2; l <= (m + 1) / 2; l++) {
    cnt[a[l - 1]] -= 2;
    if (cnt[a[l - 1]] < 0) break;
    ret++;
  }
  t2++;
  return ret;
}
void solve(int m, int poss) {
  memset(ok, false, sizeof ok);
  int md = m / 2;
  if (m & 1) ok[md + 1] = true;
  while (md >= 1) {
    if (str[md] != str[m - md + 1]) break;
    ok[md] = ok[m - md + 1] = true;
    md--;
  }
  memset(cnt, 0, sizeof cnt);
  for (int i = 1; i <= m; i++) cnt[str[i]]++;
  int odd = 0;
  for (int i = 1; i <= n; i++) odd += (cnt[i] & 1);
  if (odd != (m & 1)) {
    printf("0\n");
    exit(0);
  }
  for (int i = 1; i <= m; i++) a[i] = str[i];
  long long ans = get1(m) + get2(m);
  for (int i = 1; i <= m; i++) a[i] = str[m - i + 1];
  ans += get1(m) + get2(m);
  ans *= poss;
  ans += 1ll * poss * poss;
  cout << ans << endl;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  int pos = 0;
  while (pos + 1 <= n && a[pos + 1] == a[n - pos]) pos++;
  if (pos == n) {
    long long ans = 1ll * n * (n - 1) / 2 + n;
    cout << ans << endl;
    return 0;
  }
  int m = 0;
  for (int i = pos + 1; i <= n - pos; i++) str[++m] = a[i];
  solve(m, pos + 1);
  return 0;
}
