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:
#!/usr/bin/env python3
import sys
import collections

def solve(N: int, S: str):
    counter = collections.defaultdict(int)
    for s in S:
        counter[s] += 1
    result = 1
    for k, v in counter.items():
        result *= v

    notcounter = 0
    for i in range(N):
        for j in range(i+1, N):
            diff = j - i
            if j + diff >= N:
                break
            if (S[i]!=S[j]) and (S[j]!=S[j+diff]) and (S[i]!=S[j+diff]):
                notcounter += 1
    print(result - notcounter)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
inp = sys.stdin.buffer.readline                               
def I(): return list(map(int,inp().split()))
from collections import Counter
from numpy import prod

n=I()[0]
s=input() 
cut=0
for i in range(len(s)):
    for j in range(i+1,len(s)):
        if 2*j-i>=len(s): break
        if len({s[i],s[j],s[2*j-i]})==3:
            cut+=1
d=Counter(s)
print(prod(list(d.values()))-cut)

Submission status: Wrong Answer

Solution code:

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

kumikazu = s.count('R')*s.count('B')*s.count('G')

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

print(kumikazu)

Submission status: Wrong Answer

Solution code:

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

kumikazu = s.count('R')*s.count('B')*s.count('G')

for i in range(n-2):
    for j in range(n-1):
        k = 2*j-i
        if k > n-1:
            break
        if (s[i] != s[j]) and (s[i] != s[k]) and (s[j] != s[k]):
            kumikazu -= 1

print(kumikazu)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
import math
# for AtCoder
# import fractions
from collections import deque 
from functools import reduce

input = sys.stdin.readline

n = int(input())

s = input()

s_np = np.array(s)

R_idx = [i for i, x in enumerate(s) if x == 'R']
G_idx = [i for i, x in enumerate(s) if x == 'G']
B_idx = [i for i, x in enumerate(s) if x == 'B']

cnt = 0
for R_i in R_idx:
    for G_i in G_idx:
        for B_i in B_idx:
            if abs(R_i - G_i) == abs(G_i - B_i):
                continue
            if abs(R_i - B_i) == abs(G_i - B_i):
                continue
            if abs(R_i - G_i) == abs(R_i - B_i):
                continue
            else:
                cnt += 1

Submission status: Wrong Answer

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

sum_R = 0
sum_B = 0
sum_G = 0

for i in range(N):
    if S[i] == "R":
        sum_R = sum_R +1
    if S[i] == "G":
        sum_G = sum_G+1
    if S[i] == "B":
        sum_B = sum_B +1
     
sum_A = sum_R*sum_G*sum_B

M = int((N-1)/2)

for j in range(1,M+1):
    for i in range(j):
        if S[i]!=S[j] and S[j]!=S[j+(j-i)] and S[i]!=S[j+(j-i)]:
            sum_A -=1

if N % 2 == 0:
    for i in range(1,M+1):
        if S[i] != S[M+1] and S[M+1] != S[2*(M+1)-(i)] and S[i] != S[2*(M+1)-(i)]:
            sum_A -= 1
    
print(sum_A)

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import math

    
def main():
	num = int(input())
	moji = input()
	count = 0
	
	for i in range(num):
		point = i
		if moji[i] == 'R':
			while not moji.find('G',point+1) == -1:
				count += moji[moji.find('G',point+1):].count('B')
#				print (str(i)+" "+str(moji.find('G',point+1))+" "+str(moji[moji.find('G',point+1):].count('B')))
				if len(moji) > moji.find('G',point+1)+moji.find('G',point+1)-i:
					if moji[moji.find('G',point+1)+moji.find('G',point+1)-i] == 'B':
						count -= 1
