TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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.

Submission attempts (in order):
from math import gcd
k = int(input())
gcdl = [[0 for i in range(k + 1)] for i in range(k + 1)]
for i in range(1, k + 1):
    for j in range(1, k + 1):
        gcdl[i][j] = gcd(i, j)
s = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        for l in range(1, k + 1):
            s += gcdl[i][gcdl[j][l]]

print(s)


n = int(input())
s = list(input())
cnt = {
    "R": 0,
    "G": 0,
    "B": 0
}

for i, c in enumerate(s):
    cnt[c] += 1

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

print(ans-d)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)

n = int(input())
s = input()
ans = s.count('B') * s.coufnt('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)


n = int(input())
s = input()
ans = s.count('R') * s.count('G') * s.count('B')
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)


Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
#from operator import itemgetter
#from collections import Counter
#import heapq
N = int(input())
S = input()
#N, M = map(int, input().split())
#A = list(map(lambda x: int(x)*(-1), input().split()))


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

START_TIME = time.time()
for i, s in enumerate(S):
    if s == 'R':
        R.append(i)
    elif s == 'G':
        G.append(i)
    else:
        B.append(i)
answer = len(R)*len(G)*len(B)
hiku = 0
for r in R:
    for g in G:
        for b in B:
            if b > max(r,g)+abs(r-g):
                break
            if abs(r-g) == abs(g-b) or abs(r-b) == abs(b-g) or abs(b-r) == abs(r-g):
                hiku += 1
answer -= hiku
print(answer)



N = int(input())
S = input()
#N, M = map(int, input().split())
#A = list(map(lambda x: int(x)*(-1), input().split()))


R  =[]
G  =[]
B  =[]
for i, s in enumerate(S):
    if s == 'R':
        R.append(i)
    elif s == 'G':
        G.append(i)
    else:
        B.append(i)
answer = len(R)*len(G)*len(B)
hiku = 0

