def main():

    N = int(eval(input()))

    S = eval(input())

    RGBdict = {"R":0,"G":0,"B":0}

    for i in range(N):

        RGBdict[S[i]] += 1



    if N%2 == 0:

        maxsa = (N//2) -1

    else:

        maxsa = N//2



    tmp = N - 2

    cnt = 0

    for j in range(maxsa+1):

        num = tmp-(j*2)

        for k in range( num ):

            if (S[N-num+k] != S[N-num+k-j-1]) and (S[N-num+k] != S[N-num+k-2*j-2]) and (S[N-num+k-j-1] != S[N-num+k-2*j-2]):

                cnt += 1



    ans = RGBdict["R"]*RGBdict["G"]*RGBdict["B"]

    ans -= cnt

    return ans



print((main()))

def main():

    N = int(eval(input()))

    S = eval(input())

    dict = {'R':0, 'B':0, 'G':0}

    for i in range(N):

        dict[S[i]] += 1

    ans = dict['R']*dict['B']*dict['G']

    for i in range(N-2):

        if (N-i)%2 == 0:

            tmp = int((N-i)/2)-1

        else:

            tmp = (N-i)//2

        for j in range(1,tmp+1):

            if S[i]!=S[i+j] and S[i]!=S[i+2*j] and S[i+j]!=S[i+2*j]:

                ans = ans - 1



    return ans



print((main()))  

def main():
    N = int(eval(input()))
    S = eval(input())
    RGBdict = {"R": 0, "G": 0, "B": 0}
    for i in range(N):
        RGBdict[S[i]] += 1
    if N % 2 == 0:
        maxsa = (N // 2) - 1
    else:
        maxsa = N // 2
    tmp = N - 2
    cnt = 0
    for j in range(maxsa + 1):
        num = tmp - (j * 2)
        for k in range(num):
            if (
                (S[N - num + k] != S[N - num + k - j - 1])
                and (S[N - num + k] != S[N - num + k - 2 * j - 2])
                and (S[N - num + k - j - 1] != S[N - num + k - 2 * j - 2])
            ):
                cnt += 1
    ans = RGBdict["R"] * RGBdict["G"] * RGBdict["B"]
    ans -= cnt
    return ans


print((main()))

def main():
    N = int(eval(input()))
    S = eval(input())
    dict = {"R": 0, "B": 0, "G": 0}
    for i in range(N):
        dict[S[i]] += 1
    ans = dict["R"] * dict["B"] * dict["G"]
    for i in range(N - 2):
        if (N - i) % 2 == 0:
            tmp = int((N - i) / 2) - 1
        else:
            tmp = (N - i) // 2
        for j in range(1, tmp + 1):
            if S[i] != S[i + j] and S[i] != S[i + 2 * j] and S[i + j] != S[i + 2 * j]:
                ans = ans - 1
    return ans


print((main()))

-    RGBdict = {"R": 0, "G": 0, "B": 0} +    dict = {"R": 0, "B": 0, "G": 0} -        RGBdict[S[i]] += 1 -    if N % 2 == 0: -        maxsa = (N // 2) - 1 -    else: -        maxsa = N // 2 -    tmp = N - 2 -    cnt = 0 -    for j in range(maxsa + 1): -        num = tmp - (j * 2) -        for k in range(num): -            if ( -                (S[N - num + k] != S[N - num + k - j - 1]) -                and (S[N - num + k] != S[N - num + k - 2 * j - 2]) -                and (S[N - num + k - j - 1] != S[N - num + k - 2 * j - 2]) -            ): -                cnt += 1 -    ans = RGBdict["R"] * RGBdict["G"] * RGBdict["B"] -    ans -= cnt +        dict[S[i]] += 1 +    ans = dict["R"] * dict["B"] * dict["G"] +    for i in range(N - 2): +        if (N - i) % 2 == 0: +            tmp = int((N - i) / 2) - 1 +        else: +            tmp = (N - i) // 2 +        for j in range(1, tmp + 1): +            if S[i] != S[i + j] and S[i] != S[i + 2 * j] and S[i + j] != S[i + 2 * j]: +                ans = ans - 1