Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

#N = 39
#S = "RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB"
N=int(input())
S=input()
r = len(S.replace("G", "").replace("B", ""))
g = len(S.replace("R", "").replace("B", ""))
b = len(S.replace("R", "").replace("G", ""))
b = N - r - g
 
ans = r * g * b
 
is_break = False
for i in range(N):
    for j in range(i, int((N+i)/2 + 1)):
        k = 2 * j - i
        if (0 <= i) & (i < j) & (j < k) & (k < N):
            s = S[i] + S[j] + S[k]
            if ("R" in s) & ("G" in s) & ("B" in s):
                    ans -= 1
print(ans)


Fixed submission:

#S = "RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB"# * 1000
#N = len(S)

N=int(input())
S=input()
r = len(S.replace("G", "").replace("B", ""))
g = len(S.replace("R", "").replace("B", ""))
b = N - r - g
 
ans = r * g * b
 
is_break = False
for i in range(N):
    for j in range(i, int((N+i)/2 + 1)):
        k = 2 * j - i
        if k < N:
            s = S[i] + S[j] + S[k]
            if ("R" in s) & ("G" in s) & ("B" in s):
                    ans -= 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

#N = 39
#S = "RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB"
N=int(input())
S=input()
r = len(S.replace("G", "").replace("B", ""))
g = len(S.replace("R", "").replace("B", ""))
#b = len(S.replace("R", "").replace("G", ""))
b = N - r - g
 
ans = r * g * b
 
for i in range(N):
    for k in [N - k_ - 1 for k_ in range(N)]:
        if i >= k:
            break
            
        tar_j = i + k
        if (tar_j > 2 * i) & (tar_j < 2 * k):
            if np.mod(tar_j, 2) == 0:
                j = int(tar_j / 2)
                s = S[i] + S[j] + S[k]
                if ("R" in s) & ("G" in s) & ("B" in s):
                    ans -= 1
        else:
            break
print(ans)


Fixed submission:

#S = "RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB"# * 1000
#N = len(S)

N=int(input())
S=input()
r = len(S.replace("G", "").replace("B", ""))
g = len(S.replace("R", "").replace("B", ""))
b = N - r - g
 
ans = r * g * b
 
is_break = False
for i in range(N):
    for j in range(i, int((N+i)/2 + 1)):
        k = 2 * j - i
        if k < N:
            s = S[i] + S[j] + S[k]
            if ("R" in s) & ("G" in s) & ("B" in s):
                    ans -= 1

print(ans)

Buggy python submission (verdict: Runtime Error):
import numpy as np

#N = 39
#S = "RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB"
N=int(input())
S=input()
r = len(S.replace("G", "").replace("B", ""))
g = len(S.replace("R", "").replace("B", ""))
#b = len(S.replace("R", "").replace("G", ""))
b = N - r - g
 
ans = r * g * b
 
for i in range(N):
    for k in [N - k_ - 1 for k_ in range(N)]:
        tar_j = i + k
        if (tar_j > 2 * i) & (tar_j < 2 * k):
            if np.mod(tar_j, 2) == 0:
                j = int(tar_j / 2)
                s = S[i] + S[j] + S[k]
                if ("R" in s) & ("G" in s) & ("B" in s):
                    ans -= 1
        else:
            break
print(ans)


Fixed submission:

#S = "RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB"# * 1000
#N = len(S)

N=int(input())
S=input()
r = len(S.replace("G", "").replace("B", ""))
g = len(S.replace("R", "").replace("B", ""))
b = N - r - g
 
ans = r * g * b
 
is_break = False
for i in range(N):
    for j in range(i, int((N+i)/2 + 1)):
        k = 2 * j - i
        if k < N:
            s = S[i] + S[j] + S[k]
            if ("R" in s) & ("G" in s) & ("B" in s):
                    ans -= 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

#N = 39
#S = "RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB"
N=int(input())
S=input()
r = len(S.replace("G", "").replace("B", ""))
g = len(S.replace("R", "").replace("B", ""))
#b = len(S.replace("R", "").replace("G", ""))
b = N - r - g
 
ans = r * g * b
 
for i in range(N):
    for k in [N - k_ - 1 for k_ in range(N)]:
        tar_j = i + k
        if (tar_j > 2 * i) & (tar_j < 2 * k):
            if np.mod(tar_j, 2) == 0:
                j = int(tar_j / 2)
                s = S[i] + S[j] + S[k]
                if ("R" in s) & ("G" in s) & ("B" in s):
                    ans -= 1
        else:
            break
print(ans)


Fixed submission:

#S = "RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB"# * 1000
#N = len(S)

