Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n=int(input())
    s=input()
    r = [0]*n
    g = [0]*n
    b = [0]*n
    ans = 1

    dict = {"R":r, "G":g, "B":b}

    for i in range(n):
        dict[s[i]][i] = 1
    
    ans = sum(dict["R"])*sum(dict["G"])*sum(dict["B"])
 
    for i in range(n):
        for j in range(i,n):
            s1 = s[i]
            s2 = s[j]
            if s1 != s2:
                t = (s1,s2)
                for s3 in "RGB":
                    if s3 not in t:
                        if 2*j-i < n and dict[s3][2*j-i] == 1:
                            ans -= 1
                        continue

    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
def main():
    n=int(input())
    s=input()
    ans = 1

    r_cnt = s.count("R")
    g_cnt = s.count("G")

    ans = r_cnt*g_cnt*(n-r_cnt-g_cnt)
 
    for i in range(n):
        for j in range(i,n):
            s1 = s[i]
            s2 = s[j]
            if s1 != s2:
                t = (s1,s2)
                for s3 in "RGB":
                    if s3 not in t:
                        if 2*j-i < n and s[2*j-i] == s3:
                            ans -= 1
                        continue

    print(ans)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n=int(input())
    s=input()
    r = [0]*n
    g = [0]*n
    b = [0]*n
    ans = 1

    dict = {"R":r, "G":g, "B":b}

    for i in range(n):
        dict[s[i]][i] = 1
    
    for l in dict.values():
        ans *= sum(l)
 
    for i in range(n):
        for j in range(i,n):
            if dict[s[i]][j] == 0:                
                s1 = s[i]
                s2 = s[j]
                t = (s1,s2)
                for s3 in "RGB":
                    if s3 not in t:
                        if 2*j-i < n and dict[s3][2*j-i] == 1:
                            ans -= 1

    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
def main():
    n=int(input())
    s=input()
    ans = 1

    r_cnt = s.count("R")
    g_cnt = s.count("G")

    ans = r_cnt*g_cnt*(n-r_cnt-g_cnt)
 
    for i in range(n):
        for j in range(i,n):
            s1 = s[i]
            s2 = s[j]
            if s1 != s2:
                t = (s1,s2)
                for s3 in "RGB":
                    if s3 not in t:
                        if 2*j-i < n and s[2*j-i] == s3:
                            ans -= 1
                        continue

    print(ans)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n=int(input())
    s=input()
    r = [0]*n
    g = [0]*n
    b = [0]*n
    ans = 0

    dict = {"R":r, "G":g, "B":b}

    for i in range(n):
        dict[s[i]][i] = 1
 
    def rgb_sum(t,i,j):
        for s3 in "RGB":
            if s3 not in t:
                if 2*j-i < n:
                    return sum(dict[s3][j+1:]) - dict[s3][2*j-i]
                else:
                    return sum(dict[s3][j+1:])
                break

    for i in range(n):
        for j in range(i,n):
            if dict[s[i]][j] == 0:                
                s1 = s[i]
                s2 = s[j]
                t = (s1,s2)
                ans += rgb_sum(t,i,j)

    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
def main():
    n=int(input())
    s=input()
    ans = 1

    r_cnt = s.count("R")
    g_cnt = s.count("G")

    ans = r_cnt*g_cnt*(n-r_cnt-g_cnt)
 
    for i in range(n):
        for j in range(i,n):
            s1 = s[i]
            s2 = s[j]
            if s1 != s2:
                t = (s1,s2)
                for s3 in "RGB":
                    if s3 not in t:
                        if 2*j-i < n and s[2*j-i] == s3:
                            ans -= 1
                        continue

    print(ans)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n=int(input())
    s=input()
    r = [0]*n
    g = [0]*n
    b = [0]*n
    ans = 0

    dict = {"R":r, "G":g, "B":b}

    for i in range(n):
        dict[s[i]][i] = 1
 
    def rgb_sum(t,i,j):
        for s3 in "RGB":
            if s3 not in t:
                if 2*j-i < n:
                    return sum(dict[s3][j+1:]) - dict[s3][2*j-i]
                else:
                    return sum(dict[s3][j+1:])
                break

    for i in range(n):
        for j in range(i,n):
            s1 = s[i]
            s2 = s[j]
            t = (s1,s2)
            if s1 != s2:
                ans += rgb_sum(t,i,j)

    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
