Buggy python submission (verdict: Time Limit Exceeded):

N = int(input())
S = input()

ans = 0
r = range(N)
kumis = []

for i in r:
    for j in r:
        if j < i: continue
        dji = 2*j -i
        for k in r:
            if k < j: continue
            if dji == k: continue
            kumis.append(tuple([i, j, k]))

for kumi in kumis:
    i, j, k = kumi
    if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
        ans += 1

# for i in r:
#     for j in r:
#         if j < i: continue
#         for k in r:
#             if k < j: continue
#             if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
#                 kumis.append(tuple([i,j,k]))

# for kumi in kumis:
#     i,j,k = kumi
#     if j-i != k-j:
#         ans+=1

print(ans)

Fixed submission:

N = int(input())
S = input()

r = S.count("R")
g = S.count("G")
b = S.count("B")

all_case = r*g*b

excluded_case = 0
for i in range(N):
    for j in range(i+1, N):
        if S[i] == S[j]: continue
        k = j*2-i
        if k>= N or S[k] == S[i] or S[k] == S[j]: continue
        excluded_case += 1

print(all_case-excluded_case)

Buggy python submission (verdict: Time Limit Exceeded):

N = int(input())
S = input()

ans = 0
r = range(N)
kumis = []
for i in r:
    for j in r:
        if j < i: continue
        for k in r:
            if k < j: continue
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                kumis.append(tuple([i,j,k]))

for kumi in kumis:
    i,j,k = kumi
    if j-i != k-j:
        ans+=1

print(ans)

Fixed submission:

N = int(input())
S = input()

r = S.count("R")
g = S.count("G")
b = S.count("B")

all_case = r*g*b

excluded_case = 0
for i in range(N):
    for j in range(i+1, N):
        if S[i] == S[j]: continue
        k = j*2-i
        if k>= N or S[k] == S[i] or S[k] == S[j]: continue
        excluded_case += 1

print(all_case-excluded_case)

Buggy python submission (verdict: Time Limit Exceeded):

N = int(input())
S = input()

ans = 0
r = range(N)
for i in r:
    for j in r:
        if j < i: continue
        if S[i] == S[j]: continue
        dji = j - i
        for k in r:
            if k < i: continue
            if k < j: continue
            if S[i] == S[k]: continue
            if S[j] == S[k]: continue
            dkj = k - j
            if dji == dkj: continue
            ans += 1


print(ans)

Fixed submission:

N = int(input())
S = input()

r = S.count("R")
g = S.count("G")
b = S.count("B")

all_case = r*g*b

excluded_case = 0
for i in range(N):
    for j in range(i+1, N):
        if S[i] == S[j]: continue
        k = j*2-i
        if k>= N or S[k] == S[i] or S[k] == S[j]: continue
        excluded_case += 1

print(all_case-excluded_case)

Buggy python submission (verdict: Time Limit Exceeded):

N = int(input())
S = input()

ans = 0
r = range(N)
for i in r:
    for j in r:
        if j == i: break
        if S[i] == S[j]: continue
        dji = j - i
        for k in r:
            if k == i: break
            if k == j: break
            if S[i] == S[k]: continue
            if S[j] == S[k]: continue
            dkj = k - j
            if dji == dkj: continue
            ans += 1


print(ans)

Fixed submission:

N = int(input())
S = input()

r = S.count("R")
g = S.count("G")
b = S.count("B")

all_case = r*g*b

excluded_case = 0
for i in range(N):
    for j in range(i+1, N):
        if S[i] == S[j]: continue
        k = j*2-i
        if k>= N or S[k] == S[i] or S[k] == S[j]: continue
        excluded_case += 1

print(all_case-excluded_case)

Buggy python submission (verdict: Time Limit Exceeded):

N = int(input())
S = input()

ans = 0

from itertools import combinations

l = list(range(1, N+1))
c = combinations(l, 3)

def cond2(a,b,c):
    a -= 1
    b -= 1
    c -= 1
    if b-a == c-b:
        return False
    return True

ll = []
for v in c:
    if cond2(v[0], v[1], v[2]):
        ll.append(v)

ans = 0
for t in ll:
    x, y, z = t[0], t[1], t[2]
    x -= 1
    y -= 1
    z -= 1
    if S[x] == S[y] or S[x] == S[z] or S[y] == S[z]:
        continue
    ans += 1

print(ans)

Fixed submission:

N = int(input())
S = input()

r = S.count("R")
g = S.count("G")
b = S.count("B")

all_case = r*g*b

excluded_case = 0
for i in range(N):
    for j in range(i+1, N):
        if S[i] == S[j]: continue
        k = j*2-i
        if k>= N or S[k] == S[i] or S[k] == S[j]: continue
        excluded_case += 1

print(all_case-excluded_case)