#						print (-1)
				point = moji.find('G',point+1)
			point = i
			while not moji.find('B',point+1) == -1:
				count += moji[moji.find('B',point+1):].count('G')
				if len(moji) > moji.find('B',point+1)+moji.find('B',point+1)-i:
					if moji[moji.find('B',point+1)+moji.find('B',point+1)-i] == 'G':
						count -= 1
				point = moji.find('B',point+1)
		elif moji[i] == "G":
			while not moji.find('R',point+1) == -1:
				count += moji[moji.find('R',point+1):].count('B')
				print (str(i)+" "+str(moji.find('R',point+1))+" "+str(moji[moji.find('R',point+1):].count('B')))
				if len(moji) > moji.find('R',point+1)+moji.find('R',point+1)-i:
					if moji[moji.find('R',point+1)+moji.find('R',point+1)-i] == 'B':
						count -= 1
						print (-1)
				point = moji.find('R',point+1)
			point = i
			while not moji.find('B',point+1) == -1:
				count += moji[moji.find('B',point+1):].count('R')
				print (str(i)+" "+str(moji.find('B',point+1))+" "+str(moji[moji.find('B',point+1):].count('R')))
				if len(moji) > moji.find('B',point+1)+moji.find('B',point+1)-i:
					if moji[moji.find('B',point+1)+moji.find('B',point+1)-i] == 'R':
						count -= 1
						print (-1)
				point = moji.find('B',point+1)
		elif moji[i] == "B":
			while not moji.find('G',point+1) == -1:
				count += moji[moji.find('G',point+1):].count('R')
				print (str(i)+" "+str(moji.find('G',point+1))+" "+str(moji[moji.find('G',point+1):].count('R')))
				if len(moji) > moji.find('G',point+1)+moji.find('G',point+1)-i:
					if moji[moji.find('G',point+1)+moji.find('G',point+1)-i] == 'R':
						count -= 1
						print (-1)
				point = moji.find('G',point+1)
			point = i
			while not moji.find('R',point+1) == -1:
				count += moji[moji.find('R',point+1):].count('G')
				print (str(i)+" "+str(moji.find('R',point+1))+" "+str(moji[moji.find('R',point+1):].count('G')))
				if len(moji) > moji.find('R',point+1)+moji.find('R',point+1)-i:
					if moji[moji.find('R',point+1)+moji.find('R',point+1)-i] == 'G':
						count -= 1
						print (-1)
				point = moji.find('R',point+1)
	
	print (count)

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
c =0

N = int(input())+1
S = input()


for i in range(1,N):
    if i > N:
        continue
    for j in range(1,N):
        if j>N:
            continue
        for k in range(1,N):
            
            if j > k or i > j:
                continue
            elif k>N:
                continue
            elif S[i-1] == S[k-1] or S[j-1] == S[k-1] or S[i-1] == S[j-1]:
                continue
            elif j - i == k - j:
                continue
            else:
                c += 1
                print(i,j,k)
print(c)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import itertools

def main():
  N = int(stdin.readline())
  sentence = stdin.readline()
  
  ans = 0
  
  for (x, y, z) in itertools.combinations(range(N), 3):
    if x - y != y - z:
        if (sentence[x] != sentence[y]) & (sentence[y] != sentence[z]):
            ans += 1
      
  print(ans)
  
if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
A = int(input())
B = input()
count_r = B.count("R")
count_g = B.count("G")
count_b = B.count("B")
ans = count_b * count_g * count_r
for i in range(A):
    for j in range(A):
        d = i+j
        f = d+j
        if f >= A:
            break
        if B[i] != B[d] != B[f]:
            ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
c =0

N = int(input())
S = input()
for i in range(1,N+1):
    for j in range(1,N+1):
        for k in range(1,N+1):
            if i > j or j > k:
                continue
            elif S[i-1] == S[j-1]:
                continue
            elif S[i-1] == S[k-1]:
                continue
            elif S[j-1] == S[k-1]:
                continue
            elif j - i == k - j:
                continue
            else:
                c += 1
                print(i,j,k)
print(c)

Submission status: Wrong Answer

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

