def main():

    n = int(eval(input()))

    s = list(eval(input()))

    r = [0] * n

    g = [0] * n

    b = [0] * n

    # print(s)

    for i, rgb in enumerate(s):

        if rgb == 'R':

            r[i] += 1

        elif rgb == 'G':

            g[i] += 1

        else:

            b[i] += 1



        if i != 0:

            r[i] += r[i-1]

            g[i] += g[i-1]

            b[i] += b[i-1]

    # print(r)

    ans = 0

    mid = [0] * n

    # print('A')

    for i, rgb in enumerate(s):

        # print(i)



        # print('A')

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

            # print(i,j,rgb)

            if i+j >= n or i-j < 0:

                break

            # print(s[i-j],rgb,s[i+j])

            if rgb != s[i-j] and s[i-j] != s[i+j] and rgb != s[i+j]:

                mid[i] += 1





    print((r[-1] * g[-1] * b[-1] - sum(mid)))

    # # print(mid)

    # for i, ss in enumerate(s):

    #     if i == 0:

    #         continue

    #     if ss == 'R':

    #         tmp = g[i-1] * (b[-1] - b[i])

    #         tmp += b[i-1] * (g[-1] - g[i])

    #         tmp -= mid[i]

    #     elif ss == 'G':

    #         tmp = r[i-1] * (b[-1] - b[i])

    #         tmp += b[i-1] * (r[-1] - r[i])

    #         tmp -= mid[i]

    #     else:

    #         tmp = g[i-1] * (r[-1] - r[i])

    #         tmp += r[i-1] * (g[-1] - g[i])

    #         tmp -= mid[i]

    #     ans += tmp

    # print(ans)



if __name__=='__main__':

    main()

def main():

    n = int(eval(input()))

    s = list(eval(input()))

    r = 0

    g = 0

    b = 0

    # print(s)

    for i, rgb in enumerate(s):

        if rgb == 'R':

            r += 1

        elif rgb == 'G':

            g += 1

        else:

            b += 1





    # print(r)

    ans = 0

    mid = 0

    # print('A')

    for i, rgb in enumerate(s):

        # print(i)



        # print('A')

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

            # print(i,j,rgb)

            if i+j >= n or i-j < 0:

                break

            # print(s[i-j],rgb,s[i+j])

            if rgb != s[i-j] and s[i-j] != s[i+j] and rgb != s[i+j]:

                mid += 1





    print((r * g * b - mid))

    # # print(mid)

    # for i, ss in enumerate(s):

    #     if i == 0:

    #         continue

    #     if ss == 'R':

    #         tmp = g[i-1] * (b[-1] - b[i])

    #         tmp += b[i-1] * (g[-1] - g[i])

    #         tmp -= mid[i]

    #     elif ss == 'G':

    #         tmp = r[i-1] * (b[-1] - b[i])

    #         tmp += b[i-1] * (r[-1] - r[i])

    #         tmp -= mid[i]

    #     else:

    #         tmp = g[i-1] * (r[-1] - r[i])

    #         tmp += r[i-1] * (g[-1] - g[i])

    #         tmp -= mid[i]

    #     ans += tmp

    # print(ans)



if __name__=='__main__':

    main()

def main():
    n = int(eval(input()))
    s = list(eval(input()))
    r = [0] * n
    g = [0] * n
    b = [0] * n
    # print(s)
    for i, rgb in enumerate(s):
        if rgb == "R":
            r[i] += 1
        elif rgb == "G":
            g[i] += 1
        else:
            b[i] += 1
        if i != 0:
            r[i] += r[i - 1]
            g[i] += g[i - 1]
            b[i] += b[i - 1]
    # print(r)
    ans = 0
    mid = [0] * n
    # print('A')
    for i, rgb in enumerate(s):
        # print(i)
        # print('A')
        for j in range(1, i + 1):
            # print(i,j,rgb)
            if i + j >= n or i - j < 0:
                break
            # print(s[i-j],rgb,s[i+j])
            if rgb != s[i - j] and s[i - j] != s[i + j] and rgb != s[i + j]:
                mid[i] += 1
    print((r[-1] * g[-1] * b[-1] - sum(mid)))
    # # print(mid)
    # for i, ss in enumerate(s):
    #     if i == 0:
    #         continue
    #     if ss == 'R':
    #         tmp = g[i-1] * (b[-1] - b[i])
    #         tmp += b[i-1] * (g[-1] - g[i])
    #         tmp -= mid[i]
    #     elif ss == 'G':
    #         tmp = r[i-1] * (b[-1] - b[i])
    #         tmp += b[i-1] * (r[-1] - r[i])
    #         tmp -= mid[i]
    #     else:
    #         tmp = g[i-1] * (r[-1] - r[i])
    #         tmp += r[i-1] * (g[-1] - g[i])
    #         tmp -= mid[i]
    #     ans += tmp
    # print(ans)


if __name__ == "__main__":
    main()

def main():
    n = int(eval(input()))
    s = list(eval(input()))
    r = 0
    g = 0
    b = 0
    # print(s)
    for i, rgb in enumerate(s):
        if rgb == "R":
            r += 1
        elif rgb == "G":
            g += 1
        else:
            b += 1
    # print(r)
    ans = 0
    mid = 0
    # print('A')
    for i, rgb in enumerate(s):
        # print(i)
        # print('A')
        for j in range(1, i + 1):
            # print(i,j,rgb)
            if i + j >= n or i - j < 0:
                break
            # print(s[i-j],rgb,s[i+j])
            if rgb != s[i - j] and s[i - j] != s[i + j] and rgb != s[i + j]:
                mid += 1
    print((r * g * b - mid))
    # # print(mid)
    # for i, ss in enumerate(s):
    #     if i == 0:
    #         continue
    #     if ss == 'R':
    #         tmp = g[i-1] * (b[-1] - b[i])
    #         tmp += b[i-1] * (g[-1] - g[i])
    #         tmp -= mid[i]
    #     elif ss == 'G':
    #         tmp = r[i-1] * (b[-1] - b[i])
    #         tmp += b[i-1] * (r[-1] - r[i])
    #         tmp -= mid[i]
    #     else:
    #         tmp = g[i-1] * (r[-1] - r[i])
    #         tmp += r[i-1] * (g[-1] - g[i])
    #         tmp -= mid[i]
    #     ans += tmp
    # print(ans)


if __name__ == "__main__":
    main()

-    r = [0] * n -    g = [0] * n -    b = [0] * n +    r = 0 +    g = 0 +    b = 0 -            r[i] += 1 +            r += 1 -            g[i] += 1 +            g += 1 -            b[i] += 1 -        if i != 0: -            r[i] += r[i - 1] -            g[i] += g[i - 1] -            b[i] += b[i - 1] +            b += 1 -    mid = [0] * n +    mid = 0 -                mid[i] += 1 -    print((r[-1] * g[-1] * b[-1] - sum(mid))) +                mid += 1 +    print((r * g * b - mid))