Problem:


Score : 400 points

Problem Statement

We have a string S of length N consisting of R, G, and B.

Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions:

S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k.

j - i \neq k - j.

Constraints

1 \leq N \leq 4000

S is a string of length N consisting of R, G, and B.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the number of triplets in question.

Sample Input 1

4
RRGB

Sample Output 1

1

Only the triplet (1,~3,~4) satisfies both conditions. The triplet (2,~3,~4) satisfies the first condition but not the second, so it does not count.

Sample Input 2

39
RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB

Sample Output 2

1800



Sample input:
4
RRGB


Sample output:
1

Submission status: Wrong Answer

Solution code:
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    N = int(input())
    S = input()[:-1]

    A = [[] for _ in range(3)]
    for i in range(N):
        if S[i:i+1] == "R":
            A[0].append(i)
        if S[i:i+1] == "G":
            A[1].append(i)
        if S[i:i+1] == "B":
            A[2].append(i)

    res = 0
    for P in itertools.permutations(range(3)):
        a = P[0]
        b = P[1]
        c = P[2]
        for i in A[a]:
            x = bisect.bisect_left(A[b], i)
            for j in A[b][x:]:
                res += len(A[c]) - bisect.bisect_left(A[c], j)
    
    for l in range(1, math.ceil((N-1)/2)):
        for n in range(N - l*2):
            if S[n] != S[n+l] and S[n+l] != S[n+l*2] and S[n+l*2] != S[n]:
                res -= 1
    
    print(res)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
s = list(input())

ss = collections.Counter(s)
ans = 1
for i in ss:
    ans *= ss[i]

for i in range(n - 1):
    for j in range(i + 1, n):
        sub = j - i
        sub2 = (n - 1) - j
        if sub <= sub2:
            if s[i] != s[j] and s[j] != s[j + sub] and s[i] != s[j + sub]:
                ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
from math import gcd
n = int(input())
res = 0
for i in range(1, n+1):
    for j in range(1, n+1):
        for k in range(1, n+1):
            res += gcd(gcd(i, j), k)
print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())

R=[0]*n
G=[0]*n
B=[0]*n

for i in range(n):
    if s[i]=='R':
        R[i]=1
    elif s[i]=='G':
        G[i]=1
    elif s[i]=='B':
        B[i]=1

