Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [s for s in input()]
ans = S.count("R") * S.count("G") * S.count("B")

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

print(ans)


Fixed submission:
N = int(input())
S = [s for s in input()]
ans = S.count("R") * S.count("G") * S.count("B")

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

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [s for s in input()]
exc = 0
ans = S.count("R") * S.count("G") * S.count("B")

for i in range(N - 2):
    for j in range(i + 1, N - 1):
        k = j + (j - i)
        if N - 1 < k:
            continue
        A = S[i]
        B = S[j]
        C = S[k]
        if A == B or B == C or A == C:
            continue
        else:
            ans -= 1

print(ans)


Fixed submission:
N = int(input())
S = [s for s in input()]
ans = S.count("R") * S.count("G") * S.count("B")

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

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
exc = 0
ans = S.count("R") * S.count("G") * S.count("B")

for i in range(N - 2):
    for j in range(i + 1, N - 1):
        if N - 1 < j + (j - i):
            continue
        elif S[i] == S[j] or S[j + (j - i)] == S[i] or S[j + (j - i)] == S[j]:
            continue
        else:
            ans -= 1

print(ans)


Fixed submission:
N = int(input())
S = [s for s in input()]
ans = S.count("R") * S.count("G") * S.count("B")

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

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
exc = 0
ans = S.count("R") * S.count("G") * S.count("B")

for i in range(N - 2):
    for j in range(i + 1, N - 1):
        k = j + (j - i)
        if N - 1 < k:
            continue
        elif S[i] == S[j] or S[k] == S[i] or S[k] == S[j]:
            continue
        else:
            ans -= 1

print(ans)


Fixed submission:
N = int(input())
S = [s for s in input()]
ans = S.count("R") * S.count("G") * S.count("B")

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

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
exc = 0
ans = S.count("R") * S.count("G") * S.count("B")

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

print(ans)


Fixed submission:
N = int(input())
S = [s for s in input()]
ans = S.count("R") * S.count("G") * S.count("B")

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

print(ans)

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

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

ans = S.count("R") * S.count("G") * S.count("B") - exc
print(ans)


Fixed submission:
N = int(input())
S = [s for s in input()]
ans = S.count("R") * S.count("G") * S.count("B")

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

print(ans)

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

for i in range(N - 2):
    for j in range(1, N - 1):
        k = j + (j - i)
        if i > j or k < 2 or N - 1 < k:
            continue
        if S[k] != S[i] and S[k] != S[j] and S[i] != S[j]:
            exc += 1

ans = S.count("R") * S.count("G") * S.count("B") - exc
print(ans)


Fixed submission:
N = int(input())
S = [s for s in input()]
ans = S.count("R") * S.count("G") * S.count("B")

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

print(ans)

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

for i in range(N - 2):
    for j in range(1, N - 1):
        d = j - i
        if d <= 0 or d + j > N - 1 or S[i] == S[j]:
            continue
        k = d + j
        if S[k] != S[i] and S[k] != S[j]:
            exc += 1

ans = S.count("R") * S.count("G") * S.count("B") - exc
print(ans)


Fixed submission:
N = int(input())
S = [s for s in input()]
ans = S.count("R") * S.count("G") * S.count("B")

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

print(ans)

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

for i in range(N):
    for j in range(N):
        d = j - i
        if d <= 0 or d + j > N - 1 or S[i] == S[j]:
            continue
        k = d + j
        if S[k] != S[i] and S[k] != S[j]:
            exc += 1

ans = S.count("R") * S.count("G") * S.count("B") - exc
print(ans)

Fixed submission:
N = int(input())
S = [s for s in input()]
ans = S.count("R") * S.count("G") * S.count("B")

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

print(ans)