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

r_ary = []
g_ary = []
b_ary = []

for i in (s):
    if i == 'R':
        r_ary.append(i)
    elif i == 'G':
        g_ary.append(i)
    elif i == 'B':
        b_ary.append(i)

r = len(r_ary)
g = len(g_ary)
b = len(b_ary)
'''
r = s.count('R')
g = s.count('G')
b = s.count('B')
'''
# 1つ目の条件を満たす
first_conditions = r*g*b
# 1つ目の条件は満たすが、2つ目の条件は満たさない
# 2つ目の条件を満たすということは、(i,j,k)のときk=2j-i
for i in range(n-2):
    for j in range(i+1,n-1):
        if 2*j-i<n and s[i]!=s[2*j-i] and s[j]!=s[2*j-i] and s[i]!=s[j]:
            first_conditions -= 1
print(first_conditions)

Fixed submission:
n = int(input())
s = input()
r_ary = []
g_ary = []
b_ary = []
for i in (s):
    if i == 'R':
        r_ary.append(i)
    elif i == 'G':
        g_ary.append(i)
    elif i == 'B':
        b_ary.append(i)
r = len(r_ary)
g = len(g_ary)
b = len(b_ary)
first_conditions = r*g*b
for i in range(n-2):
    for j in range(i+1,n-1):
        if 2*j-i<n and s[i]!=s[2*j-i] and s[j]!=s[2*j-i] and s[i]!=s[j]:
            first_conditions -= 1
print(first_conditions)

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

r_ary = []
g_ary = []
b_ary = []

for i in (s):
    if i == 'R':
        r_ary.append(i)
    elif i == 'G':
        g_ary.append(i)
    elif i == 'B':
        b_ary.append(i)

r = len(r_ary)
g = len(g_ary)
b = len(b_ary)
'''
r = s.count('R')
g = s.count('G')
b = s.count('B')
'''
# 1つ目の条件を満たす
first_conditions = r*g*b
# 1つ目の条件は満たすが、2つ目の条件は満たさない
second_condition = 0
# 2つ目の条件を満たすということは、(i,j,k)のときk=2j-i
for i in range(n-2):
    for j in range(i+1,n-1):
        if 2*j-i<n and s[i]!=s[2*j-i] and s[j]!=s[2*j-i] and s[i]!=s[j]:
            second_condition += 1
print(first_conditions-second_condition)

Fixed submission:
n = int(input())
s = input()
r_ary = []
g_ary = []
b_ary = []
for i in (s):
    if i == 'R':
        r_ary.append(i)
    elif i == 'G':
        g_ary.append(i)
    elif i == 'B':
        b_ary.append(i)
r = len(r_ary)
g = len(g_ary)
b = len(b_ary)
first_conditions = r*g*b
for i in range(n-2):
    for j in range(i+1,n-1):
        if 2*j-i<n and s[i]!=s[2*j-i] and s[j]!=s[2*j-i] and s[i]!=s[j]:
            first_conditions -= 1
print(first_conditions)

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

r = s.count('R')
g = s.count('G')
b = s.count('B')

# 1つ目の条件を満たす
first_conditions = r*g*b
# 1つ目の条件は満たすが、2つ目の条件は満たさない
second_condition = 0
# 2つ目の条件を満たすということは、(i,j,k)のときk=2j-i
for i in range(n-2):
    for j in range(i+1,n-1):
        if 2*j-i<n and s[i]!=s[2*j-i] and s[j]!=s[2*j-i] and s[i]!=s[j]:
            second_condition += 1
print(first_conditions-second_condition)

Fixed submission:
n = int(input())
s = input()
r_ary = []
g_ary = []
b_ary = []
for i in (s):
    if i == 'R':
        r_ary.append(i)
    elif i == 'G':
        g_ary.append(i)
    elif i == 'B':
        b_ary.append(i)
r = len(r_ary)
g = len(g_ary)
b = len(b_ary)
first_conditions = r*g*b
for i in range(n-2):
    for j in range(i+1,n-1):
        if 2*j-i<n and s[i]!=s[2*j-i] and s[j]!=s[2*j-i] and s[i]!=s[j]:
            first_conditions -= 1
