#!/usr/bin/env python3



MOD = 10**9

def make_divisors(n):

    divisors = []

    for i in range(1, int(n**0.5)+1):

        if n % i == 0:

            divisors.append(i)

            if i != n // i:

                divisors.append(n//i)

    return divisors



N = int(eval(input()))

S = eval(input())





ans = S.count('R') * S.count('G') * S.count('B')



SN = []



for s in S:

    if s == 'R': SN.append(-1)

    elif s == 'G': SN.append(0)

    else: SN.append(1)



rem2 = ['RRR', 'GGG', 'BBB']



count = 0

for i in range(1, N-1):

    index = i

    left = i - 1

    right = i + 1

    f = True

    while f:

        if left == -1 or right == N:

            break

        if SN[left] == SN[index] and SN[index] == SN[right] == 0 : pass

        elif SN[left] + SN[index] + SN[right] == 0 :

            count+= 1

        

        left -= 1

        right += 1



print((ans-count))

N = int(eval(input()))

S = eval(input())

 

 

ans = S.count('R') * S.count('G') * S.count('B')

 

SN = []

 

for s in S:

    if s == 'R': SN.append(-1)

    elif s == 'G': SN.append(0)

    else: SN.append(1)

 

rem2 = ['RRR', 'GGG', 'BBB']

 

count = 0

for i in range(1, N-1):

    index = i

    left = i - 1

    right = i + 1

    f = True

    while f:

        if left == -1 or right == N:

            break

        if SN[left] == SN[index] and SN[index] == SN[right] == 0 : pass

        elif SN[left] + SN[index] + SN[right] == 0 :

            count+= 1

        

        left -= 1

        right += 1

 

print((ans-count))
#!/usr/bin/env python3
MOD = 10**9


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    return divisors


N = int(eval(input()))
S = eval(input())
ans = S.count("R") * S.count("G") * S.count("B")
SN = []
for s in S:
    if s == "R":
        SN.append(-1)
    elif s == "G":
        SN.append(0)
    else:
        SN.append(1)
rem2 = ["RRR", "GGG", "BBB"]
count = 0
for i in range(1, N - 1):
    index = i
    left = i - 1
    right = i + 1
    f = True
    while f:
        if left == -1 or right == N:
            break
        if SN[left] == SN[index] and SN[index] == SN[right] == 0:
            pass
        elif SN[left] + SN[index] + SN[right] == 0:
            count += 1
        left -= 1
        right += 1
print((ans - count))

N = int(eval(input()))
S = eval(input())
ans = S.count("R") * S.count("G") * S.count("B")
SN = []
for s in S:
    if s == "R":
        SN.append(-1)
    elif s == "G":
        SN.append(0)
    else:
        SN.append(1)
rem2 = ["RRR", "GGG", "BBB"]
count = 0
for i in range(1, N - 1):
    index = i
    left = i - 1
    right = i + 1
    f = True
    while f:
        if left == -1 or right == N:
            break
        if SN[left] == SN[index] and SN[index] == SN[right] == 0:
            pass
        elif SN[left] + SN[index] + SN[right] == 0:
            count += 1
        left -= 1
        right += 1
print((ans - count))

-#!/usr/bin/env python3 -MOD = 10**9 - - -def make_divisors(n): -    divisors = [] -    for i in range(1, int(n**0.5) + 1): -        if n % i == 0: -            divisors.append(i) -            if i != n // i: -                divisors.append(n // i) -    return divisors - -