for i in range(1, (N-1)//2+1):
    #for j in range(N-i-i-2):
    j = 0
    while j + i*2 < N:
        if S[j] != S[j+i] and S[j+i] != S[j+i+i] and S[j] != S[j+i+i]:
            hiku += 1
        j+= 1
answer -= hiku
print(answer)


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
from itertools import product as pro

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

r = [i for i in range(n) if s[i] == 'R']
g = [i for i in range(n) if s[i] == 'G']
b = [i for i in range(n) if s[i] == 'B']
cnt = len(r)*len(g)*len(b)

len = max(len(r), len(g), len(b))
if len == len(r):
    max1 = set(r)
    min1 = g
    min2 = b

if len == len(g):
    max1 = set(g)
    min1 = r
    min2 = b

if len == len(b):
    max1 = set(b)
    min1 = g
    min2 = r

for i, j in pro(min1, min2):
    if 2*j-i in max1:
        cnt -= 1
    if 2*i-j in max1:
        cnt -= 1
    if (i+j)/2 in max1:
        cnt -= 1

print(cnt)


from itertools import product as pro

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

r = [i for i in range(n) if s[i] == 'R']
g = [i for i in range(n) if s[i] == 'G']
b = [i for i in range(n) if s[i] == 'B']
cnt = len(r) * len(g) * len(b)

length = max(len(r), len(g), len(b))
for i, j, k in [(r, g, b), (g, b, r), (b, r, g)]:
    if length == len(i):
        max1 = set(i)
        min1, min2 = j, k

for i, j in pro(min1, min2):
    if ((2*j-i) or (2*i-j) or ((i+j)/2)) in max1:
        cnt -= 1

print(cnt)

from itertools import product as pro

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

r = [i for i in range(n) if s[i] == 'R']
g = [i for i in range(n) if s[i] == 'G']
b = [i for i in range(n) if s[i] == 'B']
cnt = len(r) * len(g) * len(b)

length = max(len(r), len(g), len(b))
for i, j, k in [(r, g, b), (g, b, r), (b, r, g)]:
    if length == len(i):
        max1 = set(i)
        min1, min2 = j, k

for i, j in pro(min1, min2):
    if 2*j-i in max1:
        cnt -= 1
    if 2*i-j in max1:
        cnt -= 1
    if (i+j)/2 in max1:
        cnt -= 1

print(cnt)

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
s=list(map(ord,input().split()))
R=[0]
G=[0]
B=[0]
for i in s:
  R.append(R[-1])
  G.append(G[-1])
  B.append(B[-1])
  if i==82:R[-1]+=1
  elif i=="71":G[-1]+=1
  else:B[-1]+=1
ans=0
for i in range(n-2):
  for j in range(i+1,n-1):
    if s[i]==s[j]:continue
    if 82 not in [s[i],s[j]]:
      ans+=R[-1]-R[j]
      if j+(j-i)<n:
        if s[j+(j-i)]==82:ans-=1
    elif 71 not in [s[i],s[j]]:
      ans+=G[-1]-G[j]
      if j+(j-i)<n:
        if s[j+(j-i)]==71:ans-=1
    else:
      ans+=B[-1]-B[j]
      if j+(j-i)<n:
        if s[j+(j-i)]==66:ans-=1
print(ans)


n=int(input())
s=list(map(ord,input().split()))
R=[0]
G=[0]
B=[0]
for i in s:
  R.append(R[-1])
  G.append(G[-1])
  B.append(B[-1])
  if i==82:R[-1]+=1
  elif i==71:G[-1]+=1
  else:B[-1]+=1
ans=0
for i in range(n-2):
  for j in range(i+1,n-1):
    if s[i]==s[j]:continue
    if 82 not in [s[i],s[j]]:
      ans+=R[-1]-R[j]
      if j+(j-i)<n:
        if s[j+(j-i)]==82:ans-=1
    elif 71 not in [s[i],s[j]]:
      ans+=G[-1]-G[j]
      if j+(j-i)<n:
        if s[j+(j-i)]==71:ans-=1
    else:
      ans+=B[-1]-B[j]
      if j+(j-i)<n:
        if s[j+(j-i)]==66:ans-=1
print(ans)

n=int(input())
s=input()
r=g=b=0
for i in s:
  if i=="R":r+=1
  elif i=="G":g+=1
  else:b+=1
ans=r*g*b
for i in range(n-2):
  for j in range(i+1,n-1):
    k=j+(j-i)
    if k>=n:break
    if not(s[i]==s[j] or s[j]==s[k] or s[i]==s[k]):ans-=1
print(ans)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    s_li = list(input().rstrip())

    r_li = []
    g_li = []
    b_li = []

    for i in range(n):
        if s_li[i] == 'R':
            r.append(i)
        elif s_li[i] == 'G':
            g.append(i)
        elif s_li[i] == 'B':
            b.append(i)

    if (len(r_li) < 1 or len(g_li) < 1) or len(b_li) < 1:
        print(0)
    else:
        all_c = len(r_li) * len(g_li) * len(b_li)

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

                if (s_li[i] != s_li[j] and s_li[j] != s_li[k]) and s_li[i] != s_li[k]:
                    all_c -= 1

        print(all_c)

if __name__ == '__main__':
    main()


import sys
input = sys.stdin.readline

def main():
    n = int(input())
    s_li = list(input().rstrip())

    r_li = []
    g_li = []
    b_li = []

    for i in range(n):
        if s_li[i] == 'R':
            r_li.append(i)
        elif s_li[i] == 'G':
            g_li.append(i)
        elif s_li[i] == 'B':
            b_li.append(i)

    if (len(r_li) < 1 or len(g_li) < 1) or len(b_li) < 1:
        print(0)
    else:
        all_c = len(r_li) * len(g_li) * len(b_li)

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

                if (s_li[i] != s_li[j] and s_li[j] != s_li[k]) and s_li[i] != s_li[k]:
                    all_c -= 1

        print(all_c)

if __name__ == '__main__':
    main()


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
s = list(input())
ans = s.count('R')*s.count('G')*s.count('B')

for i in range(n):
  if s[i] == 'R':
    s[i] = 1
  elif s[i] == 'G':
    s[i]
  elif s[i] == 'B':
    s[i] = 4
  
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)


n = int(input())
s = list(input())
ans = s.count('R')*s.count('G')*s.count('B')

