#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
map<int, int> m, m1, m2;
int n, a[N];
long long calc(int x, int y) { return 1LL * (x + 1) * (n - y); }
int main() {
  while (scanf("%d", &n) != EOF) {
    m.clear();
    for (int i = 0; i < n; ++i) {
      scanf("%d", &a[i]);
    }
    int l = 0, r = n - 1;
    while (l < r && a[l] == a[r]) {
      l++;
      r--;
    }
    if (l >= r) {
      cout << 1LL * (n + 1) * n / 2 << endl;
      continue;
    }
    for (int i = l; i <= r; ++i) {
      m[a[i]]++;
    }
    int c = 0, num = -1;
    for (map<int, int>::iterator it = m.begin(); it != m.end(); ++it) {
      if (it->second & 1) {
        c++;
        num = it->first;
      }
    }
    if (c > 1) {
      puts("0");
      continue;
    }
    if (c == 1) {
      m[num]--;
    }
    int a1, a2;
    m1 = m;
    for (int i = l;; ++i) {
      if (m1[a[i]] > 0) {
        m1[a[i]] -= 2;
      } else {
        a1 = i;
        break;
      }
    }
    if (a1 == (l + r + 1) / 2 &&
        (n % 2 == 0 || (n % 2 == 1 && a[l + r / 2] == num))) {
      while (a[a1] == a[r + l - a1]) {
        a1++;
      }
    }
    m2 = m;
    for (int i = r;; --i) {
      if (m2[a[i]] > 0) {
        m2[a[i]] -= 2;
      } else {
        a2 = i;
        break;
      }
    }
    if (a2 == (l + r) / 2 &&
        (n % 2 == 0 || (n % 2 == 1 && a[l + r / 2] == num))) {
      while (a[a2] == a[r + l - a2]) {
        a2--;
      }
    }
    cout << calc(l, a2) + calc(a1, r) - calc(l, r) << endl;
  }
}
