#include <iostream> using namespace std; const int N = 1e5 + 10; typedef long long ll; ll pro[26][N],nex[26][N]; int main() { int n;cin>>n; string str;cin>>str; str = ' ' + str; for(int i = 1;i<=n;i++){ for(int j = 0;j<26;j++) pro[j][i] = pro[j][i-1]; pro[str[i]-'a'][i]++; } for(int i = n;i>=1;i--){ for(int j = 0;j<26;j++) nex[j][i] = nex[j][i+1]; nex[str[i]-'a'][i]++; } long long ans = 0; for(int i = 2;i<n;i++){ int c = str[i] -'a'; for(int j = 0;j<26;j++){ if(j==c) continue; ans += pro[j][i] * nex[c][i+1]; } } cout<<ans; return 0; } // 64 位输出请用 printf("%lld")