for i in range(n):
  if s[i] == 'R':
    s[i] = 1
  elif s[i] == 'G':
    s[i]
  elif s[i] = 4
  
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)

n = int(input())
s = list(input())
ans = s.count('R')*s.count('G')*s.count('B')

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


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
s = input()
r = s.count('R')
g = s.count('G')
b = s.count('B')
c = 0
for i in range(n-1):
  for j in range(i+1, (n+1)//2):
    k = j*2-i
    if k >= n:
        continue
    if len(set([s[i], s[j], s[k]]))==3:
      c += 1
print(r*g*b-c)

N = int(input())
S = input()
r = S.count('R')
g = S.count('G')
b = S.count('B')
c = 0
for i in range(N-2):
  for j in range(i+1,(i+N+1)//2):
    k = j*2-i
    if len(set([S[i], S[j], S[k]]))==3:
      c += 1
print(r*g*b-c)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import bisect
N = int(input())
S = list(input())
R_i = []
G_i = []
B_i = []
for i in range(N):
  if S[i] == "R": R_i.append(i)
  elif S[i] == "G": G_i.append(i)
  else: B_i.append(i)

r = len(R_i)
g = len(G_i)
b = len(B_i)

ans = 0
for i in range(N):
  for j in range(1, N-i):
    if S[i] == "R":
      print(i+j in G_i , b - bisect.bisect_right(B_i,i + j) > 0)
      if i+j in G_i and b - bisect.bisect_right(B_i,i + 2 * j) > 0:
        ans += b - bisect.bisect_right(B_i,i + 2 * j)
        if i + j + j in b: ans -= 1
      elif i+ j in B_i and g - bisect.bisect_right(G_i,i + 2 * j) > 0:
        ans += g - bisect.bisect_right(G_i,i + 2 * j)
        if i + j + j in g: ans -= 1
    elif S[i] == "G":
      if i+j in R_i and b - bisect.bisect_right(B_i,i + 2 * j) > 0:
        ans += b - bisect.bisect_right(B_i,i + 2 * j)
        if i + j + j in b: ans -= 1
      elif i+j in B_i and r - bisect.bisect_right(R_i,i + 2 * j) > 0:
        ans += r - bisect.bisect_right(R_i,i + 2 * j)
        if i + j + j in r: ans -= 1
    else:
      if i+j in R_i and g - bisect.bisect_right(G_i,i + 2 * j) > 0:
        ans += g - bisect.bisect_right(G_i,i + 2 * j)
        if i + j + j in g: ans -= 1
      elif i+j in G_i and r - bisect.bisect_right(R_i,i + 2 * j) > 0:
        ans += r - bisect.bisect_right(R_i,i + 2 * j)
        if i + j + j in r: ans -= 1
print(ans)

N = int(input())
S = input()
R = S.count("R")
G = S.count("G")
B = S.count("B")

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

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

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N=int(input())

S=list(input())
m=0

a=S.count("R")
b=S.count("G")
c=S.count("B")

num=a*b*c

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

ースコード 

Copy
Copy
N=int(input())
 
S=list(input())
m=0
 
a=S.count("R")
b=S.count("G")
c=S.count("B")
 
num=a*b*c
 
for i in range(N-2):
  for j in range(i+1,N-1):
    k=2*j-i 
    if k>N-1:
      break
    elif S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
      m+=1
      
print(num-m)

N=int(input())
 
S=list(input())
m=0
 
a=S.count("R")
b=S.count("G")
c=S.count("B")
 
num=a*b*c
 
for i in range(N-2):
  for j in range(i+1,N-1):
    k=2*j-i 
    if k>N-1:
      break
    elif S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
      m+=1
      
print(num-m)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
s=input()
ans=0
r=g=b=0
R=[0 for _ in range(n)]
G=[0 for _ in range(n)]
B=[0 for _ in range(n)]
for i in range(i):
    if s[i]='R':r+=1
    elif s[i]='G':g+=1
    else:b+=1
    R[i]=r
    G[i]=g
    B[i]=b
for i in range(n):
    if s[i]='R':ans+=G[i]*(B[-1]-B[i])+B[i]*(G[-1]-G[i])
    elif s[i]='G':ans+=R[i]*(B[-1]-B[i])+B[i]*(R[-1]-R[i])
    else:ans+=R[i]*(G[-1]-G[i])+G[i]*(R[-1]-R[i])
print(ans)

from collections import Counter as C
n=int(input())
S=list(input())
a=1
L=C(S).most_common(3)
for l in L:
  a*=l[1]
for i in range(1,n):
  for j in range(n-2*i):
    if len(set((S[j],S[j+i],S[j+2*i])))==3:
      a-=1
print(a if len(L)>2 else 0)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
# -*- coding: utf-8 -*-
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)
    
count = 0

for r in R:
  for g in G:
    for b in B:
      S = sorted([r,g,b])
      if S[0]+S[2]!=2*S[1]:
        count += 1

# -*- coding: utf-8 -*-
N = int(input())
S = input()

R = 0
G = 0
B = 0

for i in range(N):
  if S[i] == 'R':
    R += 1
  elif S[i] == 'G':
    G += 1
  else:
    B += 1

count = 0
for i in range(N-2):
  for j in range(i+1,N-1):
    k = 2*j-i
    if k>=N:
      break
    a,b,c = S[i],S[j],S[k]
    if a!=b and b!=c and c!=a:
      count += 1

print(R*G*B-count)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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 d in range(N//2+1):
        j = i + d
        k = j + d
        if k < N:
        	if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            	ans -= 1
print(ans)

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)

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


Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
s = input()
r = s.count("R")
g = s.count("G")
b = s.count("B")
num = 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[k] != s[i]:
            n

n = int(input())
s = input()
r = s.count("R")
g = s.count("G")
b = s.count("B")
num = 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[k] != s[i]:
            num -=1
print(num)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
s = input()

ans = 0
for i in range(n-2):
	s1 = s[i]
	for j in range(i+1,n-1):
    	s2 = s[j]
        if s1 == s2:
        	pass
        else:
        	s[2*j-i] != s1 and s[2*j-i] != s2:
            ans += 1
print(ans)

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


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
s=input()
r,g,b=0,0,0
for i in range(n):
    if s[i]=="R":
        r+=1
    elif s[i]=="G":
        g+=1
    else:
        b+=1
chohuku=0
double=0
for i in range(1,n-1):
    for j in range(1,min(i+1,n-1-i)):
        chohuku+=1
        k=j+i
        l=i-j
        if s[i]==s[k] or s[i]==s[l] or s[l]==s[k]:
            double+=1
ans=r*g*b-chohuku+double
print(ans)

n=int(input())
s=input()
R,G,B=[],[],[]
ans,r,g,b=0,0,0,0
for i in range(n):
  if s[i]=="R":
    R.append(i)
    r+=1
    if G!=[] and B!=[]:
      for gg in G:
        if (gg+i)/2 in B:
          ans+=b-1
        else:
          ans+=b
      for bb in B:
        if (bb+i)/2 in G:
          ans+=g-1
        else:
          ans+=g
  elif s[i]=="G":
    G.append(i)
    g+=1
    if R!=[] and B!=[]:
      for rr in R:
        if (rr+i)/2 in B:
          ans+=b-1
        else:
          ans+=b
      for bb in B:
        if (bb+i)/2 in R:
          ans+=r-1
        else:
          ans+=r
  else:
    B.append(i)
    b+=1
    if G!=[] and R!=[]:
      for gg in G:
        if (gg+i)/2 in R:
          ans+=r-1
        else:
          ans+=r
      for rr in R:
        if (rr+i)/2 in G:
          ans+=g-1
        else:
          ans+=g
print(ans)

n=int(input())
s=input()
r,g,b=0,0,0
for i in range(n):
    if s[i]=="R":
        r+=1
    elif s[i]=="G":
        g+=1
    else:
        b+=1
chohuku=0
double=0
for i in range(1,n-1):
    for j in range(1,min(i+1,n-i)):
        chohuku+=1
        k=j+i
        l=i-j
        if s[i]!=s[k] and s[i]!=s[l] and s[l]!=s[k]:
            double+=1
ans=r*g*b-double
print(r,g,b,ans)

n=int(input())
s=input()
r,g,b=0,0,0
for i in range(n):
    if s[i]=="R":
        r+=1
    elif s[i]=="G":
        g+=1
    else:
        b+=1
chohuku=0
double=0
for i in range(1,n-1):
    for j in range(1,min(i+1,n-i)):
        chohuku+=1
        k=j+i
        l=i-j
        if s[i]!=s[k] and s[i]!=s[l] and s[l]!=s[k]:
            double+=1
ans=r*g*b-double
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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=len(r)*len(g)*len(b)
for i in g:
  for j in b:
    i+j=a
    if a%2==0 and (a//2 in r):
      ans-=1
for i in r:
  for j in b:
    i+j=a
    if a%2==0 and (a//2 in g):
      ans-=1
for i in g:
  for j in r:
    i+j=a
    if a%2==0 and (a//2 in b):
      ans-=1
print(ans)


import bisect
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=len(r)*len(g)*len(b)
r.append(n*4)
g.append(n*4)
b.append(n*4)
for i in g:
  for j in b:
    a=i+j
    if a%2==0 and r[bisect.bisect_left(r, a//2)]==a//2:
      ans-=1
for i in r:
  for j in b:
    a=i+j
    if a%2==0 and g[bisect.bisect_left(g, a//2)]==a//2:
      ans-=1
for i in g:
  for j in r:
    a=i+j
    if a%2==0 and b[bisect.bisect_left(b, a//2)]==a//2:
      ans-=1
print(ans+3)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
s = input()

def im(l, x):
    return [i for i, _x in enumerate(l) if _x == x]
R = im(s, "R")
G = im(s, "G")
B = im(s, "B")

ext = 0
if n >= 3:
    for i in range((n-3)//2):
        for j in range(n-(3+2*i)+1):
            if s[j] != s[j+i+1] and s[j] != s[j+2*(i+1)] and s[j+i+1] != s[j+2*(i+1)]:
                ext += 1

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


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

def im(l, x):
    return [i for i, _x in enumerate(l) if _x == x]
R = im(s, "R")
G = im(s, "G")
B = im(s, "B")

ext = 0
if n >= 3:
    for i in range((n-3)//2+1):
        for j in range(n-(3+2*i)+1):
            if s[j] != s[j+i+1] and s[j] != s[j+2*(i+1)] and s[j+i+1] != s[j+2*(i+1)]:
                ext += 1

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


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
s = input()

count = 0
r=0
g=0
b=0
for i in range(0,n):
  if s[i] == 'R':
    r = r + 1
  if s[i]=='G':
    g = g+1
  if s[i]=='B':
    b = b+1
    
for i in range(0,n-3):
  ii = s[i]
  for j in range(i+1, n-1):
    jj = s[j]
    if ii==jj:
      continue
    if (2*j-i)<=(n-1):
      if ii!=s[2*j-i] and jj!=s[2*j-i]:
        count = count + 1
print(r*g*b-count)


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

count = 0
r=0
g=0
b=0
for i in range(0,n):
  if s[i] == 'R':
    r = r + 1
  if s[i]=='G':
    g = g+1
  if s[i]=='B':
    b = b+1
    
for i in range(0,n):
  ii = s[i]
  for j in range(i+1, n):
    jj = s[j]
    if ii==jj:
      continue
    if (2*j-i)<=(n-1):
      if ii!=s[2*j-i] and jj!=s[2*j-i]:
        count = count + 1
print(r*g*b-count)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
s = input()
ans = 0
for i in range(n-2):
  for j in range(i+1, n-1):
    if s[i] != s[j]:
    for k in range(j+1, n):
      if s[j] != s[k] and s[k]!= s[i]:
        if j-i != k-j:
          ans +=1
print(ans)

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 i in range(n-2):
  for d in range((n-i-1)//2+1):
    j = i+d
    k = j+d
    if i in r and j in g and k in b:
      NGs += 1
    elif i in r and j in b and k in g:
      NGs += 1
    elif i in g and j in r and k in b:
      NGs += 1
    elif i in g and j in b and k in r:
      NGs += 1
    elif i in b and j in r and k in g:
      NGs += 1
    elif i in b and j in g and k in r:
      NGs += 1
print(len(r)*len(g)*len(b)-NGs)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
s = input()

num = len(s)
ans = 0
for i in range(num):
    a = set(s[i])
    for j in range(i+1, num):
        if s[j] in a:
            continue
        a.add(s[j])
        for k in range(j+1, num):
            if s[k] in a or j-i == k-j:
                continue
            ans += 1
        a.remove()

print(ans)


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

num = len(s)
ans = s.count('R')*s.count('G')*s.count('B')

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


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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)

N = int(input())
N -= 1
S = str(input())
count = S.count('R') * S.count('G') * S.count('B')
for i in range(N):
    for j in range(i,N+1):
        k = 2*j - i
        if k > N:
            pass
        elif S[i] == S[j] or S[i] == S[k] or S[j] == S[k]:
            pass
        else:
            count -= 1
print(count)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = 4000
s = "RGB" * 1333 + "R"
rgb = s.count("R") * s.count("G") * s.count("B")
for i in range(n-2):
  for j in range(i+1, n-1):
    d = j - i
    k = j + d
    if n <= k: break
    if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
      rgb -= 1
print(rgb)      


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


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n= int(input())
s = input()
ans = 0
li_r = []
li_g = []
li_b = []
for i in range(n):
  if li[i] == "R":
    li_r.append(i+1)
  elif li[i] == "G":
    li_g.append(i+1)
  elif li[i] == "B":
    li_b.append(i+1)
for i in li_r:
  for j in li_g:
    if 2*j - i in li_b:
      ans += len(li_b) -1
    else:
      ans += len(li_b)
print(ans)

#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)
import bisect
import heapq
import itertools
import math
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]









n = I()
s = input()
c = Counter(s)
ans = 0
for i in range(n):
    for k in range(i+1,n):
        if (i+k)%2 == 0:
            j = (i+k)//2
            if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
                ans+=1
ans_2 = c["R"]*c["G"]*c["B"]
print(ans_2-ans)

Verdicts: Runtime Error

Accepted
Problem: 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.

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

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





N = int(input())  # 1 <= N <= 4000
S = input()  # [RGB]{N}
L = {
    'R': tuple(i for i, v in enumerate(S) if v == 'R'),
    'G': tuple(i for i, v in enumerate(S) if v == 'G'),
    'B': tuple(i for i, v in enumerate(S) if v == 'B')
}
R_length = len(L['R'])
G_length = len(L['G'])
B_length = len(L['B'])

ans = R_length * G_length * B_length
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]:
            ans -= 1
print(ans)





Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
s=input()
s=list(s)
r=[]
g=[]
b=[]
for i in range(n):
    if s[i]=="R":
        r.append(i)
    elif s[i]=="G":    
        g.append(i)
    else:
        b.append(i)
print(r)       
print(g)    
print(b)    
cnt=0    
for j in r:
    for l in g:
        if (2*l-j) or (2*j-l) in b:
            cnt+=1
print(len(r)*len(g)*len(b)-cnt+1)

n=int(input())
s=input()
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:
            break
        if s[i]!= s[j] and s[i]!=s[k] and s[i+j]!= s[k] :
            ans-=1
print(ans)

n=int(input())
s=input()
ans=s.count("R")*s.count("G")*s.count("B")
for i in range(n):
  for j in range(i,n):
    if 2*j-i>=n:
      break
    else:
      if s[i]!=s[j]!=s[2*j-i]!=s[i]:
        ans-=1
print(ans)

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
 
str = input()
sum = 0
pointer = n
for i in range(n-2):
  if i == poitner:
    break
  for j in range(i+1, n-1):
    for k in range(j+1, n):
      if str[i] == str[j]:
        pointer = j
        break
      elif str[i] != str[k] and str[j] != str[k] and j - i != k - j:
        sum += 1
print(sum)

n = int(input())
 
str = input()
sum = 0
for i in range(n-2):
  for j in range(i+1, n-1):
     if str[i] == str[j]:
        break
    for k in range(j+1, n):
      if str[i] != str[k] and str[j] != str[k] and j - i != k - j:
        sum += 1

print(sum)

n = int(input())
 
str = input()

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

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
S = list(input())
A = S.count("R") * S.count("G") * S.count("B")

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

print(A)


N = int(input())
S = list(input())
A = S.count("R") * S.count("G") * S.count("B")

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

print(A)


    




N = int(input())
S = list(input())
A = S.count("R") * S.count("G") * S.count("B")

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

print(A)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
s = input()
r = s.count("R")
g = s.count("G")
b = s.count("B")
cnt= 0
for i in range(n):
    for j in range(i,n):
        if s[i] != s[j] and s[i] != s[2*j-i] and s[j] != s[2*j-i] and 2*j-i<n:
            cnt += 1
print(r*g*b-cnt)

# abc162_d.py
n = int(input())
s = input()
r = s.count("R")
g = s.count("G")
b = s.count("B")
cnt= 0
for i in range(n):
    for j in range(i,n):
        if 2*j-i<n:
            if s[i] != s[j] and s[i] != s[2*j-i] and s[j] != s[2*j-i]:
                cnt += 1
print(r*g*b-cnt)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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, int((N+i)/2 + 1)):
        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)

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)

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 +1 )):
        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)

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
s = input()

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

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

print(ans)

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):
        if i+(2*d) >= n: break
        if s[i] != s[i+d] and s[i] != s[i+(2*d)] and s[i+d] != s[i+(2*d)]:
            ans -= 1
            
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
l = [input() for _ in range(2)]
S = l[1]
N = int(l[0])
count = 0

indexR = []
indexG = []
indexB = []

i = 0
j = 0
k = 0

for a in range(N):
    character = S[a:a+1]

    if character == 'R':
        indexR.append(a+1)
    elif character == 'G':
        indexG.append(a+1)
    elif character == 'B':
        indexB.append(a+1)

for r in indexR:
    for g in indexG:
        for b in indexB:
            mean = (max[r, g, b] + min[r, g, b])/2
            if mean != r and mean != g and mean != b:
                count = count + 1
print(count)

l = [input() for _ in range(2)]
S = l[1]
N = int(l[0])
count = 0

indexR = []
indexG = []
indexB = []

i = 0
j = 0
k = 0

for a in range(N):
    character = S[a:a+1]

    if character == 'R':
        indexR.append(a+1)
    elif character == 'G':
        indexG.append(a+1)
    elif character == 'B':
        indexB.append(a+1)

maxi = 0
mini = 0

for r in indexR:
    maxi = r
    mini = r
    for g in indexG:
        if g < mini:
            mini = g
        if g > maxi:
            maxi = g
        for b in indexB:
            if b < mini:
                mini = b
            if b > maxi:
                maxi = b
            mean = (maxi - mini)/2
            if mean != r and mean != g and mean != b:
                count = count + 1
print(count)

l = [input() for _ in range(2)]
S = l[1]
N = int(l[0])
count = 0

indexR = []
indexG = []
indexB = []

i = 0
j = 0
k = 0

for a in range(N):
    character = S[a:a+1]

    if character == 'R':
        indexR.append(a+1)
    elif character == 'G':
        indexG.append(a+1)
    elif character == 'B':
        indexB.append(a+1)

for r in indexR:
    for g in indexG:
        for b in indexB:
            mean = (max[r, g, b] + min[r, g, b]/2)
            if mean != r and mean != g and mean != b:
                count = count + 1
print(count)

from collections import Counter

N = int(input())
S = input()
cnt = Counter(S)

ans = cnt['R']*cnt['G']*cnt['B']


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

print(ans)

Verdicts: Runtime Error

Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import sys
import clipboard





if sys.platform == 'ios':
	sample = clipboard.get()
	file = open('input_file.txt', 'w')
	file.write(sample)
	file.close()
	sys.stdin = open('input_file.txt')
# -----------------------------
						

# D - RGB Triplets

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

r, g, b = 0, 0, 0

for s in S:
	if s == 'R':
		r += 1
	elif s == 'G':
		g += 1
	else:
		b += 1

ans = r * g * b

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[i] != S[k] and S[j] != S[k]:
				if j -i == k -j:
					ans -= 1

print(ans) 

# D - RGB Triplets
	
N = int(input())
S = input()
	
r, g, b = 0, 0, 0
	
for s in S:
	if s == 'R':
		r += 1
	elif s == 'G':
		g += 1
	else:
		b += 1
	
ans = r * g * b
	
for i in range(N - 2):
	for j in range(i + 1, N - 1):
		k = j * 2 - i
			
		if k < N:
			if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
				if j -i == k -j:
					ans -= 1
	
print(ans)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import numpy as np

in_list = []
for i in range(2):
    in_list.append(input())
N,S = in_list
N = int(N)
res = 0
find_ind = []
for i in ['R','G','B']:
    find = (np.array(list(S)) == i)
    find_ind.append(find.argsort()[::-1][:sum(find)])
    # print(len(find_ind[-1]))

find_ind = np.array(find_ind)
rg_diff = find_ind[0] - find_ind[1].reshape(len(find_ind[1]),1)
rg_diff = np.abs(rg_diff)
# print(rg_diff)
gb_diff = find_ind[1] - find_ind[2].reshape(len(find_ind[2]),1)
gb_diff = np.abs(gb_diff)
gb_diff = gb_diff.T
# print(gb_diff)
br_diff = find_ind[2] - find_ind[0].reshape(len(find_ind[0]),1)
br_diff = np.abs(br_diff)

# print(br_diff)

res = 0

for i in range(len(find_ind[1])):
    res += np.sum((rg_diff[i] - gb_diff[i].reshape(len(gb_diff[i]),1)) == 0)
for i in range(len(find_ind[0])):
    res += np.sum((rg_diff[:,i] - br_diff[i].reshape(len(br_diff[i]),1)) == 0)
br_diff = br_diff.T
for i in range(len(find_ind[2])):
    res += np.sum((gb_diff[:,i] - br_diff[i].reshape(len(br_diff[i]),1)) == 0)


print(len(find_ind[0])*len(find_ind[1])*len(find_ind[2])-res)



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

res = 0
for i in range(N-2):
    n = 1
    while True:
        j = i+n
        k = j+n
        if k > N-1: break
        res += (S[i] != S[j] and S[j] != S[k] and S[k] != S[i])
        n += 1
    
    
rgb = S.count("R") * S.count("G") * S.count("B")
print(rgb - res)


Verdicts: Time Limit Exceeded

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
s = str(input())

R, G, B = [], [], []
for i, c in enumerate(s):
  if c == 'R': R.append(i)
  elif c == 'G': G.append(i)
  else: B.append(i)

ans = 0
for r in R:
  for g in G:
    if r < g: x, y = r, g
    else: x, y = g, r

    ans += len(X3)
    if x*2 - y >= 0:
      if s[x*2 - y] == 'B': ans -= 1
    if (x + y) % 2 == 0:
      if s[(x+y)//2] == 'B': ans -= 1
    if y*2 - x < len(s):
      if s[y*2 - x] == 'B': ans -= 1

print(ans)

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

R, G, B = [], [], []
for i, c in enumerate(s):
  if c == 'R': R.append(i)
  elif c == 'G': G.append(i)
  else: B.append(i)

ans = 0
for r in R:
  for g in G:
    if r < g: x, y = r, g
    else: x, y = g, r

    ans += len(B)
    if x*2 - y >= 0:
      if s[x*2 - y] == 'B': ans -= 1
    if (x + y) % 2 == 0:
      if s[(x+y)//2] == 'B': ans -= 1
    if y*2 - x < len(s):
      if s[y*2 - x] == 'B': ans -= 1

print(ans)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
s=input()

r_cnt=s.count("R")
g_cnt=s.count("G")
b_cnt=s.count("B")

ans=r_cnt*g_cnt*b_cnt

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

print(ans)

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

r_cnt=s.count("R")
g_cnt=s.count("G")
b_cnt=s.count("B")

ans=r_cnt*g_cnt*b_cnt

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[k]!=s[i]:
            ans-=1

print(ans)   

Verdicts: Runtime Error

Accepted