Buggy python submission (verdict: Time Limit Exceeded):
#D
n = int(input())
s = input()
s_l = list(s)
a = [0 for _ in range(n)]
for i in range(n):
    if s[i] =='R':
        a[i] = 0
    elif s[i] == 'G':
        a[i] = 1
    else:
        a[i] = 2
        

cnt = 0
for i in range(n-2):
    for j in range(i,n-1):
        if a[i] != a[j]:
            for k in range(j,n):
                if a[i] != a[k] and a[j] != a[k] and j-i != k-j:
                    cnt += 1

print(cnt)
     

Fixed submission:
#D
n = int(input())
s = input()
s_l = list(s)

a = s_l.count('R') * s_l.count('G') * s_l.count('B')
cnt = 0
#i,j,kがそれぞれ異なり、j-i = k-jであるものを求める
for i in range(n-2):
    for j in range(i,n-1):
        if 2*j - i < n:
            if s_l[i] != s_l[j] and s_l[i] != s_l[2*j-i] and s_l[j] != s_l[2*j-i]:
                cnt += 1
                
print(a - cnt)

Buggy python submission (verdict: Time Limit Exceeded):
#D
n = int(input())
s = input()
s_l = list(s)


cnt = 0
for i in range(n-2):
    for j in range(i,n-1):
        if s_l[i] != s_l[j]:
            for k in range(j,n):
                if s_l[i] != s_l[k] and s_l[j] != s_l[k] and j-i != k-j:
                    cnt += 1

print(cnt)
     

Fixed submission:
#D
n = int(input())
s = input()
s_l = list(s)

a = s_l.count('R') * s_l.count('G') * s_l.count('B')
cnt = 0
#i,j,kがそれぞれ異なり、j-i = k-jであるものを求める
for i in range(n-2):
    for j in range(i,n-1):
        if 2*j - i < n:
            if s_l[i] != s_l[j] and s_l[i] != s_l[2*j-i] and s_l[j] != s_l[2*j-i]:
                cnt += 1
                
print(a - cnt)

Buggy python submission (verdict: Time Limit Exceeded):
#D
n = int(input())
s = input()
s_l = tuple(s)


cnt = 0
for i in range(n-2):
    for j in range(i,n-1):
        if s_l[i] != s_l[j]:
            for k in range(j,n):
                if s_l[i] != s_l[k] and s_l[j] != s_l[k] and j-i != k-j:
                    cnt += 1

print(cnt)

Fixed submission:
#D
n = int(input())
s = input()
s_l = list(s)

a = s_l.count('R') * s_l.count('G') * s_l.count('B')
cnt = 0
#i,j,kがそれぞれ異なり、j-i = k-jであるものを求める
for i in range(n-2):
    for j in range(i,n-1):
        if 2*j - i < n:
            if s_l[i] != s_l[j] and s_l[i] != s_l[2*j-i] and s_l[j] != s_l[2*j-i]:
                cnt += 1
                
print(a - cnt)

Buggy python submission (verdict: Time Limit Exceeded):
#D
n = int(input())
s = input()
s_l = tuple(s)
cnt = 0
for i in range(n-2):
    for j in range(i,n-1):
        if s_l[i] != s_l[j]:
            for k in range(j,n):
                if s_l[i] != s_l[k] and s_l[j] != s_l[k] and j-i != k-j:
                    cnt += 1

print(cnt)
     

Fixed submission:
#D
n = int(input())
s = input()
s_l = list(s)

a = s_l.count('R') * s_l.count('G') * s_l.count('B')
cnt = 0
#i,j,kがそれぞれ異なり、j-i = k-jであるものを求める
for i in range(n-2):
    for j in range(i,n-1):
        if 2*j - i < n:
            if s_l[i] != s_l[j] and s_l[i] != s_l[2*j-i] and s_l[j] != s_l[2*j-i]:
                cnt += 1
                
print(a - cnt)

Buggy python submission (verdict: Time Limit Exceeded):
#D
n = int(input())
s = input()
s_l = list(s)
cnt = 0
for i in range(n-2):
    for j in range(i,n-1):
        if s[i] != s[j]:
            for k in range(j,n):
                if s[i] != s[k] and s[j] != s[k]:
                    if j-i != k-j:
                        cnt += 1

print(cnt)
     

Fixed submission:
#D
n = int(input())
s = input()
s_l = list(s)

a = s_l.count('R') * s_l.count('G') * s_l.count('B')
cnt = 0
#i,j,kがそれぞれ異なり、j-i = k-jであるものを求める
for i in range(n-2):
    for j in range(i,n-1):
        if 2*j - i < n:
            if s_l[i] != s_l[j] and s_l[i] != s_l[2*j-i] and s_l[j] != s_l[2*j-i]:
                cnt += 1
                
print(a - cnt)