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:

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

ans = 0
r = range(N)
kumis = []
for i in r:
    for j in r:
        if j < i: continue
        for k in r:
            if k < j: continue
            if S[i] != S[j] and S[i] != S[j] and S[j] != S[k]:
                kumis.append(tuple([i,j,k]))

for kumi in kumis:
    i,j,k = kumi
    if j-i != k-j:
        ans+=1

print(ans)

Submission status: Wrong Answer

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

    r_index = []
    g_index = []
    b_index = []
    for index in range(len(S)):
        if S[index] == 'R':
            r_index.append(index)
        elif S[index] == 'G':
            g_index.append(index)
        else:
            b_index.append(index)
    if len(r_index) * len(g_index) * len(b_index) == 0:
        print(0)
        return

    i = 0
    sum = 0
    while i < len(S):
        a = S[i]
        j = i
        while j < len(S) - 1:
            j += 1
            if S[j] == a:
                continue

            l = 2 * j - i
            b = S[j]
            k = l
            while k < len(S)- 1:
                k += 1
                if S[k] == a or S[k] == b or l == k:
                    continue
                sum += 1
        i += 1
    print(sum)

if __name__ == '__main__':
    quest_d()

Submission status: Wrong Answer

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

cnt = 0
for i in range(N):
    for j in range(1,N):
        l = i - j
        r = i + j
        if (l < 0) or (N-1 < r): break
        if (S[l] != S[i]) and (S[i] != S[r]) and (S[l] != S[r]): cnt += 1

from collections import Counter
c = Counter(S)
ans = 1
for v in c.values(): ans *= v
print(ans-cnt)

Submission status: Wrong Answer

Solution code:
from sys import stdin
n = int(input())
s = stdin.readline()
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
count1 = r*g*b
count2 = 0
for i in range(0,n-3):
    for j in range(i+1,n-2):
        if 2*j-i<=n-1:
            if (s[i] != s[j])and(s[i] != s[2*j-i])and(s[j] != s[2*j-i]):
               count2 += 1
print(count1-count2)

Submission status: Wrong Answer

Solution code:
from sys import stdin
n = int(input())
s = stdin.readline()
rind = []
gind = []
bind = []
ans = 0
for i in range(n):
    if s[i] == "R":
        rind.append(i+1)
    elif s[i] == "G":
        gind.append(i+1)
    else:
        bind.append(i+1)
print(rind,gind,bind)
for i in range(len(rind)):
    for j in range(len(gind)):
        for k in range(len(bind)):
            ind = [rind[i],gind[j],bind[k]]
            a = sorted(ind)
            if a[0] + a[2] != 2*a[1]:
                ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
