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

i_range = [int(x) for x in range(1, N-1)]
j_range = [int(x) for x in range(2, N)]
k_range = [int(x) for x in range(3, N+1)]

val = 0

for k in k_range:
    S_k = S[k-1]
    for j in j_range:
        if(j >= k):
            break
        S_j = S[j-1]
        for i in i_range:
            if(i >= j):
                break
            S_i = S[i-1]
            if((S_i != S_j) and (S_j != S_k) and (S_i != S_k) and (j-i != k-j)):
                val = val + 1

print(val)

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


"""
脳死で全探索で探すとO(n^3）で時間がかかる。
→1つめの条件で予め絞った後に、そこからさらに絞り込むやり方をやる。（補集合を引くパターン）
j-i=k-jを満たすもの（すなわちk=2j-i）を求めて、あとで引き算すればOK.
≠は＝で考えて引き算のほうがよい。
"""

r_count = S.count('R')
g_count = S.count('G')
b_count = S.count('B')


val = 0

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

print((r_count * g_count * b_count) - val)

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

i_range = [int(x) for x in range(1, N-1)]
j_range = [int(x) for x in range(2, N)]
k_range = [int(x) for x in range(3, N+1)]

val = 0

for k in k_range:
    S_k = S[k-1]
    for j in j_range:
        if(j >= k):
            break
        S_j = S[j-1]
        for i in i_range:
            if(i >= j):
                break
            S_i = S[i-1]
            if((S_i != S_j) and (S_j != S_k) and (S_i != S_k) and (j-i != k-j)):
                val = val + 1

print(val)

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


"""
脳死で全探索で探すとO(n^3）で時間がかかる。
→1つめの条件で予め絞った後に、そこからさらに絞り込むやり方をやる。（補集合を引くパターン）
j-i=k-jを満たすもの（すなわちk=2j-i）を求めて、あとで引き算すればOK.
≠は＝で考えて引き算のほうがよい。
"""

r_count = S.count('R')
g_count = S.count('G')
b_count = S.count('B')


val = 0

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

print((r_count * g_count * b_count) - val)

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

i_range = [int(x) for x in range(1, N-1)]
j_range = [int(x) for x in range(2, N)]
k_range = [int(x) for x in range(3, N+1)]

val = 0

for k in k_range:
    for j in j_range:
        if(j >= k):
            break
        for i in i_range:
            if(i >= j):
                break
            if((S[i-1] != S[j-1]) and (S[j-1] != S[k-1]) and (S[i-1] != S[k-1]) and (j-i != k-j)):
                val = val + 1


print(val)

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


"""
脳死で全探索で探すとO(n^3）で時間がかかる。
→1つめの条件で予め絞った後に、そこからさらに絞り込むやり方をやる。（補集合を引くパターン）
j-i=k-jを満たすもの（すなわちk=2j-i）を求めて、あとで引き算すればOK.
≠は＝で考えて引き算のほうがよい。
"""

r_count = S.count('R')
g_count = S.count('G')
b_count = S.count('B')


val = 0

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

print((r_count * g_count * b_count) - val)

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

i_range = [int(x) for x in range(1, N-1)]
j_range = [int(x) for x in range(2, N)]
k_range = [int(x) for x in range(3, N+1)]

val = 0

for k in k_range:
    for j in j_range:
        if(j >= k):
            break
        for i in i_range:
            if(i >= j):
                break
            if((S[i-1] != S[j-1]) and (S[j-1] != S[k-1]) and (S[i-1] != S[k-1])):
                if(j-i != k-j):
                    val = val + 1

print(val)

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


"""
脳死で全探索で探すとO(n^3）で時間がかかる。
→1つめの条件で予め絞った後に、そこからさらに絞り込むやり方をやる。（補集合を引くパターン）
j-i=k-jを満たすもの（すなわちk=2j-i）を求めて、あとで引き算すればOK.
≠は＝で考えて引き算のほうがよい。
"""

r_count = S.count('R')
g_count = S.count('G')
b_count = S.count('B')


val = 0

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

print((r_count * g_count * b_count) - val)

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

i_range = [int(x) for x in range(1, N-1)]
j_range = [int(x) for x in range(2, N)]
k_range = [int(x) for x in range(3, N+1)]

val = 0


"""
for k in k_range:
    for j in j_range:
        for i in i_range:
            judge = ""
            if( (j-i == k-j) or (i >= j) or (j >= k)):
                print("(i, j, k) = ({}, {}, {}) break".format(i, j, k))
                break
            if((S[i-1] != S[j-1]) and (S[j-1] != S[k-1]) and (S[i-1] != S[k-1])):
                val = val + 1
                judge = "〇"
            else:
                judge = "×"
            print("(i, j, k) = ({}, {}, {}) -> ({}, {}, {}) {}".format(i, j, k, S[i-1], S[j-1], S[k-1], judge))
"""


for k in k_range:
    for j in j_range:
        if(j >= k):
            break
        for i in i_range:
            if(i >= j):
                break
            if((S[i-1] != S[j-1]) and (S[j-1] != S[k-1]) and (S[i-1] != S[k-1])):
                if(j-i != k-j):
                    judge = "〇"
                    val = val + 1
                else:
                    judge = "×"
            #print("(i, j, k) = ({}, {}, {}) -> ({}, {}, {}) {}".format(i, j, k, S[i-1], S[j-1], S[k-1], judge))

print(val)

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


"""
脳死で全探索で探すとO(n^3）で時間がかかる。
→1つめの条件で予め絞った後に、そこからさらに絞り込むやり方をやる。（補集合を引くパターン）
j-i=k-jを満たすもの（すなわちk=2j-i）を求めて、あとで引き算すればOK.
≠は＝で考えて引き算のほうがよい。
"""

r_count = S.count('R')
g_count = S.count('G')
b_count = S.count('B')


val = 0

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

print((r_count * g_count * b_count) - val)