Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
string = input()
r = 0
g = 0
b = 0
for c in string:
    if c == 'R':
        r += 1
    elif c == 'G':
        g += 1
    else:
        b += 1
ans = r*g*b
for i in range(n):
    for j in range(i+1, n):
        if 2*j - i >= n:
            break
        
        if string[i] == string[j]: 
            continue
        rgb = set(['R', 'G', 'B'])
        rgb.remove(string[i])
        rgb.remove(string[j])
        k = rgb.pop()
        if 2*j-i < n and string[2*j-i] == k:
            ans -= 1
print(ans)
        
        


Fixed submission:
n = int(input())
string = input()
r = 0
g = 0
b = 0
for c in string:
    if c == 'R':
        r += 1
    elif c == 'G':
        g += 1
    else:
        b += 1
ans = r*g*b
for i in range(n):
    for j in range(i+1, n):
        if 2*j - i >= n:
            break
        
        if string[i] != string[j] and string[i] != string[2*j-i] and string[j] != string[2*j-i]:
            ans -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
string = input()
r = 0
g = 0
b = 0
for c in string:
    if c == 'R':
        r += 1
    elif c == 'G':
        g += 1
    else:
        b += 1
ans = r*g*b
for i in range(n):
    for j in range(i+1, n):
        if string[i] == string[j]: 
            continue
        rgb = set(['R', 'G', 'B'])
        rgb.remove(string[i])
        rgb.remove(string[j])
        k = rgb.pop()
        if 2*j-i < n and string[2*j-i] == k:
            ans -= 1
print(ans)
        
        


Fixed submission:
n = int(input())
string = input()
r = 0
g = 0
b = 0
for c in string:
    if c == 'R':
        r += 1
    elif c == 'G':
        g += 1
    else:
        b += 1
ans = r*g*b
for i in range(n):
    for j in range(i+1, n):
        if 2*j - i >= n:
            break
        
        if string[i] != string[j] and string[i] != string[2*j-i] and string[j] != string[2*j-i]:
            ans -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
string = input()
rs = [0]
gs = [0]
bs = [0]
for idx, c in enumerate(string):
    add = [0]*3
    if c == 'R':
        add[0] += 1
    elif c == 'G':
        add[1] += 1
    else:
        add[2] += 1
    for l, s in zip((rs, gs, bs), add):
        l.append(l[idx]+s)

d = {'R':rs, 'G': gs, 'B': bs}
ans = 0
for i in range(n):
    for j in range(i+1, n):
        if string[i] == string[j]: 
            continue
        rgb = set(['R', 'G', 'B'])
        rgb.remove(string[i])
        rgb.remove(string[j])
        k = rgb.pop()
        cumsum = d[k]
        ans += cumsum[-1] - cumsum[j+1]
        if 2*j-i < n and string[2*j-i] == k:
            ans -= 1

print(ans)
        
        


Fixed submission:
n = int(input())
string = input()
r = 0
g = 0
b = 0
for c in string:
    if c == 'R':
        r += 1
    elif c == 'G':
        g += 1
    else:
        b += 1
ans = r*g*b
for i in range(n):
    for j in range(i+1, n):
        if 2*j - i >= n:
            break
        
        if string[i] != string[j] and string[i] != string[2*j-i] and string[j] != string[2*j-i]:
            ans -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
string = input()

r=g=b=0

for idx, s in enumerate(string):
    if s == 'R':
        r+=1
    elif s == 'B':
        b+=1
    elif s == 'G':
        g+=1

ans = r*g*b

for i in range(n):
    for j in range(i+1, n):
        k = 2*j - i
        if k < n and len(set([string[i],string[j], string[k]])) == 3:
            ans -= 1

print(ans)
            



Fixed submission:
n = int(input())
string = input()
r = 0
g = 0
b = 0
for c in string:
    if c == 'R':
        r += 1
    elif c == 'G':
        g += 1
    else:
        b += 1
ans = r*g*b
for i in range(n):
    for j in range(i+1, n):
        if 2*j - i >= n:
            break
        
        if string[i] != string[j] and string[i] != string[2*j-i] and string[j] != string[2*j-i]:
            ans -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
string = input()

# r=g=b=0

# for idx, s in enumerate(string):
#     if s == 'R':
#         r+=1
#     elif s == 'B':
#         b+=1
#     elif s == 'G':
#         g+=1

