

def main():

    n = int(eval(input()))

    s = eval(input())

    r,g,b = 0,0,0

    for i in s:

        if i == 'R': r += 1

        elif i == 'G': g += 1

        elif i == 'B': b += 1

    ans = r*g*b

    for j in range(n):

        for i in range(j):

            k = j+(j-i)

            if k < n:

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

                    continue

                ans -= 1

    print(ans)

if __name__ == "__main__":

    main()


def main():

    n = int(eval(input()))

    s = eval(input())

    r,g,b = 0,0,0

    for i in s:

        if i == 'R': r += 1

        elif i == 'G': g += 1

        elif i == 'B': b += 1

    ans = r*g*b

    for j in range(n):

        sj = s[j]

        for i in range(j):

            k = j+(j-i)

            if k < n:

                si = s[i]

                sk = s[k]

                if si == sj or si == sk or sk == sj:

                    continue

                ans -= 1

    print(ans)

if __name__ == "__main__":

    main()
def main():
    n = int(eval(input()))
    s = eval(input())
    r, g, b = 0, 0, 0
    for i in s:
        if i == "R":
            r += 1
        elif i == "G":
            g += 1
        elif i == "B":
            b += 1
    ans = r * g * b
    for j in range(n):
        for i in range(j):
            k = j + (j - i)
            if k < n:
                if s[i] == s[j] or s[i] == s[k] or s[k] == s[j]:
                    continue
                ans -= 1
    print(ans)


if __name__ == "__main__":
    main()

def main():
    n = int(eval(input()))
    s = eval(input())
    r, g, b = 0, 0, 0
    for i in s:
        if i == "R":
            r += 1
        elif i == "G":
            g += 1
        elif i == "B":
            b += 1
    ans = r * g * b
    for j in range(n):
        sj = s[j]
        for i in range(j):
            k = j + (j - i)
            if k < n:
                si = s[i]
                sk = s[k]
                if si == sj or si == sk or sk == sj:
                    continue
                ans -= 1
    print(ans)


if __name__ == "__main__":
    main()

+        sj = s[j] -                if s[i] == s[j] or s[i] == s[k] or s[k] == s[j]: +                si = s[i] +                sk = s[k] +                if si == sj or si == sk or sk == sj: