func_code_string: #include <bits/stdc++.h>   inline long long Input() {     long long ret = 0;     bool isN = 0;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) isN = 1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       ret = ret * 10 + c -  0 ;       c = getchar();     }     return isN ? -ret : ret;   }   inline void Output(long long x) {     if (x < 0) {       putchar( - );       x = -x;     }     int len = 0, data[20];     while (x) {       data[len++] = x % 10;       x /= 10;     }     if (!len) data[len++] = 0;     while (len--) putchar(data[len] + 48);     putchar(  n );   }   #pragma comment(linker,  /STACK:124000000,124000000 )   const long double PI = acos(-1.0);   using namespace std;   int num[100005];   int shit[100005];   int a[100005], n;   long long work1(int id) {     memset(shit, 0, sizeof(shit));     if (num[a[(n + 1) / 2]] & 1) {       int i;       for (i = n / 2; i; i--) {         if (a[i] != a[n + 1 - i]) break;       }       for (int j = id; j <= i; j++) {         shit[a[j]]++;         shit[a[n - j + 1]]--;       }       int j, cnt = 0;       bool flag = 1;       for (j = 0; j <= n; j++) {         if (shit[j] != 0) {           flag = 0;           if (shit[j] < 0) cnt++;         }       }       if (cnt == 0) return 1LL * id * (n - id + 1 - i);       for (j = i + 1; j < n - i + 1; j++) {         shit[a[j]] += 1;         if (shit[a[j]] >= 0 && shit[a[j]] - 2 < 0) cnt--;         if (cnt == 0) {           return 1LL * id * (n - id + 1 - j);         }       }       for (j = n - i + 1; j <= n; j++) {         shit[a[j]] += 2;         if (shit[a[j]] >= 0 && shit[a[j]] - 2 < 0) cnt--;         if (cnt == 0) {           return 1LL * id * (n - id + 1 - j);         }       }     } else {       for (int j = id; j <= (n + 1) / 2; j++) {         shit[a[j]]++;         shit[a[n - j + 1]]--;       }       shit[a[(n + 1) / 2]]++;       int j, cnt = 0;       bool flag = 1;       for (j = 0; j <= n; j++) {         if (shit[j] != 0) {           if (shit[j] < 0) cnt++;         }       }       if (cnt == 0) return 1LL * id * (n - id + 1 - (n + 1) / 2);       for (j = n + 2 - (n + 1) / 2; j <= n; j++) {         shit[a[j]] += 2;         if (shit[a[j]] >= 0 && shit[a[j]] - 2 < 0) cnt--;         if (cnt == 0) {           return 1LL * id * (n - id + 1 - j);         }       }     }   }   long long work2(int id) {     memset(shit, 0, sizeof(shit));     int i;     for (i = n / 2; i; i--) {       if (a[i] != a[n + 1 - i]) break;     }     for (int j = id; j <= i; j++) {       shit[a[j]]++;       shit[a[n - j + 1]]--;     }     int j, cnt = 0;     bool flag = 1;     for (j = 0; j <= n; j++) {       if (shit[j] != 0) {         flag = 0;         if (shit[j] < 0) cnt++;       }     }     if (cnt == 0) return 1LL * id * (n - id + 1 - i);     for (j = i + 1; j < n - i + 1; j++) {       shit[a[j]] += 1;       if (shit[a[j]] >= 0 && shit[a[j]] - 2 < 0) cnt--;       if (cnt == 0) {         return 1LL * id * (n - id + 1 - j);       }     }     for (j = n - i + 1; j <= n; j++) {       shit[a[j]] += 2;       if (shit[a[j]] >= 0 && shit[a[j]] - 2 < 0) cnt--;       if (cnt == 0) {         return 1LL * id * (n - id + 1 - j);       }     }   }   long long solve() {     long long ans = 0;     int i, id;     for (i = 1; i <= n; i++) {       if (a[i] != a[n + 1 - i]) {         ans = ans + 1LL * i * i;         id = i;         break;       }     }     if (i == n + 1) return 1LL * n * (n + 1) / 2;     if (n & 1) {       ans = ans + work1(id);       for (int i = 1; i <= n / 2; i++) swap(a[i], a[n + 1 - i]);       ans = ans + work1(id);     } else {       ans = ans + work2(id);       for (int i = 1; i <= n / 2; i++) swap(a[i], a[n + 1 - i]);       ans = ans + work2(id);     }     return ans;   }   int main() {     while (scanf( %d , &n) != EOF) {       memset(num, 0, sizeof(num));       for (int i = 1; i <= n; i++) {         scanf( %d , a + i);         num[a[i]]++;       }       int cnt = 0;       for (int i = 1; i <= n; i++) {         if (num[i] & 1) cnt++;       }       if (cnt >= 2) {         printf( 0 n );         continue;       }       printf( %I64d n , solve());     }     return 0;   }   