Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

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

cnt = Counter(S)

ans = cnt['R'] * cnt['G'] * cnt['B']

for i in range(N):
  for j in range(i+1, N):
    k = j + j - i
    if k < N :
      if (S[i] != S[j]) & (S[j] != S[k]) & (S[k] != S[i]) :
        ans -= 1

print(ans)

Fixed submission:
from collections import Counter

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

cnt = Counter(S)

ans = cnt['R'] * cnt['G'] * cnt['B']

for i in range(N):
  for j in range(i+1, N):
    k = j + j - i
    if k < N :
      if (S[i] == S[j]) or (S[j] == S[k]) or (S[k] == S[i]) :
        continue
      ans -= 1

print(ans)

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

ans = S.count('R')*S.count('G')*S.count('B')

for i in range(N):
  for j in range(i+1, N):
    k = j + j - i
    if k < N :
      if (S[i] != S[j]) & (S[j] != S[k]) & (S[k] != S[i]) :
        ans -= 1

print(ans)

Fixed submission:
from collections import Counter

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

cnt = Counter(S)

ans = cnt['R'] * cnt['G'] * cnt['B']

for i in range(N):
  for j in range(i+1, N):
    k = j + j - i
    if k < N :
      if (S[i] == S[j]) or (S[j] == S[k]) or (S[k] == S[i]) :
        continue
      ans -= 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

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

rgb = S.count('R')*S.count('G')*S.count('B')

ans = 0
for comb in list(itertools.combinations(range(N), 2)):
  i, j = comb
  
  if (j*2 -i) < N:
    if (S[i] != S[j]) & (S[j] != S[j*2 -i]) & (S[j*2 -i] != S[i]) :
      ans += 1

print(rgb - ans)

Fixed submission:
from collections import Counter

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

cnt = Counter(S)

ans = cnt['R'] * cnt['G'] * cnt['B']

for i in range(N):
  for j in range(i+1, N):
    k = j + j - i
    if k < N :
      if (S[i] == S[j]) or (S[j] == S[k]) or (S[k] == S[i]) :
        continue
      ans -= 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

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

ans = 0
for comb in list(itertools.combinations(range(N), 3)):
  i, j, k = comb
  
  if (S[i] != S[j]) & (S[j] != S[k]) & (S[k] != S[i]) :
    if (j + j - i - k) != 0 :
      ans += 1

print(ans)

Fixed submission:
from collections import Counter

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

cnt = Counter(S)

ans = cnt['R'] * cnt['G'] * cnt['B']

for i in range(N):
  for j in range(i+1, N):
    k = j + j - i
    if k < N :
      if (S[i] == S[j]) or (S[j] == S[k]) or (S[k] == S[i]) :
        continue
      ans -= 1

print(ans)

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

# R,G,Bのそれぞれのインデックスをリストで取得する
r_index = []
g_index = []
b_index = []
for i in range(len(S)):
  if S[i]=='R':
    r_index.append(i)
  elif S[i]=='G':
    g_index.append(i)
  else:
    b_index.append(i)

#　全組み合わせ(制約1)
rgb_num = len(r_index) * len(g_index) * len(b_index)

# 組み合わせを全探索して、制約2に当てはまるものをカウントする(i, j, k)
ck = 0
for r in r_index:
  for g in g_index:

    # x < y
    if r < g :
      x, y = r, g
    else:
      x,y = g, r
    
    # (i, j, k) = (x, y, b) or (x, b, y) or (b, x, y)
    # (x, y, b)
    i = x
    j = y
    if (j*2 -i) in b_index:
      ck += 1

    # (x, b, y)
    i = x
    k = y
    if (i + k) / 2 in b_index:
      ck += 1

    # (b, x, y)
    j = x
    k = y
    if (j*2 -k) in b_index:
      ck += 1

print(rgb_num - ck)

Fixed submission:
from collections import Counter

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

cnt = Counter(S)

ans = cnt['R'] * cnt['G'] * cnt['B']

for i in range(N):
  for j in range(i+1, N):
    k = j + j - i
    if k < N :
      if (S[i] == S[j]) or (S[j] == S[k]) or (S[k] == S[i]) :
        continue
      ans -= 1

print(ans)

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

# R,G,Bのそれぞれのインデックスをリストで取得する
r_index = []
g_index = []
b_index = []
for i in range(len(S)):
  if S[i]=='R':
    r_index.append(i)
  elif S[i]=='G':
    g_index.append(i)
  else:
    b_index.append(i)

