import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
//输入字符串
String str = sc.next();
//后缀和数组,suffix[i+1][j]表示str中第i个字母之后的对应字母出现次数
int[][] suffix = new int[n + 1][26];
for (int i = n - 1; i >= 0; i--) {
char c = str.charAt(i);
for (int j = 0; j < 26; j++) {
suffix[i][j] = suffix[i + 1][j];
}
suffix[i][c - 'a']++;
}
//记录所有"abb"型子序列的个数
long res = 0;
for (int i = 0; i < n; i++) {
char c = str.charAt(i);
for (int j = 0; j < 26; j++) {
//加上当前字母为前缀,所组成的"abb"型子序列的个数
if (j != c - 'a' && suffix[i][j] >= 2) {
res += suffix[i + 1][j] * (suffix[i + 1][j] - 1) / 2;
}
}
}
System.out.println(res);
}
}