N = int(eval(input()))

S = eval(input())



bad_list = ['RGB', 'RBG', 'GRB', 'GBR', 'BRG', 'BGR']

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

other_map = {'R': 'GB', 'G': 'RB', 'B': 'RG'}

res = 0

for (i, s) in enumerate(S):

  other = other_map[s]

  res += RGB[other[0]] * RGB[other[1]]

  

  for j in range(((i+1)//2)+1)[1:]:

    if S[i::-j][:3] in bad_list:

      res -= 1



  RGB[s] += 1





print(res)
N = int(eval(input()))

S = eval(input())



bad_list = ['RGB', 'RBG', 'GRB', 'GBR', 'BRG', 'BGR']

res = S.count("R") * S.count("G") * S.count("B")

for (i, s) in enumerate(S):

  

  for j in range(((i+1)//2)+1)[1:]:

    if S[i::-j][:3] in bad_list:

      res -= 1





print(res)
N = int(eval(input()))
S = eval(input())
bad_list = ["RGB", "RBG", "GRB", "GBR", "BRG", "BGR"]
RGB = {"R": 0, "G": 0, "B": 0}
other_map = {"R": "GB", "G": "RB", "B": "RG"}
res = 0
for (i, s) in enumerate(S):
    other = other_map[s]
    res += RGB[other[0]] * RGB[other[1]]
    for j in range(((i + 1) // 2) + 1)[1:]:
        if S[i::-j][:3] in bad_list:
            res -= 1
    RGB[s] += 1
print(res)

N = int(eval(input()))
S = eval(input())
bad_list = ["RGB", "RBG", "GRB", "GBR", "BRG", "BGR"]
res = S.count("R") * S.count("G") * S.count("B")
for (i, s) in enumerate(S):
    for j in range(((i + 1) // 2) + 1)[1:]:
        if S[i::-j][:3] in bad_list:
            res -= 1
print(res)

-RGB = {"R": 0, "G": 0, "B": 0} -other_map = {"R": "GB", "G": "RB", "B": "RG"} -res = 0 +res = S.count("R") * S.count("G") * S.count("B") -    other = other_map[s] -    res += RGB[other[0]] * RGB[other[1]] -    RGB[s] += 1