# D - RGB Triplets

from collections import defaultdict





def main():

    _ = int(eval(input()))

    S = input().rstrip()

    indices = defaultdict(set)

    for i, c in enumerate(S):

        indices[c].add(i)

    cnt = len(indices["R"]) * len(indices["G"]) * len(indices["B"])

    for c1, c2, c3 in ["RGB", "GBR", "BRG"]:

        cnt -= sum(

            (i + j) % 2 == 0 and (i + j) // 2 in indices[c3]

            for i in indices[c1]

            for j in indices[c2]

        )

    print(cnt)





if __name__ == "__main__":

    main()

# D - RGB Triplets

from collections import defaultdict





def main():

    _ = int(eval(input()))

    S = input().rstrip()

    indices = defaultdict(set)

    for i, c in enumerate(S):

        indices[c].add(2 * i)

    cnt = len(indices["R"]) * len(indices["G"]) * len(indices["B"])

    for c1, c2, c3 in ["RGB", "GBR", "BRG"]:

        cnt -= sum(

            (i + j) // 2 in indices[c3] for i in indices[c1] for j in indices[c2]

        )

    print(cnt)





if __name__ == "__main__":

    main()

# D - RGB Triplets
from collections import defaultdict


def main():
    _ = int(eval(input()))
    S = input().rstrip()
    indices = defaultdict(set)
    for i, c in enumerate(S):
        indices[c].add(i)
    cnt = len(indices["R"]) * len(indices["G"]) * len(indices["B"])
    for c1, c2, c3 in ["RGB", "GBR", "BRG"]:
        cnt -= sum(
            (i + j) % 2 == 0 and (i + j) // 2 in indices[c3]
            for i in indices[c1]
            for j in indices[c2]
        )
    print(cnt)


if __name__ == "__main__":
    main()

# D - RGB Triplets
from collections import defaultdict


def main():
    _ = int(eval(input()))
    S = input().rstrip()
    indices = defaultdict(set)
    for i, c in enumerate(S):
        indices[c].add(2 * i)
    cnt = len(indices["R"]) * len(indices["G"]) * len(indices["B"])
    for c1, c2, c3 in ["RGB", "GBR", "BRG"]:
        cnt -= sum(
            (i + j) // 2 in indices[c3] for i in indices[c1] for j in indices[c2]
        )
    print(cnt)


if __name__ == "__main__":
    main()

-        indices[c].add(i) +        indices[c].add(2 * i) -            (i + j) % 2 == 0 and (i + j) // 2 in indices[c3] -            for i in indices[c1] -            for j in indices[c2] +            (i + j) // 2 in indices[c3] for i in indices[c1] for j in indices[c2]