import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); char[] s = sc.next().toCharArray(); sc.close(); long ans = 0; long[][][][] dp = new long[5][26][26][26]; for (int i = 0; i < n; i++) { int c = s[i] - 'A'; for (int j = 0; j < 26; j++) { if (j == c) { continue; } for (int j2 = 0; j2 < 26; j2++) { if (j2 == c || j2 == j) { continue; } for (int j3 = 0; j3 < 26; j3++) { if (j3 == c || j3 == j || j3 == j2) { continue; } ans += dp[4][j][j2][j3]; } } } for (int j = 0; j < 26; j++) { for (int j2 = 0; j2 < 26; j2++) { if (j != j2 && j != c && j2 != c) { dp[4][j][j2][c] += dp[3][j][j2][0]; } } } for (int j2 = 0; j2 < 26; j2++) { if (j2 != c) { dp[3][c][j2][0] += dp[2][c][j2][0]; } } for (int j = 0; j < 26; j++) { if (j != c) { dp[2][j][c][0] += dp[1][j][0][0]; } } dp[1][c][0][0]++; } System.out.println(ans); } }