def main():

    N = int(eval(input()))

    S = eval(input())

    

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

    colors = set(list('RGB'))



    for i in range(N-2):

        for j in range(i+1, i+1+(N-1-i)//2):

            k = j + (j - i)

            if set([S[i], S[j], S[k]]) == colors:

                ans -= 1

            

    print(ans)





if __name__ == "__main__":

    main()
def main():

    N = int(eval(input()))

    S = eval(input())

    

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



    for i in range(N-2):

        for j in range(i+1, i+1+(N-1-i)//2):

            k = j + (j - i)

            if len(set([S[i], S[j], S[k]])) == 3:

                ans -= 1

            

    print(ans)





if __name__ == "__main__":

    main()
def main():
    N = int(eval(input()))
    S = eval(input())
    ans = S.count("R") * S.count("G") * S.count("B")
    colors = set(list("RGB"))
    for i in range(N - 2):
        for j in range(i + 1, i + 1 + (N - 1 - i) // 2):
            k = j + (j - i)
            if set([S[i], S[j], S[k]]) == colors:
                ans -= 1
    print(ans)


if __name__ == "__main__":
    main()

def main():
    N = int(eval(input()))
    S = eval(input())
    ans = S.count("R") * S.count("G") * S.count("B")
    for i in range(N - 2):
        for j in range(i + 1, i + 1 + (N - 1 - i) // 2):
            k = j + (j - i)
            if len(set([S[i], S[j], S[k]])) == 3:
                ans -= 1
    print(ans)


if __name__ == "__main__":
    main()

-    colors = set(list("RGB")) -            if set([S[i], S[j], S[k]]) == colors: +            if len(set([S[i], S[j], S[k]])) == 3: