Misha has an array of n integers indexed by integers from 1 to n. Let's define palindrome degree of array a as the number of such index pairs (l, r)(1 ≤ l ≤ r ≤ n), that the elements from the l-th to the r-th one inclusive can be rearranged in such a way that the whole array will be a palindrome. In other words, pair (l, r) should meet the condition that after some rearranging of numbers on positions from l to r, inclusive (it is allowed not to rearrange the numbers at all), for any 1 ≤ i ≤ n following condition holds: a[i] = a[n - i + 1]. 

Your task is to find the palindrome degree of Misha's array.

Input

The first line contains integer n (1 ≤ n ≤ 105).

The second line contains n positive integers a[i] (1 ≤ a[i] ≤ n), separated by spaces — the elements of Misha's array.

Output

In a single line print the answer to the problem.

Examples

Input

3
2 2 2


Output

6


Input

6
3 6 5 3 3 5


Output

0


Input

5
5 5 2 5 2


Output

4

Note

In the first sample test any possible pair (l, r) meets the condition.

In the third sample test following pairs (1, 3), (1, 4), (1, 5), (2, 5) meet the condition.
#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;
}
