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

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

ans = 0

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

if len(R) > len(G):
    R, G = G, R
if len(G) > len(B):
    G, B = B, G
print(len(R), len(G), len(B))

for r in R:
    for g in G:
        ans += len(B)
        if (g + r) / 2 in B:
            ans -= 1
        elif (2 * g - r) in B:
            ans -= 1
        elif (2 * r - g) in B:
            ans -= 1
print(ans)

Submission status: Wrong Answer

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

upper = s.count("R")*s.count("G")*s.count("B")

def counting(x):
  count = 0
  for i in range(math.ceil(x/2)):
    if s[x-1]!=s[x-1-i] and s[x-1-i]!=s[x-1-2*i] and s[x-1-2*i]!=s[x-1]:
      count += 1
    else:
      count += 0
  return count

if n>=3:
  minus = [0]*(n+1)
  if s[0]!=s[1] and s[1]!=s[2] and s[2]!=s[0]:
    minus [3] = 1
  else:
    minus [3] = 0
  for i in range(4,n):
    minus[i+1] = minus[i]+counting(i+1)
  print(int(upper-minus[n]))
else:
  print(int(0))

Submission status: Wrong Answer

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

upper = s.count("R")*s.count("G")*s.count("B")

minus = [0]*(n+1)
if s[0]!=s[1] and s[1]!=s[2] and s[2]!=s[0]:
  minus [3] = 1
else:
  minus [3] = 0

def counting(x):
  count = 0
  for i in range(math.ceil(x/2)):
    if s[x-1]!=s[x-1-i] and s[x-1-i]!=s[x-1-2*i] and s[x-1-2*i]!=s[x-1]:
      count += 1
    else:
      count += 0
  return count

for i in range(4,n):
  minus[i+1] = minus[i]+counting(i+1)

print(int(upper-minus[n]))

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')
tot = r_num*g_num*b_num
print(tot)
for i in range(n):
    for j in range(i+1,n):
        k = j+(j-i)

        if k<n:
            if s[i]!=s[j] and s[i]!=s[k] and s[j] != s[k]:
                tot -= 1

print(tot)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
N=int(input())
S=[str(input()) for _ in range(N)]
t=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[j-1]!=S[k-1] and S[k-1]!=S[i-1] and j-i!=k-j:
        t+=1
print(t)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