print(first_conditions)

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

r = s.count('R')
g = s.count('G')
b = s.count('B')

# 1つ目の条件を満たす
first_conditions = r*g*b
# 1つ目の条件は満たすが、2つ目の条件は満たさない
second_condition = 0
sum_ = 0
# 2つ目の条件を満たすということは、(i,j,k)のときk=2j-i
for i in range(n):
    for j in range(i,n):
        if 2*j-i< n  and s[i] != s[2*j-i] and s[j] != s[2*j-i] and s[i] != s[j]:
            second_condition += 1
print(first_conditions-second_condition)

Fixed submission:
n = int(input())
s = input()
r_ary = []
g_ary = []
b_ary = []
for i in (s):
    if i == 'R':
        r_ary.append(i)
    elif i == 'G':
        g_ary.append(i)
    elif i == 'B':
        b_ary.append(i)
r = len(r_ary)
g = len(g_ary)
b = len(b_ary)
first_conditions = r*g*b
for i in range(n-2):
    for j in range(i+1,n-1):
        if 2*j-i<n and s[i]!=s[2*j-i] and s[j]!=s[2*j-i] and s[i]!=s[j]:
            first_conditions -= 1
print(first_conditions)

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

r = s.count('R')
g = s.count('G')
b = s.count('B')

# 1つ目の条件を満たす
first_conditions = r*g*b
# 一つ目の条件は満たすが、2つ目の条件は満たさない
second_condition = 0
sum_ = 0
for i in range(n):
    r_ = s[i]
    for j in range(i,n):
        g_ = s[j]
        if r_ != g_:
            for k in range(j,n):
                if j-i == k-j  and g_ != s[k] and r_ != s[k]:
                    second_condition += 1
print(first_conditions-second_condition)

Fixed submission:
n = int(input())
s = input()
r_ary = []
g_ary = []
b_ary = []
for i in (s):
    if i == 'R':
        r_ary.append(i)
    elif i == 'G':
        g_ary.append(i)
    elif i == 'B':
        b_ary.append(i)
r = len(r_ary)
g = len(g_ary)
b = len(b_ary)
first_conditions = r*g*b
for i in range(n-2):
    for j in range(i+1,n-1):
        if 2*j-i<n and s[i]!=s[2*j-i] and s[j]!=s[2*j-i] and s[i]!=s[j]:
            first_conditions -= 1
print(first_conditions)

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

r = s.count('R')
g = s.count('G')
b = s.count('B')

# 1つ目の条件を満たす
first_conditions = r*g*b
# 一つ目の条件は満たすが、2つ目の条件は満たさない
second_condition = 0
sum_ = 0
for i in range(n):
    r_ = s[i]
    for j in range(i,n):
        g_ = s[j]
        for k in range(j,n):
            if j-i == k-j and r_ != g_ and g_ != s[k] and r_ != s[k]:
                second_condition += 1
print(first_conditions-second_condition)

Fixed submission:
n = int(input())
s = input()
r_ary = []
g_ary = []
b_ary = []
for i in (s):
    if i == 'R':
        r_ary.append(i)
    elif i == 'G':
        g_ary.append(i)
    elif i == 'B':
        b_ary.append(i)
r = len(r_ary)
g = len(g_ary)
b = len(b_ary)
first_conditions = r*g*b
for i in range(n-2):
    for j in range(i+1,n-1):
        if 2*j-i<n and s[i]!=s[2*j-i] and s[j]!=s[2*j-i] and s[i]!=s[j]:
            first_conditions -= 1
print(first_conditions)

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

r = s.count('R')
g = s.count('G')
b = s.count('B')

# 1つ目の条件を満たす
first_conditions = r*g*b
# 一つ目の条件は満たすが、2つ目の条件は満たさない
second_condition = 0
sum_ = 0
for i in range(n):
    for j in range(i,n):
        for k in range(j,n):
            if j-i == k-j and s[i] != s[j] and s[j] != s[k] and s[i] != s[k]:
                second_condition += 1
