n = int(eval(input()))

s = eval(input())



rinds, ginds, binds = [], [], set()



for i in range(n):

    if s[i] == 'R': rinds.append(i)

    elif s[i] == 'G': ginds.append(i)

    else: binds.add(i)



rlen, glen, blen = len(rinds), len(ginds), len(binds)





ans = 0



for i in rinds:

    for j in ginds:

        dist = abs(i-j)

        i_ = min(i, j)

        j_ = max(i, j)

        ans += blen

        # i' < j' < k

        if j_ + dist in binds:

            ans -= 1

        if dist%2==0 and i_ + dist//2 in binds:

            ans -= 1

        if i_ - dist in binds:

            ans -= 1



        # if binsearch_same(binds, blen, dist, j_):

        #     ans -= 1

        # # i'< k < j' 

        # if dist%2==0 and binsearch_same(binds, blen, dist//2, i_):

        #     ans -= 1

        # # # k < i' < j'

        # if binsearch_same(binds, blen, -dist, i_):

        #     ans -= 1



print(ans)































# n = input()

# print('Yes' if '7' in n else 'No')



# n = int(input())

# ans = 0

# for i in range(1, n+1):

#     if i%3 == 0 or i%5==0:

#         pass

#     else:

#         ans += i

# print(ans)





# k = int(input())

# def gcd(a, b):

#     if b == 0:

#         return a

#     return gcd(b, a%b)



# ans = 0

# for a in range(1, k+1):

#     for b in range(1, k+1):

#         for c in range(1, k+1):

#             ans += gcd(gcd(a, b), c)

# print(ans)
def solution1():

    # https://www.youtube.com/watch?v=aRdGRrsRo7I 

    n = int(eval(input()))

    s = eval(input())

    r, g, b = 0, 0, 0

    for i in s:

        if i == 'R': r += 1

        elif i == 'G': g += 1

        else: b += 1

    

    total = r*g*b

    # all permutations of rgb are valid, to check if s[i], s[j], s[k] is a permutation of 'rgb' we could use counter. Or neat trick: ASCII value of the sum of s[i] + s[j] + s[k] is same.



    is_rgb = ord('R') + ord('G') + ord('B')



    for i in range(n):

        for j in range(i+1, n):

            # Condition 2 fails when: i - j = k - j --> k = 2*j - i

            k = 2*j - i

            if k < n:

                if ord(s[i]) + ord(s[j]) + ord(s[2*j-i]) == is_rgb:

                    total -= 1

    print(total)



solution1()
n = int(eval(input()))
s = eval(input())
rinds, ginds, binds = [], [], set()
for i in range(n):
    if s[i] == "R":
        rinds.append(i)
    elif s[i] == "G":
        ginds.append(i)
    else:
        binds.add(i)
rlen, glen, blen = len(rinds), len(ginds), len(binds)
ans = 0
for i in rinds:
    for j in ginds:
        dist = abs(i - j)
        i_ = min(i, j)
        j_ = max(i, j)
        ans += blen
        # i' < j' < k
        if j_ + dist in binds:
            ans -= 1
        if dist % 2 == 0 and i_ + dist // 2 in binds:
            ans -= 1
        if i_ - dist in binds:
            ans -= 1
        # if binsearch_same(binds, blen, dist, j_):
        #     ans -= 1
        # # i'< k < j'
        # if dist%2==0 and binsearch_same(binds, blen, dist//2, i_):
        #     ans -= 1
        # # # k < i' < j'
        # if binsearch_same(binds, blen, -dist, i_):
        #     ans -= 1
print(ans)
# n = input()
# print('Yes' if '7' in n else 'No')
# n = int(input())
# ans = 0
# for i in range(1, n+1):
#     if i%3 == 0 or i%5==0:
#         pass
#     else:
#         ans += i
# print(ans)
# k = int(input())
# def gcd(a, b):
#     if b == 0:
#         return a
#     return gcd(b, a%b)
# ans = 0
# for a in range(1, k+1):
#     for b in range(1, k+1):
#         for c in range(1, k+1):
#             ans += gcd(gcd(a, b), c)
# print(ans)

def solution1():
    # https://www.youtube.com/watch?v=aRdGRrsRo7I
    n = int(eval(input()))
    s = eval(input())
    r, g, b = 0, 0, 0
    for i in s:
        if i == "R":
            r += 1
        elif i == "G":
            g += 1
        else:
            b += 1
    total = r * g * b
    # all permutations of rgb are valid, to check if s[i], s[j], s[k] is a permutation of 'rgb' we could use counter. Or neat trick: ASCII value of the sum of s[i] + s[j] + s[k] is same.
    is_rgb = ord("R") + ord("G") + ord("B")
    for i in range(n):
        for j in range(i + 1, n):
            # Condition 2 fails when: i - j = k - j --> k = 2*j - i
            k = 2 * j - i
            if k < n:
                if ord(s[i]) + ord(s[j]) + ord(s[2 * j - i]) == is_rgb:
                    total -= 1
    print(total)


solution1()

-n = int(eval(input())) -s = eval(input()) -rinds, ginds, binds = [], [], set() -for i in range(n): -    if s[i] == "R": -        rinds.append(i) -    elif s[i] == "G": -        ginds.append(i) -    else: -        binds.add(i) -rlen, glen, blen = len(rinds), len(ginds), len(binds) -ans = 0 -for i in rinds: -    for j in ginds: -        dist = abs(i - j) -        i_ = min(i, j) -        j_ = max(i, j) -        ans += blen -        # i' < j' < k -        if j_ + dist in binds: -            ans -= 1 -        if dist % 2 == 0 and i_ + dist // 2 in binds: -            ans -= 1 -        if i_ - dist in binds: -            ans -= 1 -        # if binsearch_same(binds, blen, dist, j_): -        #     ans -= 1 -        # # i'< k < j' -        # if dist%2==0 and binsearch_same(binds, blen, dist//2, i_): -        #     ans -= 1 -        # # # k < i' < j' -        # if binsearch_same(binds, blen, -dist, i_): -        #     ans -= 1 -print(ans) -# n = input() -# print('Yes' if '7' in n else 'No') -# n = int(input()) -# ans = 0 -# for i in range(1, n+1): -#     if i%3 == 0 or i%5==0: -#         pass -#     else: -#         ans += i -# print(ans) -# k = int(input()) -# def gcd(a, b): -#     if b == 0: -#         return a -#     return gcd(b, a%b) -# ans = 0 -# for a in range(1, k+1): -#     for b in range(1, k+1): -#         for c in range(1, k+1): -#             ans += gcd(gcd(a, b), c) -# print(ans) +def solution1(): +    # https://www.youtube.com/watch?v=aRdGRrsRo7I +    n = int(eval(input())) +    s = eval(input()) +    r, g, b = 0, 0, 0 +    for i in s: +        if i == "R": +            r += 1 +        elif i == "G": +            g += 1 +        else: +            b += 1 +    total = r * g * b +    # all permutations of rgb are valid, to check if s[i], s[j], s[k] is a permutation of 'rgb' we could use counter. Or neat trick: ASCII value of the sum of s[i] + s[j] + s[k] is same. +    is_rgb = ord("R") + ord("G") + ord("B") +    for i in range(n): +        for j in range(i + 1, n): +            # Condition 2 fails when: i - j = k - j --> k = 2*j - i +            k = 2 * j - i +            if k < n: +                if ord(s[i]) + ord(s[j]) + ord(s[2 * j - i]) == is_rgb: +                    total -= 1 +    print(total) + + +solution1()