n = int(eval(input()))

s = eval(input())



r = 0

g = 0

b = 0



for i in range(n):

    if s[i] == 'R':

        r += 1

    elif s[i] == 'G':

        g += 1

    else:

        b += 1

ans = r * b * g



for c in range(n):

    center = s[c]

    for dif in range(n):

        if dif + c > n - 1 or c - dif < 0:

            continue

        left = s[c - dif]

        right = s[c + dif]

        if left != center and center != right and right != left:

            ans -= 1

print(ans)
def main():

    n = int(eval(input()))

    l = list(eval(input()))

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

    for c in range(n):

        center = l[c]

        for dif in range(n):

            if dif + c > n - 1 or c - dif < 0:

                continue

            left = l[c - dif]

            right = l[dif + c]

            if left != center and center != right and right != left:

                ans -= 1

    print(ans)





if __name__ == '__main__':

    main()
n = int(eval(input()))
s = eval(input())
r = 0
g = 0
b = 0
for i in range(n):
    if s[i] == "R":
        r += 1
    elif s[i] == "G":
        g += 1
    else:
        b += 1
ans = r * b * g
for c in range(n):
    center = s[c]
    for dif in range(n):
        if dif + c > n - 1 or c - dif < 0:
            continue
        left = s[c - dif]
        right = s[c + dif]
        if left != center and center != right and right != left:
            ans -= 1
print(ans)

def main():
    n = int(eval(input()))
    l = list(eval(input()))
    ans = l.count("R") * l.count("G") * l.count("B")
    for c in range(n):
        center = l[c]
        for dif in range(n):
            if dif + c > n - 1 or c - dif < 0:
                continue
            left = l[c - dif]
            right = l[dif + c]
            if left != center and center != right and right != left:
                ans -= 1
    print(ans)


if __name__ == "__main__":
    main()

-n = int(eval(input())) -s = eval(input()) -r = 0 -g = 0 -b = 0 -for i in range(n): -    if s[i] == "R": -        r += 1 -    elif s[i] == "G": -        g += 1 -    else: -        b += 1 -ans = r * b * g -for c in range(n): -    center = s[c] -    for dif in range(n): -        if dif + c > n - 1 or c - dif < 0: -            continue -        left = s[c - dif] -        right = s[c + dif] -        if left != center and center != right and right != left: -            ans -= 1 -print(ans) +def main(): +    n = int(eval(input())) +    l = list(eval(input())) +    ans = l.count("R") * l.count("G") * l.count("B") +    for c in range(n): +        center = l[c] +        for dif in range(n): +            if dif + c > n - 1 or c - dif < 0: +                continue +            left = l[c - dif] +            right = l[dif + c] +            if left != center and center != right and right != left: +                ans -= 1 +    print(ans) + + +if __name__ == "__main__": +    main()