#　全組み合わせ(制約1)
rgb_num = len(r_index) * len(g_index) * len(b_index)

# 組み合わせを全探索して、制約2に当てはまるものをカウントする(i, j, k)
ck = 0
for r in r_index:
  for g in g_index:

    # x < y
    if r < g :
      x, y = r, g
    else:
      x,y = g, r
    
    # (i, j, k) = (x, y, b) or (x, b, y) or (b, x, y)
    # (x, y, b)
    i = x
    j = y
    if (j*2 -i) in b_index:
      ck += 1

    # (x, b, y)
    i = x
    k = y
    if (i + k) / 2 in b_index:
      ck += 1

    # (b, x, y)
    j = x
    k = y
    if (j*2 -k) in b_index:
      ck += 1

print(rgb_num - ck)

Fixed submission:
from collections import Counter

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

cnt = Counter(S)

ans = cnt['R'] * cnt['G'] * cnt['B']

for i in range(N):
  for j in range(i+1, N):
    k = j + j - i
    if k < N :
      if (S[i] == S[j]) or (S[j] == S[k]) or (S[k] == S[i]) :
        continue
      ans -= 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

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

# R,G,Bのそれぞれのインデックスをリストで取得する
r_index = []
g_index = []
b_index = []
for i in range(len(S)):
  if S[i]=='R':
    r_index.append(i)
  elif S[i]=='G':
    g_index.append(i)
  else:
    b_index.append(i)

#　全組み合わせ(制約1)
rgb_num = len(r_index) * len(g_index) * len(b_index)

# 組み合わせを全探索して、制約2に当てはまるものをカウントする
ck = 0
for rgb in list(itertools.product(r_index, g_index, b_index)):
  rgb_list = list(rgb)
  rgb_list.sort()
  i, j, k = rgb_list

  if (j*2 -i -k)==0:
    ck += 1

print(rgb_num - ck)

Fixed submission:
from collections import Counter

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

cnt = Counter(S)

ans = cnt['R'] * cnt['G'] * cnt['B']

for i in range(N):
  for j in range(i+1, N):
    k = j + j - i
    if k < N :
      if (S[i] == S[j]) or (S[j] == S[k]) or (S[k] == S[i]) :
        continue
      ans -= 1

print(ans)

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

# R,G,Bのそれぞれのインデックスをリストで取得する
r_index = []
g_index = []
b_index = []
for i in range(len(S)):
  if S[i]=='R':
    r_index.append(i)
  elif S[i]=='G':
    g_index.append(i)
  else:
    b_index.append(i)

#　全組み合わせ(制約1)
rgb_num = len(r_index) * len(g_index) * len(b_index)

# 組み合わせを全探索して、制約2に当てはまるものをカウントする
ck = 0
for r in r_index:
  for g in g_index:
    for b in b_index:
      lis = [r, g, b]
      lis.sort()
      i, j, k = lis

      if (j*2 -i -k)==0:
        ck += 1

print(rgb_num - ck)

Fixed submission:
from collections import Counter

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

cnt = Counter(S)

ans = cnt['R'] * cnt['G'] * cnt['B']

for i in range(N):
  for j in range(i+1, N):
    k = j + j - i
    if k < N :
      if (S[i] == S[j]) or (S[j] == S[k]) or (S[k] == S[i]) :
        continue
      ans -= 1

print(ans)

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

# R,G,Bのそれぞれのインデックスをリストで取得する
r_index = []
g_index = []
b_index = []
for i in range(len(S)):
  if S[i]=='R':
    r_index.append(i)
  elif S[i]=='G':
    g_index.append(i)
  else:
    b_index.append(i)

#　全組み合わせ(制約1)
rgb_num = len(r_index) * len(g_index) * len(b_index)

# 組み合わせを全探索して、制約2に当てはまるものをカウントする
ck = 0
for r in r_index:
  for g in g_index:
    for b in b_index:
      lis = [r, g, b]
      lis.sort()
      i, j, k = lis

      if (j*2 -i -k)==0:
        ck += 1

print(rgb_num - ck)

Fixed submission:
from collections import Counter

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

cnt = Counter(S)

ans = cnt['R'] * cnt['G'] * cnt['B']

for i in range(N):
  for j in range(i+1, N):
    k = j + j - i
    if k < N :
      if (S[i] == S[j]) or (S[j] == S[k]) or (S[k] == S[i]) :
        continue
      ans -= 1

print(ans)