#include <bits/stdc++.h>
using namespace std;
int _pow(int a, int b, int mo) {
  int tmp = 1;
  a %= mo;
  for (; b; b >>= 1) {
    if (b & 1) tmp = (long long)tmp * a % mo;
    a = (long long)a * a % mo;
  }
  return tmp;
}
template <class T>
inline void R(T &xx) {
  xx = 0;
  char ch = getchar();
  bool F = 0;
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') F = 1, ch = getchar();
  while (ch >= '0' && ch <= '9')
    xx = xx + xx + (xx << 3) + ch - 48, ch = getchar();
  if (F) xx = -xx;
}
int tt, cnt[200011], a[200011], s1, s2, le, ri, n;
long long ans;
inline void modi(int x, int f) {
  tt -= cnt[x] <= 0;
  cnt[x] += f;
  tt += cnt[x] <= 0;
}
bool che(int l, int r) {
  if (min(l - 1, n - r) > s1 - 1) return 0;
  if (r < s2 || l > n - s2 + 1) return 0;
  pair<int, int> p = (n - l + 1 > r)
                         ? make_pair(max(n - r + 1, r + 1), n - l + 1)
                         : make_pair(n - r + 1, min(n - l + 1, l - 1));
  while (le < p.first) modi(a[le++], -1);
  while (le > p.first) modi(a[--le], 1);
  while (ri > p.second) modi(a[ri--], -1);
  while (ri < p.second) modi(a[++ri], 1);
  return tt == n;
}
int main() {
  R(n);
  tt = n;
  for (int i = 1; i <= n; i++) R(a[i]), modi(a[i], 1);
  int l1 = 0;
  for (int i = 1; i <= n; i++)
    if (cnt[i] & 1) l1++;
  if (l1 >= 2) return puts("0"), 0;
  s1 = 1;
  s2 = n + 1 >> 1;
  while (s1 <= n && a[s1] == a[n - s1 + 1]) s1++;
  while (s2 >= 1 && a[s2] == a[n - s2 + 1]) s2--;
  le = 1;
  ri = n;
  int l = 1;
  for (int r = 1; r <= n; r++) {
    modi(a[r], -1);
    while (l <= r && che(l, r)) modi(a[l], 1), l++;
    ans += l - 1;
  }
  cout << ans << endl;
  return 0;
}
