n = int(eval(input()))



sl = list(eval(input()))



sum_r = sl.count("R")

sum_g = sl.count("G")

sum_b = sl.count("B")



rl = []

gl = []

bl = []



for s in sl:

    if s == "R":

        sum_r -= 1

    if s == "G":

        sum_g -= 1

    if s == "B":

        sum_b -= 1

    rl.append(sum_r)

    gl.append(sum_g)

    bl.append(sum_b)

ans = 0

for i in range(n):

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

        k = j + j - i

        if sl[i] == sl[j]:

            continue

        if "R" not in [sl[i], sl[j]]:

            ans += rl[j]

            if k < n:

                if sl[k] == "R":

                    ans -= 1

        if "G" not in [sl[i], sl[j]]:

            ans += gl[j]

            if k < n:

                if sl[k] == "G":

                    ans -= 1

        if "B" not in [sl[i], sl[j]]:

            ans += bl[j]

            if k < n:

                if sl[k] == "B":

                    ans -= 1

print(ans)
n = int(eval(input()))

sl = list(eval(input()))



ans = sl.count("R") * sl.count("G") * sl.count("B")



for i in range(n):

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

        k = 2 * j - i

        if k < n:

            if len({sl[i], sl[j], sl[k]}) ==  3:

                ans -= 1



print(ans)



n = int(eval(input()))
sl = list(eval(input()))
sum_r = sl.count("R")
sum_g = sl.count("G")
sum_b = sl.count("B")
rl = []
gl = []
bl = []
for s in sl:
    if s == "R":
        sum_r -= 1
    if s == "G":
        sum_g -= 1
    if s == "B":
        sum_b -= 1
    rl.append(sum_r)
    gl.append(sum_g)
    bl.append(sum_b)
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        k = j + j - i
        if sl[i] == sl[j]:
            continue
        if "R" not in [sl[i], sl[j]]:
            ans += rl[j]
            if k < n:
                if sl[k] == "R":
                    ans -= 1
        if "G" not in [sl[i], sl[j]]:
            ans += gl[j]
            if k < n:
                if sl[k] == "G":
                    ans -= 1
        if "B" not in [sl[i], sl[j]]:
            ans += bl[j]
            if k < n:
                if sl[k] == "B":
                    ans -= 1
print(ans)

n = int(eval(input()))
sl = list(eval(input()))
ans = sl.count("R") * sl.count("G") * sl.count("B")
for i in range(n):
    for j in range(i + 1, n):
        k = 2 * j - i
        if k < n:
            if len({sl[i], sl[j], sl[k]}) == 3:
                ans -= 1
print(ans)

-sum_r = sl.count("R") -sum_g = sl.count("G") -sum_b = sl.count("B") -rl = [] -gl = [] -bl = [] -for s in sl: -    if s == "R": -        sum_r -= 1 -    if s == "G": -        sum_g -= 1 -    if s == "B": -        sum_b -= 1 -    rl.append(sum_r) -    gl.append(sum_g) -    bl.append(sum_b) -ans = 0 +ans = sl.count("R") * sl.count("G") * sl.count("B") -        k = j + j - i -        if sl[i] == sl[j]: -            continue -        if "R" not in [sl[i], sl[j]]: -            ans += rl[j] -            if k < n: -                if sl[k] == "R": -                    ans -= 1 -        if "G" not in [sl[i], sl[j]]: -            ans += gl[j] -            if k < n: -                if sl[k] == "G": -                    ans -= 1 -        if "B" not in [sl[i], sl[j]]: -            ans += bl[j] -            if k < n: -                if sl[k] == "B": -                    ans -= 1 +        k = 2 * j - i +        if k < n: +            if len({sl[i], sl[j], sl[k]}) == 3: +                ans -= 1