#include <bits/stdc++.h>   using namespace std;   int count1[100005], count2[100005], count3[100005];   bool can_be_palin(int *a, int size) {     int i, no_of_odd = 0;     for (i = 0; i < size; i++) no_of_odd += a[i] % 2;     return (no_of_odd <= 1);   }   bool is_palin(int *a, int l, int r) {     for (int i = l; i <= (l + r) / 2; i++)       if (a[i] != a[r + l - i]) return false;     return true;   }   bool func(int *a, int n, int end, int l, int r) {     int i;     fill(count1, count1 + n + 1, 0);     fill(count2, count2 + n + 1, 0);     if (end - l + 1 >= r - end) {       for (i = l; i <= end; i++) count1[a[i]]++;       for (i = r; i > end; i--) count2[a[i]]++;       for (i = 1; i <= n; i++) {         if (count2[i] > count1[i]) return false;         count1[i] -= count2[i];       }       return can_be_palin(count1, n + 1);     } else {       for (i = l; i <= end; i++) count1[a[i]]++;       for (i = r; i >= r - end + l; i--) count2[a[i]]++;       for (i = 1; i <= n; i++) {         if (count2[i] > count1[i]) return false;         count1[i] -= count2[i];       }       return can_be_palin(count1, n + 1) && is_palin(a, end + 1, r - end + l - 1);     }   }   bool func2(int *a, int n, int end, int l, int r) {     int i;     fill(count1, count1 + n + 1, 0);     fill(count2, count2 + n + 1, 0);     if (r - end + 1 >= end - l) {       for (i = r; i >= end; i--) count1[a[i]]++;       for (i = l; i < end; i++) count2[a[i]]++;       for (i = 1; i <= n; i++) {         if (count2[i] > count1[i]) return false;         count1[i] -= count2[i];       }       return can_be_palin(count1, n + 1);     } else {       for (i = r; i >= end; i--) count1[a[i]]++;       for (i = l; i <= l + r - end; i++) count2[a[i]]++;       for (i = 1; i <= n; i++) {         if (count2[i] > count1[i]) return false;         count1[i] -= count2[i];       }       return can_be_palin(count1, n + 1) && is_palin(a, r - end + l + 1, end - 1);     }   }   int main() {     int n, i;     scanf( %d , &n);     long long ans = 0;     int a[n];     for (i = 0; i < n; i++) scanf( %d , &a[i]);     for (i = 0; i < n / 2 && a[i] == a[n - 1 - i]; i++)       ;     if (i == n / 2) {       printf( %I64d , (long long)n * (n + 1) / 2);       return 0;     }     int l = i, r = n - 1 - i, left_prev = l, right_prev = r, end = (l + r) / 2;     int prev_pos = -1;     while (left_prev < end - 1 && end < right_prev - 1) {       bool flag = true;       flag = func(a, n, end, l, r);       int mid1 = (end + left_prev) / 2;       int mid2 = (end + right_prev) / 2;       if (flag == false) {         left_prev = end;         end = mid2;       } else {         right_prev = end;         prev_pos = end;         end = mid1;       }     }     for (int k = left_prev; k < r && k < right_prev; k++)       if (func(a, n, k, l, r) == true)         prev_pos = (prev_pos == -1) ? k : min(prev_pos, k);     if (prev_pos != -1) ans += (long long)(l + 1) * (r - prev_pos);     right_prev = r, left_prev = l, end = (l + r) / 2;     prev_pos = -1;     while (end < right_prev - 1 && left_prev < end - 1) {       bool flag = true;       flag = func2(a, n, end, l, r);       int mid1 = (end + right_prev) / 2;       int mid2 = (end + left_prev) / 2;       if (flag == false) {         right_prev = end;         end = mid2;       } else {         left_prev = end;         prev_pos = end;         end = mid1;       }     }     for (int k = right_prev; k > l && k > left_prev; k--)       if (func2(a, n, k, l, r) == true)         prev_pos = (prev_pos == -1) ? k : max(prev_pos, k);     if (prev_pos != -1) ans += (long long)(n - r) * (prev_pos - l);     fill(count1, count1 + n + 1, 0);     for (i = l; i <= r; i++) count1[a[i]]++;     if (can_be_palin(count1, n + 1) == true) ans += (long long)(l + 1) * (n - r);     printf( %I64d , ans);   }