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

num_r, num_g = S.count('R'), S.count('G')
num_b = N - num_r - num_g
max_ans = num_r * num_g * num_b
count_not_ans = 0
S = list(S)

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

print(max_ans - count_not_ans)


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

num_r, num_g = S.count('R'), S.count('G')
num_b = N - num_r - num_g
max_ans = num_r * num_g * num_b
count_not_ans = 0
S = list(S)

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

print(max_ans - count_not_ans)

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

num_r, num_g = S.count('R'), S.count('G')
num_b = N - num_r - num_g
max_ans = num_r * num_g * num_b
count_not_ans = 0

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

print(max_ans - count_not_ans)


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

num_r, num_g = S.count('R'), S.count('G')
num_b = N - num_r - num_g
max_ans = num_r * num_g * num_b
count_not_ans = 0
S = list(S)

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

print(max_ans - count_not_ans)

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

num_r, num_g = S.count('R'), S.count('G')
num_b = N - num_r - num_g
max_ans = num_r * num_g * num_b
count_not_ans = 0

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

print(max_ans - count_not_ans)


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

num_r, num_g = S.count('R'), S.count('G')
num_b = N - num_r - num_g
max_ans = num_r * num_g * num_b
count_not_ans = 0
S = list(S)

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

print(max_ans - count_not_ans)

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

num_r, num_g = S.count('R'), S.count('G')
num_b = N - num_r - num_g
max_ans = num_r * num_g * num_b
count_not_ans = 0
S = list(S)

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

print(max_ans - count_not_ans)


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

num_r, num_g = S.count('R'), S.count('G')
num_b = N - num_r - num_g
max_ans = num_r * num_g * num_b
count_not_ans = 0
S = list(S)

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

print(max_ans - count_not_ans)

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

num_r, num_g, num_b = S.count('R'), S.count('G'), S.count('B')
max_ans = num_r * num_g * num_b
count_not_ans = 0
S = list(S)

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

print(max_ans - count_not_ans)


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

num_r, num_g = S.count('R'), S.count('G')
num_b = N - num_r - num_g
max_ans = num_r * num_g * num_b
count_not_ans = 0
S = list(S)

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

print(max_ans - count_not_ans)