#include <bits/stdc++.h>
using namespace std;
int inp[100005];
int cnt[100005];
bool isPalin() {
  bool ans = false;
  for (int i = 0; i < 100004; i++)
    if (cnt[i] & 1) {
      if (!ans)
        ans = true;
      else
        return false;
    }
  return true;
}
bool check(int st, int ed, int m, bool f) {
  memset(cnt, 0, sizeof cnt);
  if (f == 0) {
    for (int i = st; i <= m; i++) cnt[inp[i]]++;
    while (st <= ed) {
      if (st <= m && ed <= m) return isPalin();
      if (st <= m) {
        if (st != ed) {
          if (!cnt[inp[ed]])
            return false;
          else
            cnt[inp[ed]]--;
        }
      } else if (inp[st] != inp[ed])
        return false;
      st++, ed--;
    }
  } else {
    for (int i = m; i <= ed; i++) cnt[inp[i]]++;
    while (st <= ed) {
      if (st >= m && ed >= m) return isPalin();
      if (m <= ed) {
        if (st != ed) {
          if (!cnt[inp[st]])
            return false;
          else
            cnt[inp[st]]--;
        }
      } else if (inp[st] != inp[ed])
        return false;
      st++, ed--;
    }
  }
  return true;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &inp[i]);
  int st = 0, ed = n - 1;
  while (st <= ed) {
    if (inp[st] == inp[ed])
      st++, ed--;
    else
      break;
  }
  if (st > ed) {
    printf("%lld\n", 1LL * n * (n + 1) / 2);
    return 0;
  }
  int i1, i2;
  int f, l, mid;
  f = st;
  l = ed + 1;
  while (f < l) {
    mid = (f + l) / 2;
    if (check(st, ed, mid, 0))
      l = mid;
    else
      f = mid + 1;
  }
  i1 = l;
  if (i1 == ed + 1) i1 = n;
  f = st - 1;
  l = ed;
  while (f < l) {
    mid = (f + l + 1) / 2;
    if (check(st, ed, mid, 1))
      f = mid;
    else
      l = mid - 1;
  }
  i2 = f;
  if (i2 == st - 1) i2 = -1;
  long long ans = 0;
  ans += (st + 1) * 1LL * (n - i1);
  ans += (n - ed) * 1LL * (i2 + 1);
  if (i1 != n) ans -= (st + 1) * 1LL * (n - ed);
  printf("%lld\n", ans);
  return 0;
}
