using System.Collections.Generic; using System; public class Hello { static void Main() { var n = int.Parse(Console.ReadLine().Trim()); var s = Console.ReadLine().Trim(); getAns(n, s); } static int check2(int n, int[] t, int x, int y, int p) { var res = 0; for (int i = p; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { if (t[i] == t[j]) continue; if (t[i] != x && t[i] != y && t[j] != x && t[j] != y) res++; } } return res; } static int check(int n, int[] t, int L, int r) { var res = 0; for (int i = L + 1; i < r; i++) { if (t[i] != t[L]) res += check2(n, t, t[L], t[i], r + 1); } return res; } static void getAns(int n, string s) { var t = new int[n]; var aa = new List[26]; for (int i = 0; i < 26; i++) aa[i] = new List(); for (int i = 0; i < n; i++) { var w = s[i] - 'A'; t[i] = w; aa[w].Add(i); } var ans = 0; for (int i = 0; i < 26; i++) { var aac = aa[i].Count; if (aac > 1) { for (int j = 0; j < aac - 1; j++) { for (int k = j + 1; k < aac; k++) { ans += check(n, t, aa[i][j], aa[i][k]); } } } } Console.WriteLine(ans); } }