Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    s = input()
    R = []
    G = []
    B = []
    R_a = R.append
    G_a = G.append
    B_a = B.append

    for i in range(n):
        if s[i] == "R":
            R_a(i + 1)
        elif s[i] == "G":
            G_a(i + 1)
        else:
            B_a(i + 1)

    def chk(R,G,B):
        res = 0
        for r in R:
            for g in G:
                for b in B:
                    if r + g != b * 2 and g + b != r * 2 and b + r != g * 2:
                        res += 1
        return res
    if len(R) > len(G):
        print(chk(G, B, R))
    elif len(G) > len(B):
            print(chk(B, R, G))
    elif len(B) > len(R):
        print(chk(R, G, B))
    else:
        print(chk(R, G, B))

if __name__ == '__main__':
    main()


Fixed submission:
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    s = input()
    R = 0
    G = 0
    B = 0

    for i in range(n):
        if s[i] == "R":
            R += 1
        elif s[i] == "G":
            G += 1
        else:
            B += 1
            
    res = R*G*B
    for i in range(n - 2):
        for j in range(i + 1, i + 1 + (n - 1 - i) // 2):
            k = j + (j - i)
            if s[i] != s[j] != s[k] != s[i]:
                res -= 1
    print(res)
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    s = input()
    R = []
    G = []
    B = []
    R_a = R.append
    G_a = G.append
    B_a = B.append

    for i in range(n):
        if s[i] == "R":
            R_a(i + 1)
        elif s[i] == "G":
            G_a(i + 1)
        else:
            B_a(i + 1)
    res = 0
    for r in R:
        for g in G:
            for b in B:
                if r + g != b * 2 and g + b != r * 2 and b + r != g * 2:
                    res += 1
    print(res)
if __name__ == '__main__':
    main()


Fixed submission:
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    s = input()
    R = 0
    G = 0
    B = 0

    for i in range(n):
        if s[i] == "R":
            R += 1
        elif s[i] == "G":
            G += 1
        else:
            B += 1
            
    res = R*G*B
    for i in range(n - 2):
        for j in range(i + 1, i + 1 + (n - 1 - i) // 2):
            k = j + (j - i)
            if s[i] != s[j] != s[k] != s[i]:
                res -= 1
    print(res)
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    s = input()
    R = []
    G = []
    B = []

    for i in range(n):
        if s[i] == "R":
            R.append(i + 1)
        elif s[i] == "G":
            G.append(i + 1)
        else:
            B.append(i + 1)
    res = 0
    for r in R:
        for g in G:
            for b in B:
                if r + g != b * 2 and g + b != r * 2 and b + r != g * 2:
                    res += 1
    print(res)
if __name__ == '__main__':
    main()


Fixed submission:
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    s = input()
    R = 0
    G = 0
    B = 0

    for i in range(n):
        if s[i] == "R":
            R += 1
        elif s[i] == "G":
            G += 1
        else:
            B += 1
            
    res = R*G*B
    for i in range(n - 2):
        for j in range(i + 1, i + 1 + (n - 1 - i) // 2):
            k = j + (j - i)
            if s[i] != s[j] != s[k] != s[i]:
                res -= 1
    print(res)
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    s = input()
    R = []
    G = []
    B = []

    for i in range(n):
        if s[i] == "R":
            R.append(i + 1)
        elif s[i] == "G":
            G.append(i + 1)
        else:
            B.append(i + 1)

    res = 0
    for r in R:
        for g in G:
            for b in B:
                x = max(r, g, b)
                y = min(r, g, b)
                z = r + g + b - x - y
                if x + y != z * 2:
                    res += 1
    print(res)
if __name__ == '__main__':
    main()


Fixed submission:
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    s = input()
    R = 0
    G = 0
    B = 0

    for i in range(n):
        if s[i] == "R":
            R += 1
        elif s[i] == "G":
            G += 1
        else:
            B += 1
            
    res = R*G*B
    for i in range(n - 2):
        for j in range(i + 1, i + 1 + (n - 1 - i) // 2):
            k = j + (j - i)
            if s[i] != s[j] != s[k] != s[i]:
                res -= 1
    print(res)
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    s = input()
    R = []
    G = []
    B = []

    for i in range(n):
        if s[i] == "R":
            R.append(i + 1)
        elif s[i] == "G":
            G.append(i + 1)
        else:
            B.append(i + 1)

    res = 0
    for r in R:
        for g in G:
            for b in B:
                x = max(r, g, b)
                y = min(r, g, b)
                z = r + g + b - x - y
                if x + y != z * 2:
                    res += 1
    print(res)
if __name__ == '__main__':
    main()


Fixed submission:
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    s = input()
    R = 0
    G = 0
    B = 0

    for i in range(n):
        if s[i] == "R":
            R += 1
        elif s[i] == "G":
            G += 1
        else:
            B += 1
            
    res = R*G*B
    for i in range(n - 2):
        for j in range(i + 1, i + 1 + (n - 1 - i) // 2):
            k = j + (j - i)
            if s[i] != s[j] != s[k] != s[i]:
                res -= 1
    print(res)
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
R = []
G = []
B = []

for i in range(n):
    if s[i] == "R":
        R.append(i+1)
    elif s[i] == "G":
        G.append(i+1)
    else:
        B.append(i+1)

res = 0
for r in R:
    for g in G:
        for b in B:
            lis = [r,g,b]
            lis.sort()
            if lis[0] + lis[2] != lis[1] * 2:
                res += 1
print(res)

Fixed submission:
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    s = input()
    R = 0
    G = 0
    B = 0

    for i in range(n):
        if s[i] == "R":
            R += 1
        elif s[i] == "G":
            G += 1
        else:
            B += 1
            
    res = R*G*B
    for i in range(n - 2):
        for j in range(i + 1, i + 1 + (n - 1 - i) // 2):
            k = j + (j - i)
            if s[i] != s[j] != s[k] != s[i]:
                res -= 1
    print(res)
if __name__ == '__main__':
    main()