Buggy python submission (verdict: Runtime Error):
import sys
from collections import Counter


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    N = int(input())
    S = input()
    C = Counter(S)
    r = C.get("R")
    g = C.get("G")
    b = C.get("B")
    answer = r * g * b
    for left in range(N):
        for mid in range(left + 1, N):
            right = mid * 2 - left
            if right < N:
                if S[right] != S[mid] and S[mid] != S[left] and S[right] != S[left]:
                    answer -= 1
    print(answer)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
from collections import Counter


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    S = input()
    C = Counter(S)
    R = C.get("R", 0)
    G = C.get("G", 0)
    B = C.get("B", 0)
    ans = R * G * B
    for left in range(N):
        for mid in range(left + 1, N):
            right = mid + mid - left
            if right < N:
                if S[right] != S[mid] and S[mid] != S[left] and S[right] != S[left]:
                    ans -= 1
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
import sys
from collections import Counter


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    N = int(input())
    S = input()
    C = Counter(S)
    r = C.get("R")
    g = C.get("G")
    b = C.get("B")
    answer = r * g * b
    for left in range(N):
        for mid in range(left + 1, N):
            right = mid * 2 - left
            if right < N:
                if S[right] != S[mid] and S[mid] != S[left] and S[right] != S[left]:
                    answer = -1
    print(answer)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
from collections import Counter


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    S = input()
    C = Counter(S)
    R = C.get("R", 0)
    G = C.get("G", 0)
    B = C.get("B", 0)
    ans = R * G * B
    for left in range(N):
        for mid in range(left + 1, N):
            right = mid + mid - left
            if right < N:
                if S[right] != S[mid] and S[mid] != S[left] and S[right] != S[left]:
                    ans -= 1
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    N = int(input())
    S = input()
    R = []
    G = []
    B = []
    for i in range(N):
        if i == 0:
            if S[0] == "R":
                R.append(1)
                B.append(0)
                G.append(0)
            elif S[0] == "B":
                R.append(0)
                B.append(1)
                G.append(0)
            else:
                R.append(0)
                B.append(0)
                G.append(1)
            continue
        if S[i] == "R":
            R.append(R[i - 1] + 1)
            B.append(B[i - 1])
            G.append(G[i - 1])
        elif S[i] == "G":
            R.append(R[i - 1])
            B.append(B[i - 1])
            G.append(G[i - 1] + 1)
        else:
            R.append(R[i - 1])
            B.append(B[i - 1] + 1)
            G.append(G[i - 1])

    answer = 0
    for i in range(N - 2):
        for j in range(i + 1, N - 1):
            if (S[i], S[j]) == ("G", "R") or (S[i], S[j]) == ("R", "G"):
                answer += B[-1] - B[j]
                if 2 * j - i < N:
                    if S[2 * j - i] == "B":
                        answer -= 1
            elif (S[i], S[j]) == ("G", "B") or (S[i], S[j]) == ("B", "G"):
                answer += R[-1] - R[j]
                if 2 * j - i < N:
                    if S[2 * j - i] == "R":
                        answer -= 1
            elif (S[i], S[j]) == ("B", "R") or (S[i], S[j]) == ("R", "B"):
                answer += G[-1] - G[j]
                if 2 * j - i < N:
                    if S[2 * j - i] == "G":
                        answer -= 1
    print(answer)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
from collections import Counter


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    S = input()
    C = Counter(S)
    R = C.get("R", 0)
    G = C.get("G", 0)
    B = C.get("B", 0)
    ans = R * G * B
    for left in range(N):
        for mid in range(left + 1, N):
            right = mid + mid - left
            if right < N:
                if S[right] != S[mid] and S[mid] != S[left] and S[right] != S[left]:
                    ans -= 1
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    N = int(input())
    S = input()
    answer = 0
    for i in range(N - 2):
        for j in range(i + 1, N - 1):
            if (S[i], S[j]) == ("G", "R") or (S[i], S[j]) == ("R", "G"):
                answer += S[j + 1 :].count("B")
                if 2 * j - i < N:
                    if S[2 * j - i] == "B":
                        answer -= 1
            elif (S[i], S[j]) == ("G", "B") or (S[i], S[j]) == ("B", "G"):
                answer += S[j + 1 :].count("R")
                if 2 * j - i < N:
                    if S[2 * j - i] == "R":
                        answer -= 1
            elif (S[i], S[j]) == ("B", "R") or (S[i], S[j]) == ("R", "B"):
                answer += S[j + 1 :].count("G")
                if 2 * j - i < N:
                    if S[2 * j - i] == "G":
                        answer -= 1
    print(answer)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
from collections import Counter


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    S = input()
    C = Counter(S)
    R = C.get("R", 0)
    G = C.get("G", 0)
    B = C.get("B", 0)
    ans = R * G * B
    for left in range(N):
        for mid in range(left + 1, N):
            right = mid + mid - left
            if right < N:
                if S[right] != S[mid] and S[mid] != S[left] and S[right] != S[left]:
                    ans -= 1
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from itertools import product


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    S = input()
    r = []
    g = []
    b = []
    for i in range(N):
        if S[i] == "R":
            r.append(i)
        elif S[i] == "G":
            g.append(i)
        else:
            b.append(i)
    A = product(r, g, b)
    ans = 0
    for a in A:
        a = list(a)
        a.sort()
        if a[2] - a[1] != a[1] - a[0]:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
from collections import Counter


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    S = input()
    C = Counter(S)
    R = C.get("R", 0)
    G = C.get("G", 0)
    B = C.get("B", 0)
    ans = R * G * B
    for left in range(N):
        for mid in range(left + 1, N):
            right = mid + mid - left
            if right < N:
                if S[right] != S[mid] and S[mid] != S[left] and S[right] != S[left]:
                    ans -= 1
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from itertools import product


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    S = input()
    r = []
    g = []
    b = []
    for i in range(N):
        if S[i] == "R":
            r.append(i)
        elif S[i] == "G":
            g.append(i)
        else:
            b.append(i)
    A = product(r, g, b)
    ans = 0
    for a in A:
        a = list(a)
        a.sort()
        if a[2] - a[1] != a[1] - a[0]:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
from collections import Counter


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    S = input()
    C = Counter(S)
    R = C.get("R", 0)
    G = C.get("G", 0)
    B = C.get("B", 0)
    ans = R * G * B
    for left in range(N):
        for mid in range(left + 1, N):
            right = mid + mid - left
            if right < N:
                if S[right] != S[mid] and S[mid] != S[left] and S[right] != S[left]:
                    ans -= 1
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from itertools import product


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    S = input()
    r = []
    g = []
    b = []
    for i in range(N):
        if S[i] == "R":
            r.append(i)
        elif S[i] == "G":
            g.append(i)
        else:
            b.append(i)
    A = product(r, g, b)
    ans = 0
    for a in A:
        a = list(a)
        x = abs(a[0] - a[1])
        y = abs(a[1] - a[2])
        z = abs(a[0] - a[2])
        if x != y and y != z and z != x:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
from collections import Counter


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    S = input()
    C = Counter(S)
    R = C.get("R", 0)
    G = C.get("G", 0)
    B = C.get("B", 0)
    ans = R * G * B
    for left in range(N):
        for mid in range(left + 1, N):
            right = mid + mid - left
            if right < N:
                if S[right] != S[mid] and S[mid] != S[left] and S[right] != S[left]:
                    ans -= 1
    print(ans)


if __name__ == "__main__":
    main()