#include <bits/stdc++.h>
using namespace std;
namespace my_useful_tools {
const int INF = 0x3f3f3f3f;
inline void pc(char c) { putchar(c); }
template <class T>
inline T gcd(T a, T b) {
  return b == 0 ? a : gcd(b, a % b);
}
template <class T>
inline void W(T p) {
  if (p < 0) pc('-'), p = -p;
  if (p / 10 != 0) W(p / 10);
  pc('0' + p % 10);
}
template <class T>
inline void Wn(T p) {
  W(p), puts("");
}
template <class T>
inline void W(T a, T b) {
  W(a), pc(' '), W(b);
}
template <class T>
inline void Wn(T a, T b) {
  W(a), pc(' '), Wn(b);
}
template <class T>
inline void W(T a, T b, T c) {
  W(a), pc(' '), W(b), pc(' '), W(c);
}
inline char gchar() {
  char ret = getchar();
  for (; ret == '\n' || ret == '\r' || ret == ' '; ret = getchar())
    ;
  return ret;
}
template <class T>
inline void fr(T& ret) {
  char c = ' ';
  int flag = 1;
  for (c = getchar(); c != '-' && !('0' <= c && c <= '9'); c = getchar())
    ;
  if (c == '-')
    flag = -1, ret = 0;
  else
    ret = c - '0';
  for (c = getchar(); '0' <= c && c <= '9'; c = getchar())
    ret = ret * 10 + c - '0';
  ret = ret * flag;
}
inline int fr() {
  int x;
  fr(x);
  return x;
}
template <class T>
inline void fr(T& a, T& b) {
  fr(a), fr(b);
}
template <class T>
inline void fr(T& a, T& b, T& c) {
  fr(a), fr(b), fr(c);
}
template <class T>
inline T fast_pow(T base, T index, T mod = 2147483647, T ret = 1) {
  for (; index; index >>= 1, base = base * base % mod)
    if (index & 1) ret = ret * base % mod;
  return ret;
}
const int maxv = 100, maxe = 100;
struct Edge {
  int edge, head[maxv], to[maxe], next[maxe];
  Edge() {
    edge = 0;
    memset(head, -1, sizeof head);
  }
  void addedge(int u, int v) {
    to[edge] = v, next[edge] = head[u];
    head[u] = edge++;
  }
};
};  // namespace my_useful_tools
using namespace my_useful_tools;
const int maxn = 1e5 + 100;
int n, m, a[maxn], cnt[maxn], sum, recl, recr;
int tim[maxn];
bool chk(int r) {
  for (int i = 1; i <= n; ++i) tim[i] = 0;
  if (r <= n / 2) {
    for (int i = r + 1; i <= n / 2; ++i)
      if (a[i] != a[n - i + 1]) return 0;
    for (int i = n - r + 1; i <= n - m; ++i) ++tim[a[i]];
    for (int i = m + 1; i <= r; ++i) --tim[a[i]];
    for (int i = 1; i <= n; ++i)
      if (tim[i] != 0) return 0;
    return 1;
  } else {
    for (int i = m + 1; i <= r; ++i) {
      ++tim[a[i]];
    }
    for (int i = r + 1; i <= n - m; ++i) {
      --tim[a[i]];
      if (tim[a[i]] < 0) return 0;
    }
    return 1;
  }
}
int main() {
  fr(n);
  for (int i = 1; i <= n; ++i) fr(a[i]), ++cnt[a[i]];
  for (int i = 1; i <= n; ++i) sum += cnt[i] & 1;
  if (sum >= 2) {
    puts("0");
    return 0;
  }
  m = -1;
  for (int i = 1, j = n; i <= j; ++i, --j)
    if (a[i] != a[j]) {
      m = i - 1;
      break;
    }
  if (m == -1) {
    Wn((long long)n * (n + 1) / 2);
    return 0;
  }
  int l = m + 1, r = n - m, mid;
  while (l < r) {
    mid = (l + r) >> 1;
    if (chk(mid))
      r = mid;
    else
      l = mid + 1;
  }
  recl = l;
  reverse(a + 1, a + n + 1);
  l = m + 1, r = n - m;
  while (l < r) {
    mid = (l + r) >> 1;
    if (chk(mid))
      r = mid;
    else
      l = mid + 1;
  }
  recr = n - l + 1;
  long long ans = (long long)(n - m - recl) * (m + 1) +
                  (long long)(recr - m - 1) * (m + 1) +
                  (long long)(m + 1) * (m + 1);
  Wn(ans);
  return 0;
}

### Prompt