from collections import Counter
c = Counter(s)
cnt = 0
for i in range(n):
    for a in range(1,n//2):
        j = i + a
        k = j + a
        if k >= n:
            break
        if (s[i] != s[j])&(s[j] != s[k])&(s[i] != s[k]):
            cnt += 1  
        else:
            continue
                
print(c['R']*c['B']*c['G'] - cnt)

Submission status: Wrong Answer

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

r_count = s.count('R')
g_count = s.count('G')
b_count = s.count('B')

discount = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        k = i + 2*(j-i)
        if k > n-1:
            break
        if s[i] == s[j] and s[i] == s[k]:
            discount += 1

print(r_count*g_count*b_count-discount)

Submission status: Wrong Answer

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

r_count = s.count('R')
g_count = s.count('G')
b_count = s.count('B')

discount = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        k = i + 2*(j-i)
        if k > n-1:
            break
        if s[i] == s[j] and s[i] == s[k]:
            print(str(i)+str(j)+str(k)+s[i] + s[j] + s[k])
            discount += 1

print(r_count*g_count*b_count-discount)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

from sys import stdin

import time
import numpy as np
import math



############################################

# read data for n sequences.
temp = stdin.readline().split()
N = int(temp[0])
temp = stdin.readline().split()
data = temp[0]

out = 0
for ii, i in enumerate(data[:-2]):
    for jj,j in enumerate(data[:-1]):
        if i!=j:
            for kk, k in enumerate(data):
                if i!=k and j!=k:
                    if (jj-ii) != (kk-jj):
                        out+=1
print(out)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

from sys import stdin

import time
import numpy as np
import math



############################################

# read data for n sequences.
temp = stdin.readline().split()
N = int(temp[0])
temp = stdin.readline().split()
data = temp[0]

out = 0
for ii, i in enumerate(data[:-2]):
    for jj,j in enumerate(data[:-1]):
        if i!=j:
            for kk, k in enumerate(data):
                if i!=k and j!=k:
                    ii+=1
                    jj+=1
                    kk+=1
                    if (jj-ii) != (kk-jj):
                        out+=1
print(out)

Submission status: Wrong Answer

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

r_count = s.count('R')
g_count = s.count('G')
b_count = s.count('B')

discount = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        k = i + 2*(j-i)
        if k > n-1:
            break
        if s[i] == s[j] or s[i] == s[k] or s[j] == s[k]:
            discount += 1
print(r_count*g_count*b_count-discount)

Submission status: Wrong Answer

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

count = 0
if(n < 3):
    print(0)
else:
    r_indexs = []
    g_indexs = []
    b_indexs = []
    for index, char in enumerate(s):
        if char == "R":
            r_indexs.append(index)
        elif char == "G":
            g_indexs.append(index)
        else:
            b_indexs.append(index)

    color_indexs = [r_indexs, g_indexs, b_indexs]

    for col_index in range(3):
        i_indexs_list = color_indexs[col_index]
        tmp_index1 = (col_index+1) % 3
        tmp_index2 = (col_index+2) % 3
        
        j_indexs_list = color_indexs[tmp_index1]
        k_indexs_list = color_indexs[tmp_index2]
        for i in i_indexs_list:
            for j in j_indexs_list:
                for k in k_indexs_list:
                    if j-i != k-j:
                        count += 1
        
        j_indexs_list = color_indexs[tmp_index2]
        k_indexs_list = color_indexs[tmp_index1]
        for i in i_indexs_list:
            for j in j_indexs_list:
                for k in k_indexs_list:
                    if j-i != k-j:
                        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')
c = 0
for i in range(n-1):
  for j in range(i+1, (n+1)//2):
    k = j*2-i
    if k >= n:
        continue
    if len(set([s[i], s[j], s[k]]))==3:
      c += 1
print(r*g*b-c)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
S = str(input())
s = np.array(list(S))
cnt = 0
for i in range(N-2):
    f1 = np.ones(N) * True
    f1[:i] =  False # set False at index of less than and equal to i-1
    f2 = np.where(s != s[i], True, False) #  not same color
    ff = np.array(f1*f2,dtype=bool)
    J = np.arange(N)[ff]
    print("J = ",J)
    for j in J:
        f3 = np.ones(N) * True
        f3[:j] = False  # set False at index of less than and equal to i-1
        f4 = f2*np.where(s != s[j], True, False)  # not same color
        ff = np.array(f3*f4,dtype=bool)
        K = np.arange(N)[ff]
        print("K = ", K)

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

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
S = str(input())
s = np.array(list(S))
N = len(s)
cnt = 0

for i in range(N-2):
    f1 = np.ones(N) * True
    f1[:i] =  False # set False at index of less than and equal to i-1
    f2 = np.where(s != s[i], True, False) #  not same color
    ff = np.array(f1*f2,dtype=bool)
    J = np.arange(N)[ff]
    print("J = ",J)
    for j in J:
        f3 = np.ones(N) * True
        f3[:j] = False  # set False at index of less than and equal to i-1
        f4 = f2*np.where(s != s[j], True, False)  # not same color
        ff = np.array(f3*f4,dtype=bool)
        K = np.arange(N)[ff]
        print("K = ", K)

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

Submission status: Wrong Answer

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

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

b =set(b)
lb= len(b)
ans = 0

for i in r:
    for j in g:
        x , y = min(i,j),max(i,j)
        ans_=lb
        if x-(y-x) in b:
            ans_-=1
        if y+(y-x) in b:
            ans_ -=1
        if (x%2==y%2) and (y-x)//2+x in b:
            ans_-=1
        ans +=ans_

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(input())
a=[0]*4

for i in range(N):
  if S[i]=='R':a[0]+=1
  if S[i]=='G':a[1]+=1
  if S[i]=='B':a[2]+=1
    
for i in range(N):
  for j in range(i+1,N):
    k=j+(j-i)
    if k>=N:
      break
    else:
      if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i] and j-i==k-j:
        a[3]+=1

print(a)
print(a[0]*a[1]*a[2]-a[3])

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    S = list(input())
    R = []
    G = []
    B = []
    Reval = {}
    Geval = {}
    Beval = {}
    for i in range(N):
        if S[i] == "R":
            R.append(i)
            Reval[i] = i
        elif S[i] == "G":
            G.append(i)
            Geval[i] = i
        elif S[i] == "B":
            B.append(i)
            Beval[i] = i
            #if i / 2 in R or i / 2 in G or i / 2 in B
    count = len(R)*len(G)*len(B)

    for a in R:
        for b in G:
            if (a + b)//2 in Beval:
                count -= 1
    for a in G:
        for b in B:
            if (a + b)//2 in Reval:
                count -= 1
    for a in B:
        for b in R:
            if (a + b)//2 in Geval:
                count -= 1
    print(count)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    S = list(input())
    R = []
    G = []
    B = []
    Reval = {}
    Geval = {}
    Beval = {}
    for i in range(N):
        if S[i] == "R":
            R.append(i)
            Reval[i] = i
        elif S[i] == "G":
            G.append(i)
            Geval[i] = i
        elif S[i] == "B":
            B.append(i)
            Beval[i] = i
            #if i / 2 in R or i / 2 in G or i / 2 in B
    count = len(R)*len(G)*len(B)

    for a in R:
        for b in G:
            if (a + b)//2 in Beval:
                count -= 1
    for a in G:
        for b in B:
            if (a + b)//2 in Reval:
                count -= 1
    for a in B:
        for b in G:
            if (a + b)//2 in Geval:
                count -= 1
    print(count)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(map(str,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)
ans = 0
for i in range(N):
    for j in range(1,N//2):
        if i+2*j < N:
            if S[i] != S[i+j] and S[i] != S[i+2*j] and S[i+j] != S[i+2*j]:
                ans +=1

print(len(R)*len(G)*len(B)-ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(map(str,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)
ans = 0
for i in range(N):
    for j in range(1,(N+3)//3):
        if i+2*j < N:
            if S[i] != S[i+j] and S[i] != S[i+2*j] and S[i+j] != S[i+2*j]:
                ans +=1

print(len(R)*len(G)*len(B)-ans)

Submission status: Wrong Answer

Solution code:
n= int(input())
s_list= list(input())
count=0
rr,bb,gg=0,0,0
for i in range(0,n):
    if s_list[i]=="R":
        rr=rr+1
    elif s_list[i]=="G":
        gg=gg+1
    else:
        bb=bb+1
sum=rr*gg*bb

for p in range(0,n-2):
    for q in range(p+1,n-1):
        if s_list[p] == s_list[q]:
            break
        else:
            for r in range(q+1,n):
                if s_list[r]==s_list[p] or s_list[r]==s_list[q] :
                    break
                elif r-q==q-p:
                    count = count+1
                    print(p,q,r)
print(sum-count)

Submission status: Wrong Answer

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

arr = []
R = len(list(filter(lambda x:x == 'R', s)))
G = len(list(filter(lambda x:x == 'G', s)))
B = len(list(filter(lambda x:x == 'B', s)))
tot = R*G*B
print(tot)

for i in range(n):
  for j in range(i+1, n):
    k = 2*j-i
    if k < n:
      if (s[i] != s[j]) & (s[i] != s[k]) & (s[j] != s[k]):
        tot -= 1

print(tot)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
R = 0
G = 0
B = 0
nsum = 0
for s in S:
    if s == "R":
        R += 1
    elif s == "G":
        G += 1
    else:
        B += 1
count = 0
for i in range(N):
    for k in range(i+1,N):
        if S[i] == S[k]:
            count += 1
        else:
            if 2*k - i <= N - 1:
                if S[i] == S[2*k - i] or S[k] == S[2*k - i]:
                    count += 1
print(R*G*B - count)

Submission status: Wrong Answer

Solution code:
import collections


def main():
    n = int(input())
    l = list(input())
    cnt = collections.Counter(l)
    ans = 1
    for i in cnt.values():
        ans *= i
    for c in range(n):
        center = l[c]
        for dif in range(n):
            if dif + c > n - 1 or c - dif < 0:
                continue
            left = l[c - dif]
            right = l[dif + c]
            if left != center and center != right and right != left:
                ans -= 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

ans=r*g*b
dib=0
m=0

for i in range(N-2):
    m=(N-i)//2+1
    for j in range(i+1,m):
            dib=j-i
            if j+dib<=N-1:
                if S[i]!=S[j] and S[i]!=S[j+dib] and S[j]!=S[j+dib]:
                    ans=ans-1
            
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())  # 1 <= N <= 4000
S = input()  # [RGB]{N}
L = {
    'R': tuple(i for i, v in enumerate(S) if v == 'R'),
    'G': tuple(i for i, v in enumerate(S) if v == 'G'),
    'B': tuple(i for i, v in enumerate(S) if v == 'B')
}
print(type(L['R']))

ans = 0
for i in range(N):
    for j in range(i+1, N):
        if S[i] != S[j]:
            other = list({'R', 'G', 'B'} - {S[i], S[j]})[0]
            tmp = j + j - i
            ans += len([k for k in L[other] if (k > j) and (tmp != k)])
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')
ans = R*G*B

for i in range(n):
    for d in range(1, n):
        print(i, i+d, i+2*d)
        if i+2*d > n-1: break
        if s[i] != s[i+d] and s[i+d] != s[i+2*d] and s[i] != s[i+2*d]:
            ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
S = list(s)
r = S.count('R')
g = S.count('G')
b = S.count('B')
ans = r * g * b
for k in range(n):
        for j in range(k):
            i = 2*j - k
            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:
N = int(input())
S = input()
total = 0
if N<4:
  print(0)
else:
  for i in range(N-3):
    for j in range(i+1, N-1):
      for k in range(j+1, N):
        if S[i]!=S[j]: 
          if S[j]!=S[k]: 
            if S[k]!=S[i]:
              if (j-i)!=(k-j):
                total+=1
print(total)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=str(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
r=sum(R)
g=sum(G)
b=sum(B)

ans=r*g*b

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

Submission status: Wrong Answer

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


# for i in range(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-i == k-j:
#                 continue
#             if s[i] == s[k] or s[j] == s[k]:
#                 continue
#             cnt += 1

r = 0
g = 0
b = 0

for t in s:
    if t == "R":
        r += 1
    elif t == "G":
        g += 1

b = N - r - g
cnt = r * g * b
print(r,g,b,cnt)

for i in range(1, N-1):
    j = 1
    while 0 <= i-j and i+j <= N-1:
        if s[i] != s[i-j] and s[i] != s[i+j] and s[i-j] != s[i+j]:
            cnt -= 1
        j += 1

print(cnt)

Submission status: Wrong Answer

Solution code:

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

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

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

r=len(R)
g=len(G)
b=len(B)

ans=r*g*b

for i in range(r):
    for j in range(g):
        for k in range(b):
            if G[j]-R[i]==B[k]-G[j]:
                ans=ans-1

print(ans)

Submission status: Wrong Answer

Solution code:

def main():
    n = int(input())
    s = input()
    r,g,b = 0,0,0
    for i in s:
        if i == 'r': r += 1
        elif i == 'g': g += 1
        elif i == 'b': b += 1
    ans = r*g*b
    for j in range(n):
        for i in range(j):
            k = j+(j-i)
            if k < n:
                if s[i] == s[j] or s[i] == s[k] or s[k] == s[j]:
                    continue
                ans -= 1
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

nr = s.count("R")
ng = s.count("G")
nb = s.count("B")

count = nr * ng * nb

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

print(count)

Submission status: Wrong Answer

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

nr = s.count("R")
ng = s.count("G")
nb = s.count("B")

count = nr * ng * nb

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

print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
count=0
r_list=[]
g_list=[]
b_list=[]
for i in range(len(s)):
    if s[i]=="R":
        r_list.append(i)
    elif s[i]=="G":
        g_list.append(i)
    elif s[i]=="B":
        b_list.append(i)

for i in range(1,len(s)-1):
    if n%2==0:
        if i<n//2:
            for j in range(1,i+1):
                if s[i]!=s[i-j] and s[i]!=s[i+j] and s[i+j]!=s[i-j]:
                    count+=1
        else:
            for j in range(1,n-i):
                if s[i]!=s[i-j] and s[i]!=s[i+j] and s[i+j]!=s[i-j]:
                    count+=1
    else:
            if i<(n-1)//2:
                for j in range(1,i+1):
                    if s[i]!=s[i-j] and s[i]!=s[i+j] and s[i+j]!=s[i-j]:
                        count+=1
            elif i==(n-1)//2:
                for j in range(1,n-i-1):
                    if s[i]!=s[i-j] and s[i]!=s[i+j] and s[i+j]!=s[i-j]:
                        count+=1
            elif i>(n-1)//2:
                for j in range(1,n-i):
                    if s[i]!=s[i-j] and s[i]!=s[i+j] and s[i+j]!=s[i-j]:
                        count+=1

print(len(r_list)*len(g_list)*len(b_list)-count)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
ans, gap = S.count('R') * S.count('G') * S.count('B'), 1
while gap * 2 + 1 < N:
    ans -= sum([1 for i in range(N - gap * 2)
                if {'R', 'G', 'B'} == {S[i], S[i + gap], S[i + 2 * gap]}])
    gap += 1
print(ans)

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-2):
    for k in range(j+1, n):
      if(j-i != k-j and i<j<k):
        if(s[i] != s[j] and s[j] != s[k] and s[k] != s[i]):
          c+=1
print(c)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = 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(1,(n-1)//2+1): #1から
    for rgb in zip(s,s[i:],s[i*2:]):  #rgbに連続した三つのリストの要素を入れ込む
        if len(set(rgb)) == 3:  #リストrgbをセットにまとめ、長さが
            ans -=1

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

num = 0
for i in range(1, n - 1):
    for j in range(i, n):
        for k in range(j, n + 1):
            if s[i - 1] != s[j - 1] and s[i - 1] != s[k - 1] and s[j - 1] != s[k - 1] and (j - i) != (k - j):
                num += 1
                print("({0}, {1}, {2})".format(i, j, k))
print(num)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
ans = s.count("R")*s.count("G")*s.count("B")

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

print(ans)

Submission status: Wrong Answer

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

from collections import Counter

ans = 1
for t in Counter(s).values():
    ans*=t

for step in range(1,n//2+2):
    for start in range(n):
#         print(start,step,start+2*step,n)
        if start+2*step>=n:
#             print("out!")
            break
        ans-=len(set((s[start], s[start+step],s[start+2*step])))==3
print(ans)

Submission status: Wrong Answer

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

from collections import Counter

ans = 1
for t in Counter(s).values():
    ans*=t

for step in range(1,n//2+2):
    for start in range(n):
#         print(start,step,start+2*step,n)
        if start+2*step>=n:
#             print("out!")
            break
        ans-=len(set((s[start], s[start+step],s[start+2*step])))==3
ans

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):
  for j in range(i+1, n):
    if s[i] != s[j] and s[i] != s[int((i+j)/2)] and s[int((i+j)/2)] != s[j]:
      ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

R, G, B = s.count("R"), s.count("G"), s.count("B")
ans = R * G * B

for i in range(n):
    for j in range(n // 2):
        c1 = i
        c2 = i + j
        c3 = i + j * 2
        if c3 >= n: continue
        if c1 == c2 == c3: continue
        if s[c1] != s[c2] and s[c2] != s[c3] and s[c1] != s[c3]:
            ans -= 1

print(ans)
# 012 024 036 048
# 123 135 147 159

Submission status: Wrong Answer

Solution code:
from functools import lru_cache
N = int(input())
S =input()
a = 0
for i in range(N-2):
  for j in range(i,N-1):
    for k in range(j,N):
      if S[i] != S[j] and S[i] != S[k] and S[k] != S[j] and j -i != k-j:
        a+= 1
        print(a)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
r=g=b=0
for i in s:
  if i=="R":r+=1
  elif i=="G":g+=1
  else:b+=1
print(r,g,b)

ans=r*g*b

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

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
r=g=b=0
for i in s:
  if i=="R":r+=1
  elif i=="G":g+=1
  else:b+=1
print(r,g,b)

ans=r*g*b

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

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
r=g=b=0
for i in s:
  if i=="R":r+=1
  elif i=="G":g+=1
  else:b+=1
print(r,g,b)

ans=r*g*b

for i in range(1,n):
  for j in range(n):
    if j+i+i>=n:break
    if not(s[j]==s[j+i] or s[j+i]==s[j+i+i] or s[j]==s[j+i+i]):ans-=1
print(ans)

Submission status: Wrong Answer

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

print(S)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
"""
全体で一つ目の条件を満たす組み合わせはrgb
2個目の条件を見るにはr,gの位置を固定したときにbが3つが等間隔になるように並ばないことを確認すればいい
"""

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

for i,j in enumerate(s):
    if j == "R":
        r.append(i)
    elif j == "G":
        g.append(i)
    else:
        b.append(i)
cnt = len(r)*len(g)*len(b)
print(cnt)
for i in r:
    for j in g:
        if (i+j)/2 in b:
            cnt = cnt -1
        if (abs(i-j) + max(i,j)) in b:
            cnt = cnt -1
        if (min(i,j) - abs(i-j)) in b:
            cnt = cnt -1

print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
s = list(input())
counts = dict(Counter(s))
all = 1
for i in counts.values():
    all *= i
sub = 0
for i in range(N-1):
    for j in range(i+1,N):
        if s[i]==s[j]:
            continue
        k = 2*j - i
        if k >= N:
            continue
        else:
            if (s[k]!=s[i] and s[k]!=s[j]):
                sub += 1
print(all-sub)

Submission status: Wrong Answer

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

cnt = {}
for Si in S:
    cnt[Si] = cnt.setdefault(Si, 0) + 1

ans = 1    
for key, val in cnt.items():
    ans *= val
# print("#", ans)
    
for i in range(N):
    for j in range(i + 1, N):
        k = 2 * j - i
        if k >= N: continue
        #
        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:
N = int(input())
S = input()
R = S.count('R')
G = S.count('G')
B = N-R-G
ans = R*G*B
for d in range(1,N//2):
    for i in range(N):
        if i + d*2 >= N: break
        a,b,c = S[i],S[i+d],S[i+d+d]
        if a!=b and b!=c and c!=a:
            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")
cnt = 0
for i in range(n-3):
    i_ = s[i]
    for j in range(i+1, n-1):
        if s[j] == i_: continue
        k = 2 * j - i
        j_ = s[j]
        if k >= n or s[k] == i_ or s[k] == j_: continue
        cnt += 1
print(ans - cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(input())
#print(N,A)

R=A.count('R')
G=A.count('G')
B=A.count('B')
#print(R,G,B,'R,G,B')
RGB=R*G*B
#print(RGB,'R*G*B')

#for i in range(0,N)
R_Number=[i for i, x in enumerate(A) if x == 'R']
G_Number=[i for i, x in enumerate(A) if x == 'G']
B_Number=[i for i, x in enumerate(A) if x == 'B']

# 数値を+1する関数
def calc_plas(n):
    return n + 1
 
R_Number = list(map(calc_plas, R_Number)) 
G_Number = list(map(calc_plas, G_Number)) 
B_Number = list(map(calc_plas, B_Number)) 

#print(R_Number,'R_Number',G_Number,'G_Number',B_Number,'B_Number')

for i in range(0,len(G_Number)):
    G_Number[i]=G_Number[i]*2
    
Hantei=[]    
for j in range(0,len(R_Number)):
    for k in range(0,len(B_Number)):
        Hantei.append(R_Number[j]+B_Number[k])
    
#print(Hantei,'Hantei',G_Number,'G_Number_twice')

counts=0
for i in range(0,len(Hantei)):
    for j in range(0,len(G_Number)):
        if Hantei[i]==G_Number[j]:
            counts+=1
#print(counts,'counts',len(Hantei))
print(RGB-counts)#,'Answer0')

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from bisect import bisect_left
n = int(input())
s = input()
c = 0
f = defaultdict(list)
for i in range(n):
	f[s[i]].append(i)
R, G, B = len(f['R']), len(f['G']), len(f['B'])
for i in range(n):
	for j in range(i+1, n):
		if  s[i] != s[j]:
			for k in f:
				if k != s[i] and k != s[j]:
					t = bisect_left(f[k], j+1)
					c += len(f[k][t:])
print(c)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
 
r = S.count('R')
g = S.count('G')
b = S.count('B')
max = r * g * b 
 
count = 0
for i in range(N-2):
	for j in range(i+1, N-1):
		k = 2 * j - i
		if k > N - 1:
			break
	
		if S[i] != S[j] and S[j] != S[k] and S[i] == S[k]:
			count += 1
		
		
 
print(max - count)

Submission status: Wrong Answer

Solution code:
def main():
    n, s = int(input()), input()
    r, g, b = 0, 0, 0
    for i in s:
        if i == 'R':
            r += 1
        if i == 'G':
            g += 1
        if i == 'b':
            b += 1

    ans = r * g * b
    s = tuple(s)
    v = {'R', 'G', 'B'}
    for i in range(n - 2):
        for j in range(n // 2 + 1):
            if i + j + j < n:
                if v == {s[i], s[i + j], s[i + j + j]}:
                    ans -= 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

r = str.count('R')
g = str.count('G')
b = str.count('B')
sum = r * g * b
for i in range(n-2):
  for j in range(i+1, n-1):
    k = 2 * j - i
    if k < n:
      if str[i] == str[j] or str[i] == str[k] or str[j] == str[k] :
        sum -= 1
    
print(sum)