Buggy python submission (verdict: Time Limit Exceeded):
# D - RGB Triplets

N = int(input())
S = input()

r, g, b = 0, 0, 0

for s in S:
	if s == 'R':
		r += 1
	elif s == 'G':
		g += 1
	else:
		b += 1

ans = r * g * b

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

print(ans)

Fixed submission:
# D - RGB Triplets
	
N = int(input())
S = input()
	
r, g, b = 0, 0, 0
	
for s in S:
	if s == 'R':
		r += 1
	elif s == 'G':
		g += 1
	else:
		b += 1
	
ans = r * g * b
	
for i in range(N - 2):
	for j in range(i + 1, N - 1):
		k = j * 2 - i
			
		if k < N:
			if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
				if j -i == k -j:
					ans -= 1
	
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# D - RGB Triplets

N = int(input())
S = input()

r, g, b = 0, 0, 0

for s in S:
	if s == 'R':
		r += 1
	elif s == 'G':
		g += 1
	else:
		b += 1

ans = r * g * b

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

print(ans)

Fixed submission:
# D - RGB Triplets
	
N = int(input())
S = input()
	
r, g, b = 0, 0, 0
	
for s in S:
	if s == 'R':
		r += 1
	elif s == 'G':
		g += 1
	else:
		b += 1
	
ans = r * g * b
	
for i in range(N - 2):
	for j in range(i + 1, N - 1):
		k = j * 2 - i
			
		if k < N:
			if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
				if j -i == k -j:
					ans -= 1
	
print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
import clipboard

# テストケースが複数行の場合、iOSだと一気に読み込んでしまう。
# 本番環境と同じ挙動になるように、
# iOSではテストケースをいったんテキストファイルにコピーして
# テキストファイルから input() する
if sys.platform == 'ios':
	sample = clipboard.get()
	file = open('input_file.txt', 'w')
	file.write(sample)
	file.close()
	sys.stdin = open('input_file.txt')
# -----------------------------
						

# D - RGB Triplets

N = int(input())
S = input()

r, g, b = 0, 0, 0

for s in S:
	if s == 'R':
		r += 1
	elif s == 'G':
		g += 1
	else:
		b += 1

ans = r * g * b

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

print(ans) 

Fixed submission:
# D - RGB Triplets
	
N = int(input())
S = input()
	
r, g, b = 0, 0, 0
	
for s in S:
	if s == 'R':
		r += 1
	elif s == 'G':
		g += 1
	else:
		b += 1
	
ans = r * g * b
	
for i in range(N - 2):
	for j in range(i + 1, N - 1):
		k = j * 2 - i
			
		if k < N:
			if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
				if j -i == k -j:
					ans -= 1
	
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# D - RGB Triplets

def get_rgb():
	i = 1
	
	for s in S:
		if s == 'R':
			r_list.append(i)
		elif s == 'G':
			g_list.append(i)
		else:
			b_list.append(i)
		
		i += 1
# -----------------------------


def fix_i_j():
	i = min(r, g)
	j = max(r, g)
	k = j * 2 - i
	
	global ans
	
	if k in b_list:
		ans -= 1


def fix_i_k():
	i = min(r, g)
	k = max(r, g)
	j = (i + k) / 2
	
	global ans
	
	if j in b_list:
		ans -= 1


def fix_j_k():
	j = min(r, g)
	k = max(r, g)
	i = j * 2 - k
	
	global ans
	
	if i in b_list:
		ans -= 1


N = int(input())
S = input()

r_list = []
g_list = []
b_list = []
get_rgb()

ans = len(r_list) * len(g_list) * len(b_list)

for r in r_list:
	for g in g_list:
		fix_i_j()
		fix_i_k()
		fix_j_k()
		 
print(ans)

Fixed submission:
# D - RGB Triplets
	
N = int(input())
S = input()
	
r, g, b = 0, 0, 0
	
