#include <bits/stdc++.h>
using namespace std;
const int maxn = 200020;
const int logn = 18;
const int MOd = 1e9 + 7;
int a, ar[maxn], o, e, t[maxn], b, s;
bool can(int l, int r) {
  memset(t, 0, sizeof(t));
  o = e = 0;
  for (int i = l; i <= r; i++) t[ar[i]]++;
  int y = 0;
  for (int i = b, j = s; i <= j; i++, j--) {
    if (j <= r && !y) {
      for (int k = 1; k <= a; k++) {
        while (t[k] > 1) e++, t[k] -= 2;
        if (t[k] & 1) o++;
      }
      if (o > 1) return false;
      y = 1;
    }
    if (i > r) {
      if (ar[i] != ar[j]) return false;
      continue;
    }
    if (i == j) return o;
    if (r < j) {
      if (!t[ar[j]]) return false;
      t[ar[j]]--;
    }
    if (j <= r) {
      if (!e) return false;
      e--;
    }
  }
  return true;
}
int main() {
  scanf("%d", &a);
  for (int i = 1; i <= a; i++) scanf("%d", &ar[i]);
  b = 1, s = a;
  while (ar[b] == ar[s] && b < s) b++, s--;
  if (b >= s) {
    printf("%I64d\n", (long long)a * (a + 1) / 2);
    return 0;
  }
  int r = 2;
  long long ans = 0;
  while (r--) {
    int t = b;
    for (int k = 17; k >= 0; k--)
      if (t + (1 << k) <= s && !can(b, t + (1 << k))) t += 1 << k;
    if (t == s && !can(b, s)) continue;
    t++;
    if (r == 0)
      ans += (long long)b * (s - t);
    else
      ans += (long long)b * (a - t + 1);
    reverse(ar + 1, ar + 1 + a);
  }
  cout << ans << endl;
  return 0;
}
