func_code_string: #include <bits/stdc++.h>   using namespace std;   int c[500005], n, nm[500005], g[321];   vector<int> v[55];   char s[500005], p[500005];   inline int qr() {     int x = 0, w = 1;     char a = 0;     while (a <  0  || a >  9 ) {       if (a ==  - ) w = -1;       a = getchar();     }     while (a <=  9  && a >=  0 ) {       x = (x << 3) + (x << 1) + (a ^ 48);       a = getchar();     }     return x * w;   }   inline int lowbit(int x) { return x & -x; }   void add(int x, int d) {     while (x <= n) {       c[x] += d;       x += lowbit(x);     }   }   long long qu(int x) {     long long ans = 0;     while (x) {       ans += c[x];       x -= lowbit(x);     }     return ans;   }   int main() {     n = qr();     cin >> s + 1;     for (register int i = 1; i <= n; i++) p[i] = s[n - i + 1];     for (register int i = 1; i <= n; i++) v[p[i] -  a  + 1].push_back(i);     for (register int i = 1; i <= n; i++) {       int ch = s[i] -  a  + 1;       nm[i] = v[ch][g[ch]];       ++g[ch];     }     long long ans = 0;     for (register int i = 1; i <= n; i++) {       add(nm[i], 1);       ans += qu(n) - qu(nm[i]);     }     cout << ans << endl;     return 0;   }   