Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())
    S = input()
    cnt = 0
    for i in range(N):
        for j in range(i + 1, N):
            for k in range(j + 1, N):
                if j - i == k - j:
                    if S[j] != S[i] and S[i] != S[k] and S[k] != S[j]:
                        cnt += 1
    print(S.count("R") * S.count("B") * S.count("G") - cnt)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    N = int(input())
    S = input()
    cnt = 0
    for i in range(N):
        for j in range(i + 1, N):
            k = 2 * j - i
            if k >= N:
                continue
            if S[j] != S[i] and S[i] != S[k] and S[k] != S[j]:
                cnt += 1
    print(S.count("R") * S.count("B") * S.count("G") - cnt)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())
    S = input()
    cnt = 0
    for i in range(N):
        for j in range(i + 1, N):
            for k in range(j + 1, N):
                if j - i == k - j:
                    if S[j] != S[i] and S[i] != S[k] and S[k] != S[j]:
                        cnt += 1
    print(S.count("R") * S.count("B") * S.count("G") - cnt)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    N = int(input())
    S = input()
    cnt = 0
    for i in range(N):
        for j in range(i + 1, N):
            k = 2 * j - i
            if k >= N:
                continue
            if S[j] != S[i] and S[i] != S[k] and S[k] != S[j]:
                cnt += 1
    print(S.count("R") * S.count("B") * S.count("G") - cnt)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())
    S = input()
    ans = 0
    for i in range(N - 2):
        for j in range(i, N - 1):
            for k in range(j, N):
                if j - i != k - j:
                    if S[j] != S[i] and S[i] != S[k] and S[k]!=S[j]:
                        ans += 1                                        
    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
def main():
    N = int(input())
    S = input()
    cnt = 0
    for i in range(N):
        for j in range(i + 1, N):
            k = 2 * j - i
            if k >= N:
                continue
            if S[j] != S[i] and S[i] != S[k] and S[k] != S[j]:
                cnt += 1
    print(S.count("R") * S.count("B") * S.count("G") - cnt)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())
    S = input()
    ans = 0
    for i in range(N - 2):
        for j in range(i, N - 1):
            for k in range(j, N):
                if j - i != k - j:
                    if S[j] != S[i] and S[i] != S[k] and S[k]!=S[j]:
                        ans += 1                                        
    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
def main():
    N = int(input())
    S = input()
    cnt = 0
    for i in range(N):
        for j in range(i + 1, N):
            k = 2 * j - i
            if k >= N:
                continue
            if S[j] != S[i] and S[i] != S[k] and S[k] != S[j]:
                cnt += 1
    print(S.count("R") * S.count("B") * S.count("G") - cnt)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())
    S = input()
    R = set()
    G = set()
    B = set()
    for i,s in enumerate(S):
        if s == "R":
            R.add(i)
        elif s == "B":
            B.add(i)
        else:
            G.add(i)
    ans = 0
    for r in R:
        for b in B:
            for g in G:
                k = max(r, b, g)
                i = min(r, b, g)
                j = r + b + g - k - i
                if j - i != k - j:
                    ans += 1
    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
def main():
    N = int(input())
    S = input()
    cnt = 0
    for i in range(N):
        for j in range(i + 1, N):
            k = 2 * j - i
            if k >= N:
                continue
            if S[j] != S[i] and S[i] != S[k] and S[k] != S[j]:
                cnt += 1
    print(S.count("R") * S.count("B") * S.count("G") - cnt)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())
    S = input()
    R = set()
    G = set()
    B = set()
    for i,s in enumerate(S):
        if s == "R":
            R.add(i)
        elif s == "B":
            B.add(i)
        else:
            G.add(i)
    ans = 0
    for r in R:
        for b in B:
            for g in G:
                k = max(r, b, g)
                i = min(r, b, g)
                j = r + b + g - k - i
                if j - i != k - j:
                    ans += 1
    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
def main():
    N = int(input())
    S = input()
    cnt = 0
    for i in range(N):
        for j in range(i + 1, N):
            k = 2 * j - i
            if k >= N:
                continue
            if S[j] != S[i] and S[i] != S[k] and S[k] != S[j]:
                cnt += 1
    print(S.count("R") * S.count("B") * S.count("G") - cnt)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    N = int(input())
    S = input()
    R = set()
    G = set()
    B = set()
    for i,s in enumerate():
        if s == "R":
            R.add(i)
        elif s == "B":
            B.add(i)
        else:
            G.add(i)
    ans = 0
    for r in R:
        for b in B:
            for g in G:
                k = max(r, b, g)
                i = min(r, b, g)
                j = r + b + g - k - i
                if j - i != k - j:
                    ans += 1
    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
def main():
    N = int(input())
    S = input()
    cnt = 0
    for i in range(N):
        for j in range(i + 1, N):
            k = 2 * j - i
            if k >= N:
                continue
            if S[j] != S[i] and S[i] != S[k] and S[k] != S[j]:
                cnt += 1
    print(S.count("R") * S.count("B") * S.count("G") - cnt)

if __name__ == "__main__":
    main()