# 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, doubled_indices = defaultdict(list), defaultdict(set)

    for i, c in enumerate(S):

        indices[c].append(i)

        doubled_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 in doubled_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, doubled_indices = defaultdict(list), defaultdict(set)
    for i, c in enumerate(S):
        indices[c].append(i)
        doubled_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 in doubled_indices[c3] for i in indices[c1] for j in indices[c2]
        )
    print(cnt)


if __name__ == "__main__":
    main()

-    indices = defaultdict(set) +    indices, doubled_indices = defaultdict(list), defaultdict(set) -        indices[c].add(2 * i) +        indices[c].append(i) +        doubled_indices[c].add(2 * i) -            (i + j) // 2 in indices[c3] for i in indices[c1] for j in indices[c2] +            i + j in doubled_indices[c3] for i in indices[c1] for j in indices[c2]