#include <bits/stdc++.h>
using namespace std;
template <class T>
void debug(T a, T b) {
  ;
}
template <class T>
void chmin(T& a, const T& b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T& a, const T& b) {
  if (a < b) a = b;
}
namespace std {
template <class S, class T>
ostream& operator<<(ostream& out, const pair<S, T>& a) {
  out << '(' << a.first << ',' << a.second << ')';
  return out;
}
}  // namespace std
long long int readL() {
  long long int res;
  scanf("%I64d", &res);
  return res;
}
void printL(long long int res) { printf("%I64d", res); }
int n, N;
int ar[100005];
int cnt[100005];
int C;
bool check(int* ar, int k, int n) {
  memset((cnt), 0, sizeof(cnt));
  if (n & 1) {
    int mid = n / 2;
    if (k <= mid) {
      for (int i = 1; mid - i >= k; ++i)
        if (ar[mid - i] != ar[mid + i]) return false;
      for (int i = 0; i < (k); ++i) {
        cnt[ar[i]]++;
        cnt[ar[n - 1 - i]]--;
      }
      for (int i = 0; i < (N); ++i)
        if (cnt[i] != 0) return false;
      return true;
    } else {
      for (int i = 0; i < (n); ++i) ++cnt[ar[i]];
      int odd = -1;
      for (int i = 0; i < (N); ++i)
        if (cnt[i] & 1) {
          if (odd == -1)
            odd = i;
          else
            odd = -2;
        }
      if (odd < 0) return false;
      --cnt[odd];
      for (int i = (k); i < (n); ++i) cnt[ar[i]] -= 2;
      for (int i = 0; i < (N); ++i)
        if (cnt[i] < 0) return false;
      return true;
    }
  } else {
    int half = n / 2;
    if (k <= half) {
      for (int i = 0; half - i - 1 >= k; ++i)
        if (ar[half - 1 - i] != ar[half + i]) return false;
      for (int i = 0; i < (k); ++i) {
        cnt[ar[i]]++;
        cnt[ar[n - 1 - i]]--;
      }
      for (int i = 0; i < (N); ++i)
        if (cnt[i] != 0) return false;
      return true;
    } else {
      for (int i = 0; i < (n); ++i) ++cnt[ar[i]];
      for (int i = 0; i < (N); ++i)
        if (cnt[i] & 1) return false;
      for (int i = (k); i < (n); ++i) cnt[ar[i]] -= 2;
      for (int i = 0; i < (N); ++i)
        if (cnt[i] < 0) return false;
      return true;
    }
  }
}
long long int solve(int* ar, int n) {
  int lb = 0, ub = n;
  while (ub - lb > 1) {
    int md = (lb + ub) >> 1;
    if (check(ar, md, n))
      ub = md;
    else
      lb = md;
  }
  return n - ub;
}
int main() {
  cin >> n;
  N = n;
  for (int i = 0; i < (n); ++i) scanf("%d", &ar[i]), --ar[i];
  while (C < n && ar[C] == ar[n - 1 - C]) ++C;
  long long int res = 0;
  ;
  ;
  if (C == n)
    res = n * (long long int)(n + 1) / 2;
  else {
    if (!check(ar + C, n - C * 2, n - C * 2))
      ;
    else {
      res += (C + 1) * (long long int)(C + 1);
      res += solve(ar + C, n - C * 2) * (long long int)(C + 1);
      reverse(ar + C, ar + n - C);
      res += solve(ar + C, n - C * 2) * (long long int)(C + 1);
    }
  }
  cout << res << endl;
  return 0;
}
