#include <bits/stdc++.h>
using namespace std;
const int Maxn = ((int)1e5) + 100;
int arr[Maxn], n;
map<int, int> num, numL, numR;
long long Solve(int a[]) {
  int l = 0, r = n - 1;
  while (a[l] == a[r] && l < r) ++l, --r;
  if (l >= r) return n * 1ll * (n + 1) / 2;
  for (int(i) = (l); (i) <= (r); ++(i)) num[a[i]] += 1;
  int odds = 0, key = -1;
  for (auto it = num.begin(); it != num.end(); ++it)
    if ((it->second) & 1) odds += 1, key = it->first;
  if (odds > 1) return 0;
  int oks = 0, l2 = l - 1;
  while (oks < num.size()) {
    numL[a[++l2]] += 1;
    int _a = numL[a[l2]] << 1;
    int _b = _a - 2, _c = num[a[l2]];
    if (_a >= _c && _b < _c) ++oks;
  }
  oks = 0;
  int r2 = r + 1;
  while (oks < num.size()) {
    numR[a[--r2]] += 1;
    int _a = numR[a[r2]] << 1;
    int _b = _a - 2, _c = num[a[r2]];
    if (_a >= _c && _b < _c) ++oks;
  }
  int mid = (r + l) >> 1;
  if (l2 <= mid && (!(n & 1) || a[mid] == key)) {
    int g, h;
    if (n & 1)
      g = mid - 1, h = mid + 1;
    else
      g = mid, h = mid + 1;
    while (a[g] == a[h]) --g, ++h;
    l2 = g, r2 = h;
  }
  long long sum = 0;
  sum += (l + 1) * 1ll * (n - l2);
  sum += (n - r) * 1ll * (r2 + 1);
  sum -= (l + 1) * 1ll * (n - r);
  return sum;
}
int main() {
  iostream::sync_with_stdio(false);
  cin >> n;
  for (int(i) = (0); (i) <= (n - 1); ++(i)) cin >> arr[i];
  cout << Solve(arr) << endl;
  return 0;
}
