Problem p02714 (python)

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

if N == 1 or N == 2:
    ans = 0
else:
    R = S.count('R')
    G = S.count('G')
    B = S.count('B')
    rgb = R * G * B

    count = 0
    for i in range(N - 2):
        for j in range(i + 1, N - 1):
            k = 2 * j - i
            if k >= N:
                break 
            if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                count += 1
    ans = rgb - count

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter

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

if N == 1 or N == 2:
    ans = 0
else:
    c = Counter(S)
    tmp = c.most_common()
    rgb = tmp[0][1] * tmp[1][1] * tmp[2][1]

    count = 0
    for i in range(N - 2):
        for j in range(i + 1, N - 1):
            k = 2 * j - i
            if k >= N:
                break 
            if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                count += 1
    ans = rgb - count

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter

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

if N == 1 or N == 2:
    ans = 0
else:
    c = Counter(S)
    tmp = c.most_common()
    rgb = tmp[0][1] * tmp[1][1] * tmp[2][1]

    count = 0
    for i in range(N - 2):
        for j in range(i + 1, N - 1):
            k = 2 * j - i
            if j + 1 <= k < N and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                count += 1
    ans = rgb - count

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter

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

if N == 1 or N == 2:
    ans = 0
else:
    c = Counter(S)
    tmp = c.most_common()
    rgb = tmp[0][1] * tmp[1][1] * tmp[2][1]

    count = 0
    for i in range(N - 2):
        for j in range(i + 1, N - 1):
            k = 2 * j - i
            if j + 1 <= k < N and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                count += 1
    ans = rgb - count

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter

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

c = Counter(S)
tmp = c.most_common()
rgb = tmp[0][1] * tmp[1][1] * tmp[2][1]

count = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        k = 2 * j - i
        if j + 1 <= k < N and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
            count += 1

print(rgb - count)

Buggy submission (verdict: Runtime Error):
from collections import Counter

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

c = Counter(S)
tmp = c.most_common()
rgb = tmp[0][1] * tmp[1][1] * tmp[2][1]

count = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        k = 2 * j - i
        if 0 <= k < N and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
            count += 1

print(rgb - count)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()

def f(N, S):
    d = {}
    for c in S:
        if c not in d:
            d[c] = 1
        else:
            d[c] += 1

    if d["R"] == 0 or d["G"] == 0 or d["B"] == 0:
        return 0

    total = d["R"] * d["G"] * d["B"]


    dame = 0
    for i in range(1, N - 1):
        for j in range(i + 1, N):
            k = 2 * j - i
            if j < k < N+1 and S[i-1] != S[j-1] and S[j-1] != S[k-1] and S[i-1] != S[k-1]:
                    dame += 1

    return (total - dame)

val = f(N, S)
print(val)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()

d = {}
for c in S:
    if c not in d:
        d[c] = 1
    else:
        d[c] += 1
total = d["R"] * d["G"] * d["B"]


dame = 0
for i in range(1, N - 1):
    for j in range(i + 1, N):
        k = 2 * j - i
        if j < k < N+1 and S[i-1] != S[j-1] and S[j-1] != S[k-1] and S[i-1] != S[k-1]:
                dame += 1



if d["R"] == 0 or d["G"] == 0 or d["B"] == 0:
    print(0)
else:
    print(total - dame)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()

d = {}
for c in S:
    if c not in d:
        d[c] = 1
    else:
        d[c] += 1
total = d["R"] * d["G"] * d["B"]
#print(total)

dame = 0
for i in range(1, N - 1):
    for j in range(i + 1, N):
        k = 2 * j - i
        if j < k < N+1 and S[i-1] != S[j-1] and S[j-1] != S[k-1] and S[i-1] != S[k-1]:
                dame += 1
#print(dame)

print(total - dame)