Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
Rindexes = []
Gindexes = []
Bindexes = []
for i in range(N):
  if S[i] == 'R':
    Rindexes.append(i)
  elif S[i] == 'G':
    Gindexes.append(i)
  elif S[i] == 'B':
    Bindexes.append(i)

total = len(Rindexes) * len(Gindexes) * len(Bindexes)
count = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    k = 2*j - i
    if S[i] != S[j]:
      if S[i] != 'R' and S[j] != 'R' and k in Rindexes:
        count += 1
      elif S[i] != 'G' and S[j] != 'G' and k in Gindexes:
        count += 1
      elif S[i] != 'B' and S[j] != 'B' and k in Bindexes:
        count += 1
print(total - count)


Fixed submission:
N = int(input())
S = input()
rcount = 0
gcount = 0
bcount = 0
for i in range(N):
  if S[i] == 'R':
    rcount += 1
  elif S[i] == 'G':
    gcount += 1
  elif S[i] == 'B':
    bcount += 1

total = rcount * gcount * bcount
count = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    k = 2*j - i
    if k < N and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
      count += 1
print(total - count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
Rindexes = [i for i, x in enumerate(S) if x == 'R']
Gindexes = [i for i, x in enumerate(S) if x == 'G']
Bindexes = [i for i, x in enumerate(S) if x == 'B']

total = len(Rindexes) * len(Gindexes) * len(Bindexes)
count = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    k = 2*j - i
    if S[i] != S[j]:
      if S[i] != 'R' and S[j] != 'R' and k in Rindexes:
        count += 1
      elif S[i] != 'G' and S[j] != 'G' and k in Gindexes:
        count += 1
      elif S[i] != 'B' and S[j] != 'B' and k in Bindexes:
        count += 1
print(total - count)

Fixed submission:
N = int(input())
S = input()
rcount = 0
gcount = 0
bcount = 0
for i in range(N):
  if S[i] == 'R':
    rcount += 1
  elif S[i] == 'G':
    gcount += 1
  elif S[i] == 'B':
    bcount += 1

total = rcount * gcount * bcount
count = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    k = 2*j - i
    if k < N and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
      count += 1
print(total - count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
Rindexes = [i for i, x in enumerate(S) if x == 'R']
Gindexes = [i for i, x in enumerate(S) if x == 'G']
Bindexes = [i for i, x in enumerate(S) if x == 'B']

total = len(Rindexes) * len(Gindexes) * len(Bindexes)
count = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    k = 2*j - i
    if S[i] != S[j]:
      if S[i] != 'R' and S[j] != 'R' and k in Rindexes:
        count += 1
      elif S[i] != 'G' and S[j] != 'G' and k in Gindexes:
        count += 1
      elif S[i] != 'B' and S[j] != 'B' and k in Bindexes:
        count += 1
print(total - count)

Fixed submission:
N = int(input())
S = input()
rcount = 0
gcount = 0
bcount = 0
for i in range(N):
  if S[i] == 'R':
    rcount += 1
  elif S[i] == 'G':
    gcount += 1
  elif S[i] == 'B':
    bcount += 1

total = rcount * gcount * bcount
count = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    k = 2*j - i
    if k < N and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
      count += 1
print(total - count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
Rindexes = [i for i, x in enumerate(S) if x == 'R']
Gindexes = [i for i, x in enumerate(S) if x == 'G']
Bindexes = [i for i, x in enumerate(S) if x == 'B']
count = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    if S[i] != S[j]:
      diff_ji = j - i
      if S[i] != 'R' and S[j] != 'R':
        count += len(list(filter(lambda k: j < k and j - i != k - j, Rindexes)))
      elif S[i] != 'G' and S[j] != 'G':
        count += len(list(filter(lambda k: j < k and j - i != k - j, Gindexes)))
      elif S[i] != 'B' and S[j] != 'B':
        count += len(list(filter(lambda k: j < k and j - i != k - j, Bindexes)))
print(count)


Fixed submission:
N = int(input())
S = input()
rcount = 0
gcount = 0
bcount = 0
for i in range(N):
  if S[i] == 'R':
    rcount += 1
  elif S[i] == 'G':
    gcount += 1
  elif S[i] == 'B':
    bcount += 1

total = rcount * gcount * bcount
count = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    k = 2*j - i
    if k < N and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
      count += 1
print(total - count)

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):
    if S[i] != S[j]:
      diff_ji = j - i
      for k in range(j+1, N):
        if S[i] != S[k] and S[j] != S[k] and diff_ji != k - j:
          count += 1
print(count)


Fixed submission:
N = int(input())
S = input()
rcount = 0
gcount = 0
bcount = 0
for i in range(N):
  if S[i] == 'R':
    rcount += 1
  elif S[i] == 'G':
    gcount += 1
  elif S[i] == 'B':
    bcount += 1

total = rcount * gcount * bcount
count = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    k = 2*j - i
    if k < N and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
      count += 1
print(total - count)

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

Rindexes = [i for i, x in enumerate(S) if x == 'R']
Gindexes = [i for i, x in enumerate(S) if x == 'G']
Bindexes = [i for i, x in enumerate(S) if x == 'B']
count = 0

# rgb
for i in Rindexes:
  for j in filter(lambda j: i < j, Gindexes):
    count += len(list(filter(lambda k: j < k and j - i != k - j, Bindexes)))
# rbg
for i in Rindexes:
  for j in filter(lambda j: i < j, Bindexes):
    count += len(list(filter(lambda k: j < k and j - i != k - j, Gindexes)))
# grb
for i in Gindexes:
  for j in filter(lambda j: i < j, Rindexes):
    count += len(list(filter(lambda k: j < k and j - i != k - j, Bindexes)))
# gbr
for i in Gindexes:
  for j in filter(lambda j: i < j, Bindexes):
    count += len(list(filter(lambda k: j < k and j - i != k - j, Rindexes)))
# brg
for i in Bindexes:
  for j in filter(lambda j: i < j, Rindexes):
    count += len(list(filter(lambda k: j < k and j - i != k - j, Gindexes)))
# bgr
for i in Bindexes:
  for j in filter(lambda j: i < j, Gindexes):
    count += len(list(filter(lambda k: j < k and j - i != k - j, Rindexes)))
print(count)

Fixed submission:
N = int(input())
S = input()
rcount = 0
gcount = 0
bcount = 0
for i in range(N):
  if S[i] == 'R':
    rcount += 1
  elif S[i] == 'G':
    gcount += 1
  elif S[i] == 'B':
    bcount += 1

total = rcount * gcount * bcount
count = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    k = 2*j - i
    if k < N and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
      count += 1
print(total - count)

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):
    if S[i] != S[j]:
      diff_ji = j - i
      for k in range(j+1, N):
        if S[i] != S[k] and S[j] != S[k] and diff_ji != k - j:
          count += 1
print(count)


Fixed submission:
N = int(input())
S = input()
rcount = 0
gcount = 0
bcount = 0
for i in range(N):
  if S[i] == 'R':
    rcount += 1
  elif S[i] == 'G':
    gcount += 1
  elif S[i] == 'B':
    bcount += 1

total = rcount * gcount * bcount
count = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    k = 2*j - i
    if k < N and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
      count += 1
print(total - count)

Buggy python submission (verdict: Time Limit Exceeded):

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

Fixed submission:
N = int(input())
S = input()
rcount = 0
gcount = 0
bcount = 0
for i in range(N):
  if S[i] == 'R':
    rcount += 1
  elif S[i] == 'G':
    gcount += 1
  elif S[i] == 'B':
    bcount += 1

total = rcount * gcount * bcount
count = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    k = 2*j - i
    if k < N and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
      count += 1
print(total - count)