ans = string.count('R')*string.count('G')*string.count('B')

for i in range(n):
    for k in range(i+1, n):
        if string[i] != string[k]:
            if (k+i)%2 == 0 and len(set([string[i], string[k], string[(k+i)//2]])) ==3:
                ans -= 1

print(ans)
            



Fixed submission:
n = int(input())
string = input()
r = 0
g = 0
b = 0
for c in string:
    if c == 'R':
        r += 1
    elif c == 'G':
        g += 1
    else:
        b += 1
ans = r*g*b
for i in range(n):
    for j in range(i+1, n):
        if 2*j - i >= n:
            break
        
        if string[i] != string[j] and string[i] != string[2*j-i] and string[j] != string[2*j-i]:
            ans -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
string = input()

r=g=b=0

for idx, s in enumerate(string):
    if s == 'R':
        r+=1
    elif s == 'B':
        b+=1
    elif s == 'G':
        g+=1

ans = r*g*b

for i in range(n):
    for k in range(i+1, n):
        if string[i] != string[k]:
            if (k+i)%2 == 0 and len(set([string[i], string[k], string[(k+i)//2]])) ==3:
                ans -= 1

print(ans)
            



Fixed submission:
n = int(input())
string = input()
r = 0
g = 0
b = 0
for c in string:
    if c == 'R':
        r += 1
    elif c == 'G':
        g += 1
    else:
        b += 1
ans = r*g*b
for i in range(n):
    for j in range(i+1, n):
        if 2*j - i >= n:
            break
        
        if string[i] != string[j] and string[i] != string[2*j-i] and string[j] != string[2*j-i]:
            ans -= 1
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
string = input()

r=g=b=0

for idx, s in enumerate(string):
    if s == 'R':
        r+=1
    elif s == 'B':
        b+=1
    elif s == 'G':
        g+=1

ans = r*g*b

for i in range(n):
    for k in range(i+1, n):
        if string[i] != string[k]:
            if (k+i)%2 == 0 and len(set(string[i], string[k], string[(k+i)//2])) ==3:
                ans -= 1

print(ans)
            



Fixed submission:
n = int(input())
string = input()
r = 0
g = 0
b = 0
for c in string:
    if c == 'R':
        r += 1
    elif c == 'G':
        g += 1
    else:
        b += 1
ans = r*g*b
for i in range(n):
    for j in range(i+1, n):
        if 2*j - i >= n:
            break
        
        if string[i] != string[j] and string[i] != string[2*j-i] and string[j] != string[2*j-i]:
            ans -= 1
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
string = input()

r=g=b=0

for idx, s in enumerate(string):
    if s == 'R':
        r+=1
    elif s == 'B':
        b+=1
    elif s == 'G':
        g+=1

ans = r*g*b

for i in range(n):
    for k in range(i+1, n):
        if string[i] != string[k]:
            if (k+i)%2 == 0 and len(set(string[i], string[k], string[(k+i)//2]) ==3:
                ans -= 1

print(ans)

Fixed submission:
n = int(input())
string = input()
r = 0
g = 0
b = 0
for c in string:
    if c == 'R':
        r += 1
    elif c == 'G':
        g += 1
    else:
        b += 1
ans = r*g*b
for i in range(n):
    for j in range(i+1, n):
        if 2*j - i >= n:
            break
        
        if string[i] != string[j] and string[i] != string[2*j-i] and string[j] != string[2*j-i]:
            ans -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
string = input()

r=g=b=0

for idx, s in enumerate(string):
    if s == 'R':
        r+=1
    elif s == 'B':
        b+=1
    elif s == 'G':
        g+=1

ans = r*g*b

for i in range(n):
    for k in range(i+1, n):
        rgb = set(['R','G','B'])
        if string[i] != string[k]:
            rgb.remove(string[i])
            rgb.remove(string[k])
            if (k+i)%2 == 0 and string[(k+i)//2] in rgb:
                ans -= 1

print(ans)

Fixed submission:
n = int(input())
string = input()
r = 0
g = 0
b = 0
for c in string:
    if c == 'R':
        r += 1
    elif c == 'G':
        g += 1
    else:
        b += 1
ans = r*g*b
for i in range(n):
    for j in range(i+1, n):
        if 2*j - i >= n:
            break
        
        if string[i] != string[j] and string[i] != string[2*j-i] and string[j] != string[2*j-i]:
            ans -= 1
print(ans)