import sys

input = lambda: sys.stdin.readline().rstrip()

inp = sys.stdin.buffer.readline                               

def I(): return list(map(int,inp().split()))

from collections import Counter

from numpy import prod



n=I()[0]

s=eval(input()) 

cut=0

for i in range(len(s)):

    for j in range(i+1,len(s)):

        if 2*j-i>=len(s): break

        if len({s[i],s[j],s[2*j-i]})==3:

            cut+=1

d=Counter(s)

if len(d)<3: print((0))

else: print((prod(list(d.values()))-cut))



import sys

input = lambda: sys.stdin.readline().rstrip()

inp = sys.stdin.buffer.readline                               

def I(): return list(map(int,inp().split()))

from collections import Counter



n=I()[0]

s=eval(input()) 

cut=0

for i in range(len(s)):

    for j in range(i+1,len(s)):

        if 2*j-i>=len(s): break

        if not(s[i]==s[j] or s[i]==s[2*j-i] or s[j]==s[2*j-i]): 

            cut+=1

d=Counter(s) ; mul=1

for i in list(d.values()):

    mul*=i

if len(d)<3: print((0))

else: print((mul-cut))





            

import sys

input = lambda: sys.stdin.readline().rstrip()
inp = sys.stdin.buffer.readline


def I():
    return list(map(int, inp().split()))


from collections import Counter
from numpy import prod

n = I()[0]
s = eval(input())
cut = 0
for i in range(len(s)):
    for j in range(i + 1, len(s)):
        if 2 * j - i >= len(s):
            break
        if len({s[i], s[j], s[2 * j - i]}) == 3:
            cut += 1
d = Counter(s)
if len(d) < 3:
    print((0))
else:
    print((prod(list(d.values())) - cut))

import sys

input = lambda: sys.stdin.readline().rstrip()
inp = sys.stdin.buffer.readline


def I():
    return list(map(int, inp().split()))


from collections import Counter

n = I()[0]
s = eval(input())
cut = 0
for i in range(len(s)):
    for j in range(i + 1, len(s)):
        if 2 * j - i >= len(s):
            break
        if not (s[i] == s[j] or s[i] == s[2 * j - i] or s[j] == s[2 * j - i]):
            cut += 1
d = Counter(s)
mul = 1
for i in list(d.values()):
    mul *= i
if len(d) < 3:
    print((0))
else:
    print((mul - cut))

-from numpy import prod -        if len({s[i], s[j], s[2 * j - i]}) == 3: +        if not (s[i] == s[j] or s[i] == s[2 * j - i] or s[j] == s[2 * j - i]): +mul = 1 +for i in list(d.values()): +    mul *= i -    print((prod(list(d.values())) - cut)) +    print((mul - cut))