ans=0
for i in range(n):
    if R[i]==1:
        lG=sum(G[:i])
        lB=sum(B[:i])
        rG=sum(G[i:])
        rB=sum(B[i:])
        ans+=(lG+rG)*(lB+rB)
        for j in range(1,n//2):
            if R[i]==1:
                if 0<=i-j<n and 0<=i+j<n:
                    if G[i-j]==1 and B[i+j]==1:
                        ans-=1
                    if B[i-j]==1 and G[i+j]==1:
                        ans-=1
                if 0<i-2*j<n:
                    if G[i-j]==1 and B[i-2*j]==1:
                        ans-=1
                    if B[i-j]==1 and G[i-2*j]==1:
                        ans-=1
                if 0<=i+2*j<n:
                    if G[i+j]==1 and B[i+2*j]==1:
                        ans-=1
                    if B[i+j]==1 and G[i+2*j]==1:
                        ans-=1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()

ans=0

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

print(str(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
r = 0
g = 0
b = 0
if (n==3):
    print(0)
    exit()


for i in range(n):
    if (s[i]=="R"):
        r += 1
    elif (s[i]=="G"):
        g += 1
    else:
        b += 1
da = r*g*b
count = 0
if (n%2==1):
    for i in range (0,n//2-1):
        for j in range(0,n-2*(i+1)):
            if (s[j]!=s[j+i+1] and s[j+i+1]!=s[j+2*(i+1)] and s[j+2*(i+1)]!=s[j]):
                count += 1
else:
    for i in range (0,n//2-1):
        for j in range(0,n-2*(i+1)):
            if (s[j]!=s[j+i+1] and s[j+i+1]!=s[j+2*(i+1)] and s[j+2*(i+1)]!=s[j]):
                count += 1
                      
print(da -count)

Submission status: Wrong Answer

Solution code:
import collections

n=int(input())	
s=input()

c = collections.Counter(s)

ans_count = c['R'] * c['G'] * c['B']

for i in range((n-1)//2):
    for j in range(n):
        if j+(2*i) >= n:
            break

        if s[j] != s[j+i] and s[j+i] != s[j+(2*i)] and s[j] != s[j+(2*i)]:
            ans_count -= 1


print(ans_count)

Submission status: Wrong Answer

Solution code:
N= int(input())
S=input()
r=[]
g=[]
b=[]
for i in range(N):
    if S[i]=="R":
        r.append(i)
    elif S[i]=="G":
        g.append(i)
    else:
        b.append(i)
print(r)
print(g)
print(b)
t=0
for i in range(len(r)):
    for j in range(len(g)):
        p=0
        for k in range(len(b)):
            if p<3:
                if abs(r[i]-g[j])!=abs(b[k]-g[j]) and abs(r[i]-b[k])!=abs(b[k]-g[j]) and abs(r[i]-g[j])!=abs(b[k]-r[i]):
                    t=t+1
                else:
                    p+=1
            else:
                t = t + 1
print(t)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ans = s.count("R")*s.count("G")*s.count("B")
for i in range(1,n//2+10):
  j = 0
  while j+2*i <= n-1:
    print([j, j+i, j+2*i])
    if s[j] != s[j+i] and s[j] != s[j+2*i] and s[j+i] != s[j+2*i]:
      ans -= 1
    j += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
c=s.count
r,g,b=c('R'),c('G'),c('B')
t=0
for k in ('RGB','RBG','GRB','GBR','BRG','BGR'):
  for w in range(1,n//2):
    for i in range(n):
      if i+w*2<n:
        t+=s[i:i+w*2+1:w]==k
print(r*g*b-t)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
S = list(input())
c = Counter(S)
# print('c', c)

if len(c) != 3:
    print(0)
    exit()

con1 = 1
for v in c.values():
    con1 *= v

not_con2 = 0
for d in range(2101):
    for i in range(2101):
        j = i + d
        k = j + d
        if N - 1 < k:
            continue
        # print('S', S[i], S[j], S[k], i, j, k)
        if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
            not_con2 += 1

# print('not_con2', not_con2)
ans = con1 - not_con2
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
r=[]
g=[]
b=[]
ans=0

for i in range(n):
    if s[i]=="R":
        r.append(i+1)
    elif s[i]=="G":
        g.append(i+1)
    elif s[i]=="B":
        b.append(i+1)
for i in r:
    for j in g:
        for k in b:
            if abs(j-i)!=abs(k-j):
                ans+=1
            
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())

cnt = sum([1 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] != S[k] and j-i != k-j
          ])   
        
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()

ans = 0
r = S.count('R')
g = S.count('G')
b = S.count('B')
RGB = set(['R', 'G', 'B'])

exclude = 0
for d in range(1, N // 2):
    for i in range(N - 2 * d):
        if set([S[i], S[i + d], S[i + 2 * d]]) == RGB:
            exclude += 1
print(r * g * b - exclude if N > 3 else 0)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
ans = 0
for i in range(N):
    for j in range(i+1,N):
        if S[i] != S[j]:
            for k in range(j+1,N):
                if j-i != k-j and S[j] != S[k] and S[i] != S[k]:
                    ans += 1
                    print(S[i],S[j],S[k])
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
n = int(input())
s = input()
ans = 0
R_list = []
G_list = []
B_list = []
for i in range(1, n+1):
    if s[i-1] == 'R':
        R_list.append(i)
    elif s[i-1] == 'G':
        G_list.append(i)
    else:
        B_list.append(i)

xxx_list = list(itertools.product(R_list, G_list, B_list))
for rgb in xxx_list:
    if rgb[2] - rgb[1] != rgb[1] - rgb[0] and rgb[0] != rgb[1] != rgb[2]:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()

r_cnt = s.count('R')
g_cnt = s.count('G')
b_cnt = s.count('B')

total = r_cnt * g_cnt * b_cnt

for i in range(n // 2):
    for j in range(n):
        ptr1 = j
        ptr2 = j + i
        ptr3 = j + 2 * i
        if ptr3 >= n:
            break
        else:
            if s[ptr1] != s[ptr2] and s[ptr2] != s[ptr3] and s[ptr1] != s[ptr3]:
                total -= 1

print(total)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
Rcount = 0
Gcount = 0
Bcount = 0
for i in S:
    if i == "R":
        Rcount += 1
    if i == "G":
        Gcount += 1
    if i == "B":
        Bcount += 1

sum2 = Rcount * Gcount * Bcount

for i in range(1, len(S) // 2):
    for j in range(len(S)-(i*2)):
        #print(j, j+i, j+i*2)
        if S[j] != S[j + i] and S[j] != S[j + (i * 2)] and S[j+i] != S[j+(i*2)]:
            sum2 -= 1
print(sum2)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(str(input()))

ri = [n+1 for n, v in enumerate(s) if v == 'R']
gi = [n+1 for n, v in enumerate(s) if v == 'G']
bi = [n+1 for n, v in enumerate(s) if v == 'B']

print(ri,gi,bi)
ans = 0

for r in ri:
    for g in gi:
        for b in bi:
            if r < g and g < b:
                if g - r != b - g:
                    ans += 1
            elif g < r and r < b:
                if r - g != b - r:
                    ans += 1
            elif r < b and b < g:
                if b - r != g - b:
                    ans += 1
            elif g < b and b < r:
                if b - g != r - b:
                    ans += 1
            elif b < r and r < g:
                if r - b != g - r:
                    ans += 1
            elif b < g and g < r:
                if g - b != r - g:
                    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
r = 0
g = 0
b = 0
for i in range(n):
    if (s[i]=="R"):
        r += 1
    elif (s[i]=="G"):
        g += 1
    else:
        b += 1
da = r*g*b
count = 0
if (n%2==1):
    for i in range (0,n//2-1):
        for j in range(0,n-2*(i+1)):
            if (s[j]!=s[j+i+1] and s[j+i+1]!=s[j+2*(i+1)] and s[j+2*(i+1)]!=s[j]):
                count += 1
else:
    for i in range (0,n//2-1):
        for j in range(0,n-2*(i+1)):
            if (s[j]!=s[j+i+1] and s[j+i+1]!=s[j+2*(i+1)] and s[j+2*(i+1)]!=s[j]):
                count += 1
                      
print(da -count)

Submission status: Wrong Answer

Solution code:
x = int(input())
s = list(input())
di = {'R':0, 'G':0, 'B':0}
for i in s:
    di[i] += 1
c = 0 #重複を数える
p = (len(s) - 3) // 2
for i in range(len(s)-2):
    j = 0
    while(j < p + 1 and i+(2*j)<=len(s)-1):
        ss = s[i] + s[i+j] + s[i+(2*j)]
        j += 1
        if ss == 'GBR'or ss ==  'GRB' or ss ==  'RBG' or ss == 'RGB' or  ss == 'BGR' or ss == 'BRG':
                c += 1
print(di['R'] * di['G'] * di['B'] - c)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()

count = 0

for i in range(n-3):
    for j in range(i+1, n-2):
        if s[i] == s[j]:
            continue
        for k in range(j+1, n-1):
            if s[i] == s[k] or s[j] == s[k]:
                continue
            else:
                if j - i == k - j:
                    continue
                else:
                    count += 1

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()

r_list = []
g_list = []
b_list = []

res = 0

for i in range(n):
    if(s[i] == "R"):
        r_list.append(i)
    elif(s[i] == "G"):
        g_list.append(i)
    elif(s[i] == "B"):
        b_list.append(i)

# print(r_list)
# print(g_list)
# print(b_list)

for r_index in range(len(r_list)):
    for g_index in range(len(g_list)):
        for b_index in range(len(b_list)):
            # print(r_list[r_index], g_list[g_index], b_list[b_index])
            if b_list[b_index] > g_list[g_index] and g_list[g_index] > r_list[r_index]:
                if b_list[b_index]-g_list[g_index] != g_list[g_index]-r_list[r_index]:
                    # print(r_list[r_index], g_list[g_index], b_list[b_index])
                    res += 1
print(res)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from functools import reduce

N = int(input())
S = input()
cnt = 0
a = defaultdict(int)

for d in range((N-3)//2+1):
    left = 0
    middle = d+1
    right = 2*(d+1)
    while right < N:
        if d ==0:
            a[S[left]] += 1
        if S[left] != S[middle] and S[left] != S[right] and S[middle] != S[right]:
            cnt += 1
        left += 1
        middle += 1 
        right += 1
a[S[N-2]] += 1
a[S[N-1]] += 1
print(reduce(lambda x,y: x*y,a.values()) - cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()

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

print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
S = input()
C = Counter([s for s in S]).values()
ans = 1
for c in C:
    ans *= c
for i in range(n):
    mid = i + 1
    last = i + 2
    while last < n:
        if S[i] != S[mid] and S[mid] != S[last] and S[last] != S[i]:
            ans -= 1
        mid += 1
        last += 2
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
D = {"R": [], "G": [], "B": []}
for i in range(N):
  D[S[i]].append(i)
print(D)
p = 1
for i in D:
  p *= len(D[i])
cnt = 0
for i in range(N):
  for j in range(i+1, N):
    if 2 * j - i < N:
      if S[i] != S[j] and S[j] != S[2*j-i] and S[2*j-i] != S[i]:
        cnt += 1
print(p-cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(input())
cnt = 0
for i in range(1,N+1):
  for j in range(i+1,N+1):
    if S[i-1]==S[j-1]:
      break
    for k in range(j+1,N+1):
      if S[i-1]==S[k-1] or S[j-1]==S[k-1]:
        break
      elif j-i == k-j:
        break
      else:
        cnt = cnt+1
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(input())

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

print(int(ans/2 + 1))

Submission status: Wrong Answer

Solution code:
n = int(input())
s=input()
r=[]
g=[]
b=[]
for i,c in enumerate(s):
    if 'R' == c:
        r.append(i+1)
    elif 'G' == c:
        g.append(i+1)
    elif 'B' == c:
        b.append(i+1)
count=0
for i in r:
    for j in g:
        for k in b:
            if j*2-i-k != 0:
                count+=1
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ans = s.count("R")*s.count("G")*s.count("B")
for i in range(1,n//2):
  j = 0
  while j+2*i <= n-1:
    if s[j] != s[j+i] and s[j] != s[j+2*i] and s[j+i] != s[j+2*i]:
      ans -= 1
    j += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

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

R_ind = np.array([i for i in range(N) if S[i] == 'R'])
G_ind = np.array([i for i in range(N) if S[i] == 'G'])
B_ind = np.array([i for i in range(N) if S[i] == 'B'])

def solve(a,b,c,N):
	la,lb,lc = len(a), len(b), len(c)
	lmax = max(la,lb,lc)
	if la == lmax:
		C = a
		A = b
		B = c
	elif lb == lmax:
		C = b
		A = a
		B = c
	else:
		C = c
		A = a
		B = b
	C.sort()
	lC = len(C)
	ans = 0
	for num_a in A:
		for num_b in B:
			l, r = min(num_a, num_b), max(num_a, num_b)
			tmp = r-l
			ll = l-tmp
			if 0 <= ll:
				ind = np.searchsorted(C, ll)
				if ind == lC:
					break
				if C[ind] == ll:
					ans -= 1
			rr = r + tmp
			if N-1 >= rr:
				ind = np.searchsorted(C, rr)
				if ind == lC:
					break
				if C[ind] == rr:
					ans -= 1
			if tmp % 2 == 0:
				lr = l + tmp//2
				ind = np.searchsorted(C, lr)
				if ind == lC:
					break
				if C[ind] == lr:
					ans -= 1
			ans += lC
	return ans


ans = solve(R_ind, G_ind, B_ind,N)
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    s = input()
    res = 0
    r = []
    g = []
    b = []
    for i, c in enumerate(s):
        if c == 'R':
            r.append(i)
        elif c == 'G':
            g.append(i)
        else:
            b.append(i)
    
    cnt = 0
    for i in r:
        for j in g:
            diff = abs(j-i)
            for k in b:
                if abs(i-k) != diff and abs(j-k) != diff:
                    cnt += 1
    print(cnt)
                    


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(input())
cnt = 0
for i in range(1,N+1):
  for j in range(1,N+1):
    if S[i-1]==S[j-1]:
      break
    for k in range(1,N+1):
      if S[i-1]==S[k-1] or S[j-1]==S[k-1]:
        break
      elif j-i == k-j:
        break
      else:
        cnt = cnt+1
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()

ans = 0
r = S.count('R')
g = S.count('G')
b = S.count('B')
RGB = set(['R', 'G', 'B'])

exclude = 0
for d in range(1, N // 2):
    for i in range(N - 2 * d):
        if set([S[i], S[i + d], S[i + 2 * d]]) == RGB:
            exclude += 1
print(r * g * b - exclude)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

import bisect
n = ni()
s = ns()

r,g,b = [],[],[]

for i in range(n):
    if s[i] == 'R':
        r.append(i)
    elif s[i] == 'G':
        g.append(i)
    else:
        b.append(i)

ans = 0

print(r,g,b)

for i in range(n):
    if s[i] == 'R':
        p = bisect.bisect_right(g,i)
        for j in range(p,len(g)):
            q = bisect.bisect_right(b,g[j])
            ans += (len(b)-q)
            if g[j]*2-i < n and s[g[j]*2-i] == 'B':
                ans -= 1
        y = bisect.bisect_right(b,i)
        for j in range(y,len(b)):
            q = bisect.bisect_right(g,b[j])
            ans += (len(g)-q)
            if b[j]*2-i < n and s[b[j]*2-i] == 'G':
                ans -= 1
    elif s[i] == 'G':
        p = bisect.bisect_right(r,i)
        for j in range(p,len(r)):
            q = bisect.bisect_right(b,r[j])
            ans += (len(b)-q)
            if r[j]*2-i < n and s[r[j]*2-i] == 'B':
                ans -= 1
        p = bisect.bisect_right(b,i)
        for j in range(p,len(b)):
            q = bisect.bisect_right(r,b[j])
            ans += (len(r)-q)
            if b[j]*2-i < n and s[b[j]*2-i] == 'R':
                ans -= 1
    else:
        p = bisect.bisect_right(g,i)
        for j in range(p,len(g)):
            q = bisect.bisect_right(r,g[j])
            ans += (len(r)-q)
            if g[j]*2-i < n and s[g[j]*2-i] == 'R':
                ans -= 1
        p = bisect.bisect_right(r,i)
        for j in range(p,len(r)):
            q = bisect.bisect_right(g,r[j])
            ans += (len(g)-q)
            if r[j]*2-i < n and s[r[j]*2-i] == 'G':
                ans -= 1
    
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left

N = int(input())
S = input()
r = []
g = []
b = []
for idx, i in enumerate(S):
    if i == 'R':
        r.append(idx)
    elif i == 'G':
        g.append(idx)
    else:
        b.append(idx)

r.sort()
g.sort()
b = set(b)
b_l = len(b)

answer = 0
for j in g:
    for i in r:
        if i > j:
            i, j = j, i
        cnt = b_l
        if j + j - i in b:
            cnt -= 1
        if i - (j - i) in b:
            cnt -= 1
        if (j - i) % 2 == 0 and (j - i) // 2 in b:
            cnt -= 1
        answer += cnt
print(answer)

Submission status: Wrong Answer

Solution code:
from math import gcd
k = int(input())
gcdl = [[0 for i in range(k + 1)] for i in range(k + 1)]
for i in range(1, k + 1):
    for j in range(1, k + 1):
        gcdl[i][j] = gcd(i, j)
s = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        for l in range(1, k + 1):
            s += gcdl[i][gcdl[j][l]]

print(s)

Submission status: Wrong Answer

Solution code:
n = int(input())
s=input()
r=[]
g=[]
b=[]
for i,c in enumerate(s):
    if 'R' == c:
        r.append(i+1)
    elif 'G' == c:
        g.append(i+1)
    elif 'B' == c:
        b.append(i+1)
print(r,g,b)
count=0
for i in r:
    for j in g:
        for k in b:
            if j*2-i-k != 0:
                count+=1
print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter


def main(N=None, S=None):
    if not N or not S:
        N = int(input())
        S = input()
    c = Counter(S)
    ans = c["R"]*c["G"]*c["B"]
    for hop in range(1, N//2):
        for start in range(N):
            i = start
            j = start + hop
            k = start + hop*2
            if k >= N:
                break
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                ans -= 1
            # print(i, j, k, ans)
    print(ans)
    return ans


if __name__ == "__main__":
    # assert main(4, "RRGB") == 1
    # assert main(39, "RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB") == 1800
    main()

Submission status: Wrong Answer

Solution code:
def main():
    #from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    #r = input()
    #n = int(input())
    #a, b = map(int, input().split())
    #s, y = input().split()
    #a = input().split()
    #a = list(map(int, input().split()))
    #a = [list(input().split()) for i in range(n)]
    #a = [int(input()) for i in range(n)]
    #a = [list(map(int, input().split())) for i in range(n)]
    #a = [int(s) - 1 for s in input().split()]
    #l=[int(input()) for _ in range(int(input()))]
    #res = 0
    n=int(input())
    s=list(input())
    if len(set(s)) < 3:
      print(0)
      return 0
    from collections import Counter
    c=Counter(s)
    res=c['R']*c['G']*c['B']

    for j in range(2,n):
      for w in range(1,2001):
        i=j-w
        k=j+w

        if i>=0 and k<n:
          if s[i]!=s[j] and s[i]!=s[k] and s[j]!=s[k]:
            res-=1
    print(res)
    return 0

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

N = int(input())
S = input()
if N < 3:
    print(0)
    sys.exit()

c = Counter(S)

ans = 1
for v in c.values():
    ans *= v
if ans == 0:
    print(ans)
    sys.exit()

for i in range(N):

    for step in range(1, N):
        if i+2*step > N - 1:
            break
        ok = True
        ok &= S[i] != S[i+step]
        ok &= S[i] != S[i+2*step]
        ok &= S[i+step] != S[i+2*step]
        if ok:
            ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]
p = primes(4000)
p.append(1)

n = int(input())
s = str(input())
numr = s.count("R")
numg = s.count("G")
numb = s.count("B")
ans = numr*numb*numg
for i in range(len(s)):
    if s[i] == "R":
        for j in range(len(s)):
            if s[j] == "G" and j in p:
                ans -= s[(i%abs(i-j))::abs(i-j)].count("B")
                # print(i,j,s[(i%abs(i-j))::abs(i-j)])
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
S = input()
res = 1
for i in Counter(S).values():
    res *= i

k = 1
while k <= N/2:
    for i in range(N-2*k):
        if S[i] != S[i+k] and S[i+k] != S[i+2*k] and S[i] != S[i+2*k]:
            res -= 1
    k+=1

print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
R = 0
G = 0
B = 0
ans = 0
for i in range(N):
    if S[i] == 'R':
        R+= 1
    elif S[i] =='G':
        G+= 1
    else:
        B+= 1
ans = R*G*B
for i in range(int(N/2)):
    for j in range(i,N-i):
        if S[j-i] != S[j] and S[j] != S[j+i] and S[j+i] != S[j-i]:
            ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()

cnt = 0
for i in range(N):
  for j in range(i + 1, N - 1):
    if S[i] == S[j]:
      continue
      for k in range(j + 1, N):
        if S[i] != S[k] and S[j] != S[k] and (j - i != k - j):
          cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]
p = primes(2000)
p.append(1)

n = int(input())
s = str(input())
numr = s.count("R")
numg = s.count("G")
numb = s.count("B")
ans = numr*numb*numg
for i in range(len(s)):
    if s[i] == "R":
        for j in range(len(s)):
            if s[j] == "G" and j in p:
                ans -= s[(i%abs(i-j))::abs(i-j)].count("B")
                # print(i,j,s[(i%abs(i-j))::abs(i-j)])
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    s = input()
    count = 0
    for i in range(n):
        for j in range(i + 1, n):
            if s[i] == s[j] or j * 2 > i + n:
                continue
            for k in range(j + 1, n):
                if s[i] == s[k] or s[j] == s[k] or (j - i) == (k - j):
                    continue
                else:
                    count += 1
    print(count)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
count = 0
for i in range(len(S)):
    for i2 in range(i,len(S)):
        for i3 in range(i2,len(S)):
            if i != i2 and i2 != i3 and i3 != i and S[i] == "R" and S[i2] == "G" and S[i3] == "B" and i2 - i != i3 - i2:
                count += 1
print(count)

Submission status: Wrong Answer

Solution code:
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]
p = primes(2000)

n = int(input())
s = str(input())
numr = s.count("R")
numg = s.count("G")
numb = s.count("B")
ans = numr*numb*numg
for i in range(len(s)):
    if s[i] == "R":
        for j in range(len(s)):
            if s[j] == "G" and j in p:
                ans -= s[(i%abs(i-j))::abs(i-j)].count("B")
                print(i,j,s[(i%abs(i-j))::abs(i-j)])
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()

r=0
g=0
b=0
for i in range(n):
    if s[i]=="R":
        r+=1
    elif s[i]=="G":
        g+=1
    else:
        b+=1

m=0
for i in range(1,1998):
    for j in range(n-2*i):
        A=s[j]
        B=s[j+i]
        C=s[j+2*i]
        if A!=B and B!=C and C!=A:
            m+=1

ans=r*g*b
print(ans-m)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
s = input()
slen = len(s)
d = Counter(s)
res = 1
for v in d.values():
    res *= v
#print(res)
for step in range(1, slen):
    for start in range(slen):
        i = start
        j = i + step
        k = j + step
        if k >= slen:
            continue
        ijk = [s[i], s[j], s[k]]
        # print("ijk is", ijk)
        if 'R' in ijk and 'G' in ijk and 'B' in ijk:
            res -= 1

print(res)

Submission status: Wrong Answer

Solution code:
length = int(input())
rgb = input()
count = 0

r = [index for index, r in enumerate(rgb, start=1) if r == 'R']
g = [index for index, g in enumerate(rgb, start=1) if g == 'G']
b = [index for index, b in enumerate(rgb, start=1) if b == 'B']

for rr in r:
    for gg in g:
        for bb in b:
            if rr != gg != bb and gg-rr != bb-gg:
                count += 1
print(count)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N = int(input())
    S = input()

    R = []
    G = []
    B = []

    for i, s in enumerate(S):
        if s == 'R':
            R.append(i)
            continue
        elif s == 'G':
            G.append(i)
            continue
        elif s == 'B':
            B.append(i)
    
    print(R)
    print(G)
    print(B)
    
    total = 0

    for r in R:
        for g in G:
            for b in B:
                li = sorted([r, g, b])
                if li[1] - li[0] != li[2] - li[1]:
                    total += 1
    
    print(total)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
R = []
G = []
B = []
for i in range(N):
    if S[i] == "R":
        R.append(i)
    if S[i] == "G":
        G.append(i)
    if S[i] == "B":
        B.append(i)
count = 0

for a in R:
    for b in G:
        for c in B:
            if b - a != c - b:
                count += 1
print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
S = input()
c = Counter(S)
print(c["R"] * c["G"] * c["B"]-S.count("RGB"))

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
s = str(input())
rn = collections.Counter(s)['R']
gn = collections.Counter(s)['G']
bn = collections.Counter(s)['B']
ans = rn*gn*bn
if ans == 0:
     print(0)
elif n==3 and ans ==1:
     print(0)
else:
     for i in range(1,n//2):
          for j in range(n-2*i):
               if s[j] != s[j+i] and s[j+2*i] != s[j+i] and s[j] != s[j+2*i]:
                    ans-=1
     print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()

count = 0
# i: 0～N-2
for i in range(0, N-2):
    for j in range(i+1, N-1):
        if S[i] == S[j]:
            continue
        for k in range(j+1, N):
            if j == (k + i) / 2 or S[j] == S[k]:
                continue
            else:
                count += 1

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(input())

sum = 0

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

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    from sys import stdin
    input = stdin.readline
    from collections import Counter

    n = int(input())
    s = input()[:-1]
    
    c = Counter(s)
    minus = 0
    for i in range(1,(n+1)//2):
        for j in range(n-2*i):
            if (s[j] != s[j+i]) and (s[j] != s[j+2*i]) and (s[j+i] != s[j+2*i]):
                minus += 1

    cnt = 1
    for value in c.values():
        cnt *= value
    print(int(cnt-minus))