#include <bits/stdc++.h>
using namespace std;
bool isPal(vector<int>& Vec, int N, int left) {
  int I;
  for (I = left; I < N / 2 && Vec[I] == Vec[N - 1 - I]; I++) {
  }
  if (I == N / 2) return true;
  return false;
}
bool Cambiar(vector<int>& V, int l, int r, int R) {
  if (r < (l + R) / 2 || (r == (l + R) / 2 && (R - l + 1) % 2 == 0)) {
    if (isPal(V, V.size(), r + 1)) {
      vector<int> V1, V2;
      for (int I2 = l; I2 <= r; I2++) {
        V1.push_back(V[I2]);
      }
      for (int I2 = R - V1.size() + 1; I2 <= R; I2++) {
        V2.push_back(V[I2]);
      }
      sort(V1.begin(), V1.end());
      sort(V2.begin(), V2.end());
      if (V1 == V2) return true;
      return false;
    } else
      return false;
  }
  vector<int> V1, V2;
  for (int I = l; I < r + 1; I++) {
    V1.push_back(V[I]);
  }
  for (int I = r + 1; I <= R; I++) {
    V2.push_back(V[I]);
  }
  vector<int> V3;
  sort(V1.begin(), V1.end());
  sort(V2.begin(), V2.end());
  int ind = 0;
  bool H = false;
  int I = 0;
  for (; I < V2.size() && ind < V1.size(); I++) {
    for (; ind < V1.size() && V2[I] != V1[ind]; ind++) {
      V3.push_back(V1[ind]);
    }
    ind++;
  }
  if (I == V2.size()) {
    for (; ind < V1.size(); ind++) {
      V3.push_back(V1[ind]);
    }
    int impar = 0;
    int contadorr = 1;
    for (int I3 = 1; I3 < V3.size(); I3++) {
      if (V3[I3] == V3[I3 - 1]) {
        contadorr++;
      } else {
        if (contadorr % 2 == 1) {
          impar++;
        }
        contadorr = 1;
      }
    }
    if (impar > 1 || (V3.size() % 2 == 0 && impar == 1)) {
      return false;
    } else
      return true;
  } else {
    return false;
  }
}
bool Cambiar2(vector<int>& V, int l, int r, int L) {
  if (l > (r + L + 1) / 2 || (l == (r + L + 1) / 2 && (r - L + 1) % 2 == 0)) {
    if (isPal(V, V.size(), L + (r - l + 1))) {
      vector<int> V1, V2;
      for (int I2 = l; I2 <= r; I2++) {
        V1.push_back(V[I2]);
      }
      for (int I2 = L; I2 < L + (r - l + 1); I2++) {
        V2.push_back(V[I2]);
      }
      sort(V1.begin(), V1.end());
      sort(V2.begin(), V2.end());
      if (V1 == V2) return true;
      return false;
    } else
      return false;
  }
  vector<int> V1, V2;
  for (int I = l; I <= r; I++) {
    V1.push_back(V[I]);
  }
  for (int I = L; I < l; I++) {
    V2.push_back(V[I]);
  }
  vector<int> V3;
  sort(V1.begin(), V1.end());
  sort(V2.begin(), V2.end());
  int ind = 0;
  bool H = false;
  int I = 0;
  for (; I < V2.size() && ind < V1.size(); I++) {
    for (; ind < V1.size() && V2[I] != V1[ind]; ind++) {
      V3.push_back(V1[ind]);
    }
    ind++;
  }
  if (I == V2.size()) {
    for (; ind < V1.size(); ind++) {
      V3.push_back(V1[ind]);
    }
    int impar = 0;
    int contadorr = 1;
    for (int I3 = 1; I3 < V3.size(); I3++) {
      if (V3[I3] == V3[I3 - 1]) {
        contadorr++;
      } else {
        if (contadorr % 2 == 1) {
          impar++;
        }
        contadorr = 1;
      }
    }
    if (impar > 1 || (V3.size() % 2 == 0 && impar == 1)) {
      return false;
    } else
      return true;
  } else {
    return false;
  }
}
int main() {
  int N;
  scanf("%d", &N);
  vector<int> Vec(N);
  for (int I = 0; I < N; I++) {
    scanf("%d", &Vec[I]);
  }
  if (isPal(Vec, N, 0)) {
    long long int J = N;
    printf("%I64d\n", J * (J + 1) / 2);
    return 0;
  }
  int I;
  for (I = 0; I < N / 2 && Vec[I] == Vec[N - 1 - I]; I++) {
  }
  int left = I, l = I;
  int right = N - 1 - I;
  bool J = false;
  for (int m = (left + right) / 2; left != right; m = (left + right) / 2) {
    if (Cambiar(Vec, l, m, N - 1 - I)) {
      right = m;
      J = true;
    } else {
      left = m + 1;
    }
  }
  if (!J) {
    printf("0\n");
    return 0;
  }
  int l1 = I, l2 = left;
  bool JJ = false;
  left = I;
  right = N - 1 - I;
  int r = N - 1 - I;
  for (int m = (left + right) / 2; left != right; m = (left + right) / 2) {
    if (Cambiar2(Vec, m, r, I)) {
      left = m + 1;
      J = true;
    } else {
      right = m;
    }
  }
  if (left == r && (J == false)) {
    printf("0\n");
    return 0;
  }
  int r1 = left - 1, r2 = r;
  long long cant = (long long)((long long)((long long)r1 - (long long)l1) *
                               (long long)((long long)N - (long long)r2)) +
                   (long long)((long long)((long long)r2 - (long long)l2) *
                               (long long)((long long)l1 + (long long)1)) +
                   (long long)((long long)((long long)N - (long long)r2) *
                               (long long)((long long)l1 + (long long)1));
  printf("%I64d\n", cant);
  return 0;
}
