#include <bits/stdc++.h>
using namespace std;
long long n, L, R, X;
long long DP[100100];
bool check() {
  unordered_map<long long, int> Q;
  for (long long i = 0; i < X; i++) {
    Q[DP[L + i]]++;
    Q[DP[R - i]]--;
  }
  unordered_map<long long, int>::iterator it;
  int ct = 0;
  for (it = Q.begin(); it != Q.end(); ++it) {
    if ((it->second) != 0) ct++;
  }
  if (ct > 1) return 0;
  return 1;
}
bool checks() {
  unordered_map<long long, int> Q;
  for (long long i = 0; i < n; i++) {
    Q[DP[i]]++;
  }
  unordered_map<long long, int>::iterator it;
  int ct = 0;
  for (it = Q.begin(); it != Q.end(); ++it) {
    if ((it->second) % 2 != 0) ct++;
  }
  if (ct > 1) return 0;
  return 1;
}
bool coverL(long long p) {
  unordered_map<long long, int> Q;
  long long i, j, k;
  for (i = L; i <= p; i++) Q[DP[i]]++;
  for (i = p + 1; i <= R; i++) Q[DP[i]]--;
  unordered_map<long long, int>::iterator it;
  int ct = 0;
  for (it = Q.begin(); it != Q.end(); ++it) {
    if ((it->second) < 0) return 0;
    if ((it->second) % 2 != 0) ct++;
  }
  if (ct > 1) return 0;
  return 1;
}
bool coverR(long long p) {
  unordered_map<long long, int> Q;
  long long i, j, k;
  for (i = L; i < p; i++) Q[DP[i]]--;
  for (i = p; i <= R; i++) Q[DP[i]]++;
  unordered_map<long long, int>::iterator it;
  int ct = 0;
  for (it = Q.begin(); it != Q.end(); ++it) {
    if ((it->second) < 0) return 0;
    if ((it->second) % 2 != 0) ct++;
  }
  if (ct > 1) return 0;
  return 1;
}
int main() {
  ios::sync_with_stdio(false);
  long long i, j, k, n1, n2, m1, m2, x, y, z;
  long long res;
  memset(DP, 0, sizeof(DP));
  cin >> n;
  for (i = 0; i < n; i++) cin >> DP[i];
  L = 0;
  R = (n - 1);
  X = n / 2;
  if (checks() == 0) {
    cout << 0 << endl;
    return 0;
  }
  n1 = 0;
  while (n1 < n / 2 && DP[n1] == DP[n - n1 - 1]) n1++;
  n1--;
  if ((n1 + 1) == (n / 2)) {
    res = n * (n + 1) / 2;
    cout << res << endl;
    return 0;
  }
  m1 = n / 2;
  m1--;
  m2 = n - 1 - m1;
  n2 = 0;
  while (n2 < n / 2 && DP[m1 - n2] == DP[m2 + n2]) n2++;
  n2--;
  L = n1 + 1;
  R = n - 1 - L;
  X = n / 2 - (n1 + 1) - (n2 + 1);
  if (n2 != -1 || n % 2 == 1) {
    if (check() == 1) {
      res = 2 * (n - (L + X) + 1) * (L + 1);
      res -= (L + 1) * (L + 1);
      cout << res << endl;
      return 0;
    }
  }
  long long sm = n / 2, bg = R, md, p1, p2;
  while (sm + 1 < bg) {
    md = (sm + bg) / 2;
    if (coverL(md) == 0) {
      sm = md;
    } else {
      bg = md;
    }
  }
  while (coverL(sm) == 1 && sm >= L) sm--;
  while (coverL(sm) == 0) sm++;
  p1 = sm;
  sm = L;
  bg = n / 2 - 1;
  while (sm + 1 < bg) {
    md = (sm + bg) / 2;
    if (coverR(md) == 0) {
      bg = md;
    } else {
      sm = md;
    }
  }
  while (coverR(bg) == 1 && bg <= R) bg++;
  while (coverR(bg) == 0) bg--;
  p2 = bg;
  res = (L + 1) * (n - p1);
  res += (n - R) * (p2 + 1);
  res -= (L + 1) * (L + 1);
  cout << res << endl;
  return 0;
}
