def calc(i, j, B1, len_b):

    extra = 0

    d = j - i



    # i < j < k

    k1 = d + j

    if k1 < len_b:

        extra += B1[k1]



    # k < i < j

    k2 = i - d

    if 0 <= k2 and k2 < len_b:

        extra += B1[k2]



    # i < k < j

    s = i + j

    if s % 2 == 0:

        k3 = s // 2

        if k3 < len_b:

            extra += B1[k3]

    return extra



def main():

    N = int(eval(input()))

    S = eval(input())

    R, G, B = [], [], []

    RGB = {'R': R, 'G': G, 'B': B}

    for i in range(N):

        RGB[S[i]].append(i)

    num_r, num_g, num_b = len(R), len(G), len(B)

    if num_r == 0 or num_g == 0 or num_b == 0:

        print((0))

        return



    len_b = (B[-1] + 1)

    B1 = [0]*len_b

    for b in B:

        B1[b] = 1

    # print(R, G, B)

    ans = num_r * num_g * num_b

    for i in R:

        for j in G:

            ans -= calc(min(i, j), max(i, j), B1, len_b)

    print(ans)



if __name__ == '__main__':

    main()

def calc(i, j, B1, len_b):

    extra = 0

    d = j - i



    # i < j < k

    k1 = d + j

    if k1 < len_b:

        extra += B1[k1]



    # k < i < j

    k2 = i - d

    if 0 <= k2 and k2 < len_b:

        extra += B1[k2]



    # i < k < j

    s = i + j

    if s % 2 == 0:

        k3 = s // 2

        if k3 < len_b:

            extra += B1[k3]

    return extra



def main():

    N = int(eval(input()))

    S = eval(input())

    R, G, B = [], [], []

    num_r, num_g, num_b = 0, 0, 0

    for i in range(N):

        s = S[i]

        if s == 'R':

            R.append(i)

            num_r += 1

        elif s == 'G':

            G.append(i)

            num_g += 1

        elif s == 'B':

            B.append(i)

            num_b += 1

    if len(R) == 0 or len(G) == 0 or len(B) == 0:

        print((0))

        return

    len_b = (B[-1] + 1)

    B1 = [0]*len_b

    for b in B:

        B1[b] = 1

    # print(R, G, B)

    ans = 0

    for i in R:

        for j in G:

            ans += num_b

            if i < j:

                ans -= calc(i, j, B1, len_b)

            else:

                ans -= calc(j, i, B1, len_b)

    print(ans)



if __name__ == '__main__':

    main()

def calc(i, j, B1, len_b):
    extra = 0
    d = j - i
    # i < j < k
    k1 = d + j
    if k1 < len_b:
        extra += B1[k1]
    # k < i < j
    k2 = i - d
    if 0 <= k2 and k2 < len_b:
        extra += B1[k2]
    # i < k < j
    s = i + j
    if s % 2 == 0:
        k3 = s // 2
        if k3 < len_b:
            extra += B1[k3]
    return extra


def main():
    N = int(eval(input()))
    S = eval(input())
    R, G, B = [], [], []
    RGB = {"R": R, "G": G, "B": B}
    for i in range(N):
        RGB[S[i]].append(i)
    num_r, num_g, num_b = len(R), len(G), len(B)
    if num_r == 0 or num_g == 0 or num_b == 0:
        print((0))
        return
    len_b = B[-1] + 1
    B1 = [0] * len_b
    for b in B:
        B1[b] = 1
    # print(R, G, B)
    ans = num_r * num_g * num_b
    for i in R:
        for j in G:
            ans -= calc(min(i, j), max(i, j), B1, len_b)
    print(ans)


if __name__ == "__main__":
    main()

def calc(i, j, B1, len_b):
    extra = 0
    d = j - i
    # i < j < k
    k1 = d + j
    if k1 < len_b:
        extra += B1[k1]
    # k < i < j
    k2 = i - d
    if 0 <= k2 and k2 < len_b:
        extra += B1[k2]
    # i < k < j
    s = i + j
    if s % 2 == 0:
        k3 = s // 2
        if k3 < len_b:
            extra += B1[k3]
    return extra


def main():
    N = int(eval(input()))
    S = eval(input())
    R, G, B = [], [], []
    num_r, num_g, num_b = 0, 0, 0
    for i in range(N):
        s = S[i]
        if s == "R":
            R.append(i)
            num_r += 1
        elif s == "G":
            G.append(i)
            num_g += 1
        elif s == "B":
            B.append(i)
            num_b += 1
    if len(R) == 0 or len(G) == 0 or len(B) == 0:
        print((0))
        return
    len_b = B[-1] + 1
    B1 = [0] * len_b
    for b in B:
        B1[b] = 1
    # print(R, G, B)
    ans = 0
    for i in R:
        for j in G:
            ans += num_b
            if i < j:
                ans -= calc(i, j, B1, len_b)
            else:
                ans -= calc(j, i, B1, len_b)
    print(ans)


if __name__ == "__main__":
    main()

-    RGB = {"R": R, "G": G, "B": B} +    num_r, num_g, num_b = 0, 0, 0 -        RGB[S[i]].append(i) -    num_r, num_g, num_b = len(R), len(G), len(B) -    if num_r == 0 or num_g == 0 or num_b == 0: +        s = S[i] +        if s == "R": +            R.append(i) +            num_r += 1 +        elif s == "G": +            G.append(i) +            num_g += 1 +        elif s == "B": +            B.append(i) +            num_b += 1 +    if len(R) == 0 or len(G) == 0 or len(B) == 0: -    ans = num_r * num_g * num_b +    ans = 0 -            ans -= calc(min(i, j), max(i, j), B1, len_b) +            ans += num_b +            if i < j: +                ans -= calc(i, j, B1, len_b) +            else: +                ans -= calc(j, i, B1, len_b)