#include <bits/stdc++.h>
using namespace std;
vector<int> f;
int N;
void add(deque<int>& a, int l, int r) {
  for (int i = l; i <= r; i++) f[a[i]]++;
}
bool is_palindrome() {
  int cnt = 0;
  for (int i = 0; i < N; i++) cnt += (f[i] & 1);
  return cnt <= 1;
}
int subtract(vector<int>& a, vector<int>& b) {
  int cnt = 0;
  for (int i = 0; i < b.size(); i++) cnt += abs(a[i] - b[i]);
  return cnt;
}
int good_pref(deque<int>& a) {
  int n = a.size();
  int lo = 0, hi = n;
  while (lo != hi) {
    int mid = (lo + hi) >> 1;
    bool good = true;
    if (mid <= (n >> 1)) {
      for (int i = mid; i < n - mid; i++) {
        if (a[i] != a[n - i - 1]) {
          good = false;
          break;
        }
      }
      if (good) {
        f.assign(N, 0);
        add(a, 0, mid - 1);
        vector<int> tmp = f;
        f.assign(N, 0);
        add(a, n - mid, n - 1);
        if (subtract(tmp, f)) good = false;
        f.assign(N, 0);
      }
    } else {
      add(a, 0, mid - 1);
      vector<int> tmp = f;
      f.assign(N, 0);
      add(a, mid, n - 1);
      int cnt = 0;
      for (int i = 0; i < N; i++) {
        if (tmp[i] < f[i]) {
          good = false;
          break;
        }
        cnt += f[i] - tmp[i];
      }
      if (cnt > 1) good = false;
      f.assign(N, 0);
    }
    if (good)
      hi = mid;
    else
      lo = mid + 1;
  }
  return lo;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  N = n + 1;
  f.resize(N, 0);
  deque<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  add(a, 0, n - 1);
  if (!is_palindrome()) {
    cout << "0\n";
    return 0;
  }
  f.assign(n + 1, 0);
  while (!a.empty() && a.front() == a.back()) {
    a.pop_back();
    if (!a.empty()) a.pop_front();
  }
  if (a.size() <= 1) {
    cout << ((n * (n + 1ll)) >> 1ll) << "\n";
    return 0;
  }
  long long pf = good_pref(a);
  reverse(a.begin(), a.end());
  long long sf = good_pref(a);
  long long m = a.size(), overlap = max(0ll, pf + sf - m);
  long long ok = ((n - m) / 2ll + 1ll) * ((n - m) / 2ll + 1ll);
  long long rest = ((n - m) / 2ll + 1ll) * (2 * m - pf - sf);
  cout << ok + rest << "\n";
  return 0;
}
