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:
def find_triplets(n, rgb):
    count = 0

    for i in range(n):
        for j in range(n):
            for k in range(n):
                if rgb[i] == 'R' and rgb[j] == "G" and rgb[k] == "B":
                    if rgb[i] != rgb[j] and rgb[i] != rgb[k] and rgb[j] != rgb[k]:
                        s = rgb[i] + rgb[j] + rgb[k]
                        if s == "RGB":
                            if j - i != k - j:
                                count += 1

    print(count)


if __name__ == '__main__':
    n = int(input())
    s = input()

    find_triplets(n, s)

Submission status: Wrong Answer

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

ans = 0

def first(a,b,c):
    if S[a] != S[b] and S[a] != S[c] and S[b] != S[c]:
        return 0
    else:
        return 1

def second(i,j,k):
    if j-i != k-j:
        return 0
    else:
        return 1

def third(i,j,k):
    if i < j and j < k:
        return 0
    else:
        return 0

for i in range(N):
    for j in range(N):
        for k in range(N):
            check = 0
            check += first(i,j,k)#index型の時
            check += second(i+1,j+1,k+1)#数値として１から使い始めたいとき
            check += third(i+1,j+1,k+1)
            if check == 0:
                ans += 1

print(ans)

Submission status: Wrong Answer

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

ans = 0

def first(i,j,k):
    if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
        return 0
    else:
        return 1

def second(i,j,k):
    if j-i != k-j:
        return 0
    else:
        return 1

for i in range(N):
    for j in range(N):
        for k in range(N):
            check = 0
            check += first(i,j,k)#index型の時
            check += second(i+1,j+1,k+1)#数値として１から使い始めたいとき
            if check == 0:
                ans += 1

print(ans)

Submission status: Wrong Answer

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

ans = 0

def first(a,b,c):
    if S[a] != S[b] and S[a] != S[c] and S[b] != S[c]:
        return 0
    else:
        return 1

def second(i,j,k):
    if j-i != k-j:
        return 0
    else:
        return 0

for i in range(N):
    for j in range(N):
        for k in range(N):
            check = 0
            check += first(i,j,k)#index型の時
            check += second(i+1,j+1,k+1)#数値として１から使い始めたいとき
            if check == 0:
                ans += 1

print(ans)

Submission status: Wrong Answer

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

#print(N, S) 

def rgbcnt(r, b, g):
  cnt = 0
  for i in range(0, N):
    if S[i] != r:
      continue
    for j in range(i+1, N):
      if S[j] != g:
        continue
      for k in range(j+1, N):
        if S[k] == b:
          cnt += 1
  return cnt
#

ans = 0
ans += rgbcnt("R", "G", "B")
#print(ans)
ans += rgbcnt("R", "B", "G")
#print(ans)
ans += rgbcnt("G", "R", "B")
#print(ans)
ans += rgbcnt("G", "B", "R")
#print(ans)
ans += rgbcnt("B", "R", "G")
#print(ans)
ans += rgbcnt("B", "G", "R")

print(ans)
#I, K, N  = map(int, input().split())
#L = list(map(int, input().split()))

Submission status: Wrong Answer

Solution code:
import sys

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

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

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

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

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

Submission status: Wrong Answer

Solution code:
import itertools
n = int(input())
s = str(input())
r = {}
b = {}
g = {}
for i in range(len(s)):
    if s[i] == 'R':
        r[i+1] = s[i]
    elif s[i] == 'B':
        b[i+1] = s[i]
    else:
        g[i+1] = s[i]