N=int(input())
S=input()
r = len(S.replace("G", "").replace("B", ""))
g = len(S.replace("R", "").replace("B", ""))
b = N - r - g
 
ans = r * g * b
 
is_break = False
for i in range(N):
    for j in range(i, int((N+i)/2 + 1)):
        k = 2 * j - i
        if k < N:
            s = S[i] + S[j] + S[k]
            if ("R" in s) & ("G" in s) & ("B" in s):
                    ans -= 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N=int(input())
S=input()
r = len([x for x in S if x == "R"])
g = len([x for x in S if x == "G"])
b = len([x for x in S if x == "B"])
 
ans = r * g * b
 
for i in range(N):
  for k in [N - k_ - 1 for k_ in range(N)]:
    tar_j = i + k
    if (tar_j > 2 * i) & (tar_j < 2 * k):
      if np.mod(tar_j, 2) == 0:
        j = int(tar_j / 2)
        s = S[i] + S[j] + S[k]
        if ("R" in s) & ("G" in s) & ("B" in s):
          ans -= 1
    else:
      break
print(ans)


Fixed submission:

#S = "RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB"# * 1000
#N = len(S)

N=int(input())
S=input()
r = len(S.replace("G", "").replace("B", ""))
g = len(S.replace("R", "").replace("B", ""))
b = N - r - g
 
ans = r * g * b
 
is_break = False
for i in range(N):
    for j in range(i, int((N+i)/2 + 1)):
        k = 2 * j - i
        if k < N:
            s = S[i] + S[j] + S[k]
            if ("R" in s) & ("G" in s) & ("B" in s):
                    ans -= 1

print(ans)

Buggy python submission (verdict: Runtime Error):
import numpy as np
import pandas as pd
N=int(input())
S=input()

S_list = pd.Series([x for x in S])
r = sum(S_list == "R")
g = sum(S_list == "G")
b = sum(S_list == "B")
 
ans = r * g * b
 
for i in range(N):
  for k in [N - k_ - 1 for k_ in range(N)]:
    tar_j = i + k
    if (tar_j > 2 * i) & (tar_j < 2 * k):
      if np.mod(tar_j, 2) == 0:
        j = int(tar_j / 2)
        s = S[i] + S[j] + S[k]
        if ("R" in s) & ("G" in s) & ("B" in s):
          ans -= 1
    else:
      break
print(ans)


Fixed submission:

#S = "RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB"# * 1000
#N = len(S)

N=int(input())
S=input()
r = len(S.replace("G", "").replace("B", ""))
g = len(S.replace("R", "").replace("B", ""))
b = N - r - g
 
ans = r * g * b
 
is_break = False
for i in range(N):
    for j in range(i, int((N+i)/2 + 1)):
        k = 2 * j - i
        if k < N:
            s = S[i] + S[j] + S[k]
            if ("R" in s) & ("G" in s) & ("B" in s):
                    ans -= 1

print(ans)

Buggy python submission (verdict: Runtime Error):
import numpy as np
import pandas as pd

#N=int(input())
#S=input()
S_list = pd.Series([x for x in S])
r = sum(S_list == "R")
g = sum(S_list == "G")
b = sum(S_list == "B")
 
ans = r * g * b
 
for i in range(N):
  for k in [N - k_ - 1 for k_ in range(N)]:
    tar_j = i + k
    if (tar_j > 2 * i) & (tar_j < 2 * k):
      if np.mod(tar_j, 2) == 0:
        j = int(tar_j / 2)
        s = S[i] + S[j] + S[k]
        if ("R" in s) & ("G" in s) & ("B" in s):
          ans -= 1
    else:
      break
print(ans)


Fixed submission:

#S = "RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB"# * 1000
#N = len(S)

N=int(input())
S=input()
r = len(S.replace("G", "").replace("B", ""))
g = len(S.replace("R", "").replace("B", ""))
b = N - r - g
 
ans = r * g * b
 
is_break = False
for i in range(N):
    for j in range(i, int((N+i)/2 + 1)):
        k = 2 * j - i
        if k < N:
            s = S[i] + S[j] + S[k]
            if ("R" in s) & ("G" in s) & ("B" in s):
                    ans -= 1

print(ans)

Buggy python submission (verdict: Runtime Error):
import numpy as np
N=int(input())
S=input()
r = sum(S == "R")
g = sum(S == "G")
b = sum(S == "B")

ans = r * g * b

