Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
R_sum = [0]*N
G_sum = [0]*N
B_sum = [0]*N
rcnt = 0
gcnt = 0
bcnt = 0
cnt = 0
for c in S:
    if c == 'R':
        rcnt += 1
    elif c == 'G':
        gcnt += 1
    elif c == 'B':
        bcnt += 1
    R_sum[cnt] = rcnt
    G_sum[cnt] = gcnt
    B_sum[cnt] = bcnt
    cnt += 1

anssum = 0
for i in range(N):
    for j in range(i + 1, N):
        if S[i] == S[j]: continue
        clist = [S[i], S[j]]
        diff_idx = j - i

        if not ('R' in clist):
            anssum += (R_sum[N-1] - R_sum[j-1])
            if diff_idx + j < N:
                if S[diff_idx + j] == 'R':
                    anssum -= 1
        elif not ('G' in clist):
            anssum += (G_sum[N-1] - G_sum[j-1])
            if diff_idx + j < N:
                if S[diff_idx + j] == 'G':
                    anssum -= 1
        elif not ('B' in clist):
            anssum += (B_sum[N-1] - B_sum[j-1])
            if diff_idx + j < N:
                if S[diff_idx + j] == 'B':
                    anssum -= 1
print(anssum)


Fixed submission:
N = int(input())
S = input()
R_sum = [0]*N
G_sum = [0]*N
B_sum = [0]*N
rcnt = 0
gcnt = 0
bcnt = 0
cnt = 0
for c in S:
    if c == 'R':
        rcnt += 1
    elif c == 'G':
        gcnt += 1
    elif c == 'B':
        bcnt += 1
    R_sum[cnt] = rcnt
    G_sum[cnt] = gcnt
    B_sum[cnt] = bcnt
    cnt += 1

anssum = 0
for i in range(N):
    for j in range(i + 1, N):
        if S[i] == S[j]: continue
        clist = [S[i], S[j]]
        diff_idx = j - i

        if not ('R' in clist):
            anssum += (R_sum[N-1] - R_sum[j-1])
            if diff_idx + j < N:
                if S[diff_idx + j] == 'R':
                    anssum -= 1
        elif not ('G' in clist):
            anssum += (G_sum[N-1] - G_sum[j-1])
            if diff_idx + j < N:
                if S[diff_idx + j] == 'G':
                    anssum -= 1
        elif not ('B' in clist):
            anssum += (B_sum[N-1] - B_sum[j-1])
            if diff_idx + j < N:
                if S[diff_idx + j] == 'B':
                    anssum -= 1
print(anssum)

Buggy python submission (verdict: Runtime Error):
import numpy as np
N = int(input())
S = input()
R_sum = np.zeros(N, dtype=np.int16)
G_sum = np.zeros(N, dtype=np.int16)
B_sum = np.zeros(N, dtype=np.int16)
rcnt = 0
gcnt = 0
bcnt = 0
cnt = 0
for c in S:
    if c == 'R':
        rcnt += 1
    elif c == 'G':
        gcnt += 1
    elif c == 'B':
        bcnt += 1
    R_sum[cnt] = rcnt
    G_sum[cnt] = gcnt
    B_sum[cnt] = bcnt
    cnt += 1

anssum = 0
for i in range(N):
    for j in range(i + 1, N):
        if S[i] == S[j]: continue
        clist = [S[i], S[j]]
        diff_idx = j - i

        if not ('R' in clist):
            anssum += (R_sum[N-1] - R_sum[j-1])
            if diff_idx + j < N:
                if S[diff_idx + j] == 'R':
                    anssum -= 1
        elif not ('G' in clist):
            anssum += (G_sum[N-1] - G_sum[j-1])
            if diff_idx + j < N:
                if S[diff_idx + j] == 'G':
                    anssum -= 1
        elif not ('B' in clist):
            anssum += (B_sum[N-1] - B_sum[j-1])
            if diff_idx + j < N:
                if S[diff_idx + j] == 'B':
                    anssum -= 1
print(anssum)


Fixed submission:
N = int(input())
S = input()
R_sum = [0]*N
G_sum = [0]*N
B_sum = [0]*N
rcnt = 0
gcnt = 0
bcnt = 0
cnt = 0
for c in S:
    if c == 'R':
        rcnt += 1
    elif c == 'G':
        gcnt += 1
    elif c == 'B':
        bcnt += 1
    R_sum[cnt] = rcnt
    G_sum[cnt] = gcnt
    B_sum[cnt] = bcnt
    cnt += 1

anssum = 0
for i in range(N):
    for j in range(i + 1, N):
        if S[i] == S[j]: continue
        clist = [S[i], S[j]]
        diff_idx = j - i

        if not ('R' in clist):
            anssum += (R_sum[N-1] - R_sum[j-1])
            if diff_idx + j < N:
                if S[diff_idx + j] == 'R':
                    anssum -= 1
        elif not ('G' in clist):
            anssum += (G_sum[N-1] - G_sum[j-1])
            if diff_idx + j < N:
                if S[diff_idx + j] == 'G':
                    anssum -= 1
        elif not ('B' in clist):
            anssum += (B_sum[N-1] - B_sum[j-1])
            if diff_idx + j < N:
                if S[diff_idx + j] == 'B':
                    anssum -= 1
print(anssum)