def main():
    n=int(input())
    s=input()
    ans = 1

    r_cnt = s.count("R")
    g_cnt = s.count("G")

    ans = r_cnt*g_cnt*(n-r_cnt-g_cnt)
 
    for i in range(n):
        for j in range(i,n):
            s1 = s[i]
            s2 = s[j]
            if s1 != s2:
                t = (s1,s2)
                for s3 in "RGB":
                    if s3 not in t:
                        if 2*j-i < n and s[2*j-i] == s3:
                            ans -= 1
                        continue

    print(ans)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n=int(input())
    s=input()
    r = [0]*n
    g = [0]*n
    b = [0]*n
    ans = 0

    for i in range(n):
        s1 = s[i]
        if s1 == "R":
            r[i] = 1
        elif s1 == "G":
            g[i] = 1
        else:
            b[i] = 1
    
    dict = {"R":r, "G":g, "B":b}

    def rgb_sum(t,i,j):
        for s3 in "RGB":
            if s3 not in t:
                if 2*j-i < n:
                    return sum(dict[s3][j+1:]) - dict[s3][2*j-i]
                else:
                    return sum(dict[s3][j+1:])

    for i in range(n):
        for j in range(i,n):
            s1 = s[i]
            s2 = s[j]
            t = (s1,s2)
            if s1 != s2:
                ans += rgb_sum(t,i,j)

    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
def main():
    n=int(input())
    s=input()
    ans = 1

    r_cnt = s.count("R")
    g_cnt = s.count("G")

    ans = r_cnt*g_cnt*(n-r_cnt-g_cnt)
 
    for i in range(n):
        for j in range(i,n):
            s1 = s[i]
            s2 = s[j]
            if s1 != s2:
                t = (s1,s2)
                for s3 in "RGB":
                    if s3 not in t:
                        if 2*j-i < n and s[2*j-i] == s3:
                            ans -= 1
                        continue

    print(ans)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
r = [0]*n
g = [0]*n
b = [0]*n
ans = 0

for i in range(n):
    s1 = s[i]
    if s1 == "R":
        r[i] = 1
    elif s1 == "G":
        g[i] = 1
    else:
        b[i] = 1

for i in range(n):
    for j in range(i,n):
        s1 = s[i]
        s2 = s[j]
        t = (s1,s2)
        if s1 != s2:
            if "R" not in t:
                if 2*j-i < n:
                    ans += sum(r[j+1:]) - r[2*j-i]
                else:
                    ans += sum(r[j+1:])
            elif "G" not in t:
                if 2*j-i < n:
                    ans += sum(g[j+1:]) - g[2*j-i]
                else:
                    ans += sum(g[j+1:])
            else:
                if 2*j-i < n:
                    ans += sum(b[j+1:]) - b[2*j-i]
                else:
                    ans += sum(b[j+1:])

print(ans)


Fixed submission:
def main():
    n=int(input())
    s=input()
    ans = 1

    r_cnt = s.count("R")
    g_cnt = s.count("G")

    ans = r_cnt*g_cnt*(n-r_cnt-g_cnt)
 
    for i in range(n):
        for j in range(i,n):
            s1 = s[i]
            s2 = s[j]
            if s1 != s2:
                t = (s1,s2)
                for s3 in "RGB":
                    if s3 not in t:
                        if 2*j-i < n and s[2*j-i] == s3:
                            ans -= 1
                        continue

    print(ans)

if __name__ == "__main__":
    main()