n = int(input()) s = input().strip() count = 0 # We need to select 5 distinct indices i1 < i2 < i3 < i4 < i5 in the string s # such that s[i1] == s[i3], and all other characters (s[i2], s[i4], s[i5]) are distinct and != s[i1] for i1 in range(n): for i2 in range(i1 + 1, n): for i3 in range(i2 + 1, n): for i4 in range(i3 + 1, n): for i5 in range(i4 + 1, n): # Check if s[i1] == s[i3] if s[i1] == s[i3]: # Check other conditions a, b, c, d, e = s[i1], s[i2], s[i3], s[i4], s[i5] # a == c is already true # b, d, e must be distinct and != a if b != a and d != a and e != a: if b != d and b != e and d != e: count += 1 print(count)