for s in S:
	if s == 'R':
		r += 1
	elif s == 'G':
		g += 1
	else:
		b += 1
	
ans = r * g * b
	
for i in range(N - 2):
	for j in range(i + 1, N - 1):
		k = j * 2 - i
			
		if k < N:
			if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
				if j -i == k -j:
					ans -= 1
	
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# D - RGB Triplets

def get_rgb():
	i = 1
	
	for s in S:
		if s == 'R':
			r_list.append(i)
		elif s == 'G':
			g_list.append(i)
		else:
			b_list.append(i)
		
		i += 1
# -----------------------------


def fix_i_j():
	i = min(r, g)
	j = max(r, g)
	k = j * 2 - i
	
	global ans
	
	if k in b_list:
		ans -= 1


def fix_i_k():
	i = min(r, g)
	k = max(r, g)
	j = (i + k) / 2
	
	global ans
	
	if j in b_list:
		ans -= 1


def fix_j_k():
	j = min(r, g)
	k = max(r, g)
	i = j * 2 - k
	
	global ans
	
	if i in b_list:
		ans -= 1


N = int(input())
S = input()

r_list = []
g_list = []
b_list = []
get_rgb()

ans = len(r_list) * len(g_list) * len(b_list)

for r in r_list:
	for g in g_list:
		fix_i_j()
		fix_i_k()
		fix_j_k()
		 
print(ans)

Fixed submission:
# D - RGB Triplets
	
N = int(input())
S = input()
	
r, g, b = 0, 0, 0
	
for s in S:
	if s == 'R':
		r += 1
	elif s == 'G':
		g += 1
	else:
		b += 1
	
ans = r * g * b
	
for i in range(N - 2):
	for j in range(i + 1, N - 1):
		k = j * 2 - i
			
		if k < N:
			if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
				if j -i == k -j:
					ans -= 1
	
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# D - RGB Triplets

def get_rgb():
	i = 1
	
	for s in S:
		if s == 'R':
			r_list.append(i)
		elif s == 'G':
			g_list.append(i)
		else:
			b_list.append(i)
		
		i += 1
# -----------------------------


N = int(input())
S = input()

r_list = []
g_list = []
b_list = []
get_rgb()

ans = 0

for r in r_list:
	for g in g_list:
		for b in b_list:
			list = [r, g, b]
			list.sort()
			i, j, k = list
			
			if j - i != k -j:
				ans += 1

print(ans)

Fixed submission:
# D - RGB Triplets
	
N = int(input())
S = input()
	
r, g, b = 0, 0, 0
	
for s in S:
	if s == 'R':
		r += 1
	elif s == 'G':
		g += 1
	else:
		b += 1
	
ans = r * g * b
	
for i in range(N - 2):
	for j in range(i + 1, N - 1):
		k = j * 2 - i
			
		if k < N:
			if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
				if j -i == k -j:
					ans -= 1
	
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# D - RGB Triplets

def get_rgb():
	i = 1
	
	for s in S:
		if s == 'R':
			r_list.append(i)
		elif s == 'G':
			g_list.append(i)
		else:
			b_list.append(i)
		
		i += 1
# -----------------------------


N = int(input())
S = input()

r_list = []
g_list = []
b_list = []
get_rgb()

ans = 0

for r in r_list:
	for g in g_list:
		for b in b_list:
			list = [r, g, b]
			list.sort()
			i, j, k = list
			
			if j - i != k -j:
				ans += 1

print(ans)

Fixed submission:
# D - RGB Triplets
	
N = int(input())
S = input()
	
r, g, b = 0, 0, 0
	
for s in S:
	if s == 'R':
		r += 1
	elif s == 'G':
		g += 1
	else:
		b += 1
	
ans = r * g * b
	
for i in range(N - 2):
	for j in range(i + 1, N - 1):
		k = j * 2 - i
			
		if k < N:
			if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
				if j -i == k -j:
					ans -= 1
	
print(ans)