# RGBそれぞれの字数カウント
R = S.count('R')
G = S.count('G')
B = S.count('B')

# 条件２の対象数カウント
ad = R * G * B
ed = 0

for i in range(0, N):
  for j in range(1, N):
    if (i + j) >= N or (i + j * 2) >= N:
      break
    # 判定
    if S[i] != S[i+j] and S[j] != S[i+j*2] and S[i+j*2] != S[i+j]:
      ed += 1

print(ad-ed)

Submission status: Wrong Answer

Solution code:
c =0

N = int(input())
S = input()
for i in range(0,N):
    for j in range(0,N):
        for k in range(0,N):
            print('k',k)
            if i > j or j > k:
                continue
            elif S[i] == S[j]:
                continue
            elif S[i] == S[k]:
                continue
            elif S[j] == S[k]:
                continue
            elif (j - i) == (k - j):
                continue
            else:
                c += 1
print(c)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
s=input()
l=list(s)
c=Counter(l)
d=dict(c)
sum=1
for key,value in d.items():
    sum=sum*value
R=[]
B=[]
G=[]
r=0
b=0
g=0
for i in range(len(s)):
    if s[i]=='R':
        R.append(i)
        r+=1
    elif s[i]=='B':
        B.append(i)
        b+=1
    else:
        G.append(i)
        g+=1

if r>g:R,G=G,R
if b>g:B,G=G,B

for i in R:
    for j in B:
        k=max(i,j)+abs(i-j)
        if k in G:sum-=1
        k=min(i,j)-abs(i-j)
        if k in G:sum-=1
        k=(i+j)/2
        if k in G:sum-=1
print(sum)

Submission status: Wrong Answer

Solution code:
a=int(input())
moji=input()
r=[]
g=[]
b=[]
for i in range(a):
    if moji[i]=="R":
        r.append(i)
    elif moji[i]=="G":
        g.append(i)
    else:
        b.append(i)
res=len(r)*len(g)*len(b)
if len(r)==0 or len(g)==0 or len(b)==0:
    print(0)
else:
    min_len={0:r,1:g,2:b}
    if len(min_len[0])>len(min_len[1]):
        tmp=min_len[0]
        min_len[0]=min_len[1]
        min_len[1]=tmp
    if len(min_len[1])>len(min_len[2]):
        tmp=min_len[1]
        min_len[1]=min_len[2]
        min_len[2]=tmp
    if len(min_len[0])>len(min_len[1]):
        tmp=min_len[0]
        min_len[0]=min_len[1]
        min_len[1]=tmp
    a1=[]
    for i in range(3):
        a1.append(min_len[i])
    
    for i in a1[0]:
        for j in a1[1]:
            if 2*max(i,j)-min(i,j) in a1[2]:
                res-=1
    print(res)

Submission status: Wrong Answer

Solution code:
a=int(input())
moji=input()
r=[]
g=[]
b=[]
for i in range(a):
    if moji[i]=="R":
        r.append(i)
    elif moji[i]=="G":
        g.append(i)
    else:
        b.append(i)
res=len(r)*len(g)*len(b)
if len(r)==0 or len(g)==0 or len(b)==0:
    print(0)
else:
    min_len={0:r,1:g,2:b}
    if len(min_len[0])>len(min_len[1]):
        tmp=min_len[0]
        min_len[0]=min_len[1]
        min_len[1]=tmp
    if len(min_len[1])>len(min_len[2]):
        tmp=min_len[1]
        min_len[1]=min_len[2]
        min_len[2]=tmp
    if len(min_len[0])>len(min_len[1]):
        tmp=min_len[0]
        min_len[0]=min_len[1]
        min_len[1]=tmp
    a1=[]
    for i in range(3):
        a1.append(min_len[i])
    I=a1[0]
    J=a1[1]
    K=a1[2]
    for i in I:
        for j in J:
            dif=abs(i-j)
            min_i_j=min(i,j)
            max_i_j=max(i,j)
            if -dif+min_i_j in K:
                res-=1
            elif dif+max_i_j in K:
                res-=1
            elif dif%2==0 and  int(dif/2)+min_i_j in K:
                res-=1
    print(res)

