def main():

    n=int(eval(input()))

    s=eval(input())

    ans=0

    d=dict()

    dr=[0]*n

    dg=[0]*n

    db=[0]*n

    mr=[0]*n

    mg=[0]*n

    mb=[0]*n



    for i in range(n):

        if s[i]=='R':

            dr[i]=1

            mr[i]=1

        if s[i]=='G':

            dg[i]=1

            mg[i]=1

        if s[i]=='B':

            db[i]=1

            mb[i]=1



    for i in range(n-1):

        mr[n-2-i]+=mr[n-1-i]

        mg[n-2-i]+=mg[n-1-i]

        mb[n-2-i]+=mb[n-1-i]



    for i in range(n-2):

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

            if s[i]==s[j]:

                continue

            if s[i]=='R' and s[j]=='G':

                k=1

            elif s[i]=='R' and s[j]=='B':

                k=2

            elif s[i]=='G' and s[j]=='R':

                k=1

            elif s[i]=='G' and s[j]=='B':

                k=0

            elif s[i]=='B' and s[j]=='R':

                k=2

            elif s[i]=='B' and s[j]=='G':

                k=0

            #print(k)

            

            if k==0:

                ans+=mr[j+1]

                if (j+(j-i))<n:

                    ans-=dr[j+(j-i)]

            if k==1:

                ans+=mb[j+1]

                if (j+(j-i))<n:

                    ans-=db[j+(j-i)]

            if k==2:

                ans+=mg[j+1]

                if (j+(j-i))<n:

                    ans-=dg[j+(j-i)]



    print(ans)

        







main()
# ABC162D - RGB Triplets

def main():

    n=int(eval(input()))

    s=eval(input())

    ans=0

    d=[[0]*n for _ in range(3)]

    m=[[0]*n for _ in range(3)]

    l=[[0,2,1],[2,1,0],[1,0,2]]



    for i in range(n):

        d[ord(s[i])%3][i]=1

        m[ord(s[i])%3][i]=1



    for j in range(3):

        for i in range(n-1,0,-1):

            m[j][i-1]+=m[j][i]



    for i in range(n-2):

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

            if s[i]==s[j]:

                continue

            ans+=m[l[ord(s[i])%3][ord(s[j])%3]][j+1]

            if j*2-i<n:

                ans-=d[l[ord(s[i])%3][ord(s[j])%3]][j*2-i]



    print(ans)

        

main()
def main():
    n = int(eval(input()))
    s = eval(input())
    ans = 0
    d = dict()
    dr = [0] * n
    dg = [0] * n
    db = [0] * n
    mr = [0] * n
    mg = [0] * n
    mb = [0] * n
    for i in range(n):
        if s[i] == "R":
            dr[i] = 1
            mr[i] = 1
        if s[i] == "G":
            dg[i] = 1
            mg[i] = 1
        if s[i] == "B":
            db[i] = 1
            mb[i] = 1
    for i in range(n - 1):
        mr[n - 2 - i] += mr[n - 1 - i]
        mg[n - 2 - i] += mg[n - 1 - i]
        mb[n - 2 - i] += mb[n - 1 - i]
    for i in range(n - 2):
        for j in range(i, n - 1):
            if s[i] == s[j]:
                continue
            if s[i] == "R" and s[j] == "G":
                k = 1
            elif s[i] == "R" and s[j] == "B":
                k = 2
            elif s[i] == "G" and s[j] == "R":
                k = 1
            elif s[i] == "G" and s[j] == "B":
                k = 0
            elif s[i] == "B" and s[j] == "R":
                k = 2
            elif s[i] == "B" and s[j] == "G":
                k = 0
            # print(k)
            if k == 0:
                ans += mr[j + 1]
                if (j + (j - i)) < n:
                    ans -= dr[j + (j - i)]
            if k == 1:
                ans += mb[j + 1]
                if (j + (j - i)) < n:
                    ans -= db[j + (j - i)]
            if k == 2:
                ans += mg[j + 1]
                if (j + (j - i)) < n:
                    ans -= dg[j + (j - i)]
    print(ans)


main()

# ABC162D - RGB Triplets
def main():
    n = int(eval(input()))
    s = eval(input())
    ans = 0
    d = [[0] * n for _ in range(3)]
    m = [[0] * n for _ in range(3)]
    l = [[0, 2, 1], [2, 1, 0], [1, 0, 2]]
    for i in range(n):
        d[ord(s[i]) % 3][i] = 1
        m[ord(s[i]) % 3][i] = 1
    for j in range(3):
        for i in range(n - 1, 0, -1):
            m[j][i - 1] += m[j][i]
    for i in range(n - 2):
        for j in range(i + 1, n - 1):
            if s[i] == s[j]:
                continue
            ans += m[l[ord(s[i]) % 3][ord(s[j]) % 3]][j + 1]
            if j * 2 - i < n:
                ans -= d[l[ord(s[i]) % 3][ord(s[j]) % 3]][j * 2 - i]
    print(ans)


main()

+# ABC162D - RGB Triplets -    d = dict() -    dr = [0] * n -    dg = [0] * n -    db = [0] * n -    mr = [0] * n -    mg = [0] * n -    mb = [0] * n +    d = [[0] * n for _ in range(3)] +    m = [[0] * n for _ in range(3)] +    l = [[0, 2, 1], [2, 1, 0], [1, 0, 2]] -        if s[i] == "R": -            dr[i] = 1 -            mr[i] = 1 -        if s[i] == "G": -            dg[i] = 1 -            mg[i] = 1 -        if s[i] == "B": -            db[i] = 1 -            mb[i] = 1 -    for i in range(n - 1): -        mr[n - 2 - i] += mr[n - 1 - i] -        mg[n - 2 - i] += mg[n - 1 - i] -        mb[n - 2 - i] += mb[n - 1 - i] +        d[ord(s[i]) % 3][i] = 1 +        m[ord(s[i]) % 3][i] = 1 +    for j in range(3): +        for i in range(n - 1, 0, -1): +            m[j][i - 1] += m[j][i] -        for j in range(i, n - 1): +        for j in range(i + 1, n - 1): -            if s[i] == "R" and s[j] == "G": -                k = 1 -            elif s[i] == "R" and s[j] == "B": -                k = 2 -            elif s[i] == "G" and s[j] == "R": -                k = 1 -            elif s[i] == "G" and s[j] == "B": -                k = 0 -            elif s[i] == "B" and s[j] == "R": -                k = 2 -            elif s[i] == "B" and s[j] == "G": -                k = 0 -            # print(k) -            if k == 0: -                ans += mr[j + 1] -                if (j + (j - i)) < n: -                    ans -= dr[j + (j - i)] -            if k == 1: -                ans += mb[j + 1] -                if (j + (j - i)) < n: -                    ans -= db[j + (j - i)] -            if k == 2: -                ans += mg[j + 1] -                if (j + (j - i)) < n: -                    ans -= dg[j + (j - i)] +            ans += m[l[ord(s[i]) % 3][ord(s[j]) % 3]][j + 1] +            if j * 2 - i < n: +                ans -= d[l[ord(s[i]) % 3][ord(s[j]) % 3]][j * 2 - i]