Buggy python submission (verdict: Time Limit Exceeded):
S = input()
S = list(input())
S_len = len(S)
ans = 0
i = 0
for _ in range(S_len):
  for j in range(len(S)-i-1):
    if S[i] == S[i+j+1]:
      continue
    for k in range(len(S)-i-j-2):
      if j != k and S[i] != S[i+j+1] and S[i] != S[i+k+j+2] and S[i+k+j+2] != S[i+j+1]:
          ans+=1
  S  = S[1:]
print(ans)

Fixed submission:
S = input()
S = list(input())
S_len = len(S)
ans = 0
i = 0
for _ in range(S_len):
  if S[0] == 'R':
    ans += S[1:].count('B') * S[1:].count('G')
    for j in range(int(len(S)/2+1)):
      try:
        if S[j+1] != S[j*2+2] and S[j*2+2] !='R' and S[j+1] !='R':
          ans-=1
      except:
        pass
  if S[0] == 'B':
    ans += S[1:].count('R') * S[1:].count('G')
    for j in range(int(len(S)/2+1)):
      try:
        if S[j+1] != S[j*2+2] and S[j*2+2] !='B' and S[j+1] !='B':
          ans-=1
      except:
        pass
  if S[0] == 'G':
    ans += S[1:].count('B') * S[1:].count('R')
    for j in range(int(len(S)/2+1)):
      try:
        if S[j+1] != S[j*2+2] and S[j*2+2] !='G' and S[j+1] !='G':
          ans-=1
      except:
        pass
  S  = S[1:]
print(ans)

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

ans = 0
for i in range(len(S)):
  for j in range(len(S)-i-1):
    if S[i] == S[i+j+1]:
      continue
    for k in range(len(S)-i-j-2):
      if j != k and S[i] != S[i+j+1] and S[i] != S[i+k+j+2] and S[i+k+j+2] != S[i+j+1]:
        ans+=1
print(ans)

Fixed submission:
S = input()
S = list(input())
S_len = len(S)
ans = 0
i = 0
for _ in range(S_len):
  if S[0] == 'R':
    ans += S[1:].count('B') * S[1:].count('G')
    for j in range(int(len(S)/2+1)):
      try:
        if S[j+1] != S[j*2+2] and S[j*2+2] !='R' and S[j+1] !='R':
          ans-=1
      except:
        pass
  if S[0] == 'B':
    ans += S[1:].count('R') * S[1:].count('G')
    for j in range(int(len(S)/2+1)):
      try:
        if S[j+1] != S[j*2+2] and S[j*2+2] !='B' and S[j+1] !='B':
          ans-=1
      except:
        pass
  if S[0] == 'G':
    ans += S[1:].count('B') * S[1:].count('R')
    for j in range(int(len(S)/2+1)):
      try:
        if S[j+1] != S[j*2+2] and S[j*2+2] !='G' and S[j+1] !='G':
          ans-=1
      except:
        pass
  S  = S[1:]
print(ans)

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

ans = 0
for i in range(len(S)):
  for j in range(len(S)-i-1):
    if S[i] == S[i+j+1]:
      continue
    for k in range(len(S)-i-j-2):
      if j != k and S[i] != S[i+j+1] and S[i] != S[i+k+j+2] and S[i+k+j+2] != S[i+j+1]:
        ans+=1
print(ans)

Fixed submission:
S = input()
S = list(input())
S_len = len(S)
ans = 0
i = 0
for _ in range(S_len):
  if S[0] == 'R':
    ans += S[1:].count('B') * S[1:].count('G')
    for j in range(int(len(S)/2+1)):
      try:
        if S[j+1] != S[j*2+2] and S[j*2+2] !='R' and S[j+1] !='R':
          ans-=1
      except:
        pass
  if S[0] == 'B':
    ans += S[1:].count('R') * S[1:].count('G')
    for j in range(int(len(S)/2+1)):
      try:
        if S[j+1] != S[j*2+2] and S[j*2+2] !='B' and S[j+1] !='B':
          ans-=1
      except:
        pass
  if S[0] == 'G':
    ans += S[1:].count('B') * S[1:].count('R')
    for j in range(int(len(S)/2+1)):
      try:
        if S[j+1] != S[j*2+2] and S[j*2+2] !='G' and S[j+1] !='G':
          ans-=1
      except:
        pass
  S  = S[1:]
print(ans)

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

ans = 0
ans_ = 0
for i in range(len(S)):
  for j in range(len(S)-i-1):
    for k in range(len(S)-i-j-2):
      if j != k and S[i] != S[i+k+1] and S[i] != S[i+k+j+2] and S[i+k+j+2] != S[i+k+1]:
        ans+=1
print(ans)

Fixed submission:
S = input()
S = list(input())
S_len = len(S)
ans = 0
i = 0
for _ in range(S_len):
  if S[0] == 'R':
    ans += S[1:].count('B') * S[1:].count('G')
    for j in range(int(len(S)/2+1)):
      try:
        if S[j+1] != S[j*2+2] and S[j*2+2] !='R' and S[j+1] !='R':
          ans-=1
      except:
        pass
  if S[0] == 'B':
    ans += S[1:].count('R') * S[1:].count('G')
    for j in range(int(len(S)/2+1)):
      try:
        if S[j+1] != S[j*2+2] and S[j*2+2] !='B' and S[j+1] !='B':
          ans-=1
      except:
        pass
  if S[0] == 'G':
    ans += S[1:].count('B') * S[1:].count('R')
    for j in range(int(len(S)/2+1)):
      try:
        if S[j+1] != S[j*2+2] and S[j*2+2] !='G' and S[j+1] !='G':
          ans-=1
      except:
        pass
  S  = S[1:]
print(ans)