Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(map(str,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)
ans = 0
for i in range(N):
    for j in range(1,N//2+2):
        if i+2*j < N:
            if S[i] != S[i+j] and S[i] != S[i+2*j] and S[i+j] != S[i+2*j]:
                ans +=1

print(len(R)*len(G)*len(B)-ans)

Fixed submission:
N = int(input())
S = list(map(str,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
ans = 0
for i in range(N):
    for j in range(1,N//2+2):
        if i+2*j < N:
            if S[i] != S[i+j] and S[i] != S[i+2*j] and S[i+j] != S[i+2*j]:
                ans +=1

print(r*g*b-ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(map(str,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)
ans = 0
for i in range(N):
    for j in range(1,N):
        if i+2*j < N:
            if S[i] != S[i+j] and S[i] != S[i+2*j] and S[i+j] != S[i+2*j]:
                ans +=1

print(len(R)*len(G)*len(B)-ans)

Fixed submission:
N = int(input())
S = list(map(str,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
ans = 0
for i in range(N):
    for j in range(1,N//2+2):
        if i+2*j < N:
            if S[i] != S[i+j] and S[i] != S[i+2*j] and S[i+j] != S[i+2*j]:
                ans +=1

print(r*g*b-ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(map(str,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)
ans = 0
for i in range(len(R)):
    for j in range(len(G)):
        for k in range(len(B)):
            kumi = sorted([R[i],G[j],B[k]])
            if not kumi[1] - kumi[0] == kumi[2] - kumi[1]:
                ans += 1

print(ans)


Fixed submission:
N = int(input())
S = list(map(str,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
ans = 0
for i in range(N):
    for j in range(1,N//2+2):
        if i+2*j < N:
            if S[i] != S[i+j] and S[i] != S[i+2*j] and S[i+j] != S[i+2*j]:
                ans +=1

print(r*g*b-ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(map(str,input()))

ans = 0
for i in range(N):
    for j in range(i,N):
        if S[i]==S[j]:
            continue
        else:
            for k in range(j,N):
                if j-i==k-j:
                    continue
                else:
                    if  S[i]==S[k] or S[k]==S[j]:
                        continue
                    else:
                        ans += 1

print(ans)

Fixed submission:
N = int(input())
S = list(map(str,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
ans = 0
for i in range(N):
    for j in range(1,N//2+2):
        if i+2*j < N:
            if S[i] != S[i+j] and S[i] != S[i+2*j] and S[i+j] != S[i+2*j]:
                ans +=1

print(r*g*b-ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(map(str,input()))

ans = 0
for i in range(N):
    for j in range(i,N):
        for k in range(j,N):
            if j-i==k-j:
                continue
            else:
                if S[i]==S[j] or S[i]==S[k] or S[k]==S[j]:
                    continue
                else:
                    ans += 1

print(ans)

Fixed submission:
N = int(input())
S = list(map(str,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
ans = 0
for i in range(N):
    for j in range(1,N//2+2):
        if i+2*j < N:
            if S[i] != S[i+j] and S[i] != S[i+2*j] and S[i+j] != S[i+2*j]:
                ans +=1

print(r*g*b-ans)