Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter as coun
from itertools import combinations as comb

import sys
input = sys.stdin.readline

N = int(input())
S = input()

C = coun(S)
ans = C["R"] * C["G"] * C["B"]
for i, j in comb(range(N), 2):
  k = 2 * j - i
  if k < N:
    A, B, C = S[i], S[j], S[k]
    if A != B and B != C and C != A: ans -= 1

print(ans)


Fixed submission:
import sys
input = sys.stdin.readline

N = int(input())
S = input()

ans = S.count("R") * S.count("G") * S.count("B")
for i in range(N-2):
  for j in range(i+1, N-1):
    k = 2 * j - i
    if k < N:
      A, B, C = S[i], S[j], S[k]
      if A != B and B != C and C != A: ans -= 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N = int(input())
S = input()

ans = S.count("R") * S.count("G") * S.count("B")
for i in range(N-2):
  for j in range(i+1, N-1):
    k = 2 * j - i
    if k < N:
      A, B, C = S[i], S[j], S[k]
      if A != B and B != C and C != A: ans -= 1

print(ans)


Fixed submission:
import sys
input = sys.stdin.readline

N = int(input())
S = input()

ans = S.count("R") * S.count("G") * S.count("B")
for i in range(N-2):
  for j in range(i+1, N-1):
    k = 2 * j - i
    if k < N:
      A, B, C = S[i], S[j], S[k]
      if A != B and B != C and C != A: ans -= 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#from itertools import combinations as c

import sys
input = sys.stdin.readline

N = int(input())
S = input()

ans = S.count("R") * S.count("G") * S.count("B")
#for i, j in c(range(N), 2):
for i in range(N-2):
  for j in range(i+1, N-1):
    k = 2 * j - i
    if k < N:
      A, B, C = S[i], S[j], S[k]
      if A != B and B != C and C != A: ans -= 1

print(ans)

Fixed submission:
import sys
input = sys.stdin.readline

N = int(input())
S = input()

ans = S.count("R") * S.count("G") * S.count("B")
for i in range(N-2):
  for j in range(i+1, N-1):
    k = 2 * j - i
    if k < N:
      A, B, C = S[i], S[j], S[k]
      if A != B and B != C and C != A: ans -= 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations as c

import sys
input = sys.stdin.readline

N = int(input())
S = input()

ans = S.count("R") * S.count("G") * S.count("B")
for i, j in c(range(N), 2):
  k = 2 * j - i
  if k < N:
    A, B, C = S[i], S[j], S[k]
    """
    if A == B or B == C or C == A: continue
    ans -= 1
    """
    if A != B and B != C and C != A: ans -= 1
print(ans)


Fixed submission:
import sys
input = sys.stdin.readline

N = int(input())
S = input()

ans = S.count("R") * S.count("G") * S.count("B")
for i in range(N-2):
  for j in range(i+1, N-1):
    k = 2 * j - i
    if k < N:
      A, B, C = S[i], S[j], S[k]
      if A != B and B != C and C != A: ans -= 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#from collections import Counter as coun
from itertools import combinations as comb

import sys
input = sys.stdin.readline

N = int(input())
S = input()

"""
C = coun(S)
ans = C["R"] * C["G"] * C["B"]
"""
ans = S.count("R") * S.count("G") * S.count("B")
for i, j in comb(range(N), 2):
  k = 2 * j - i
  if k < N:
    a, b, c = S[i], S[j], S[k]
    if a == b or b == c or c == a: continue
    ans -= 1
print(ans)


Fixed submission:
import sys
input = sys.stdin.readline

N = int(input())
S = input()

ans = S.count("R") * S.count("G") * S.count("B")
for i in range(N-2):
  for j in range(i+1, N-1):
    k = 2 * j - i
    if k < N:
      A, B, C = S[i], S[j], S[k]
      if A != B and B != C and C != A: ans -= 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter as coun
from itertools import combinations as comb
"""
import sys
input = sys.stdin.readline
"""
N = int(input())
S = input()

C = coun(S)
ans = C["R"] * C["G"] * C["B"]

for i, j in comb(range(N), 2):
  k = 2 * j - i
  if 0 <= k < N:
    a, b, c = S[i], S[j], S[k]
    if a == b or b == c or c == a: continue
    ans -= 1
print(ans)


Fixed submission:
import sys
input = sys.stdin.readline

N = int(input())
S = input()

ans = S.count("R") * S.count("G") * S.count("B")
for i in range(N-2):
  for j in range(i+1, N-1):
    k = 2 * j - i
    if k < N:
      A, B, C = S[i], S[j], S[k]
      if A != B and B != C and C != A: ans -= 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter as coun
