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

# N = 39
# S = "RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB"

def calculate(n, s):
    arr = list(s)

    rNum = arr.count("R")
    gNum = arr.count("G")
    bNum = arr.count("B")

    sum = 0

    for step in range(1,math.ceil(n / 2) + 1):
        for i in range(n - 2*step):
            dict = {"R":False,"G":False,"B":False}

            dict.__setitem__(arr[i],True)
            dict.__setitem__(arr[i+step],True)
            dict.__setitem__(arr[i+step*2],True)

            if list(dict.values()).count(True) == 3:
                sum = sum + 1

    print(rNum*gNum*bNum - sum)



calculate(N, S)


Fixed submission:
import math
N = int(input())
S = input()

# N = 39
# S = "RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB"

def calculate(n, s):
    arr = list(s)

    rNum = arr.count("R")
    gNum = arr.count("G")
    bNum = arr.count("B")

    sum = 0

    for step in range(1,math.ceil(n / 2) + 1):
        for i in range(n - 2*step):
            s = "".join([arr[i],arr[i+step],arr[i+step*2]])
            if s == "RGB" or s == "RBG" or s == "BGR" or s == "BRG" or s == "GBR" or s == "GRB":
                sum = sum + 1


    print(rNum*gNum*bNum - sum)



calculate(N, S)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N = int(input())
S = input()

def calculate(n, s):
    arr = list(s)

    rNum = arr.count("R")
    gNum = arr.count("G")
    bNum = arr.count("B")


    sum = 0

    for i in range(n):
        for j in range(i + 1, n):
            start = i
            middle = j
            end = i + (j - i) * 2
            if end > n - 1:
                break

            dict = {"R": False, "G": False, "B": False}
            dict.__setitem__(arr[start], True)
            dict.__setitem__(arr[middle], True)
            dict.__setitem__(arr[end], True)
            dictArr = np.array(list(dict.values()))
            if np.sum(dictArr == True) == 3:
                sum = sum + 1

    print(rNum*gNum*bNum - sum)


calculate(N, S)


Fixed submission:
import math
N = int(input())
S = input()

# N = 39
# S = "RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB"

def calculate(n, s):
    arr = list(s)

    rNum = arr.count("R")
    gNum = arr.count("G")
    bNum = arr.count("B")

    sum = 0

    for step in range(1,math.ceil(n / 2) + 1):
        for i in range(n - 2*step):
            s = "".join([arr[i],arr[i+step],arr[i+step*2]])
            if s == "RGB" or s == "RBG" or s == "BGR" or s == "BRG" or s == "GBR" or s == "GRB":
                sum = sum + 1


    print(rNum*gNum*bNum - sum)



calculate(N, S)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N = int(input())
S = input()

def calculate(n, s):
    arr = list(s)

    rNum = arr.count("R")
    gNum = arr.count("G")
    bNum = arr.count("B")


    sum = 0

    for i in range(n):
        for j in range(i + 1, n):
            start = i
            middle = j
            end = i + (j - i) * 2
            if end > n - 1:
                continue

            dict = {"R": False, "G": False, "B": False}
            dict.__setitem__(arr[start], True)
            dict.__setitem__(arr[middle], True)
            dict.__setitem__(arr[end], True)
            dictArr = np.array(list(dict.values()))
            if np.sum(dictArr == True) == 3:
                sum = sum + 1

    print(rNum*gNum*bNum - sum)


calculate(N, S)


Fixed submission:
import math
N = int(input())
S = input()

# N = 39
# S = "RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB"

def calculate(n, s):
    arr = list(s)

    rNum = arr.count("R")
    gNum = arr.count("G")
    bNum = arr.count("B")

    sum = 0

    for step in range(1,math.ceil(n / 2) + 1):
        for i in range(n - 2*step):
            s = "".join([arr[i],arr[i+step],arr[i+step*2]])
            if s == "RGB" or s == "RBG" or s == "BGR" or s == "BRG" or s == "GBR" or s == "GRB":
                sum = sum + 1


    print(rNum*gNum*bNum - sum)



calculate(N, S)