def resolve():
    s = input()

    cnt = defaultdict(int)
    cnt[0] += 1
    tmp = 0
    for i, c in enumerate(s[::-1]):
        c = int(c)
        tmp = (tmp + c * pow(10, i, 2019)) % 2019
        cnt[tmp] += 1

    ans = sum(c * (c - 1) // 2 for c in cnt.values())
    print(ans)


resolve()

Submission status: Wrong Answer

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

import collections
import numpy as np
c = collections.Counter(S)
ans = 1
for item in c.values():
    ans*=item

for i in range(N):
    for j in range(i+1,N):
        k =  j+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:
N = int(input())
S = input()

import collections
import numpy as np
c = collections.Counter(S)
ans = 1
for item in c.values():
    ans*=item

for i in range(N):
    for j in range(i,N):
        k =  j+j-i
        if k > N-1:
            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 = list(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(N):
    k = 2*j-i
    if k <= N-1:
      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:
import sys
def input():
    return sys.stdin.readline()[:-1]

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

from collections import defaultdict
d = defaultdict(int)

for i in range(N):
    s = S[i]
    d[s] += 1
cnt = 0
for i in range(N-2):
    for j in range(i,N-1):
        k = 2*j - i
        if k <= N-1 and (S[i] != S[j] and S[j] != S[k] and S[k] != S[i]):
            cnt += 1
if d["R"] and d["G"] and d["B"]:
    ans = d["R"] * d["G"] * d["B"] - cnt
    print(ans)

Submission status: Wrong Answer

Solution code:
import statistics as st
n = int(input())
s = input()
NGs = 0
r = set()
g = set()
b = set()
for i in range(n):
  if s[i] == "R":
    r.add(i)
  elif s[i] == "G":
    g.add(i)
  else:
    b.add(i)
for x in r:
  for y in g:
    if y*2-x in b: #x<y<z or z<y<x
      NGs += 1
    elif (x+y)%2 == 0 and (x+y)//2 in b: #x<z<y or y<z<x
      NGs += 1
    elif x*2-y in b: #y<x<z or z<x<y
      NGs += 1
print(len(r)*len(g)*len(b)-NGs)

Submission status: Wrong Answer

Solution code:
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)
for i in r:
  for j in g:
    for k in b:
      if j-i != k-j:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n=int(input())
s=input()

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

for i in range(0,n):
    if s[i]=='R':
        r.append(i)

    elif s[i]=='G':
        g.append(i)

    elif s[i]=='B':
        b.append(i)

s=0
rl=len(r)
gl=len(g)
bl=len(b)
ml=max(rl,gl,bl)
if  ml==rl:
    d1=r
    d2=g
    d3=b
elif ml==gl:
    d1=g
    d2=r
    d3=b
else:
    d1=b
    d2=g
    d3=r

for i1 in d2:
    for i2 in d3:
        if (min(i1,i2)-np.abs(i1-i2)) in d1 or (max(i1,i2)+np.abs(i1-i2)) or (i1+i2)/2.0 in d1:
            s+=1

s2=rl*gl*bl-s
print(s2)

Submission status: Wrong Answer

Solution code:
import numpy as np
n=int(input())
s=input()

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

for i in range(0,n):
    if s[i]=='R':
        r.append(i)

    elif s[i]=='G':
        g.append(i)

    elif s[i]=='B':
        b.append(i)

s=0
rl=len(r)
gl=len(g)
bl=len(b)
ml=max(rl,gl,bl)
if  ml==rl:
    d1=r
    d2=g
    d3=b
elif ml==gl:
    d1=g
    d2=r
    d3=b
else:
    d1=b
    d2=g
    d3=r

for i1 in d2:
    for i2 in d3:
        if (min(i1,i2)-np.abs(i1-i2)) in d1 or (max(i1,i2)+np.abs(i1-i2)) or (i1+i2)/2.0 in d1:
            s+=1
        

s2=rl*gl*bl-s
print(s2)

Submission status: Wrong Answer

Solution code:
N=input()
S=input()
Sn=[]
R=0
G=0
B=0
for i in range(len(S)):
    if S[i]=='R':
        R+=1
        Sn.append(1)
    elif S[i]=='G':
        G+=1
        Sn.append(2)
    else:
        B+=1
        Sn.append(3)

count=0
for start in range(len(S)):
        for diff in range(1,int((len(S)-start+1)/2)):
            print(start,diff)
            if (Sn[start]-Sn[start+diff])*(Sn[start+diff]-Sn[start+(2*diff)])*(Sn[start]-Sn[start+(2*diff)])!=0: 
                count+=1
                
print(str((R*G*B)-count))

Submission status: Wrong Answer

Solution code:
N=input()
S=input()
R=[]
G=[]
B=[]
for i in range(len(S)):
    if S[i]=='R':
        R.append(i)
    if S[i]=='G':
        G.append(i)
    if S[i]=='B':
        B.append(i)

count=0
for i in range(len(R)):
    for j in range(len(G)):
        print(i,j)
        if max(R[i],G[j])+abs(R[i]-G[j]) in B:
            count+=1
            
        if min(R[i],G[j])-abs(R[i]-G[j]) in B:
            count+=1
            
        if (R[i]+G[j])/2 in B:
            count+=1
            

print(str((len(R)*len(G)*len(B))-count))

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    s = input()
    
    r = []
    g = []
    b = []
    rdic = {}
    gdic = {}
    bdic = {}
    
    ans = 0
    
    for i in range(n):
        if s[i] == 'R':
            r.append(i)
            rdic[2*i] = 2*i
        if s[i] == 'G':
            g.append(i)
            gdic[2*i] = 2*i
        if s[i] == 'B':
            b.append(i)
            bdic[2*i] = 2*i
    
    ans = len(r)*len(g)*len(b)
    
    for i in r:
        for j in g:
            if i+j in bdic:
                ans -= 1
    
    for i in r:
        for j in b:
            if i+j in rdic:
                ans -= 1
    
    for i in g:
        for j in b:
            if i+j in gdic:
                ans -= 1
    
    print(ans)

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    s = list(map(str, input()))
    
    r = []
    g = []
    b = []
    rdic = {}
    gdic = {}
    bdic = {}
    
    ans = 0
    
    for i in range(n):
        if s[i] == 'R':
            r.append(i)
            rdic[2*i] = 2*i
        if s[i] == 'G':
            g.append(i)
            gdic[2*i] = 2*i
        if s[i] == 'B':
            b.append(i)
            bdic[2*i] = 2*i
    
    ans = len(r)*len(g)*len(b)
    
    for i in r:
        for j in g:
            if i+j in bdic:
                ans -= 1
    
    for i in r:
        for j in b:
            if i+j in rdic:
                ans -= 1
    
    for i in g:
        for j in b:
            if i+j in gdic:
                ans -= 1
    
    print(ans)

if __name__=='__main__':
    main()

Submission status: Wrong Answer

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

r = []
g = []
b = []
rdic = {}
gdic = {}
bdic = {}

ans = 0

for i in range(n):
    if s[i] == 'R':
        r.append(i)
        rdic[2*i] = 2*i
    if s[i] == 'G':
        g.append(i)
        gdic[2*i] = 2*i
    if s[i] == 'B':
        b.append(i)
        bdic[2*i] = 2*i

ans = len(r)*len(g)*len(b)

for i in r:
    for j in g:
        if i+j in bdic:
            ans -= 1

for i in r:
    for j in b:
        if i+j in rdic:
            ans -= 1

for i in g:
    for j in b:
        if i+j in gdic:
            ans -= 1

print(ans)

Submission status: Wrong Answer

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

i = []
j = []
k = []

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

for s, d in enumerate(S):
  if d == 'R':
    i.append(s)
  elif d == 'G':
    j.append(s)
  elif d == 'B':
    k.append(s)
l_p = list(itertools.product(i, j, k))

counter = 0
for item in l_p:
    if not item[2] - item[1] == item[1] - item[0]:
        counter += 1
print(counter)

Submission status: Wrong Answer

Solution code:
import numpy as np
import math

n = int(input())
s = list(map(str, input()))

r = np.array([0]*n)
g = np.array([0]*n)
b = np.array([0]*n)

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

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

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

ans = np.sum(r) * np.sum(g) * np.sum(b)

rgb = np.array([r,g,b])

for i in range(n):
    for j in range(i+1,math.ceil((n+i)/2)):
        if (rgb[0,i]==1)and(rgb[1,j]==1)and(rgb[2,2*j-i]==1):
            ans -= 1

for i in range(n):
    for j in range(i+1,math.ceil((n+i)/2)):
        if (rgb[0,i]==1)and(rgb[2,j]==1)and(rgb[1,2*j-i]==1):
            ans -= 1

for i in range(n):
    for j in range(i+1,math.ceil((n+i)/2)):
        if (rgb[1,i]==1)and(rgb[0,j]==1)and(rgb[2,2*j-i]==1):
            ans -= 1

for i in range(n):
    for j in range(i+1,math.ceil((n+i)/2)):
        if (rgb[1,i]==1)and(rgb[2,j]==1)and(rgb[0,2*j-i]==1):
            ans -= 1

for i in range(n):
    for j in range(i+1,math.ceil((n+i)/2)):
        if (rgb[2,i]==1)and(rgb[0,j]==1)and(rgb[1,2*j-i]==1):
            ans -= 1

for i in range(n):
    for j in range(i+1,math.ceil((n+i)/2)):
        if (rgb[2,i]==1)and(rgb[1,j]==1)and(rgb[0,2*j-i]==1):
            ans -= 1

print(ans)
print(rgb)

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
s = list(map(str, input()))

r = np.array([0]*n)
g = np.array([0]*n)
b = np.array([0]*n)

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

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

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

ans = np.sum(r) * np.sum(g) * np.sum(b)

rgb = np.array([r,g,b])

for i in range(n):
    for j in range(i+1,(n+i)//2):
        if (rgb[0,i]==1)and(rgb[1,j]==1)and(rgb[2,2*j-i]==1):
            ans -= 1

for i in range(n):
    for j in range(i+1,(n+i)//2):
        if (rgb[0,i]==1)and(rgb[2,j]==1)and(rgb[1,2*j-i]==1):
            ans -= 1

for i in range(n):
    for j in range(i+1,(n+i)//2):
        if (rgb[1,i]==1)and(rgb[0,j]==1)and(rgb[2,2*j-i]==1):
            ans -= 1

for i in range(n):
    for j in range(i+1,(n+i)//2):
        if (rgb[1,i]==1)and(rgb[2,j]==1)and(rgb[0,2*j-i]==1):
            ans -= 1

for i in range(n):
    for j in range(i+1,(n+i)//2):
        if (rgb[2,i]==1)and(rgb[0,j]==1)and(rgb[1,2*j-i]==1):
            ans -= 1

for i in range(n):
    for j in range(i+1,(n+i)//2):
        if (rgb[2,i]==1)and(rgb[1,j]==1)and(rgb[0,2*j-i]==1):
            ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
s = str(input())
s_count = Counter(list(s))

ans = 1

for i, j in s_count.items():
    ans *= j

for i in range(n):
    k = 1

    while i + 2 * k < n:
        l = []
        l.append(s[i])
        l.append(s[i+k])
        l.append(s[i+2*k])
        if l.count('R') == 1 and l.count('G') == 1 and l.count('B') == 1:
            ans -= 1
        
        k += 1
    
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
s = str(input())
s_count = Counter(list(s))

ans = 1

for i, j in s_count.items():
    ans *= j

for i in range(n):
    k = 1
    while i + 2*k < n:
        l = [s[i], s[i+k], s[i+2*k]]
        l_count = Counter(l)
        res = 1
        for c, d in l_count.items():
            res *= d
        if res == 1:
            ans -= 1
        k += 1
    
print(ans)

Submission status: Wrong Answer

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

c = 0
for i in range(n//2):
  for j in range(n):
    if j + 2*i < n:
      if a[j] != a[j+i] and a[j+i] != a[j+2*i] and a[j] != a[j+2*i]:
        c+=1

ans = a.count("R") * a.count("G") * a.count("B") - c
print(ans)

Submission status: Wrong Answer

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

def main(N,S):
    count=0
    for i in range(1,N-2 +1):
        for j in range(i+1, N-1 +1):
            for k in range(j+1, N +1):
                if S[i-1]==S[j-1]:
                    continue
                    if S[j-1]==S[k-1]:
                        continue
                        if S[k-1]==S[i-1]:
                            continue
                            if j-i == k-j:
                                continue
                            else:
                                count += 1
    print(count)

if __name__=='__main__':
    main(N,S)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())

s = list(input())

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

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

    
    print(ans)
main()

Submission status: Wrong Answer

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

r , g, b = S.count("R"), S.count("G"), S.count("B")
ans = r * g * b

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

Submission status: Wrong Answer

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

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

s=0
for i in range(len(a)):
    for j in range(i+1, min(len(a),int((len(a)-1+i)/2)+1)):
        if a[i] !=a[j] and a[j]!=a[2*j-i] and a[2*j-i]!=a[i]:
            s+=1
            print(s,[i,j,2*j-i], a[i], a[j], a[2*j-i])

print(r*g*b-s)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ans = s.count('B') + s.count('G') + s.count('R')
for i in range(n):
  for j in range(i, n-1):
    k = 2*j - 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:
import itertools
N = int(input())
S = input()
#Rc1,Gc1,Bc1
out = S.count('R') * S.count('G') * S.count('B')
print(out)

RGBs = list(itertools.permutations(['R', 'G', 'B'], 3))

for i in range(1, N):
  for j in range(N-i*2):
    #三つ連続であり、RGBで構成されている
    if (S[j], S[j+i], S[j+i*2]) in RGBs:
      out -= 1
print(out)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
Sr = Sg = Sb = 0
for c in S:
    if c == 'R':
        Sr += 1
    elif c == 'G':
        Sg += 1
    else:
        Sb += 1
A = Sr * Sg * Sb
for sep in range(1,(N-1)//2):
    for i in range(N-2*sep):
        if S[i] != S[i+sep] and S[i+sep] != S[i+2*sep] and S[i] != S[i+2*sep]:
            A -= 1
print(A)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(str(input()))
a =[]
for k in range(0,n):
  for j in range(0,k):
    for i in range(0,j):
      if s[i] != s[j] and s[j] != s[k] and s[k] != s[j] and j-i != k - j:
        a.append(i)

print(len(a))

Submission status: Wrong Answer

Solution code:
from sys import stdin
import math

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


count_r = S.count('R')
count_g = S.count('G')
count_b = S.count('B')

total = count_r * count_g * count_b

for i in range(N):
    for gap in range(1, N//2):
        if i+gap+gap >= N:
            continue
        if S[i] != S[i+gap] and S[i+gap] != S[i+gap+gap] and S[i] != S[i+gap+gap]:
            total -= 1

print(total)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import math

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


count_r = S.count('R')
count_g = S.count('G')
count_b = S.count('B')

total = count_r * count_g * count_b

for i in range(N):
    for gap in range(N//2):
        if i+gap+gap >= N:
            continue
        if S[i] != S[i+gap] and S[i+gap] != S[i+gap+gap] and S[i] != S[i+gap+gap]:
            total -= 1

print(total)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import math

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


count_r = S.count('R')
count_g = S.count('G')
count_b = S.count('B')

total = count_r * count_g * count_b

for i in range(1, len(S)//2):
    for j in range(len(S)):
        if j+i+i >= len(S):
            continue
        if S[j] != S[j+i] and S[j+i] != S[j+i+i] and S[j] != S[j+i+i]:
            total -= 1

print(total)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import math

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


count_r = S.count('R')
count_g = S.count('G')
count_b = S.count('B')

total = count_r * count_g * count_b
#print(total)

for i in range(1, len(S)//2):
    for j in range(len(S)//2):
        if j+i+i >= len(S):
            continue
        #print("%d %d %d %s" % (j, j+i, j+i+i, (S[j], S[j+i], S[j+i+i])))
        #print("%s" % sorted([S[j], S[j+i], S[j+i+i]]))
        if S[j] != S[j+i] and S[j+i] != S[j+i+i] and S[j] != S[j+i+i]:
            total -= 1

print(total)

Submission status: Wrong Answer

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

index_R = [i + 1 for i, x in enumerate(s) if x == "R"]
index_B = [i + 1 for i, x in enumerate(s) if x == "B"]
index_G = [i + 1 for i, x in enumerate(s) if x == "G"]

ans = len(index_R) * len(index_B) * len(index_G)

for i in index_R:
    for j in index_B:
        if (i + j) / 2 in index_G:
            ans -= 1
        if ((i + j) / 2) - ((i-j)*3)/2 in index_G:
            ans -= 1
        if ((i + j) / 2) + ((i-j)*3)/2:
            ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

rgb = list(input())

count = 0
for i in range(n):
    # print(rgb[i])
    for j in range(i+2, n-i):
        for k in range(j+1, n-i):
            # print(i, j, k)
            if not rgb[i]==rgb[j] or not rgb[i]==rgb[k] or not rgb[j]==rgb[k] and not (j-i == k-j):
                count += 1
    
print(count)

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import deque
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def S(): return sys.stdin.readline()
def LS(): return sys.stdin.readline().split()
def LS2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h,w): return [[i for j in range(w)] for k in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)

input = sys.stdin.readline


K = I()
def gcd(a,b):
    while b!=0:
        c = a%b
        a=b
        b=c
    return a
ans = 0
for i in range(K):
    for j in range(K):
        for k in range(K):
            ans += gcd(gcd(i+1,j+1),k+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 // 2)):
    for j in range(0, n - (2 * i) + 1):
        if j + (2 * i) >= n:
            break
        if ((s[j] != s[j + i]) & (s[j] != s[j + (2 * i)]) & (s[i + j] != s[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(1, (n // 3) + 6):
    for j in range(0, n - (2 * i) + 1):
        if j + (2 * i) >= n:
            break
        if ((s[j] != s[j + i]) & (s[j] != s[j + (2 * i)]) & (s[i + j] != s[j + (2 * i)])):
            ans -= 1
        
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
r_list = set([])
b_list = set([])
g_list = set([])

for i in range(n):
    if s[i] == 'R':
        r_list.add(i)
    elif s[i] == 'B':
        b_list.add(i)
    else:
        g_list.add(i)
        
ans = len(b_list) * len(g_list) * len(r_list) - min([len(b_list), len(g_list), len(r_list)]) ** 2
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
Rcount = 0
Gcount = 0
Bcount = 0
cnt = 0
for i in range(len(s)):
         if s[i] == "R":
                  Rcount += 1
         elif s[i] == "G":
                  Gcount += 1
         elif s[i] == "B":
                  Bcount += 1
RGB = Rcount * Gcount * Bcount
for i in range(1,len(s)//2):
         for j in range(len(s)):
                  if i * 2 + j >= len(s):
                           break
                  else:
                           if s[j] != s[j+i] and s[j+i] != s[j+i+i] and s[j+i+i] != s[j]:
                                    cnt += 1
print(RGB - cnt)

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(N - 2):
    for j in range(1, N // 2):
        if N > i + j + j:
            a = S[i]
            b = S[i + j]
            c = S[i + j + j]
            if a != b and b != c and c != a:
                ret -= 1
print(ret)

Submission status: Wrong Answer

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

array = []
for i in S:
    array.append(i)


def convert_to_binary(character, string):
    array = []
    for c in string:
        if character == c:
            array.append(1)
        else:
            array.append(0)
    return array


R = convert_to_binary('R', S)
G = convert_to_binary('G', S)
B = convert_to_binary('B', S)

r_pos = 0
found = 0
for r in R:
    if r == 1:
        g_pos = 0
        for g in G:
            if g == 1:
                b_pos = 0
                for b in B:
                    if b == 1:
                        if (g_pos-r_pos) != (b_pos-g_pos):
                            found += 1
                    b_pos += 1
            g_pos += 1
    r_pos += 1

print(found)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from numba import njit
import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

N = int(input())
S = np.array(list(read().rstrip()), np.int8)

R = np.sum(S == ord('R'))
B = np.sum(S == ord('B'))
G = np.sum(S == ord('G'))


@njit
def f(S):
    N = len(S)
    ret = 0
    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[i] != S[k] and S[j] != S[k]:
                ret += 1
    return ret


answer = R * B * G - f(S)
print(answer)

Submission status: Wrong Answer

Solution code:
from numba import njit
import numpy as np
import sys
readline = sys.stdin.buffer.readline

N = int(input())
S = np.array(list(readline().rstrip()), np.int8)

R = np.sum(S == ord('R'))
B = np.sum(S == ord('B'))
G = np.sum(S == ord('G'))


@njit
def f(S):
    N = len(S)
    ret = 0
    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[i] != S[k] and S[j] != S[k]:
                ret += 1
    return ret


answer = R * B * G - f(S)
print(answer)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = "A"
S += input()
print(S)
r = 0
g = 0
b = 0
k = 0
for i in range(1, N+1):
    if S[i] == "R":
        r += 1
    elif S[i] == "G":
        g += 1
    else:
        b += 1

sum = r * g * b
for i in range(1, N-1):
    for j in range(i+1,N):
        if 2*j - i <= N:
            k = 2*j - i
            if S[j] != S[i] and S[k] != S[j] and S[i] != S[k]:
                sum -= 1

print(sum)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = "A"
S += input()
print(S)
r = 0
g = 0
b = 0
k = 0
for i in range(1, N+1):
    if S[i] == "R":
        r += 1
    elif S[i] == "G":
        g += 1
    else:
        b += 1

sum = r * g * b
for i in range(1, N-1):
    for j in range(i+1,N):
        if 2*j - i <= N:
            k = 2*j - i
        if S[j] == S[i] and S[k] == S[j] and S[i] == S[k]:
            sum -= 1

print(sum)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
r = 0
g = 0
b = 0
k = 0
for i in range(N):
    if S[i] == "R":
        r += 1
    elif S[i] == "G":
        g += 1
    else:
        b += 1

sum = r * g * b
for i in range(0, N-2):
    for j in range(i+1,N-1):
        if 2*j - i < N:
            k = 2*j - i
        if S[j] == S[i] and S[k] == S[j]:
            sum -= 1

print(sum)

Submission status: Wrong Answer

Solution code:
from math import floor
n=int(input())
s=input()
r=0
g=0
b=0
for i in range (len(s)):
  if s[i]=='R':
    r+=1
  elif s[i]=='B':
    b+=1
  else:
    g+=1
c=0
for i in range(1,floor((n-2)/2)+1,1):
  for j in range(0,n-2*i,1):
    if s[j+0*i]!=s[j+1*i] and s[j+1*i]!=s[j+2*i] and s[j+2*i]!=s[j+0*i]:
      c+=1;
      
      
ans=r*g*b-c;
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil
n=int(input())
s=input()
r=0
g=0
b=0
for i in range (len(s)):
  if s[i]=='R':
    r+=1
  elif s[i]=='B':
    b+=1
  else:
    g+=1
c=0
for i in range(1,n//2,1):
  for j in range(0,n-2*i,1):
    if s[j+0*i]!=s[j+1*i] and s[j+1*i]!=s[j+2*i] and s[j+2*i]!=s[j+0*i]:
      c+=1;
      
      
ans=r*g*b-c;
print(ans)

Submission status: Wrong Answer

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

result = string.count('R')*string.count('G')*string.count('B')

for i in range(N-2):
  for j in range(i+1, N):
    k = 2*j-1
    if k>=N:
      break
    if string[i] != string[j] != string[k]:
      result -= 1
print(result)

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
S=list(input())
s=collections.Counter(S)
m=0
m+=s["R"]*s["G"]*s["B"]
for i in range(N-2):
  for j in range(i+1,N-1):
    k=2*j-i
    if k>=N:
      break
    if s[i]!=s[j] and s[i]!=s[k] and s[j]!=s[k]:
      m-=1
print(m)

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
S=list(input())
s=collections.Counter(S)
m=0
m+=s["R"]*s["G"]*s["B"]
for i in range(N-2):
  for j in range(i+1,N-1):
    k=2*j-i
    if k>=N:
      break
    if s[i]!=s[j] and s[i]!=s[k] and s[j]!=s[k]:
      m-=1

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
S=list(input())
s=collections.Counter(S)
m=s["R"]*s["G"]*s["B"]
for i in range(N-2):
  for j in range(i+1,N-1):
    k=2*j-i
    if k>=N:
      break
    if s[i]!=s[j] and s[i]!=s[k] and s[j]!=s[k]:
      m-=1

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
S=list(input())
s=collections.Counter(S)
m=s["R"]*s["G"]*s["B"]
for i in range(N-2):
  for j in range(i+1,N-1):
    k=2*j-i
    if k>=N:
      break
    if s[i]!=s[j] and s[j]!=s[k] and s[i]!=s[k]:
      m-=1
print(m)

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
S=input()
s=collections.Counter(S)
m=s["R"]*s["G"]*s["B"]
for i in range(N-2):
  for j in range(i+1,N-1):
    k=2*j-i
    if k>N:
      break
    if s[i]!=s[j] and s[j]!=s[k] and s[i]!=s[k]:
      m-=1
print(m)

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
S=input()
s=collections.Counter(S)
m=s["R"]*s["G"]*s["B"]
for i in range(N-2):
  for j in range(i+1,N-1):
    k=2*j-i
    if k>N:
      break
    else:
      if s[i]!=s[j] and s[j]!=s[k] and s[i]!=s[k]:
        m-=1
print(m)