ans = len(r) * len(b) * len(g)
print(ans)
for i in r.keys():
    for j in b.keys():
        diff = abs(j-i)
        minb = min(i,j)-diff
        maxb = max(i,j)+diff
        if maxb in g.keys():
            ans -= 1
        if minb in g.keys():
            ans -= 1
        if((i+j)%2==0):
            if((i+j)//2 in g.keys()):
                ans -=1
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
n = int(input())
s = str(input())
r = {}
b = {}
g = {}
for i in range(len(s)):
    if s[i] == 'R':
        r[i+1] = s[i]
    elif s[i] == 'B':
        b[i+1] = s[i]
    else:
        g[i+1] = s[i]
ans = len(r) * len(b) * len(g)
for i in r.keys():
    for j in b.keys():
        diff = abs(j-i)
        if max(i,j)+diff in g.keys() or min(i,j)-diff in g.keys() or ((i+j)%2 == 0 and (i+j)//2 in g.keys()):
            ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
# 初期入力
N= int(input())
S =input()


#
R_index=[]
G_index=[]
B_index=[]
for i,v in enumerate(S):
    if v =="R":
        R_index.append(i)
    if v =="G":
        G_index.append(i)
    if v =="B":
        B_index.append(i)

# 例　R_index各要素から等距離離れたところに左にG、右にBがあればOK
R_B =[]
B_G =[]
count_ij_jk_onaji =0
for r in R_index:
    for g in G_index:
        if g-(r-g)<N :
            if S[g-(r-g)]=="B" and r<g:
                count_ij_jk_onaji +=1
                print(g,r,g-(r-g),"B")
for b in B_index:
    for r in R_index:
        if r-(b-r)<N :
            if S[r-(b-r)] == "G" and b<r:
                count_ij_jk_onaji +=1
                print(r,b,r-(b-r),"G")
for g in G_index:
    for b in B_index:
        if b-(g-b)<N :
            if S[b-(g-b)] =="R" and g<b:
                count_ij_jk_onaji +=1
                print(b,g,b-(g-b),"R")

            
#3つとも異なる文字=all
kotae_all = len(R_index) * len(G_index) * len(B_index) 
print(kotae_all -count_ij_jk_onaji)

print(kotae_all , count_ij_jk_onaji)

Submission status: Wrong Answer

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

cnt = s.count("R") * s.count("B") * s.count("G")
print(cnt)
# j - i = k -j を求める。
sub = 0 
for i in range(n):
    for j in range(i, n):
        k = 2 * j - i
        if k <= n - 1:
            if (s[i] != s[j]) and (s[j] != s[k]) and (s[i] != s[k]):
                sub += 1

print(cnt-sub)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
s = str(input())
r = 0
g = 0
for i in range(n):
  if s[i] == "R":
    r += 1
  elif s[i] == "G":
    g += 1
c = r*g*(n-r-g)
for j in range(1,n-1):
  for i in range(1,min(n-j-1,j)+1):
    if (s[j-i] != s[j]) and (s[j] != s[j+i]) and (s[j+i] != s[j-i]):
      c -= 1
print(c)
      
  
print(c)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

# 標準入力 <int>
N = int(input())

# 標準入力<str>
S = input()

ans = 0

for i in range(N - 2):

  S2 = []
  for j in range(N - i - 2):
    rgb = "RGB"
    if S[i] == S[i + j + 1]:
      continue
    rgb = rgb.replace(S[i], "")
    rgb = rgb.replace(S[i + j + 1], "")
    if i + ((j + 1) * 2) < N:
      S2 = S[i + j + 2:i + (2 * j) + 2] + S[i + (2 * j) + 3:]
    else:
      S2 = S[i + j + 2:]
    print(rgb)
    ans += S2.count(rgb)

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

import collections
c=collections.Counter(list(S))
c=list(c.values())

rgb=1
for i in range(len(c)):
    rgb*=c[i]
cnt=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[j]!=S[k] and S[k]!=S[i]:
            cnt+=1

print(rgb-cnt)

Submission status: Wrong Answer

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

import collections
c=collections.Counter(list(S))
c=list(c.values())

rgb=1
for i in range(len(c)):
    rgb*=c[i]
cnt=rgb

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

print(cnt)

Submission status: Wrong Answer

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

import collections
c=collections.Counter(list(S))
c=list(c.values())

rgb=1
for i in range(len(c)):
    rgb*=c[i]
cnt=rgb

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

print(cnt)

Submission status: Wrong Answer

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

for r in range(len(R)):
  for g in range(len(G)):
    for b in range(len(B)):
      if g - r != b - g:
        result += 1

print(result)

Submission status: Wrong Answer

Solution code:
# 初期入力
N= int(input())
S =input()

from collections import Counter
c = Counter(S)
count_all =c["R"] * c["G"] * c["B"]
count =0
for i,v in enumerate(S):
    for j in range(1,(N+1)//2):
        if 0 <= i-j and i+j <N: 
            if S[i-j]=="R" and S[i] =="G" and S[i+j] =="B":
                print(i-j,i,i+j)
                count +=1
            if S[i-j]=="R" and S[i] =="B" and S[i+j] =="G":
                print(i-j,i,i+j)
                count +=1
            if S[i-j]=="G" and S[i] =="R" and S[i+j] =="B":
                print(i-j,i,i+j)
                count +=1
            if S[i-j]=="G" and S[i] =="B" and S[i+j] =="R":
                print(i-j,i,i+j)
                count +=1
            if S[i-j]=="B" and S[i] =="G" and S[i+j] =="R":
                print(i-j,i,i+j)
                count +=1
            if S[i-j]=="B" and S[i] =="R" and S[i+j] =="G":
                count +=1
                print(i-j,i,i+j)

print(count_all - count)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
S=s.replace('R', "1").replace('G', "2").replace("B", "4")
t=list(S)
x=[int(a)+int(b)+int(c) for a in t for b in t for c in t]
print(x.count(7)//6)

Submission status: Wrong Answer

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

count = 0

for i in range(N):
    for i2 in range(N):
        for i3 in range(N):
            if i < i2 < i3:
                if S[i] == "R":
                    if S[i2] == "G":
                        if S[i3] == "B":
                            if i2 - i != i3 - i2:
                                count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np
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(N):
    j = i+d
    k = j+d
    if k >= N:
      break
    if S[i] != S[j] and S[j] != S[k] and S[i] != S[i]:
      ans -= 1
    
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
S = input()

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

ans = r*g*b

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
S=str(input())
t=N*(N-1)*(N-2)//6
print (t)
for i in range(N):
    for j in range(i+1,N):
        if S[i]==S[j]:
            t=t-(N-j-1)
        else:
            for k in range(j+1,N):
                if S[j]!=S[k] and S[i]!=S[k] and (i-j)!=(j-k):
                    continue
                else:
                    t=t-1
print (t)

Submission status: Wrong Answer

Solution code:
#D
#入力
N=int(input())
S=input()


#デバッグ用
def pront(*n):
    if debug==1:
        print(n)
        
debug=1#0:本番,1:デバッグ

#処理
R=[]
G=[]
B=[]
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)
        
pront(R,G,B)
y=0
for i in R:
    for j in G:
        for k in B:
            x=[i,j,k]
            x.sort()
            if not(x[1]-x[0]==x[2]-x[1]):
                y+=1
print(y)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
S = str(input())
count = S.count('R') * S.count('G') * S.count('B')
for i in range(N-1):
    for j in range(i,(N+i)//2):
        k = 2*j - i
        if S[i] == S[j] or S[i] == S[k] or S[j] == S[k]:
            pass
        else:
            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")
ans=r*g*b
for i in range(n):
  for j in range(i+1,n):
    k=(i+j)//2
    if s[i]!=s[j]!=s[k]!=s[i]:
      ans-=1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter    
n = int(input())
s = input()
c = Counter(s)

total = 1
for v in c.values():
    total *= v
    
ct = 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]:
            ct += 1                

print(total-ct if total - ct > 0 else 0)

Submission status: Wrong Answer

Solution code:
from collections import Counter    
n = int(input())
s = input()
c = Counter(s)

total = 1
for v in c.values():
    total *= v
    
ct = 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]:
            ct += 1                

print(total-ct)

Submission status: Wrong Answer

Solution code:
    
from collections import Counter    
n = int(input())
s = input()
c = Counter(s)

total = 1
for v in c.values():
    total *= v
    
ct = 0
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] and s[i] != s[k] and s[j] != s[k]:
            ct += 1
                

print(total-ct)

Submission status: Wrong Answer

Solution code:
from collections import Counter    
n = int(input())
s = input()
c = Counter(s)

total = 1
for v in c.values():
    total *= v
    
ct = 0
for i in range(n):
    for j in range(i,n):
        k = 2*j -i
        if k >= n:
            break
        if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
            ct += 1
                

print(total-ct)

Submission status: Wrong Answer

Solution code:
from collections import Counter    
n = int(input())
s = input()
c = Counter(s)

total = 1
for v in c.values():
    total *= v
    
ct = 0
for i in range(n):
    for j in range(i,n):
        k = 2*j -i
        if k >= n:
            break
        else:
            if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
                ct += 1
                

print(total-ct)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c = Counter(s)
ans = c['R'] * c['G'] * c['B']

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

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c = Counter(s)
print(c)
ans = c['R'] * c['G'] * c['B']

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

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    S = list(str(input()))
    sum = 0
    for i in range(0, N-2):
        si = S[i]
        for j in range(i+1, N-1):
            sj = S[j]
            k = 2*j -i  # Nを超える
            if k < N:
                sk = S[k]
                #if j - i != k -j and si != sj and si != sk and sj != sk:
                if si != sj and si != sk and sj != sk:
                    sum += 1
    print(sum)


main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

import sys
args = sys.argv

debug_flg = False
def debug(val1,val2="",val3="",val4=""):
    global debug_flg
    if debug_flg:
        print(val1,val2,val3,val4,sep=" , ")

if len(args) != 2:
    n= int(input())
    s= input()
else:
    debug_flg = True
    if args[1] == "2":
        n=39
        s="RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB"
    else:
        n=4
        s="RRGB"

snum = []
for i in range(0,n):
    if s[i-1] == "R":
        snum.append(0)
    elif s[i-1] == "G":
        snum.append(1)
    elif s[i-1] == "B":
        snum.append(2)

ret =0
for i in range(1,n-1):
    for j in range(i,n):
        if snum[i-1] == snum[j-1]:
            continue
        for k in range(j,n+1):
            if j-i == k-j:
                continue
            if snum[i-1] == snum[k-1]:
                continue
            if snum[j-1] == snum[k-1]:
                continue
            ret += 1

print(ret)

Submission status: Wrong Answer

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

num_r = s.count('R')
num_g = s.count('G')
num_b = s.count('B')

ans = num_r * num_g * num_b
for i, s_i in enumerate(s[:-2]):
    for j, s_j in enumerate(s[i+1:i+(n+i)//2], i+1):
        if s_i != s_j:
            k = 2 * j - i
            if k < n:
                s_k = s[k]
                if s_k != s_i and s_k != s_j:
                    ans -= 1
print(ans)

Submission status: Wrong Answer

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

num_r = s.count('R')
num_g = s.count('G')
num_b = s.count('B')

ans = num_r * num_g * num_b
print(ans)
for i, s_i in enumerate(s[:-2]):
    for j, s_j in enumerate(s[i+1:i+(n+i)//2], i+1):
        if s_i != s_j:
            k = 2 * j - i
            if k < n:
                s_k = s[k]
                if s_k != s_i and s_k != s_j:
                    ans -= 1
print(ans)

Submission status: Wrong Answer

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

import sys
args = sys.argv

debug_flg = False
def debug(val1,val2="",val3="",val4=""):
    global debug_flg
    if debug_flg:
        print(val1,val2,val3,val4,sep=" , ")

if len(args) != 2:
    n= int(input())
    s= input()
else:
    debug_flg = True
    if args[1] == "2":
        n=39
        s="RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB"
    else:
        n=4
        s="RRGB"

snum = []
for i in range(0,n):
    snum.append(s[i-1])

ret =0
for i in range(1,n-1):
    for j in range(i,n):
        if snum[i-1] == snum[j-1]:
            continue
        for k in range(j,n+1):
            if j-i == k-j:
                continue
            if snum[i-1] == snum[k-1]:
                continue
            if snum[j-1] == snum[k-1]:
                continue
            ret += 1

print(ret)

Submission status: Wrong Answer

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

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

for i,x in enumerate(s):
    if x == 'R':
        r.append(i+1)
    elif x == 'G':
        g.append(i+1)
    elif x == 'B':
        b.append(i+1)

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
def calc(i, j, B1, len_b):
    extra = 0
    d = j - i

    # i < j < k
    k1 = d + j
    if k1 < len_b:
        extra += B1[k1]

    # k < i < j
    k2 = i - d
    if 0 <= k2 and k2 < len_b:
        extra += B1[k2]

    # i < k < j
    s = i + j
    if s % 2 == 0:
        k3 = s // 2
        if k3 < len_b:
            extra += B1[k3]
    return extra

def main():
    N = int(input())
    S = input()
    R, G, B = [], [], []
    RGB = {'R': R, 'G': G, 'B': B}
    for i in range(N):
        RGB[S[i]].append(i)
    num_r, num_g, num_b = len(R), len(G), len(B)
    ans = num_r * num_g * num_b
    if ans == 0:
        print(0)
        return

    len_b = (B[-1] + 1)
    B1 = [0]*len_b
    for b in B:
        B1[b] = 1
    # print(R, G, B)
    for i in R:
        for j in G:
            if i > j:
                i, j = j, i
            ans -= calc(i, j, B1, len_b)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

print(count)

Submission status: Wrong Answer

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

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

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from functools import reduce

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

kw = Counter(s)
ans = reduce(lambda x, y: x * y, kw.values())

for i in range(n):
    for j in range(i + 1, n):
        k = 2 * j - i
        if j < 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:
#!/usr/bin/env python3
import sys
import collections
from functools import reduce

def solve(N: int, S: str):
    if N <= 2:
        print(0)
        return
    c = collections.Counter(S)
    rgb = reduce(lambda x, y: x*y, [int(i) for i in c.values()])
    cnt = 0
    for i in range(N):
        for j in range(i + 1, N):
            k = 2 * j - i
            if k > N - 1:
                continue
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                cnt += 1
    print(rgb - cnt)
    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:
N=int(input())
S=input()

# 各文字がどこまでにいくつ含まれるかを累積和で管理
R=[0]*N
G=[0]*N
B=[0]*N

dic={}
for c in ("R","G","B"):
  dic[c] = [0] * N

rp=0
gp=0
bp=0
for i in range(len(S)):
  if S[i]=="R":
    rp+=1
  elif S[i]=="G":
    gp+=1
  elif S[i]=="B":
    bp+=1
  dic["B"][i]=bp
  dic["R"][i]=rp
  dic["G"][i]=gp
  

print(dic["R"])
def getRest(s1,s2):
  for c in ["R","G","B"]:
    if c not in (s1,s2):
      return c

ans = 0
for i in range(N-2):
  for j in range(i+1,N-1):
    # 最初の2つの文字を固定する
    if S[i] == S[j]:
      continue
    # 探すべき文字を特定
    rest = getRest(S[i],S[j])
    ans += dic[rest][-1] - dic[rest][j]
    
    if j + (j-i) < N and S[j + (j-i)] == rest:
      ans -= 1
    
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import collections
from functools import reduce

def solve(N: int, S: str):
    c = collections.Counter(S)
    rgb = reduce(lambda x, y: x*y, [int(i) for i in c.values()])
    cnt = 0
    for i in range(N):
        for j in range(i + 1, N):
            k = 2 * j - i
            if k > N - 1:
                continue
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                cnt += 1
    print(rgb - cnt)
    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:
# -*- coding: utf-8 -*-
N = int(input())
S = input()

RR = []
GG = []
BB = []
for i in range(N):
  if(S[i] == 'R'):
    RR.append(i)
  elif(S[i] == 'G'):
    GG.append(i)
  else:
    BB.append(i)

count = 0

for r in RR:
  for g in GG:
    b1 = 2*r - g
    b2 = 2*g - r
    if((r+g)%2 == 0):
      b3 = int((r+g)/2)
    else:
      b3 = -1

    blen = len(BB)
    if(b1 in BB):
      blen -=1

Submission status: Wrong Answer

Solution code:
def calc():
  n=int(input())
  s=input()
  cnt1=0
  cnt2=0
  cnt3=0
  for i in range(n):
      if s[i]=='R':
          cnt1+=1
      elif s[i]=='G':
          cnt2+=1
      elif s[i]=='B':
          cnt3+=1
  ans=cnt1*cnt1*cnt3
  for i in range(n):
      for j in range(i+1,n):
          if 2*j-i>=n:
            continue
          if len(set([s[i],s[j],s[2*j-i]]))==3:
            ans-=1
  print(ans)
calc()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
nR = 0
nG = 0
nB = 0
cnt = 0
for i in range(N-1):
  if S[i] == 'R':
    nR += 1
  elif S[i] == 'G':
    nG += 1
  else:
    nB += 1
  for j in range(i+1, N):
    k = j - i + j
    if k < N:
      L = [S[i], S[j], S[k]]
      if 'R' in L and 'G' in L and 'B' in L:
        cnt += 1
    else:
      break
print(nR*nG*nB-cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from functools import reduce

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

kw = Counter(s)
ans = reduce(lambda x, y: x * y, kw.values())

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

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
R = [] 
G = []
B = []
i = 1
while i < N+1:
  a = S[i-1]
  if a == 'R':
    R.append(i)
  elif a == 'G':
    G.append(i)
  else:
    B.append(i)
  i += 1
  

c = 0
d = len(R)*len(G)*len(B)


if d == 0:
    print(0)
else:
    for t in range(len(R)):
        for u in range(len(G)):
            k = (R[t] + G[u])/2
            if 2*R[t]- G[u] > 0:
              l = 2*R[t]-G[u]
              if l in set(B):
                c += 1
            if 2*G[u] - R[t] > 0:
              
              m = 2*G[u]-R[t]
              if m in set(B):
                c += 1
            if k in set(B):
                c += 1

print(d-c)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from functools import reduce

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

kw = Counter(s)
ans = reduce(lambda x, y: x * y, kw.values())

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

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
a=s.count("R")
b=s.count("G")
c=s.count("B")
print(a*b*c)
ans=0
for i in range(n-2):
  for j in range(i+1,n-1):
    k=2*j-i
    if n-1>=k and not(s[i]!=s[j] and s[i]!=s[k] and s[j]!=s[k]):
        ans=ans+1
print(a*b*c-ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
a=s.count("R")
b=s.count("G")
c=s.count("B")
print(a*b*c)
ans=0
for i in range(n-2):
  for j in range(i+1,n-1):
    k=2*j-i
    if n-1>=k and (s[i]==s[j] or s[i]==s[k] or s[j]==s[k]):
        ans=ans+1
print(a*b*c-ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(input())
R,G,B = 0,0,0
for i in range(N):
    if S[i] == 'R':
        R += 1
    elif S[i] == 'B':
        B += 1
    else:
        G += 1

exc = 0
for j in range(2,N-1):
    num = 1
    while 0 <= j-num and j+num < N:
        if S[j-num] != S[j+num] and  S[j-num] != S[j] and  S[j] != S[j+num]:
            exc += 1
        num += 1

print(int(R*B*G - exc))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(input())
R,G,B = 0,0,0
for i in range(N):
    if S[i] == 'R':
        R += 1
    elif S[i] == 'B':
        B += 1
    else:
        G += 1

exc = 0
for j in range(2,N-1):
    num = 1
    while 0 <= j-num and j+num < N:
        if S[j-num] != S[j+num] and  S[j-num] != S[j] and  S[j] != S[j+num]:
            exc += 1
        num += 1

print(R*B*G - exc)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(n):
    if s[i] == 'R':
        r +=1
        R.append(i+1)
    elif s[i] == 'G':
        g += 1
        G.append(i+1)
    elif s[i] == 'B':
        b += 1
        B.append(i+1)
ans = r*g*b
for i in R:
    for j in G:
        if (i+j)//2 in B:
            ans -=1
for i in G :
    for j in B:
        if (i+j)//2 in R:
            ans -=1
for i in R:
    for j in B:
        if (i+j)//2 in G:
            ans -=1
print(ans)

Submission status: Wrong Answer

Solution code:
#D

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

ans = 0

if n < 4:
    print(0)
    exit()

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

print(ans)