Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
result = 0

r = s.count('R')
g = s.count('G')
b = s.count('B')

result = r * g * b
count = 0

for i in range(n):
    for j in range(i, n):
        k = 2 * j - i
        if j < k < n:
            if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
                count += 1

print(result-count)


Fixed submission:
n = int(input())
s = input()
result = 0

r = s.count('R')
g = s.count('G')
b = s.count('B')

result = r * g * b
count = 0

for i in range(n):
    for j in range(i, n):
        k = 2 * j - i
        if j < k < n:
            if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
                count += 1

print(result-count)

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

def judge(i,j,k):
  if j-i == k-j:
    # print(i,j,k, "false")
    return False
  else:
    if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
      # print(i,j,k, "true")
      return True
    else:
      # print(i,j,k, "false")
      return False

def main(R):
  for i in range(N):
    for j in range(i+1,N):
      for k in range(j+1,N):
        if judge(i,j,k):
          R+=1
  print(R)

main(R)

Fixed submission:
n = int(input())
s = input()
result = 0

r = s.count('R')
g = s.count('G')
b = s.count('B')

result = r * g * b
count = 0

for i in range(n):
    for j in range(i, n):
        k = 2 * j - i
        if j < k < n:
            if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
                count += 1

print(result-count)

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

def judge(i,j,k):
  if j-i == k-j:
    return False
  else:
    if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
      # print(i,j,k, "True")
      return True
  # print(i,j,k, "False")
    else:
      return False

for i in range(N):
  for j in range(i+1,N):
    for k in range(j+1,N):
      if judge(i,j,k):
        R+=1

print(R)

Fixed submission:
n = int(input())
s = input()
result = 0

r = s.count('R')
g = s.count('G')
b = s.count('B')

result = r * g * b
count = 0

for i in range(n):
    for j in range(i, n):
        k = 2 * j - i
        if j < k < n:
            if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
                count += 1

print(result-count)

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

def judge(i,j,k):
  if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
    if j-i != k-j:
      # print(i,j,k, "True")
      return True
  # print(i,j,k, "False")
  return False

for i in range(N):
  for j in range(i+1,N):
    for k in range(j+1,N):
      if judge(i,j,k):
        R+=1

print(R)

Fixed submission:
n = int(input())
s = input()
result = 0

r = s.count('R')
g = s.count('G')
b = s.count('B')

result = r * g * b
count = 0

for i in range(n):
    for j in range(i, n):
        k = 2 * j - i
        if j < k < n:
            if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
                count += 1

print(result-count)

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

def judge(i,j,k):
  if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
    if j-i != k-j:
      # print(i,j,k, "True")
      return True
  # print(i,j,k, "False")
  return False

for i in range(N):
  for j in range(i,N):
    for k in range(j,N):
      if judge(i,j,k):
        R+=1

print(R)

Fixed submission:
n = int(input())
s = input()
result = 0

r = s.count('R')
g = s.count('G')
b = s.count('B')

result = r * g * b
count = 0

for i in range(n):
    for j in range(i, n):
        k = 2 * j - i
        if j < k < n:
            if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
                count += 1

print(result-count)