Submission status: Wrong Answer

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

import numpy as np 

# Input Stdin
## 1 <= N <= 4000
## S = R/G/B length(N)

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

time0 = time.time()

num = 0
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] and (j - i) != (k - j):
                #print(str(i) + str(j) + str(k) + ' ' + S[i] + S[j] + S[k])
                num = num + 1
                
print(num)

time1 = time.time()
print('{0:.3f}s'.format(time1 - time0))

Submission status: Wrong Answer

Solution code:
#author : dokueki

import sys
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)
sys.setrecursionlimit(10**7)
mod = 1000000007


def IOE():
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("output.txt", "w")


def main():
    n = int(sys.stdin.readline())
    s = input()
    r = [i + 1 for i in range(n) if s[i] == "R"]
    g = [i + 1 for i in range(n) if s[i] == "G"]
    b = [i + 1 for i in range(n) if s[i] == "B"]
    r, g, b = set(r), set(g), set(b)
    tot = len(r) * len(g) * len(b)
    for i in r:
        for j in g:
            if abs(j - i) in b:
                tot -= 1
            if abs(2 * j - i) in b:
                tot -= 1

    print(tot)


if __name__ == "__main__":
    try:
        IOE()
    except:
        pass
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
r = len(S.replace("G", "").replace("B", ""))
g = len(S.replace("R", "").replace("B", ""))
b = N - r - g

ans = r * g
ans = ans * b

for i in range( N ):
    for j in range(i+1, int((N+i)/2 )):
        k = 2 * j - i
        if k < N:
            s = S[i] + S[j] + S[k]
            if ("R" in s) & ("G" in s) & ("B" in s):
                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')

ret = r*g*b

for i in range(1,int(n/2)):
	for j in range(0,n-2*i):
		if(s[j] != s[j+i]) and (s[j+i] != s[j+2*i]) and (s[j+2*i] != s[j]):
			ret -= 1
#			print("i:%d j:%d " %(i,j), s[j],s[j+i],s[j+2*i]," !!")
#		else:
#			print("i:%d j:%d " %(i,j), s[j],s[j+i],s[j+2*i])

print(ret)

Submission status: Wrong Answer

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

ans = S.count("R")*S.count("G")*S.count("B")

tmp=0

for i in range(N):
  for j in range(i,N):
    if j-i+j < N:
      if S[i]==S[j] and S[j]==S[j-i+j] and S[i]==S[j-i+j]:
        tmp += 1

ans = ans - tmp
print(ans)

Submission status: Wrong Answer