for i in range(N):
  for k in [N - k_ - 1 for k_ in range(N)]:
    tar_j = i + k
    if (tar_j > 2 * i) & (tar_j < 2 * k):
      if np.mod(tar_j, 2) == 0:
        j = tar_j / 2
        s = S[i] + S[j] + S[k]
        if ("R" in s) & ("G" in s) & ("B" in s):
          ans -= 1
    else:
      break
print(ans)
          

Fixed submission:

#S = "RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB"# * 1000
#N = len(S)

N=int(input())
S=input()
r = len(S.replace("G", "").replace("B", ""))
g = len(S.replace("R", "").replace("B", ""))
b = N - r - g
 
ans = r * g * b
 
is_break = False
for i in range(N):
    for j in range(i, int((N+i)/2 + 1)):
        k = 2 * j - i
        if k < N:
            s = S[i] + S[j] + S[k]
            if ("R" in s) & ("G" in s) & ("B" in s):
                    ans -= 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
str_len = int(input().rstrip())
str = input().rstrip()

rgb_nums_dict = {'R':str.count('R'), 'G':str.count('G'), 'B':str.count('B')}
total = 0
for i in range(str_len-2):
    for j in range(i+1,str_len-1):
        first_str = str[i]
        second_str = str[j]
        if first_str==second_str:
            continue
        else:
            if 2*j-i<str_len and second_str!=str[2*j-i]!=first_str:
                total-=1
                


for i in range(str_len):
    first_str = str[i]
    if first_str=='R':
        total += rgb_nums_dict['G']*rgb_nums_dict['B']
        
    elif first_str=='G':
        total += rgb_nums_dict['R']*rgb_nums_dict['B']
        
    else:#'B'
        total += rgb_nums_dict['R']*rgb_nums_dict['G']
        
    rgb_nums_dict[first_str]-=1
    if rgb_nums_dict[first_str]==0:
        break
    
print(total)


Fixed submission:
str_len = int(input().rstrip())
str = input().rstrip()

rgb_nums_dict = {'R':str.count('R'), 'G':str.count('G'), 'B':str.count('B')}
total = 0
for i in range(str_len-2):
    for j in range(i+1,str_len-1):
        first_str = str[i]
        second_str = str[j]
        if first_str==second_str:
            continue
        else:
            if 2*j-i<str_len and second_str!=str[2*j-i]!=first_str:
                total-=1
                


for i in range(str_len):
    first_str = str[i]
    if first_str=='R':
        total += rgb_nums_dict['G']*rgb_nums_dict['B']
        
    elif first_str=='G':
        total += rgb_nums_dict['R']*rgb_nums_dict['B']
        
    else:#'B'
        total += rgb_nums_dict['R']*rgb_nums_dict['G']
        
    rgb_nums_dict[first_str]-=1
    if rgb_nums_dict[first_str]==0:
        break
    
print(total)

Buggy python submission (verdict: Time Limit Exceeded):
str_len = int(input().rstrip())
str = input().rstrip()

rgb_nums_dict = {'R':str.count('R'), 'G':str.count('G'), 'B':str.count('B')}
total = 0
for i in range(str_len-2):
    for j in range(i+1,str_len-1):
        first_str = str[i]
        second_str = str[j]
        if first_str==second_str:
            continue
        else:
            if 2*j-i<str_len and second_str!=str[2*j-i]!=first_str:
                total-=1
                

for letter in str:
    first_str = letter
    
    if first_str=='R':
        total += rgb_nums_dict['G']*rgb_nums_dict['B']
        
    elif first_str=='G':
        total += rgb_nums_dict['R']*rgb_nums_dict['B']
        
    else:#'B'
        total += rgb_nums_dict['R']*rgb_nums_dict['G']
        
    rgb_nums_dict[first_str]-=1
    if rgb_nums_dict[first_str]==0:
        break

print(total)


Fixed submission:
str_len = int(input().rstrip())
str = input().rstrip()

rgb_nums_dict = {'R':str.count('R'), 'G':str.count('G'), 'B':str.count('B')}
total = 0
for i in range(str_len-2):
    for j in range(i+1,str_len-1):
        first_str = str[i]
        second_str = str[j]
        if first_str==second_str:
            continue
        else:
            if 2*j-i<str_len and second_str!=str[2*j-i]!=first_str:
                total-=1
                


for i in range(str_len):
    first_str = str[i]
    if first_str=='R':
        total += rgb_nums_dict['G']*rgb_nums_dict['B']
        
    elif first_str=='G':
        total += rgb_nums_dict['R']*rgb_nums_dict['B']
        
    else:#'B'
        total += rgb_nums_dict['R']*rgb_nums_dict['G']
        
    rgb_nums_dict[first_str]-=1
    if rgb_nums_dict[first_str]==0:
        break
    
print(total)