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 collections import Counter

N = int(input())
S = input()
c = Counter(S).values()

ans = 1
for ci in c:
    ans *= ci

for i in range(N-2):
    for d in range(1, (N-i-1)//2+1):
        if {S[i], S[i+d], S[i+2*d]} == {"R", "G", "B"}:
            ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
r,g,b = 0,0,0
r = s.count("R");g = s.count("G");b = s.count("B")
k=0    
count = r*g*b
for j in range(n):
  for i in range(j):
    if (k==2*j-i)<n:
      if s[i]!=s[k]!=s[j]!=s[i]:
        count-=1   
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
r = s.count("R");g = s.count("G");b = s.count("B")
count = r*g*b
print(count)
for j in range(n):
  for i in range(j):
    if (k:=2*j-i)<n:
      if s[i]!=s[k]!=s[j]!=s[i]:
        count-=1   
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(input())
count = S.count('R')*S.count('G')*S.count('B')
for i in range(N):
  for j in range(i+1,N):
    k = 2*j-1
    if k < N:
      if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
        count -= 1
print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
S = input()
c = Counter(S).values()

ans = 1
for ci in c:
    ans *= ci

for i in range(N-2):
    for d in range(1, (N-i)//2+1):
        if i+2*d < N and {S[i], S[i+d], S[i+2*d]} == {"R", "G", "B"}:
            ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
S = input()
c = Counter(S).values()

ans = 1
for ci in c:
    ans *= ci

for i in range(N-2):
    for d in range(1, (N-i)//2+1):
        if i+2*d < N and set([S[i], S[i+d], S[i+2*d]]) == {"R", "G", "B"}:
            ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
r,g,b = 0,0,0
r = s.count("R");g = s.count("G");b = s.count("B")
count = r*g*b
print(count)
for j in range(n):
  for i in range(j):
    if (k:=2*j-i)<n:
      if s[i]!=s[k]!=s[j]!=s[i]:
        count-=1   
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
r,g,b = 0,0,0
r = s.count("R");g = s.count("G");b = s.count("B")
k=0    
count = r*g*b
print(count)
for j in range(n):
  for i in range(j):
    if (k==2*j-i)<n:
      if s[i]!=s[k]!=s[j]!=s[i]:
        count-=1   
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
cnt = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        if s[i] == s[j]:
            break
        for k in range(j+1,n):
            if s[k] in (s[i],s[j]):
                break
            if j-i != k-j:
                cnt +=1
print(cnt)

Submission status: Wrong Answer

Solution code:
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


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

    R = set([])
    G = set([])
    B = set([])

    for i in range(N):
        temp = S[i]
        if temp == 'R':
            R.add(i)
        elif temp == 'G':
            G.add(i)
        else:
            B.add(i)

    all = [R,G,B]

    M = [len(R),len(G),len(B)]
    res = M[0] * M[1] * M[2]
    index = M.index(max(M))

    most = all.pop(index)
    first = all[0]
    second = all[1]

    count = 0

    for f in first:
        for s in second:
            temp1 = s * 2 - f
            temp2 = f * 2 - s
            temp3 = (f + s) // 2
            if (True) & (temp1 in most):
                count += 1
            if (True) & (temp2 in most):
                count += 1
            if (s + f) % 2 == 0:
                if temp3 in most:
                    count += 1

    print(res)
    res -= count
    print(res)




main()

Submission status: Wrong Answer

Solution code:
N = int(input())
R = []
G = []
B = []
RD = {}
GD = {}
BD = {}

S = input().rstrip()
S = "".join([S for i in range(100)])
for i, s in enumerate(S):
    if s == "R":
        R.append(i)
        RD[i*2] = 1
    if s == "G":
        G. append(i)
        GD[i*2] = 1
    if s == "B":
        B.append(i)
        BD[i*2] = 1

ans = len(R) * len(G) * len(B)
for r in R:
    for b in B:
        if r + b in GD:
            ans -= 1
for b in B:
    for g in G:
        if b + g in RD:
            ans -= 1
for r in R:
    for g in G:
        if r + g in BD:
            ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
#D

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

ans = 0

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

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    S = input()
    r_ind = []
    g_ind = []
    b_ind = []
    # print(list(S))
    for i,s in enumerate(list(S)):
        # print(s)
        if s == "R":
            r_ind.append(i)
        elif s == "G":
            g_ind.append(i)
        else:
            b_ind.append(i)
    d = len(r_ind)*len(g_ind)*len(b_ind)
    # print(d)
    temp = 0
    for i in r_ind:
        for j in g_ind:
            if (i+j)/2 in b_ind:
                temp += 1
            elif 2*j-i in b_ind:
                temp += 1
            elif 2*i-j in b_ind:
                temp += 1
    # print(temp)
    ans = d-temp
    # print(temp)
    print(ans)

main()

Submission status: Wrong Answer

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

rList = []
gList = []
bList = []

for indx in range(N):
    if S[indx] == 'R':
        rList.append(indx)
    elif S[indx] == 'G':
        gList.append(indx)
    elif S[indx] == 'B':
        bList.append(indx)

NoSum = 0
fList = rList
sList = gList
remain = 'B'

for fItem in fList:
    for sItem in sList:
        NoSum += 1
        prsMax = max(fItem, sItem)
        prsMin = min(fItem, sItem)
        if ((2 * prsMax - prsMin) <= N-1):
            if (S[(2 * prsMax - prsMin)] == remain):
                NoSum += 1
        
        if ((prsMax - prsMin) % 2 == 0):
            if (S[int((prsMax + prsMin)/2)] == remain):
                NoSum += 1
        
        if ((2 * prsMin - prsMax) >= 0):
            if  (S[(2 * prsMin - prsMax)] == remain):
                NoSum += 1

print(len(rList) * len(gList) * len(bList) - NoSum)

Submission status: Wrong Answer

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

rList = []
gList = []
bList = []

for indx in range(N):
    if S[indx] == 'R':
        rList.append(indx)
    elif S[indx] == 'G':
        gList.append(indx)
    elif S[indx] == 'B':
        bList.append(indx)

NoSum = 0
fList = rList
sList = gList
remain = 'B'

for fItem in fList:
    for sItem in sList:
        NoSum += 1
        # if ((2 * max(fItem, sItem) - min(fItem, sItem)) <= N-1):
        #     if (S[(2 * max(fItem, sItem) - min(fItem, sItem))] == remain):
        #         NoSum += 1
        
        # if ((max(fItem, sItem) - min(fItem, sItem)) % 2 == 0):
        #     if (S[int((max(fItem, sItem) + min(fItem, sItem))/2)] == remain):
        #         NoSum += 1
        
        # if ((2 * min(fItem, sItem) - max(fItem, sItem)) >= 0):
        #     if  (S[(2 * min(fItem, sItem) - max(fItem, sItem))] == remain):
        #         NoSum += 1

print(len(rList) * len(gList) * len(bList) - NoSum)

Submission status: Wrong Answer

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

Rs = 0
Gs = 0
Bs = 0
for i, il in enumerate(S):
    if il == 'R':
        Rs += 1
    if il == 'G':
        Gs += 1
    if il == 'B':
        Bs += 1
num = 0
for i in range(N):
    for step in range(1, N):
        j = i + step
        k = i + 2*step
        if k > N - 1:
            continue
        print(i, j, k)
        if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
            num += 1
print(Rs*Gs*Bs - num)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
f=0
ijk = list()
for i in range(N):
    for j in range(N):
        for k in range(N):
            if(i<j<k):
                if(S[i]==S[j]):
                    break
                elif(S[i]==S[k]):
                    break
                elif(S[j]==S[k]):
                    break
                else:
                    ijk.append([i+1,j+1,k+1])
# print(ijk)
for i in range(len(ijk)):
    if(ijk[i][1]-ijk[i][0] != ijk[i][2]-ijk[i][1]):
        f+=1
print(f)

Submission status: Wrong Answer

Solution code:
N= int(input())
S=input()
r=[]
g=[]
b=[]
A=0
B=0
C=0
for i in range(N):
    if S[i]=="R":
        r.append(i)
        A+=1
    elif S[i]=="G":
        g.append(i)
        B+=1
    else:
        b.append(i)
        C+=1
k=0
for i in range(N-2):
    for j in range(i+1,N-1):
        t=2*j-i
        if t<N:
            if S[i]!=S[j] and S[i]!=S[t] and S[t]!=S[j] :
                k+=1
                print(i,j,t)
print(k)
print(A*B*C-k)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import Counter

n = int(input())
s = input()
counter = Counter(list(s))
ans = 1
for c in counter.values():
    ans *= c
for i in range(n):
    for j in range(i + 1, n):
        k = j * 2 - i
        if k >= n:
            continue
        if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
            ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import*
n=int(input())
s=input()

*x,=accumulate(i=="R" for i in s)
*y,=accumulate(i=="G" for i in s)
*z,=accumulate(i=="B" for i in s)
x2=list(accumulate(i=="R" for i in s[::-1]))[::-1]
y2=list(accumulate(i=="G" for i in s[::-1]))[::-1]
z2=list(accumulate(i=="B" for i in s[::-1]))[::-1]

ans=0
if n<4:
    print(0)
else:
    for i in range(1,n-1):
        if len(set(s[i-1:i+2]))==3:
            ans-=1
        if s[i]=="R":
            ans+=y[i-1]*z2[i+1]
            ans+=z[i-1]*y2[i+1]
        elif s[i]=="G":
            ans+=x[i-1]*z2[i+1]
            ans+=z[i-1]*x2[i+1]
        elif s[i]=="B":
            ans+=x[i-1]*y2[i+1]
            ans+=y[i-1]*x2[i+1]
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
r = s.count('R')
g = s.count('G')
b = s.count('B')
ans = r*g*b
for i in range(n-3):
  for j in range(i+1,n-1):
    k = 2*j-i
    if k < n:
      if  s[i] != s[j] and s[j]!= s[k] and s[i] != s[k]:
        ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
n,s=open(0)
n=int(n)
s=[ord(c)%3for c in s]
d=[0]*3
for i in s:d[i]+=1
a=0
for i in range(n):
    d[s[i]]-=1
    b=d.copy()
    for j in range(i+1,n):
        b[s[j]]-=1
        if s[i]==s[j]:continue
        c=(0,2,1,0)[s[i]+s[j]]
        a+=b[c]
        k=j+j-i
        if k<n and s[k]==c:
            a-=1
print(a)

Submission status: Wrong Answer

Solution code:
a=int(input())
b=str(input())
sum=0

riron_sum=b.count('R')*b.count('G')*b.count('B')
print(riron_sum)
for i in range(0,a):
    for n in range(0,a+1):
        j = i+n
        k = j+n
        #print(j)
        #print(k)
        if k>=a:
        	break

        if b[i]!=b[j] and b[j]!=b[k] and b[k]!=b[i]:
                riron_sum-=1

print(riron_sum)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    S = input()
    r_ind = []
    g_ind = []
    b_ind = []
    # print(list(S))
    for i,s in enumerate(list(S)):
        print(s)
        if s == "R":
            r_ind.append(i)
        if s == "G":
            g_ind.append(i)
        if s == "B":
            b_ind.append(i)
    d = len(r_ind)*len(g_ind)*len(b_ind)
    # print(d)
    temp = 0
    for i in r_ind:
        for j in g_ind:
            for k in b_ind:
                maxid = max(i,j,k)
                minid = min(i,j,k)
                if i+j+k == (maxid+minid)*3/2:
                    temp +=1
    # print(temp)
    ans = d-temp
    print(ans)

main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    S = input()
    r_ind = []
    g_ind = []
    b_ind = []
    print(list(S))
    for i,s in enumerate(list(S)):
        print(s)
        if s == "R":
            r_ind.append(i)
        if s == "G":
            g_ind.append(i)
        if s == "B":
            b_ind.append(i)
    d = len(r_ind)*len(g_ind)*len(b_ind)
    # print(d)
    temp = 0
    for i in r_ind:
        for j in g_ind:
            for k in b_ind:
                maxid = max(i,j,k)
                minid = min(i,j,k)
                if i+j+k == (maxid+minid)*3/2:
                    temp +=1
    # print(temp)
    ans = d-temp
    print(ans)

main()

Submission status: Wrong Answer

Solution code:
K = int(input())
S = list(input())
R = []
G = []
B = []
total = 0

for a in range(0,K):
  if S[a]=="R":
    R.append(a)
  elif S[a]=="G":
    G.append(a)
  else :
    B.append(a)

for a in R:
  for b in G:
    for c in B:
      tmp = [a,b,c]
      tmp.sort
      if a+b+c != 3*tmp[1]:
        total += 1
print(total)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
count = {'R': 0, 'G': 0, 'B': 0}
for c in s:
    count[c] += 1
R, G, B = count.values()
ans = R * G * B

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

        print(i,j,k)
        if k >= n:
            continue

        if (s[i] != s[j]) & (s[i] != s[k]) & (s[j] != s[k]):
            ans -= 1
            
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = input()
R = s.count('R')
G = s.count('G')
B = s.count('B')

count = R*G*B
print(count)
cnt = 0
for i in range(len(s)):
    for d in range(N):
        j = i + d
        k = j + d
        if k >= N:
            break
        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            count -= 1
print(count)

Submission status: Wrong Answer

Solution code:
count=0

n=int(input())
l=list(map(str,input()))
i=0
while 0<=i and i<=n-3:
    
    if l[i]=='R':
        j=i+1
        while i+1<=j and j<=n-2:
            if l[j]=='R':
                j+=1
            else:
                k=j+1
                while j+1<=k and k<=n-1 and k-j!=j-i:
                    if l[k]!=l[j]:
                        count+=1
                        k+=1
                    else:
                        k+=1
                j+=1
        i+=1
    elif l[i]=='G':
        j=i+1
        while i+1<=j and j<=n-2:
            if l[j]=='G':
                j+=1
            else:
                k=j+1
                while j+1<=k and k<=n-1 and k-j!=j-i:
                    if l[k]!=l[j]:
                        count+=1
                        k+=1
                    else:
                        k+=1
                j+=1
        i+=1
    else:
        j=i+1
        while i+1<=j and j<=n-2:
            if l[j]=='B':
                j+=1
            else:
                k=j+1
                while j+1<=k and k<=n-1 and k-j!=j-i:
                    if l[k]!=l[j]:
                        count+=1
                        k+=1
                    else:
                        k+=1
                j+=1
        i+=1
print(count)

Submission status: Wrong Answer

Solution code:
N= int(input())
S=input()
r=[]
g=[]
b=[]
A=0
B=0
C=0
for i in range(N):
    if S[i]=="R":
        r.append(i)
        A+=1
    elif S[i]=="G":
        g.append(i)
        B+=1
    else:
        b.append(i)
        C+=1
k=0
for i in r:
    x=i
    for j in b:
        y=j
        if 2*x-y in b:
            k+=1
        if 2*y-x in b:
            k+=1
        if (x+y)/2 in b:
            k+=1

print(A*B*C-k)

Submission status: Wrong Answer

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

b = set(b)
cnt = len(b) * len(r) * len(g)
print(r)
print(g)
for i in r:
    original = i
    for j in g:
        i = original
        if i > j:
            i, j = j, i
        d = j - i
        if j + d in b:
            cnt -= 1
        if i - d in b:
            cnt -= 1
        if d % 2 == 0 and (i + j) // 2 in b:
            cnt -= 1
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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


c = Counter(S)

ans = 1
for v in c.values():
    ans *= v
for i in range(N):
    if N-i <= 2:
        break
    for step in range(1, N-i):
        if i+2*step > N - 1:
            break
        if S[i+step] != S[i+2*step] and S[i] != S[i+2*step] and S[i] != S[i+step]:
            ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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


c = Counter(S)

ans = 1
for v in c.values():
    ans *= v
for i in range(N):
    if N-i <= 1:
        break
    for step in range(1, N-i):
        if i+2*step > N - 1:
            break
        if S[i+step] != S[i+2*step] and S[i] != S[i+2*step] and S[i] != S[i+step]:
            ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
S=input()
lis=list(S)
C= collections.Counter(lis)
count=list(C.values())
c=0
for i in range(N):
    print(i)
    for j in range(i,(N+i-1) // 2+1):
        if(lis[i]!=lis[j]):
            if(lis[j]!=lis[2*j-i]):
                if(lis[i]!=lis[2*j-i]):
                    c+=1
if(len(count)==3):
    print(count[0]*count[1]*count[2]-c)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import collections

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

tmp=1
c = collections.Counter(S)
for cc in c.values():
    tmp*=cc

for i in range(N):
    for j in range(i+1, N):
        k = j + (j - i)
        if k >= N:
            break
        if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
            tmp-=1
print(tmp)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
c = 0
for i in range(N-2):
  for j in range(i+1,N-1):
    if S[i] != S[j]:
      RGB = 'RGB'.strip(S[i]).strip(S[j])
      S_ = S[j+1:]
      d = j - i - 1
      S_ = S_[:d]+S_[d+1:]
      c += S_.count(RGB)
print(c)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline


def main():
    n = int(input())
    s = input()

    ans = s.count('R') * s.count('G') * s.count('B')
    # print(ans)
    for i in range(n - 2):
        for j in range(i + 1, n - 1):
            k = (j - i) + j
            if k > n:
                # print(i, j, k)
                break

            if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
                ans -= 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline


def main():
    n = int(input())
    s = input()

    ans = s.count('R') * s.count('G') * s.count('B')
    print(ans)
    for i in range(n - 2):
        for j in range(i + 1, n - 1):
            k = (j - i) + j
            if k > n:
                print(i, j, k)
                break

            if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
                ans -= 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
count=0

n=int(input())
l=list(map(str,input()))
i=0
while 0<=i and i<=n-3:
    
    if l[i]=='R':
        j=i+1
        while i+1<=j and j<=n-2:
            if l[j]=='R':
                j+=1
            else:
                k=j+1
                while j+1<=k and k<=n-1 and k-j!=j-i:
                    if l[k]!=l[j]:
                        count+=1
                        k+=1
                    else:
                        k+=1
                j+=1
        i+=1
    elif l[i]=='R':
        j=i+1
        while i+1<=j and j<=n-2:
            if l[j]=='R':
                j+=1
            else:
                k=j+1
                while j+1<=k and k<=n-1 and k-j!=j-i:
                    if l[k]!=l[j]:
                        count+=1
                        k+=1
                    else:
                        k+=1
                j+=1
        i+=1
    else:
        j=i+1
        while i+1<=j and j<=n-2:
            if l[j]=='R':
                j+=1
            else:
                k=j+1
                while j+1<=k and k<=n-1 and k-j!=j-i:
                    if l[k]!=l[j]:
                        count+=1
                        k+=1
                    else:
                        k+=1
                j+=1
        i+=1
print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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


c = Counter(S)

ans = 1
for v in c.values():
    ans *= v
for i in range(N):
    if N-i <= 1:
        break
    for step in range(1, N-i):
        if i+2*step > N - 1:
            break
        ok = True
        ok = ok and S[i] != S[i+step]
        ok = ok and S[i] != S[i+2*step]
        ok = ok and S[i+step] != S[i+2*step]
        if ok:
            ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
S = input()
temp_list = []
minus = 0
for i in range(0, N-2):
    for j in range(1, N-2):
        if i+j*2 >= N:
            break
        #temp_list.append([i, i+j, i+j+j])
        if S[i] != S[i+j]:
            if S[i] != S[i+j*2]:
                if S[i+j] != S[i+j*2]:
                    minus += 1

count_dict = collections.Counter(S)

if "R" in count_dict and "G" in count_dict and "B" in count_dict:
    print(count_dict["R"]*count_dict["G"]*count_dict["B"]-minus)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import sys
import math

from collections import defaultdict
from collections import deque
def load(vtype=int):
    return vtype(input().strip())
def load_list(seplator=" ", vtype=int):
    return [vtype(v) for v in input().strip().split(seplator)]
def exit():
    import sys
    sys.exit(0)
def perm_sub(li, used):
    if len(li) == len(used):
        return [deque()]
    k = []
    for i in range(len(li)):
        if i in used:
            continue
        used.add(i)
        sub_list = perm_sub(li, used)
        for sub in sub_list:
            sub.appendleft(li[i])
        k.extend(sub_list)
        used.discard(i)
    return k
def perm_li(li):
    return perm_sub(li, set())
def perm_n(n):
    return perm_sub(list(range(n)), set())
def join_i(li, sep=""):
    return sep.join([str(e) for e in li])
def li2n(li):
    n, base = 0, 1
    for i in range(len(li)-1, -1, -1):
        n += li[i] * base
        base *= 10
    return n
def sli2ili(li):
    return [int(s) for s in li] 
def prime_list(n):
    li = [i for i in range(2, n+1)]
    for i in range(len(li)):
        if li[i] >= int(math.sqrt(n)):
            break
        if li[i] == -1:
            continue
        for j in range(i+1, len(li)):
            if li[j] % li[i] == 0:
                li[j] = -1
    return [n for n in li if n != -1]
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while True:
        r = a % b
        if r == 0: return b
        a, b = b, r
def lcm(a, b):
    return int(a * b / gcd(a,b))
def all_subset(li):
    s = []
    n = len(li)
    for bit in range(0, (1<<(n+1))):
        ss = set()
        for i in range(0, n):
            if (bit & (1 << i)):
                ss.add(li[i])
        s.append(ss)
    return s
def factorial(n):
    if n == 1:
        return 1
    return n * factorial(n-1)
def mCn(m, n):
    def factorial_ntimes(m, n):
        r = 1
        while n:
            r *= m
            m -= 1
            n -= 1
        return r
    return int(factorial_ntimes(m, n) / factorial(n))


def notab(a, b):
    s = set((a,b))
    for c in "RGB":
        if c not in s:
            return c

n  = load()
s = list(load(str))

mp = defaultdict(set)
for i in range(n):
    mp[s[i]].add(i)

cnt = 0
for i in range(0, n):
    first = s[i]
    mp[first].remove(i)
    for j in range(i + 1, n):
        if s[j] == first:
            continue
        second = s[j]
        target = notab(first, second)
        for k in range(j+1, n):
            if k-j == j-i or s[k] != target:
                continue 
            print(i, j, k)
            cnt +=1
        # if j + (j - i) < n:
        #     tmp = s[j+ (j-i)]
        #     cnt += s[j+1:].count(target)
        #     s[j+ (j-i)] = tmp
        # else:
        #     cnt += s[j+1:].count(target) 
print(cnt)

Submission status: Wrong Answer

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

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

ans = r * g * b

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

print(ans)

Submission status: Wrong Answer

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

ans=s.count("R")*s.count("B")*s.count("G")
print(ans)
for i in range(n):
    for j in range(n):
        k=(j-i)*2
        if k<n:break
        if s[i]!=s[j] and s[j]!=s[k] and s[i]!=s[k]:
            ans -=1

print(ans-1)

Submission status: Wrong Answer

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

rlist=[i for i, x in enumerate(s) if x == 'R']
glist=[i for i, x in enumerate(s) if x == 'G']
blist=[i for i, x in enumerate(s) if x == 'B']

res=0
for i in rlist:
    for j in glist:
        for s in blist:
            ff=[]
            ff.append(i)
            ff.append(j)
            ff.append(s)
            sorted(ff)
            if (j-i)!=(s-j):
                res+=1
print(res)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce
from itertools import combinations

def gcd(*numbers):
    return reduce(math.gcd, numbers)

n = int(input())
cnt=0
for i in range(1,n+1):
    for j in range(1,n+1):
        for k in range(1,n+1):

            cnt += gcd(i,j,k)

print(cnt)

Submission status: Wrong Answer

Solution code:
from itertools import combinations
n = int(input())
s = input()
list1=[]
j = 0
for i in range(n):
    list1.append(i)
for list2 in combinations(list1,3):
    if s[list2[0]] != s[list2[1]] and s[list2[0]] != s[list2[2]] and list2[1] -list2 [0] != list2[2] -list2[1]:
        j = j + 1
print(j)

Submission status: Wrong Answer

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

r = [i for i, x in enumerate(S) if x == "R"]
g = [i for i, x in enumerate(S) if x == "G"]
b = [i for i, x in enumerate(S) if x == "B"]
kotae = 0
# print(r,g,b)
rgb = [r,g,b]
len1 = [len(r),len(g),len(b)]
n3 = len1.index(min(len1))
if n3 == 0:
    n1,n2 = 1,2
elif n3 == 1:
    n1,n2 = 0,2
else:
    n1,n2 = 0,1
# print(len1)
# print(n1,n2,n3)

for i in rgb[n3]:
    k = 1
    y = len(rgb[n1])*len(rgb[n2])
    # print("y = ",y)
    while i-k >=0 and i+k < N+2:
        # print(i,k)
        if i-k in rgb[n1]:
            if i+k in rgb[n2]:
                y -= 1
            if i-2*k in rgb[n2]:
                y-=1
                
        if i-k in rgb[n2]:
            if i+k in rgb[n1]:
                y -= 1
            if i-2*k in rgb[n1]:
                y-=1
                
        if i+k in rgb[n1]:
            if i+2*k in rgb[n2]:
                y -= 1
        if i+k in rgb[n2]:
            if i+2*k in rgb[n1]:
                y -= 1
            
            

        k += 1
    kotae += y
print(kotae)

Submission status: Wrong Answer

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

count = 0
char_candidates = "RGB"
for i in range(len(s)):
    i_char = s[i]

    indexes =  [a+i+1 for a, c in enumerate(s[i+1:]) if c != i_char]
    print(indexes)
    for j in indexes:
        j_char = s[j]
        
        valid_k_char = char_candidates.replace(s[i], "").replace(s[j], "")

        target_chars = s[j+1:]
        match_count = target_chars.count(valid_k_char)

        if j + j - i < len(s) and s[j + j - i] == valid_k_char:
            match_count -= 1

        count += match_count

print(count)

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 j in range(i, N):
        k = 2*j - i
        if k > N-1:
            break
        if (S[i] != S[j]) and (S[j] != S[k]) and (S[k] != S[i]):
            ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    n = int(input())
    s = input()
    ans = 0

    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)
    
    for i in r:
        for j in g:
            for k in b:
                rg = abs(i - j)
                gb = abs(j - k)
                br = abs(k - i)

                if rg != gb \
                    and gb != br \
                    and br != rg:
                    ans += 1
    
    print(ans)

Submission status: Wrong Answer

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

ans = s.count('R') * s.count('G') * s.count('B')
print(ans)
for i in range(n):
    for j in range(i + 1, n):
        k = 2 * j - i
        # 三個目が範囲内 かつ 三文字違う かつ 距離が同じはダメ
        if k < n and (s[i] != s[j] and s[j] != s[k]
                      and s[i] != s[k]) and j - i == k - j:
            ans -= 1

print(ans)