import sys

def input(): return sys.stdin.readline().strip()



def main():

    N = int(eval(input()))

    S = eval(input())

    sub_sum = {key : [0]*N for key in "RGB"}

    

    for i, key in enumerate(S):

        sub_sum[key][i] = 1

    

    for i in range(1, N):

        for key in "RGB":

            sub_sum[key][i] += sub_sum[key][i-1]



    ans = 0

    for i in range(1, N):

        now = S[i]

        right_nums = {key:sub_sum[key][N-1]-sub_sum[key][i-1] for key in "RGB"}

        for j in range(i):

            left = S[j]

            right = [c for c in "RGB" if  c not in [now, left]][0]

            right_num = right_nums[right]

            if now != left:

                if 2*i - j < N and right_num:

                    if S[2*i - j] == right:

                        right_num -= 1

                ans += right_num

    print(ans)









if __name__ == "__main__":

    main()
import sys

def input() : return sys.stdin.readline().strip()



def main():

    N = int(eval(input()))

    S = eval(input())

    r = S.count("R")

    g = S.count("G")

    b = N-r-g



    all_num = r*g*b

    sub = 0

    for i in range(N):

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

            if S[i] == S[j]: continue

            k = j + (j - i)

            if k >= N or S[k] == S[i] or S[k] == S[j]: continue

            sub += 1

    print((all_num - sub))



if __name__ == "__main__":

    main()
import sys


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(eval(input()))
    S = eval(input())
    sub_sum = {key: [0] * N for key in "RGB"}
    for i, key in enumerate(S):
        sub_sum[key][i] = 1
    for i in range(1, N):
        for key in "RGB":
            sub_sum[key][i] += sub_sum[key][i - 1]
    ans = 0
    for i in range(1, N):
        now = S[i]
        right_nums = {key: sub_sum[key][N - 1] - sub_sum[key][i - 1] for key in "RGB"}
        for j in range(i):
            left = S[j]
            right = [c for c in "RGB" if c not in [now, left]][0]
            right_num = right_nums[right]
            if now != left:
                if 2 * i - j < N and right_num:
                    if S[2 * i - j] == right:
                        right_num -= 1
                ans += right_num
    print(ans)


if __name__ == "__main__":
    main()

import sys


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(eval(input()))
    S = eval(input())
    r = S.count("R")
    g = S.count("G")
    b = N - r - g
    all_num = r * g * b
    sub = 0
    for i in range(N):
        for j in range(i + 1, N):
            if S[i] == S[j]:
                continue
            k = j + (j - i)
            if k >= N or S[k] == S[i] or S[k] == S[j]:
                continue
            sub += 1
    print((all_num - sub))


if __name__ == "__main__":
    main()

-    sub_sum = {key: [0] * N for key in "RGB"} -    for i, key in enumerate(S): -        sub_sum[key][i] = 1 -    for i in range(1, N): -        for key in "RGB": -            sub_sum[key][i] += sub_sum[key][i - 1] -    ans = 0 -    for i in range(1, N): -        now = S[i] -        right_nums = {key: sub_sum[key][N - 1] - sub_sum[key][i - 1] for key in "RGB"} -        for j in range(i): -            left = S[j] -            right = [c for c in "RGB" if c not in [now, left]][0] -            right_num = right_nums[right] -            if now != left: -                if 2 * i - j < N and right_num: -                    if S[2 * i - j] == right: -                        right_num -= 1 -                ans += right_num -    print(ans) +    r = S.count("R") +    g = S.count("G") +    b = N - r - g +    all_num = r * g * b +    sub = 0 +    for i in range(N): +        for j in range(i + 1, N): +            if S[i] == S[j]: +                continue +            k = j + (j - i) +            if k >= N or S[k] == S[i] or S[k] == S[j]: +                continue +            sub += 1 +    print((all_num - sub))