Please create a solution in CPP to the following problem:

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.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
namespace my_useful_tools {
const int INF = 0x3f3f3f3f;
inline void pc(char c) { putchar(c); }
template <class T>
inline T gcd(T a, T b) {
  return b == 0 ? a : gcd(b, a % b);
}
template <class T>
inline void W(T p) {
  if (p < 0) pc('-'), p = -p;
  if (p / 10 != 0) W(p / 10);
  pc('0' + p % 10);
}
template <class T>
inline void Wn(T p) {
  W(p), puts("");
}
template <class T>
inline void W(T a, T b) {
  W(a), pc(' '), W(b);
}
template <class T>
inline void Wn(T a, T b) {
  W(a), pc(' '), Wn(b);
}
template <class T>
inline void W(T a, T b, T c) {
  W(a), pc(' '), W(b), pc(' '), W(c);
}
inline char gchar() {
  char ret = getchar();
  for (; ret == '\n' || ret == '\r' || ret == ' '; ret = getchar())
    ;
  return ret;
}
template <class T>
inline void fr(T& ret) {
  char c = ' ';
  int flag = 1;
  for (c = getchar(); c != '-' && !('0' <= c && c <= '9'); c = getchar())
    ;
  if (c == '-')
    flag = -1, ret = 0;
  else
    ret = c - '0';
  for (c = getchar(); '0' <= c && c <= '9'; c = getchar())
    ret = ret * 10 + c - '0';
  ret = ret * flag;
}
inline int fr() {
  int x;
  fr(x);
  return x;
}
template <class T>
inline void fr(T& a, T& b) {
  fr(a), fr(b);
}
template <class T>
inline void fr(T& a, T& b, T& c) {
  fr(a), fr(b), fr(c);
}
template <class T>
inline T fast_pow(T base, T index, T mod = 2147483647, T ret = 1) {
  for (; index; index >>= 1, base = base * base % mod)
    if (index & 1) ret = ret * base % mod;
  return ret;
}
const int maxv = 100, maxe = 100;
struct Edge {
  int edge, head[maxv], to[maxe], next[maxe];
  Edge() {
    edge = 0;
    memset(head, -1, sizeof head);
  }
  void addedge(int u, int v) {
    to[edge] = v, next[edge] = head[u];
    head[u] = edge++;
  }
};
};  // namespace my_useful_tools
using namespace my_useful_tools;
const int maxn = 1e5 + 100;
int n, m, a[maxn], cnt[maxn], sum, recl, recr;
int tim[maxn];
bool chk(int r) {
  for (int i = 1; i <= n; ++i) tim[i] = 0;
  if (r <= n / 2) {
    for (int i = r + 1; i <= n / 2; ++i)
      if (a[i] != a[n - i + 1]) return 0;
    for (int i = n - r + 1; i <= n - m; ++i) ++tim[a[i]];
    for (int i = m + 1; i <= r; ++i) --tim[a[i]];
    for (int i = 1; i <= n; ++i)
      if (tim[i] != 0) return 0;
    return 1;
  } else {
    for (int i = m + 1; i <= r; ++i) {
      ++tim[a[i]];
    }
    for (int i = r + 1; i <= n - m; ++i) {
      --tim[a[i]];
      if (tim[a[i]] < 0) return 0;
    }
    return 1;
  }
}
int main() {
  fr(n);
  for (int i = 1; i <= n; ++i) fr(a[i]), ++cnt[a[i]];
  for (int i = 1; i <= n; ++i) sum += cnt[i] & 1;
  if (sum >= 2) {
    puts("0");
    return 0;
  }
  m = -1;
  for (int i = 1, j = n; i <= j; ++i, --j)
    if (a[i] != a[j]) {
      m = i - 1;
      break;
    }
  if (m == -1) {
    Wn((long long)n * (n + 1) / 2);
    return 0;
  }
  int l = m + 1, r = n - m, mid;
  while (l < r) {
    mid = (l + r) >> 1;
    if (chk(mid))
      r = mid;
    else
      l = mid + 1;
  }
  recl = l;
  reverse(a + 1, a + n + 1);
  l = m + 1, r = n - m;
  while (l < r) {
    mid = (l + r) >> 1;
    if (chk(mid))
      r = mid;
    else
      l = mid + 1;
  }
  recr = n - l + 1;
  long long ans = (long long)(n - m - recl) * (m + 1) +
                  (long long)(recr - m - 1) * (m + 1) +
                  (long long)(m + 1) * (m + 1);
  Wn(ans);
  return 0;
}

```