Buggy python submission (verdict: Runtime Error):
count = 0
N = int(input())
S = list(input())
# for i in range(N):
#     for j in range(i+1, N):
#         for k in range(j+1, N):
#             if(S[i] != S[j] and S[i] != S[k] and S[j] != S[k] and (j - i) != (k - j)):
#                 count+=1
# print(count)

countSecond = 1
countThird = 1
for i in range(N):
    while(S[i] == S[i+countSecond]):
        if(countSecond < N):
            countSecond+=1
        else:
            break
            
    while(S[i+countSecond] == S[i + countThird]):
        if(countThird < N):
            countThird += 1
        else:
            break
    if((countSecond - i) != (countThird - i)):
        count+=1
print(count)

Fixed submission:
# 先に組み合わせの数を決める
# RとGとBの数を先に数え上げると、Rの数 * Gの数 * Bの数が組み合わせの数になる
# 累積和でもできる

#組み合わせの数は
kumiawase = 0
countR=0
countG=0
countB=0
N = int(input())
S = list(input())
for i in range(N):
    if(S[i] == "R"):
        countR += 1
    elif(S[i] == "G"):
        countG += 1
    elif(S[i] == "B"):
        countB += 1
kumiawase = countR * countG * countB

count = 0
#その組み合わせの数から、j-i = k-jをみたす数を引けばいい
#条件を満たし、かつ1つ目の条件を満たすものは
for i in range(N):
    for j in range(i+1, N):
        k = 2 * j - i
        if(k < N):
            if(S[i] != S[j] and S[i] != S[k] and S[j] != S[k]):
                count+=1

print(kumiawase - count)

Buggy python submission (verdict: Time Limit Exceeded):
count = 0
N = int(input())
S = list(input())
for i in range(N):
    for j in range(i+1, N):
        for k in range(j+1, N):
            if(S[i] != S[j] and S[i] != S[k] and S[j] != S[k] and (j - i) != (k - j)):
                count+=1
print(count)

Fixed submission:
# 先に組み合わせの数を決める
# RとGとBの数を先に数え上げると、Rの数 * Gの数 * Bの数が組み合わせの数になる
# 累積和でもできる

#組み合わせの数は
kumiawase = 0
countR=0
countG=0
countB=0
N = int(input())
S = list(input())
for i in range(N):
    if(S[i] == "R"):
        countR += 1
    elif(S[i] == "G"):
        countG += 1
    elif(S[i] == "B"):
        countB += 1
kumiawase = countR * countG * countB

count = 0
#その組み合わせの数から、j-i = k-jをみたす数を引けばいい
#条件を満たし、かつ1つ目の条件を満たすものは
for i in range(N):
    for j in range(i+1, N):
        k = 2 * j - i
        if(k < N):
            if(S[i] != S[j] and S[i] != S[k] and S[j] != S[k]):
                count+=1

print(kumiawase - count)

Buggy python submission (verdict: Time Limit Exceeded):
#4問目
count = 0
N = int(input())
S = list(input())
for i in range(N):
    for j in range(i+1, N):
        for k in range(j+1, N):
            if(S[i] != S[j] and S[i] != S[k] and S[j] != S[k]):
                if((j - i) != (k - j)):
                    count+=1
print(count)

Fixed submission:
# 先に組み合わせの数を決める
# RとGとBの数を先に数え上げると、Rの数 * Gの数 * Bの数が組み合わせの数になる
# 累積和でもできる

#組み合わせの数は
kumiawase = 0
countR=0
countG=0
countB=0
N = int(input())
S = list(input())
for i in range(N):
    if(S[i] == "R"):
        countR += 1
    elif(S[i] == "G"):
        countG += 1
    elif(S[i] == "B"):
        countB += 1
kumiawase = countR * countG * countB

count = 0
#その組み合わせの数から、j-i = k-jをみたす数を引けばいい
#条件を満たし、かつ1つ目の条件を満たすものは
for i in range(N):
    for j in range(i+1, N):
        k = 2 * j - i
        if(k < N):
            if(S[i] != S[j] and S[i] != S[k] and S[j] != S[k]):
                count+=1

print(kumiawase - count)

Buggy python submission (verdict: Time Limit Exceeded):
#4問目
count = 0
N = int(input())
S = list(input())
for i in range(N):
    for j in range(N):
        for k in range(N):
            if(i <= j and j <= k):
                if(S[i] != S[j] and S[i] != S[k] and S[j] != S[k]):
                    if((j - i) != (k - j)):
                        count+=1
print(count)

Fixed submission:
# 先に組み合わせの数を決める
# RとGとBの数を先に数え上げると、Rの数 * Gの数 * Bの数が組み合わせの数になる
# 累積和でもできる

#組み合わせの数は
kumiawase = 0
countR=0
countG=0
countB=0
N = int(input())
S = list(input())
for i in range(N):
    if(S[i] == "R"):
        countR += 1
    elif(S[i] == "G"):
        countG += 1
    elif(S[i] == "B"):
        countB += 1
kumiawase = countR * countG * countB

count = 0
#その組み合わせの数から、j-i = k-jをみたす数を引けばいい
#条件を満たし、かつ1つ目の条件を満たすものは
for i in range(N):
    for j in range(i+1, N):
        k = 2 * j - i
        if(k < N):
            if(S[i] != S[j] and S[i] != S[k] and S[j] != S[k]):
                count+=1

print(kumiawase - count)