Buggy python submission (verdict: Time Limit Exceeded):
# input
N = int(input())
S = input()

# process
R, G, B = [], [], []
for i, s in enumerate(list(S)):
    if s == 'R':
        R.append(i)
    elif s == 'G':
        G.append(i)
    else:
        B.append(i)

ans = len(R)*len(G)*len(B)
for r in R:
    for g in G:
        i, j = r, g
        if i > j:
            i, j = j, i
        
        s = j-i
        t1 = i-s
        t2 = -1
        if s%2 == 0:
            t2 = i+s//2
        t3 = j+s
        
        k = 0
        while k < len(B) and B[k] < t1:
            k += 1
        if k == len(B):
            continue
        if B[k] == t1:
            ans -= 1
        
        if t2 != -1:
            while k < len(B) and B[k] < t2:
                k += 1
            if k == len(B):
                continue
            if B[k] == t2:
                ans -= 1

        while k < len(B) and B[k] < t3:
            k += 1
        if k == len(B):
            continue
        if B[k] == t3:
            ans -= 1

# output
print(ans)


Fixed submission:
# input
N = int(input())
S = input()

# process
ans = S.count('R')*S.count('G')*S.count('B')
for i in range(N):
    for j in range(N):
        if i-j<0 or i+j >= N:
            break
        x = S[i-j]
        y = S[i]
        z = S[i+j]

        if x!= y and x != z and y != z:
            ans -= 1
            
# output
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# input
N = int(input())
S = input()

# process
R = []
G = []
B = []
for i, s in enumerate(list(S)):
    if s == 'R':
        R.append(i)
    elif s == 'G':
        G.append(i)
    else:
        B.append(i)

ans = len(R)*len(G)*len(B)
for r in R:
    for g in G:
        i, j = r, g
        if i > j:
            i, j = j, i
        
        s = j-i
        if s%2 == 0:
            if i+s//2 in B:
                ans -= 1
        if i-s in B:
            ans -= 1
        if j+s in B:
            ans -= 1
            
# output
print(ans)


Fixed submission:
# input
N = int(input())
S = input()

# process
ans = S.count('R')*S.count('G')*S.count('B')
for i in range(N):
    for j in range(N):
        if i-j<0 or i+j >= N:
            break
        x = S[i-j]
        y = S[i]
        z = S[i+j]

        if x!= y and x != z and y != z:
            ans -= 1
            
# output
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# input
N = int(input())
S = input()

# process
R = []
G = []
B = []
for i, s in enumerate(list(S)):
    if s == 'R':
        R.append(i)
    elif s == 'G':
        G.append(i)
    else:
        B.append(i)

ans = len(R)*len(G)*len(B)
for r in R:
    for g in G:
        i, j = r, g
        if i > j:
            i, j = j, i
        
        s = j-i
        t1 = -1
        if s%2 == 0:
            t1 = i+s//2
        t2 = i-s
        t3 = j+s
        
        for b in B:
            if b in (t1, t2, t3):
                ans -= 1

# output
print(ans)


Fixed submission:
# input
N = int(input())
S = input()

# process
ans = S.count('R')*S.count('G')*S.count('B')
for i in range(N):
    for j in range(N):
        if i-j<0 or i+j >= N:
            break
        x = S[i-j]
        y = S[i]
        z = S[i+j]

        if x!= y and x != z and y != z:
            ans -= 1
            
# output
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# input
N = int(input())
S = input()

# process
R = []
G = []
B = []
for i, s in enumerate(list(S)):
    if s == 'R':
        R.append(i)
    elif s == 'G':
        G.append(i)
    else:
        B.append(i)

ans = 0
for r in R:
    for g in G:
        for b in B:
            i, j, k = r, g, b
            if i > j:
                i, j = j, i
            if i > k:
                i, j, k = k, i, j
            elif j > k:
                j, k = k, j

            if k-j != j-i:
                ans += 1

# output
print(ans)


Fixed submission:
# input
N = int(input())
S = input()

# process
ans = S.count('R')*S.count('G')*S.count('B')
for i in range(N):
    for j in range(N):
        if i-j<0 or i+j >= N:
            break
        x = S[i-j]
        y = S[i]
        z = S[i+j]

        if x!= y and x != z and y != z:
            ans -= 1
            
# output
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# input
N = int(input())
S = input()

# process
R = []
G = []
B = []
for i, s in enumerate(list(S)):
    if s == 'R':
        R.append(i)
    elif s == 'G':
        G.append(i)
    else:
        B.append(i)

ans = 0
for r in R:
    for g in G:
        for b in B:
            if r < g:
                if g < b:
                    if b-g != g-r:
                        ans += 1
                else:
                    if r < b:
                        if g-b != b-r:
                            ans += 1
                    else:
                        if g-r != r-b:
                            ans += 1
            else:
                if r < b:
                    if b-r != r-g:
                        ans += 1
                else:
                    if g < b:
                        if r-b != b-g:
                            ans += 1
                    else:
                        if r-g != g-b:
                            ans += 1

# output
print(ans)


Fixed submission:
# input
N = int(input())
S = input()

# process
ans = S.count('R')*S.count('G')*S.count('B')
for i in range(N):
    for j in range(N):
        if i-j<0 or i+j >= N:
            break
        x = S[i-j]
        y = S[i]
        z = S[i+j]

        if x!= y and x != z and y != z:
            ans -= 1
            
# output
print(ans)