Solution code:
N,=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
st,=map(str, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
sum=0
st = list(st)

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

Submission status: Wrong Answer

Solution code:
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
con1 = R*G*B

#j-i = k-j　を引く
con2 =0
if N <=3: con2 =0
else:
    for i in range(N-3):
        for j in range(i+1, N-1):
            if j < 2*j - i <= N-1:
                if S[i] != S[2*j-i] and S[j] !=S[2*j-i] and S[i] != S[j]:
                    con2 +=1

print(con1-con2)

Submission status: Wrong Answer

Solution code:
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
con1 = R*G*B

#j-i = k-j　を引く
con2 =0
if N <=3: con2 =0
else:
    for i in range(N-3):
        for j in range(i+1, N-2):
            if j < 2*j - i <= N-1:
                if S[i] != S[2*j-i] and S[j] !=S[2*j-i] and S[i] != S[j]:
                    con2 +=1

print(con1-con2)

Submission status: Wrong Answer

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

val = 0

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

print(val)

Submission status: Wrong Answer

Solution code:
import sys
from random import choice,randint
inp=sys.stdin.readline
out=sys.stdout.write
flsh=sys.stdout.flush
 
sys.setrecursionlimit(10**9)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
 
def MI(): return map(int, inp().strip().split())
def LI(): return list(map(int, inp().strip().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]
def LI_(): return [int(x)-1 for x in inp().strip().split()]
def LF(): return [float(x) for x in inp().strip().split()]
def LS(): return inp().strip().split()
def I(): return int(inp().strip())
def F(): return float(inp().strip())
def S(): return inp().strip()
def pf(s): return out(s+'\n')
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

def main():
    n = I()
    s = S()
    c=0
    for i in range(n):
        for j in range(i+1,n):
            for k in range(j+1,n):
                if j-i!=k-j:
                    if s[i]!=s[j] and s[j]!=s[k]:
                        c+=1
    print(c)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3


def remain(a, b):
    if a == 'R':
        if b == 'G':
            return 'B'
        else:
            return 'G'
    elif a == 'G':
        if b == 'R':
            return 'B'
        else:
            return 'R'
    else:
        # a == 'B'
        if b == 'R':
            return 'G'
        else:
            return 'R'
    

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

cs = {}

cs['R'] = [ 0 for i in range(n) ]
cs['G'] = [ 0 for i in range(n) ]
cs['B'] = [ 0 for i in range(n) ]

for i in range(-1, - n - 1, -1):
    if i == -1:
        if s[-1] == 'R':
            cs['R'][-1] = 1
        elif s[-1] == 'G':
            cs['G'][-1] = 1
        elif s[-1] == 'B':
            cs['B'][-1] = 1
    else:
        if s[i] == 'R':
            cs['R'][i] = cs['R'][i + 1] + 1
            cs['G'][i] = cs['G'][i + 1]            
            cs['B'][i] = cs['B'][i + 1]
        elif s[i] == 'G':
            cs['R'][i] = cs['R'][i + 1]
            cs['G'][i] = cs['G'][i + 1] + 1
            cs['B'][i] = cs['B'][i + 1]            
        elif s[-1] == 'B':
            cs['R'][i] = cs['R'][i + 1]
            cs['G'][i] = cs['G'][i + 1]            
            cs['B'][i] = cs['B'][i + 1] + 1                        

            
c = 0
for i in range(n):
    for j in range(i + 1, n):
        if s[i] != s[j]:
            r = remain(s[i], s[j])
            c += cs[r][j]
            if j + j - i < n and s[j + j - i] == r:
                c -= 1
            
print(c)

Submission status: Wrong Answer

Solution code:
def function(s):
  ans = 0
  for i in range(len(s) - 2):
    for j in range(i + 1, len(s) - 1):
      if s[i] != s[j]:
        if j + j - i + 1 <= len(s):
          for k in range(2 * j - i + 1, len(s)):
            if s[i] != s[k] and s[j] != s[k]:
              ans += 1
  return ans

n = input()
s = input()

print(function(s))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

#output
from collections import Counter
answer = 0
if N <= 3:
    print(0)
else:
    for i in range(N-2):
        for j in range(i+1, N-1):
            k = 2*j-i
            if S[i] == "R":
                if S[j] == "G":
                    answer += Counter(S[j+1:])["B"]
                    if k < N:
                        if S[k] == "B":
                            answer -= 1
                elif S[j] == "B":
                    answer += Counter(S[j+1:])["G"]
                    if k < N:
                        if S[k] == "G":
                            answer -= 1
            elif S[i] == "G":
                if S[j] == "R":
                    answer += Counter(S[j+1:])["B"]
                    if k < N:
                        if S[k] == "B":
                            answer -= 1
                elif S[j] == "B":
                    answer += Counter(S[j+1:])["R"]
                    if k < N:
                        if S[k] == "R":
                            answer -= 1
            elif S[i] == "B":
                if S[j] == "R":
                    answer += Counter(S[j+1:])["G"]
                    if k < N:
                        if S[k] == "G":
                            answer -= 1
                elif S[j] == "G":
                    answer += Counter(S[j+1:])["R"]
                    if k < N:
                        if S[k] == "R":
                            answer -= 1
                
print(answer)

Submission status: Wrong Answer

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

#output
from collections import Counter
answer = 0
if N <= 3:
    print(0)
else:
    for i in range(N-2):
        for j in range(i+1, N-1):
            k = 2*j-i
            if S[i] == "R":
                if S[j] == "G":
                    answer += Counter(S[j:])["B"]
                    if k < N:
                        if S[k] == "B":
                            answer -= 1
                elif S[j] == "B":
                    answer += Counter(S[j:])["G"]
                    if k < N:
                        if S[k] == "G":
                            answer -= 1
            elif S[i] == "G":
                if S[j] == "R":
                    answer += Counter(S[j:])["B"]
                    if k < N:
                        if S[k] == "B":
                            answer -= 1
                elif S[j] == "B":
                    answer += Counter(S[j:])["R"]
                    if k < N:
                        if S[k] == "R":
                            answer -= 1
            elif S[i] == "B":
                if S[j] == "R":
                    answer += Counter(S[j:])["G"]
                    if k < N:
                        if S[k] == "G":
                            answer -= 1
                elif S[j] == "G":
                    answer += Counter(S[j:])["R"]
                    if k < N:
                        if S[k] == "R":
                            answer -= 1
                
print(answer)

Submission status: Wrong Answer

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

#output
from collections import Counter
answer = 0
if N <= 3:
    print(0)
else:
    for i in range(N-2):
        for j in range(i+1, N-1):
            if S[i] == "R":
                if S[j] == "G":
                    answer += Counter(S[j:])["B"]
                    if j < 2*j - i < N and S[2*j -i] == "B":
                        answer -= 1
                elif S[j] == "B":
                    answer += Counter(S[j:])["G"]
                    if j < 2*j - i < N and S[2*j- i] == "G":
                        answer -= 1
            elif S[i] == "G":
                if S[j] == "R":
                    answer += Counter(S[j:])["B"]
                    if j < 2*j - i < N and S[2*j -i] == "B":
                        answer -= 1
                elif S[j] == "B":
                    answer += Counter(S[j:])["R"]
                    if j< 2*j - i < N and S[2*j -i] == "R":
                        answer -= 1
            elif S[i] == "B":
                if S[j] == "R":
                    answer += Counter(S[j:])["G"]
                    if j < 2*j - i < N and S[2*j-i] == "G":
                        answer -= 1
                elif S[j] == "G":
                    answer += Counter(S[j:])["R"]
                    if j < 2*j - i < N and S[2*j -i] == "R":
                        answer -= 1
                
print(answer)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
r, g, b = map(s.count, "RGB")
ans = r*g*b
for i in range(n-2):
    for j in range(i, n-1):
        k = 2*j - i
        if k < n and s[i] != s[j] != s[k]:
            ans -= 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

r_num = s.count("R")
g_num = s.count("G")
b_num = s.count("B")

ans = r_num * b_num * g_num

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

        if (s[i] == s[j] or 
            s[j] == s[k] or
            s[i] == 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')
ans=r*g*b
for i in range(1,(n+1)//2):
  for j in range(n-2*i):
    print(s[j],s[j+i],s[j+2*i])
    if len(set([s[j],s[j+i],s[j+2*i]]))==3:
      print(j,j+i,j+2*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=s.count('B')
ans=r*g*b
for i in range(n//2):
  for j in range(n-2*i):
    if len(set([s[j],s[j+i],s[j+2*i]]))==3:
      ans-=1
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
from itertools import combinations_with_replacement

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

rgb = 'RGB'

nr = S.count(rgb[0])
ng = S.count(rgb[1])
nb = N - nr - ng
nlst = np.array([nr, ng, nb])

nmax = np.argmax(nlst)
nmin = np.argmin(nlst)

minlst, midlst = [], []
maxlst = [0]*N

for i, s in enumerate(S):
    if s==rgb[nmax]:maxlst[i] = 1
    elif s==rgb[nmin]:minlst.append(i)
    else: midlst.append(i)
minlst.sort()
midlst.sort()
      
ans = 0

for midl in midlst:
    for minl in minlst:
        mm = abs(midl - minl)
        if min(minl, midl) - mm >= 0:
            if maxlst[min(minl, midl) - mm]: ans += 1
        if max(minl, midl) + mm <= N-1:
            if maxlst[max(minl, midl) + mm]: ans += 1
        if mm % 2 == 0 and maxlst[(minl + midl) // 2]: ans += 1

print(nr * ng * nb - ans)

Submission status: Wrong Answer

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

#output
answer = 0
if N <= 3:
    print(0)
else:
    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]:
                    if S[j] != S[k]:
                        if S[k] != S[i]:
                            if j-i != k-j:
                                answer += 1
                
print(answer)

Submission status: Wrong Answer

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

#output
answer = 0
if N <= 3:
    print(0)
else:
    for i in range(N-2):
        for j in range(i+1, N-1):
            for k in range(j+1, N):
                if S[i] != S[j] and S[j] != S[k] and S[k] != S[i] and j-i != k-j:
                    answer += 1
                
print(answer)

Submission status: Wrong Answer

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


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

print(count)

Submission status: Wrong Answer

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

count = 0
for i in range(n-2):
	lis = []
	lis.append(s[i])
	for j in range(i+1,n-1):
		if not s[j] in lis :
			lis.append(s[j])
			for k in range(j+1,n):
				if not s[k] in lis :
					if j-i != k-j:
						count += 1

print(count)

Submission status: Wrong Answer

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

count = 0
for i in range(n-2):
	lis = []
	lis.append(s[i])
	for j in range(i+1,n-1):
		if not s[j] in lis :
			lis.append(s[j])
			for k in range(j+1,n):
				if not s[k] in lis :
					count += 1

print(count)

Submission status: Wrong Answer

Solution code:


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

cnt = S.count('B')*S.count('G')*S.count('R')
# for i in range(1,N-1):
#     for j in range(i+1,N):
#         if S[i-1] != S[j-1]:
#             for k in range(j+1,N+1):
#                 if S[i-1]!=S[k-1] and S[j-1]!=S[k-1] and j-i!=k-j:
#                     cnt += 1
for i in range(1,N-1):
    for j in range(i+1,N):
        k = 2*j-i
        if k>j and k<=N:
            if S[i-1]==S[j-1] or S[i-1]==S[k-1] or S[j-1]==S[k-1] :
                cnt -= 1


print(cnt)

Submission status: Wrong Answer

Solution code:


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

cnt = 0
# for i in range(1,N-1):
#     for j in range(i+1,N):
#         if S[i-1] != S[j-1]:
#             for k in range(j+1,N+1):
#                 if S[i-1]!=S[k-1] and S[j-1]!=S[k-1] and j-i!=k-j:
#                     cnt += 1
for i in range(1,N-1):
    for j in range(i+1,N):
        k = 2*j-i
        if k>j and k<=N:
            if S[i-1]==S[j-1] or S[i-1]==S[k-1] or S[j-1]==S[k-1] :
                cnt += 1


print(N-cnt)

Submission status: Wrong Answer

Solution code:
import itertools

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

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)))

# print("r:{}, g:{}, b:{}".format(r, g, b))

ans = r * g * b
RGB = list(itertools.permutations(["R", "G", "B"], 3))

# print(RGB)

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

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

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

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)))

# print("r:{}, g:{}, b:{}".format(r, g, b))

ans = r * g * b
RGB = itertools.permutations(["R", "G", "B"], 3)
for i in range(1, N):
    for j in range(1, N-i*2):
        if (S[j], S[j+i], S[j+2*i]) in RGB:
            ans -= 1

print(ans)