#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int a[N], num[N], na[N], nb[N];
long long ans;
int n, tem;
int main() {
  while (scanf("%d", &n) != EOF) {
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]), num[a[i]]++;
    bool flag = false;
    int val;
    for (int i = 1; i <= n; i++) {
      if (num[i] % 2) {
        if (flag) {
          printf("0\n");
          return 0;
        }
        flag = true;
        val = i;
      }
    }
    int tem = -1;
    for (int i = 1, j = n; i <= j; i++, j--) {
      if (a[i] != a[j]) {
        tem = i;
        break;
      }
      num[a[i]] -= 2;
    }
    if (tem == -1) {
      printf("%I64d\n", 1LL * n * (n + 1) / 2);
      return 0;
    }
    long long ans = 0;
    for (int i = tem; i <= n; i++) {
      na[a[i]]++;
      int j = n - i + 1;
      if ((i < j && na[a[i]] * 2 > num[a[i]]) || (i == j && val != a[i]) ||
          (i > j && a[i] != a[j])) {
        ans += (long long)tem * i;
        break;
      }
    }
    for (int i = n - tem + 1; i >= 1; i--) {
      nb[a[i]]++;
      int j = n - i + 1;
      if ((i > j && nb[a[i]] * 2 > num[a[i]]) || (i == j && val != a[i]) ||
          (i < j && a[i] != a[j])) {
        ans += (long long)tem * j;
        break;
      }
    }
    ans -= (long long)tem * tem;
    printf("%I64d\n", ans);
  }
}