from itertools import combinations as comb

import sys
input = sys.stdin.readline

N = int(input())
S = input()

C = coun(S)
ans = C["R"] * C["G"] * C["B"]

for i, j in comb(range(N), 2):
  k = 2 * j - i
  if 0 <= k < N:
    a, b, c = S[i], S[j], S[k]
    if a == b or b == c or c == a: continue
    ans -= 1
print(ans)


Fixed submission:
import sys
input = sys.stdin.readline

N = int(input())
S = input()

ans = S.count("R") * S.count("G") * S.count("B")
for i in range(N-2):
  for j in range(i+1, N-1):
    k = 2 * j - i
    if k < N:
      A, B, C = S[i], S[j], S[k]
      if A != B and B != C and C != A: ans -= 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter as coun
from itertools import combinations as comb

import sys
input = sys.stdin.readline

N = int(input())
S = input()

C = coun(S)
r, g = C["R"], C["G"]
b = N - r - g
ans = r * g * b

for i, j in comb(range(N), 2):
  k = 2 * j - i
  if 0 <= k < N:
    a, b, c = S[i], S[j], S[k]
    if a == b or b == c or c == a: continue
    ans -= 1
print(ans)


Fixed submission:
import sys
input = sys.stdin.readline

N = int(input())
S = input()

ans = S.count("R") * S.count("G") * S.count("B")
for i in range(N-2):
  for j in range(i+1, N-1):
    k = 2 * j - i
    if k < N:
      A, B, C = S[i], S[j], S[k]
      if A != B and B != C and C != A: ans -= 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter as coun
from itertools import combinations as comb

import sys
input = sys.stdin.readline

N = int(input())
S = input()
C = coun(S)
r, g, b = C["R"], C["G"], C["B"]
count = r * g * b

for i, j in comb(range(N), 2):
  k = 2 * j - i
  if 0 <= k < N:
    a, b, c = S[i], S[j], S[k]
    if a != b and b != c and c != a: count -= 1
print(count)


Fixed submission:
import sys
input = sys.stdin.readline

N = int(input())
S = input()

ans = S.count("R") * S.count("G") * S.count("B")
for i in range(N-2):
  for j in range(i+1, N-1):
    k = 2 * j - i
    if k < N:
      A, B, C = S[i], S[j], S[k]
      if A != B and B != C and C != A: ans -= 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

r, g, b = S.count("R"), S.count("G"), S.count("B")
count = r * g * b

for i in range(N-2):
  for j in range(i+1, N-1):
    k = 2 * j - i
    if 0 <= k < N:
      a, b, c = S[i], S[j], S[k]
      if a != b and b != c and c != a: count -= 1
print(count)


Fixed submission:
import sys
input = sys.stdin.readline

N = int(input())
S = input()

ans = S.count("R") * S.count("G") * S.count("B")
for i in range(N-2):
  for j in range(i+1, N-1):
    k = 2 * j - i
    if k < N:
      A, B, C = S[i], S[j], S[k]
      if A != B and B != C and C != A: ans -= 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
count = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    for k in range(j+1, N):
      if k != 2 * j - i:
        a, b, c = S[i], S[j], S[k]
        if a != b and b != c and c != a:
          count += 1
print(count)


Fixed submission:
import sys
input = sys.stdin.readline

N = int(input())
S = input()

ans = S.count("R") * S.count("G") * S.count("B")
for i in range(N-2):
  for j in range(i+1, N-1):
    k = 2 * j - i
    if k < N:
      A, B, C = S[i], S[j], S[k]
      if A != B and B != C and C != A: ans -= 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations as c
N = int(input())
S = list(list(input()))

count = 0
for i, j, k in c(range(N), 3):
  if j - i != k - j and S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
    count += 1

print(count)


Fixed submission:
import sys
input = sys.stdin.readline

N = int(input())
S = input()

ans = S.count("R") * S.count("G") * S.count("B")
for i in range(N-2):
  for j in range(i+1, N-1):
    k = 2 * j - i
    if k < N:
      A, B, C = S[i], S[j], S[k]
      if A != B and B != C and C != A: ans -= 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations as c
N = int(input())
S = input()

count = 0
for i, j, k in c(range(N), 3):
  if j - i != k - j and S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
    count += 1

print(count)

Fixed submission:
import sys
input = sys.stdin.readline

N = int(input())
S = input()

ans = S.count("R") * S.count("G") * S.count("B")
for i in range(N-2):
  for j in range(i+1, N-1):
    k = 2 * j - i
    if k < N:
      A, B, C = S[i], S[j], S[k]
      if A != B and B != C and C != A: ans -= 1

print(ans)