#include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  map<int, int> all;
  for (int i = 0; i < n; ++i) {
    all[a[i]]++;
  }
  int odd = 0;
  for (auto x : all) {
    if (x.second % 2) {
      odd++;
    }
  }
  if (odd > 1) {
    cout << 0;
    return 0;
  }
  int pos = -1;
  for (int i = 0; i < n; ++i) {
    if (a[i] != a[n - 1 - i]) {
      pos = i;
      break;
    }
  }
  if (pos == -1) {
    cout << (ll)n * (n - 1) / 2 + n << endl;
    return 0;
  }
  bool found[2] = {0, 0};
  ll ans = 0;
  for (int step = 0; step < 2; ++step, reverse(a.begin(), a.end())) {
    int pos2 = 0;
    for (int i = (n - 1) / 2; i >= pos; --i) {
      if (a[i] != a[n - 1 - i]) {
        pos2 = i;
        break;
      }
    }
    map<int, int> A;
    for (int i = pos; i <= pos2; ++i) {
      A[a[i]]++;
    }
    for (int i = n - 1 - pos2; i <= n - 1 - pos; ++i) {
      A[a[i]]--;
    }
    bool good = 1;
    for (auto x : A) {
      if (x.second != 0) {
        good = 0;
        break;
      }
    }
    if (good) {
      ans += (pos + 1LL) * (n - pos2);
      found[step] = 1;
      continue;
    }
    A.clear();
    for (int i = pos; i <= n - 1 - pos; ++i) {
      A[a[i]]++;
    }
    int number_bad = A.size();
    map<int, int> B;
    int r = -1;
    for (int i = pos; i <= n - 1 - pos; ++i) {
      if (A[a[i]] <= B[a[i]]) {
        continue;
      }
      A[a[i]]--;
      B[a[i]]++;
      if (A[a[i]] <= B[a[i]]) {
        number_bad--;
      }
      if (number_bad == 0) {
        r = i;
        break;
      }
    }
    if (r == -1) {
      continue;
    } else {
      ans += (pos + 1LL) * (n - r);
      found[step] = 1;
    }
  }
  if (found[0] && found[1]) {
    ans -= (pos + 1LL) * (pos + 1LL);
  }
  cout << ans;
  return 0;
}
