Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
 
str = input()
sum = 0
ans = []
for i in range(n):
  if str[i] == "R":
    ans.append(2)
  elif str[i] == "G":
    ans.append(3)
  else:
    ans.append(5)

for i in range(n-2):
  for j in range(i+1, n-1):
    for k in range(j+1, n):
      if ans[i] - ans[j] == 0:
        break
      elif j - i == k - j:
        pass
      elif ans[i] + ans[j] + ans[k] == 10:
        sum += 1
print(sum)

Fixed submission:
n = int(input())
 
str = input()

r = str.count('R')
g = str.count('G')
b = str.count('B')
sum = r * g * b
for i in range(n-2):
  for j in range(i+1, n-1):
    k = 2 * j - i
    if k < n:
      if str[i] != str[j] and str[i] != str[k] and str[j] != str[k] :
        sum -= 1
    
print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
 
str = input()
sum = 0
ans = []
for i in range(n):
  if str[i] == "R":
    ans.append(2)
  elif str[i] == "G":
    ans.append(3)
  else:
    ans.append(5)

for i in range(n-2):
  for j in range(i+1, n-1):
    for k in range(j+1, n):
      if ans[i] == ans[j]:
        break
      elif ans[i] * ans[j] * ans[k] == 30 and j - i != k - j:
        sum += 1
print(sum)

Fixed submission:
n = int(input())
 
str = input()

r = str.count('R')
g = str.count('G')
b = str.count('B')
sum = r * g * b
for i in range(n-2):
  for j in range(i+1, n-1):
    k = 2 * j - i
    if k < n:
      if str[i] != str[j] and str[i] != str[k] and str[j] != str[k] :
        sum -= 1
    
print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
 
str = input()
sum = 0
two = []
three = []
for i in range(n-3):
  for j in range(i+1, n-1):
    for k in range(j+1, n):
      if str[i] == str[j]:
        break
      elif str[i] != str[k] and str[j] != str[k] and j - i != k - j:
        sum += 1
print(sum)

Fixed submission:
n = int(input())
 
str = input()

r = str.count('R')
g = str.count('G')
b = str.count('B')
sum = r * g * b
for i in range(n-2):
  for j in range(i+1, n-1):
    k = 2 * j - i
    if k < n:
      if str[i] != str[j] and str[i] != str[k] and str[j] != str[k] :
        sum -= 1
    
print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
 
str = input()
sum = 0
for i in range(n-2):
  for j in range(i+1, n-1):
    for k in range(j+1, n):
      if str[i] == str[j]:
        break
      elif str[i] != str[k] and str[j] != str[k] and j - i != k - j:
        sum += 1
print(sum)

Fixed submission:
n = int(input())
 
str = input()

r = str.count('R')
g = str.count('G')
b = str.count('B')
sum = r * g * b
for i in range(n-2):
  for j in range(i+1, n-1):
    k = 2 * j - i
    if k < n:
      if str[i] != str[j] and str[i] != str[k] and str[j] != str[k] :
        sum -= 1
    
print(sum)

Buggy python submission (verdict: Runtime Error):
n = int(input())
 
str = input()
sum = 0
for i in range(n-2):
  for j in range(i+1, n-1):
     if str[i] == str[j]:
        break
    for k in range(j+1, n):
      if str[i] != str[k] and str[j] != str[k] and j - i != k - j:
        sum += 1

print(sum)

Fixed submission:
n = int(input())
 
str = input()

r = str.count('R')
g = str.count('G')
b = str.count('B')
sum = r * g * b
for i in range(n-2):
  for j in range(i+1, n-1):
    k = 2 * j - i
    if k < n:
      if str[i] != str[j] and str[i] != str[k] and str[j] != str[k] :
        sum -= 1
    
print(sum)

Buggy python submission (verdict: Runtime Error):
n = int(input())
 
str = input()
sum = 0
pointer = n
for i in range(n-2):
  if i == poitner:
    break
  for j in range(i+1, n-1):
    for k in range(j+1, n):
      if str[i] == str[j]:
        pointer = j
        break
      elif str[i] != str[k] and str[j] != str[k] and j - i != k - j:
        sum += 1
print(sum)

Fixed submission:
n = int(input())
 
str = input()

r = str.count('R')
g = str.count('G')
b = str.count('B')
sum = r * g * b
for i in range(n-2):
  for j in range(i+1, n-1):
    k = 2 * j - i
    if k < n:
      if str[i] != str[j] and str[i] != str[k] and str[j] != str[k] :
        sum -= 1
    
print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
 
str = input()
sum = 0
for i in range(n-2):
  for j in range(i+1, n-1):
    for k in range(j+1, n):
      if str[i] == str[j]:
        break
      elif str[i] != str[k] and str[j] != str[k] and j - i != k - j:
        sum += 1
print(sum)

Fixed submission:
n = int(input())
 
str = input()

r = str.count('R')
g = str.count('G')
b = str.count('B')
sum = r * g * b
for i in range(n-2):
  for j in range(i+1, n-1):
    k = 2 * j - i
    if k < n:
      if str[i] != str[j] and str[i] != str[k] and str[j] != str[k] :
        sum -= 1
    
print(sum)