Buggy python submission (verdict: Time Limit Exceeded):
def checkRGB(a,b,c):
    if a == b or b == c or c == a:
        return 0
    else:
        return 1

N = int(input())
S = input()

if N<4:
    print(0)
    exit()
sum1 = S.count("R")*S.count("G")*S.count("B")
sum2 = 0
for i in range(1,N):
    center = S[i]
    for j in range(i):
        left = S[j]
        if 2*i-j<N:
            right = S[2*i-j]
            sum2 +=  checkRGB(left,center,right)

print(sum1-sum2)


Fixed submission:
def checkRGB(a,b,c):
    if a == b or b == c or c == a:
        return 0
    else:
        return 1

N = int(input())
S = input()

if N<4:
    print(0)
    exit()
sum1 = S.count("R")*S.count("G")*S.count("B")
sum2 = 0
for i in range(0,N-2):
    left = S[i]
    for j in range(i+1,(N+i)//2+(N+i)%2):
        center = S[j]
        right = S[2*j-i]
        if checkRGB(left,center,right):
            sum2 += 1
print(sum1-sum2)

Buggy python submission (verdict: Time Limit Exceeded):
def checkRGB(a,b,c):
    if a == b or b == c or c == a:
        return False
    else:
        return True

N = int(input())
S = input()

if N<4:
    print(0)
    exit()
sum = S.count("R")*S.count("G")*S.count("B")
for i in range(1,N):
    center = S[i]
    for j in range(i):
        left = S[j]
        if 2*i-j<N:
            right = S[2*i-j]
            if checkRGB(left,center,right):
                sum -= 1

print(sum)


Fixed submission:
def checkRGB(a,b,c):
    if a == b or b == c or c == a:
        return 0
    else:
        return 1

N = int(input())
S = input()

if N<4:
    print(0)
    exit()
sum1 = S.count("R")*S.count("G")*S.count("B")
sum2 = 0
for i in range(0,N-2):
    left = S[i]
    for j in range(i+1,(N+i)//2+(N+i)%2):
        center = S[j]
        right = S[2*j-i]
        if checkRGB(left,center,right):
            sum2 += 1
print(sum1-sum2)

Buggy python submission (verdict: Time Limit Exceeded):
def checkRGB(a,b):
    if not("B" in a) and not("B" in b):
        return "B"
    elif not("G" in a) and not("G" in b):
        return "G"
    else:
        return "R"

N = int(input())
S = input()

if N<4:
    print(0)
    exit()
sum = 0
for i in range(1,N//2+N%2+1):
    center = S[i]
    for j in range(i):
        if S[j] != center:
            left = S[j]
            rS1 = S[i+1:2*i-j]
            rS2 = S[2*i-j+1:]
            right = checkRGB(left,center)
            sum += rS1.count(right) + rS2.count(right)
        else:
            pass
for i in range(N//2+N%2+1,N-1):
    center = S[i]
    for j in range(i+1,N):
        if S[j] != center:
            right = S[j]
            lS1 = S[:2*i-j]
            lS2 = S[2*i-j+1:i]
            left = checkRGB(right,center)
            sum += lS1.count(left) + lS2.count(left)
        else:
            pass
print(sum)


Fixed submission:
def checkRGB(a,b,c):
    if a == b or b == c or c == a:
        return 0
    else:
        return 1

N = int(input())
S = input()

if N<4:
    print(0)
    exit()
sum1 = S.count("R")*S.count("G")*S.count("B")
sum2 = 0
for i in range(0,N-2):
    left = S[i]
    for j in range(i+1,(N+i)//2+(N+i)%2):
        center = S[j]
        right = S[2*j-i]
        if checkRGB(left,center,right):
            sum2 += 1
print(sum1-sum2)