Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
N = int(input())
S = input()

R = []
G = []
B = []

for i in range(N):
  if S[i] == 'R':
    R.append(i)
  elif S[i] == 'G':
    G.append(i)
  else:
    B.append(i)

def count(X,Y,Z):
  count = 0
  for r in X:
    for g in Y:
      if (r+g)%2==0 and (r+g)//2 in Z:
        count += 1
      if 2*r-g in Z:
        count += 1
      if 2*g-r in Z:
        count += 1
  return count

if len(R)>=max(len(G),len(B)):
  print(len(R)*len(G)*len(B)-count(G,B,R))
elif len(G)>=len(R):
  print(len(R)*len(G)*len(B)-count(R,B,G))
else:
  print(len(R)*len(G)*len(B)-count(R,G,B))

Fixed submission:
# -*- coding: utf-8 -*-
N = int(input())
S = input()

R = 0
G = 0
B = 0

for i in range(N):
  if S[i] == 'R':
    R += 1
  elif S[i] == 'G':
    G += 1
  else:
    B += 1
    
count = 0
for i in range(N-1):
  for j in range(i+1,N):
    if 2*j-i>=N:
      break
    if S[i]!=S[j] and S[2*j-i]!=S[i] and S[2*j-i]!=S[j]:
      count += 1

print(R*G*B-count)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
N = int(input())
S = input()

R = []
G = []
B = []

for i in range(N):
  if S[i] == 'R':
    R.append(i)
  elif S[i] == 'G':
    G.append(i)
  else:
    B.append(i)

def count(X,Y,Z):
  count = 0
  for r in X:
    for g in Y:
      len_B = len(Z)
      if (r+g)%2==0 and (r+g)//2 in Z:
        len_B -= 1
      if 2*r-g in Z:
        len_B -= 1
      if 2*g-r in Z:
        len_B -= 1
      count += len_B
  return count

if len(R)>=max(len(G),len(B)):
  print(count(G,B,R))
elif len(G)>=len(R):
  print(count(R,B,G))
else:
  print(count(R,G,B))

Fixed submission:
# -*- coding: utf-8 -*-
N = int(input())
S = input()

R = 0
G = 0
B = 0

for i in range(N):
  if S[i] == 'R':
    R += 1
  elif S[i] == 'G':
    G += 1
  else:
    B += 1
    
count = 0
for i in range(N-1):
  for j in range(i+1,N):
    if 2*j-i>=N:
      break
    if S[i]!=S[j] and S[2*j-i]!=S[i] and S[2*j-i]!=S[j]:
      count += 1

print(R*G*B-count)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
N = int(input())
S = input()

R = []
G = []
B = []

for i in range(N):
  if S[i] == 'R':
    R.append(i)
  elif S[i] == 'G':
    G.append(i)
  else:
    B.append(i)

def count(X,Y,Z):
  count = 0
  for r in X:
    for g in Y:
      len_B = len(Z)
      if (r+g)%2==0 and (r+g)//2 in Z:
        len_B -= 1
      if 2*r-g in Z:
        len_B -= 1
      if 2*g-r in Z:
        len_B -= 1
      count += len_B
  return count

if len(R)>=max(len(G),len(B)):
  print(count(G,B,R))
elif len(G)>=len(R):
  print(count(R,B,G))
else:
  print(count(R,G,B))

Fixed submission:
# -*- coding: utf-8 -*-
N = int(input())
S = input()

R = 0
G = 0
B = 0

for i in range(N):
  if S[i] == 'R':
    R += 1
  elif S[i] == 'G':
    G += 1
  else:
    B += 1
    
count = 0
for i in range(N-1):
  for j in range(i+1,N):
    if 2*j-i>=N:
      break
    if S[i]!=S[j] and S[2*j-i]!=S[i] and S[2*j-i]!=S[j]:
      count += 1

print(R*G*B-count)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
N = int(input())
S = input()

R = []
G = []
B = []

for i in range(N):
  if S[i] == 'R':
    R.append(i)
  elif S[i] == 'G':
    G.append(i)
  else:
    B.append(i)
    
count = 0

if len(R)>=max(len(G),len(B)):
  X = G
  Y = B
  Z = R
elif len(G)>=len(R):
  X = R
  Y = B
  Z = G
else:
  X = R
  Y = G
  Z = B

for r in X:
  for g in Y:
    len_B = len(Z)
    if (r+g)%2==0 and (r+g)//2 in Z:
      len_B -= 1
    if 2*r-g in Z:
      len_B -= 1
    if 2*g-r in Z:
      len_B -= 1
    count += len_B
      

print(count)

Fixed submission:
# -*- coding: utf-8 -*-
N = int(input())
S = input()

R = 0
G = 0
B = 0

for i in range(N):
  if S[i] == 'R':
    R += 1
  elif S[i] == 'G':
    G += 1
  else:
    B += 1
    
count = 0
for i in range(N-1):
  for j in range(i+1,N):
    if 2*j-i>=N:
      break
    if S[i]!=S[j] and S[2*j-i]!=S[i] and S[2*j-i]!=S[j]:
      count += 1

print(R*G*B-count)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
N = int(input())
S = input()

R = []
G = []
B = []

for i in range(N):
  if S[i] == 'R':
    R.append(i)
  elif S[i] == 'G':
    G.append(i)
  else:
    B.append(i)
    
count = 0

for r in R:
  for g in G:
    len_B = len(B)
    if (r+g)%2==0 and (r+g)//2 in B:
      len_B -= 1
    if 2*r-g in B:
      len_B -= 1
    if 2*g-r in B:
      len_B -= 1
    count += len_B
      
print(count)

Fixed submission:
# -*- coding: utf-8 -*-
N = int(input())
S = input()

R = 0
G = 0
B = 0

for i in range(N):
  if S[i] == 'R':
    R += 1
  elif S[i] == 'G':
    G += 1
  else:
    B += 1
    
count = 0
for i in range(N-1):
  for j in range(i+1,N):
    if 2*j-i>=N:
      break
    if S[i]!=S[j] and S[2*j-i]!=S[i] and S[2*j-i]!=S[j]:
      count += 1

print(R*G*B-count)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
N = int(input())
S = input()

R = []
G = []
B = []

for i in range(N):
  if S[i] == 'R':
    R.append(i)
  elif S[i] == 'G':
    G.append(i)
  else:
    B.append(i)
    
count = 0

for r in R:
  for g in G:
    for b in B:
      S = sorted([r,g,b])
      if S[0]+S[2]!=2*S[1]:
        count += 1

print(count)

Fixed submission:
# -*- coding: utf-8 -*-
N = int(input())
S = input()

R = 0
G = 0
B = 0

for i in range(N):
  if S[i] == 'R':
    R += 1
  elif S[i] == 'G':
    G += 1
  else:
    B += 1
    
count = 0
for i in range(N-1):
  for j in range(i+1,N):
    if 2*j-i>=N:
      break
    if S[i]!=S[j] and S[2*j-i]!=S[i] and S[2*j-i]!=S[j]:
      count += 1

print(R*G*B-count)