print(first_conditions-second_condition)

Fixed submission:
n = int(input())
s = input()
r_ary = []
g_ary = []
b_ary = []
for i in (s):
    if i == 'R':
        r_ary.append(i)
    elif i == 'G':
        g_ary.append(i)
    elif i == 'B':
        b_ary.append(i)
r = len(r_ary)
g = len(g_ary)
b = len(b_ary)
first_conditions = r*g*b
for i in range(n-2):
    for j in range(i+1,n-1):
        if 2*j-i<n and s[i]!=s[2*j-i] and s[j]!=s[2*j-i] and s[i]!=s[j]:
            first_conditions -= 1
print(first_conditions)

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

r = s.count('R')
g = s.count('G')
b = s.count('B')

# 1つ目の条件を満たす
first_conditions = r*g*b
# 一つ目の条件は満たすが、2つ目の条件は満たさない
second_condition = 0
sum_ = 0
for i in range(n):
    for j in range(i,n):
        for k in range(j,n):
                if j-i == k-j and (s[i] != s[j] and s[j] != s[k] and s[i] != s[k]):
                    second_condition += 1
print(first_conditions-second_condition)

Fixed submission:
n = int(input())
s = input()
r_ary = []
g_ary = []
b_ary = []
for i in (s):
    if i == 'R':
        r_ary.append(i)
    elif i == 'G':
        g_ary.append(i)
    elif i == 'B':
        b_ary.append(i)
r = len(r_ary)
g = len(g_ary)
b = len(b_ary)
first_conditions = r*g*b
for i in range(n-2):
    for j in range(i+1,n-1):
        if 2*j-i<n and s[i]!=s[2*j-i] and s[j]!=s[2*j-i] and s[i]!=s[j]:
            first_conditions -= 1
print(first_conditions)

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

r = s.count('R')
g = s.count('G')
b = s.count('B')

# 1つ目の条件を満たす
first_conditions = r*g*b
# 一つ目の条件は満たすが、2つ目の条件は満たさない
second_condition = 0
sum_ = 0
for i in range(n):
    for j in range(n):
        for k in range(n):
            if i < j and j < k:
                if j-i == k-j and (s[i] != s[j] and s[j] != s[k] and s[i] != s[k]):
                    second_condition += 1
print(first_conditions-second_condition)

Fixed submission:
n = int(input())
s = input()
r_ary = []
g_ary = []
b_ary = []
for i in (s):
    if i == 'R':
        r_ary.append(i)
    elif i == 'G':
        g_ary.append(i)
    elif i == 'B':
        b_ary.append(i)
r = len(r_ary)
g = len(g_ary)
b = len(b_ary)
first_conditions = r*g*b
for i in range(n-2):
    for j in range(i+1,n-1):
        if 2*j-i<n and s[i]!=s[2*j-i] and s[j]!=s[2*j-i] and s[i]!=s[j]:
            first_conditions -= 1
print(first_conditions)

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

r = s.count('R')
g = s.count('G')
b = s.count('B')

# 1つ目の条件を満たす
first_conditions = r*g*b
# 一つ目の条件は満たすが、2つ目の条件は満たさない
second_condition = 0
sum_ = 0
for i in range(n):
    for j in range(n):
        for k in range(n):
            if i < j and j < k:
                if j-i == k-j and (s[i] != s[j] and s[j] != s[k] and s[i] != s[k]):
                    second_condition += 1
print(first_conditions-second_condition)

Fixed submission:
n = int(input())
s = input()
r_ary = []
g_ary = []
b_ary = []
for i in (s):
    if i == 'R':
        r_ary.append(i)
    elif i == 'G':
        g_ary.append(i)
    elif i == 'B':
        b_ary.append(i)
r = len(r_ary)
g = len(g_ary)
b = len(b_ary)
first_conditions = r*g*b
for i in range(n-2):
    for j in range(i+1,n-1):
        if 2*j-i<n and s[i]!=s[2*j-i] and s[j]!=s[2*j-i] and s[i]!=s[j]:
            first_conditions -= 1
print(first_conditions)