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):
n = int(input())
s = input()

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

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

print(r_count*g_count*b_count-discount)

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

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

    color_indexs = [r_indexs, g_indexs, b_indexs]

    for col_index in range(3):
        i_indexs_list = color_indexs[col_index]
        tmp_index1 = (col_index+1) % 3
        tmp_index2 = (col_index+2) % 3
        
        j_indexs_list = color_indexs[tmp_index1]
        k_indexs_list = color_indexs[tmp_index2]
        for i in i_indexs_list:
            for j in j_indexs_list:
                for k in k_indexs_list:
                    if j-i != k-j:
                        count += 1
        
        j_indexs_list = color_indexs[tmp_index2]
        k_indexs_list = color_indexs[tmp_index1]
        for i in i_indexs_list:
            for j in j_indexs_list:
                for k in k_indexs_list:
                    if j-i != k-j:
                        count += 1
        

print(count)


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

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

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

print(r_count*g_count*b_count-discount)

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

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

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

print(r_count*g_count*b_count-discount)

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):
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):
    
    if (S[j], S[j+i], S[j+i*2]) in RGBs:
      out -= 1
print(out)

import itertools
N = int(input())
S = input()
#Rc1,Gc1,Bc1
out = S.count('R') * S.count('G') * S.count('B')

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

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

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 = input()
C = np.array(list(itertools.combinations_with_replacement(range(1, N + 1), 3)))
count = 0
for i, j, k in C:
    if (i != 2 * j - k) and (S[i - 1] != S[j - 1] and S[i - 1] != S[k - 1] and S[j - 1] != S[k - 1]):
        count += 1
print(count)


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


for j in range(N):
    for i in range(j):
        k = 2 * j - i
        if k >= N:
            continue
        if (S[i] != S[j]) and (S[i] != S[k]) and (S[j] != S[k]):
            count -= 1
print(count)

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=input()
s=collections.Counter(S)
print(s)
ans=s['R']*s['G']*s['B']
for i in range(n):
    for d in range(n):
        j=i+d
        k=j+d
        if k>n-1:
            break
        if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
            ans-=1
print(ans)

#162D
#RGB Triplets

import collections

n=int(input())
S=input()
s=collections.Counter(S)
ans=s['R']*s['G']*s['B']
for i in range(n):
    for d in range(n):
        j=i+d
        k=j+d
        if k>n-1:
            break
        if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
            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()

Rs = 0
Gs = 0
Bs = 0
for i, il in enumerate(S):
    if il == 'R':
        Rs += 1
    if il == 'G':
        Gs += 1
    if il == 'B':
        Bs += 1
num = 0
for i in range(N):
    for step in range(1, N):
        j = i + step
        k = i + 2*step
        if k > N - 1:
            continue
        print(i, j, k)
        if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
            num += 1
print(Rs*Gs*Bs - num)


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

Rs = 0
Gs = 0
Bs = 0
for il in S:
    if il == 'R':
        Rs += 1
    if il == 'G':
        Gs += 1
    if il == 'B':
        Bs += 1
num = 0
for i in range(N):
    for step in range(1, N):
        j = i + step
        k = i + 2*step
        if k > N - 1:
            break
        if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
            num += 1
print(Rs*Gs*Bs - 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 = S.count('R') * S.count('G') * S.count('B')
for i in range(N):
  a = S[i]
  for j in range(i+1,N):
    b = S[j]
    if (i+j)%2 :
      continue
    k = (i+j)//2
    if [a,S[k],b].sort() == ['B','G','R']
      ans -= 1
      
print(ans)

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

ans = S.count('R') * S.count('G') * S.count('B')
for i in range(N):
  a = S[i]
  for j in range(i+2,N,2):
    b = S[j]
    k = (i+j)//2
    if sorted([a,S[k],b]) == ['B','G','R']:
      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 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)

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)

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

N=int(input())
S=str(input())
t=0
r=0
b=0
g=0
for i in range(N):
    if S[i]=='R':
        r+=1
    elif S[i]=='B':
        b+=1
    else:
        g+=1
for i in range(N):
    for j in range(i+1,N):
        if S[i]==S[j]:
            continue
        else:
            try:
                if S[2*j-i]!=S[j] and S[2*j-i]!=S[i]:
                    t+=1
                else:
                    continue
            except IndexError:
                break
print (r*b*g-t)

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

rcount=0
gcount=0
bcount=0
for i in range(n):
    if s[i]=="R":
        rcount+=1
    elif s[i]=="G":
        gcount+=1
    else:
        bcount+=1

al=rcount*bcount*gcount

for i in range(n-2):
    for k in range(i+1,n):
        dis=k-i
        l=k+dis
        if k+dis>n:
            continue
        if s[i]!=s[k] and s[i]!=s[l] and s[k]!=s[l]:
            al-=1

print(al)


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

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

for i in range(n-2):
    for k in range(i+1,n-1):
        l=k+(k-i)
        if l>=n:
            continue
        if s[i]!=s[k] and s[i]!=s[l] and s[k]!=s[l]:
            al-=1

print(al)


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=[]
for i,c in enumerate(s):
    if 'R' == c:
        r.append(i+1)
    elif 'G' == c:
        g.append(i+1)
    elif 'B' == c:
        b.append(i+1)
print(r,g,b)
count=0
for i in r:
    for j in g:
        for k in b:
            if j*2-i-k != 0:
                count+=1
print(count)

import collections
n = int(input())
s=input()
l=list(collections.Counter(s).values())
if len(l) == 3:
    ans=l[0]*l[1]*l[2]
    for i in range(n):
        for j in range(i+1,n):
            k = 2*j-i
            if n <= k:
                break
            if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
                ans-=1
    print(ans)
else:
    print(0)


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

I = []
J = []
K = []

for n in range(1,N+1):
  if S[n-1] == "R":
    I.append(n)
  elif S[n-1] == "G":
    J.append(n)
  else:
    K.append(n)
    
cnt = 0
for a in I:
  for b in J:
    for c in K:
      ls = [a,b,c]
      ls.sort()a
      if ls[1] - ls[0] != ls[2] - ls[1]:
        cnt += 1
    
print(cnt)

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

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

for i in range(1,N-1):
  for j in range(i+1,N):
    k = 2 * j - i
    if k > N:
      break
    if S[i-1] != S[j-1] and S[j-1] != S[k-1] and S[k-1] != S[i-1]:
      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()
ls = list(S)
count = 0
for k in range(2,N):
  for j in range(1,k):
    for i in range(0,j):
      if ls[i] != ls[j] and ls[j] != ls[k] and ls[k] != ls[i]:
        count += 1
print(count)

N = int(input())
S = input()
ls = list(S)

nr = len([r for r in S if r == 'R'])
nb = len([b for b in S if b == 'B'])
ng = len([g for g in S if g == 'G'])

ALL = nr * nb * ng
count = 0

for i in range(N-2):
  for k in range(2,N):
    j = (i + k) // 2
    if 1 <= j and j <= N:
      count += 1
      
print(ALL - count)

import itertools
N = int(input())
S = input()
ls = list(S)

nr = len([r for r in S if r == 'R'])
nb = len([b for b in S if b == 'B'])
ng = len([g for g in S if g == 'G'])

ALL = nr * nb * ng
count = 0

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

for i in range(N):
  for j in range(N-i*2):
    if (S[j], S[j+i], S[j+i*2]) in RGBs:
      count += 1
      
print(ALL - count)

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())
string = input()

r=g=b=0

for idx, s in enumerate(string):
    if s == 'R':
        r+=1
    elif s == 'B':
        b+=1
    elif s == 'G':
        g+=1

ans = r*g*b

for i in range(n):
    for k in range(i+1, n):
        if string[i] != string[k]:
            if (k+i)%2 == 0 and len(set(string[i], string[k], string[(k+i)//2]) ==3:
                ans -= 1

print(ans)

n = int(input())
string = input()

r=g=b=0

for idx, s in enumerate(string):
    if s == 'R':
        r+=1
    elif s == 'B':
        b+=1
    elif s == 'G':
        g+=1

ans = r*g*b

for i in range(n):
    for k in range(i+1, n):
        if string[i] != string[k]:
            if (k+i)%2 == 0 and len(set(string[i], string[k], string[(k+i)//2])) ==3:
                ans -= 1

print(ans)
            



n = int(input())
string = input()
r = 0
g = 0
b = 0
for c in string:
    if c == 'R':
        r += 1
    elif c == 'G':
        g += 1
    else:
        b += 1
ans = r*g*b
for i in range(n):
    for j in range(i+1, n):
        if 2*j - i >= n:
            break
        
        if string[i] != string[j] and string[i] != string[2*j-i] and string[j] != string[2*j-i]:
            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):
from numba import njit
import numpy as np
import sys
read = sys.stdin.read
readline = sys.stdin.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)


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)


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)


from numba import njit
import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
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)


Verdicts: Runtime Error

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):
 from collections import Counter
N = int(input())
S = input()
#c = Counter(S)
#print (c.most_common())
#ls = list(c.values())
ans = S.count('R') * S.count('G') * S.count('B')


for i in range(N):
    for j in range(1,N):
        a = i + j
        b = i + j + j
        if (b >= N):
            break
        else:
            l = S[i]
            m = S[a]
            r = S[b]
            if l!=m and m!=r and r!=l:
                ans -= 1
        # if (i-j<0 or i+j>=N):
        #     break
        # l = S[i-j]
        # m = S[i]
        # r = S[i+j]
        # if l!=m and m!=r and r!=l:
        #     ans -= 1
print (ans)


from collections import Counter
N = int(input())
S = input()
ans = S.count('R') * S.count('G') * S.count('B')

for i in range(N):
    for j in range(1,N):
        if (i-j<0 or i+j>=N):
            break
        l = S[i-j]
        m = S[i]
        r = S[i+j]
        if l!=m and m!=r and r!=l:
            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()
ans = s.count("R")*s.count("G")*s.count("B")
for i in range(1,n//2+10):
  j = 0
  while j+2*i <= n-1:
    print([j, j+i, j+2*i])
    if s[j] != s[j+i] and s[j] != s[j+2*i] and s[j+i] != s[j+2*i]:
      ans -= 1
    j += 1
print(ans)

n = int(input())
s = input()
ans = s.count("R")*s.count("G")*s.count("B")
for i in range(1,n//2+10):
  j = 0
  while j+2*i <= n-1:
    if s[j] != s[j+i] and s[j] != s[j+2*i] and s[j+i] != s[j+2*i]:
      ans -= 1
    j += 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,s = input().split()
s = list(s)

count = 0

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


print(count)


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

s = list(s)

k = r = b = g = count = 0

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

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

print(rbg-count)


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

sum = 0
for i in range(N):
    for j in range(i+1, N):
        if S[i] == S[j]:
            continue

        RGB = ['R','G','B']
            RGB.remove(S[j])
            RGB.remove(S[i])
            sum += S[(j+1):].count(RGB[0])

            # S[k]
            k = 2 * j - i
            if k < len(S):
                if S[k] == RGB[0]:
                    sum -= 1
print(sum)

from collections import Counter

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

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

sum = r*g*b

for i in range(N):
    for j in range(i+1, N):
        k = 2 * j - i
        if not S[i] == S[j] and not S[j] == S[k] and not S[k] == S[i]:
            sum -= 1
print(sum)

from collections import Counter

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

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

sum = r*g*b

for i in range(N):
    for j in range(i+1, N):
        k = 2 * j - i
        if k > N - 1:
            break
        if not S[i] == S[j] and not S[j] == S[k] and not S[k] == S[i]:
            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):
import math
from itertools import combinations

def main():
    k = int(input())
    res = 0
    memo = [[0 for _ in range(k+1)] for _ in range(k+1)]
    for i ian range(1, k+1):
        for j in range(i, k+1):
            tmp = math.gcd(i,j)
            memo[i][j] = tmp
            memo[j][i] = tmp

    for i in range(1, k+1):
        res += i 

    for c in combinations(range(1,k+1),2):
        ab = memo[c[0], c[1]]
        res += ab * 6

    for c in combinations(range(1,k+1), 3):
        ab = memo[c[0], c[1]]
        abc = memo[ab, c[2]]
        res += abc * 6
    print(res)


if __name__ == '__main__':
    main()


from itertools import permutations

def main():
    n = int(input())
    s = input()
    res = 0
    r = 0
    g = 0
    b = 0
    for i, c in enumerate(s):
        if c == 'R':
            r += 1
        elif c == 'G':
            g += 1
        else:
            b += 1
    
    rgb = []
    for t in permutations('RGB'):
        rgb.append(''.join(t))

    cnt = 0
    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] + s[k]) in rgb:
                cnt += 1
    print(r*g*b - cnt)


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


N = int(input())
S = input()
nR = 0
nG = 0
nB = 0
cnt = 0
for i in range(N):
  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)


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()
result = 0
'''
for i in range(N):
    print(result)
    for j in range(i+1,N):
        if S[i] != S[j]:
            for k in range(j ,N):
                if k- j == j - i:
                    continue
                if S[j] != S[k] and S[i] != S[k]:
                    result +=1
print(result)
'''
r = S.count('R')
g = S.count('G')
b = S.count('B')
target = set('RGB')
result = r * g * b
for i in range(N):
    for j in range(1, min(i, (N - i + 1)) + 1):
        if target == set(S[i] + S[i-j] + S[j + i]):
            result -= 1
print(result)

N = int(input())
S = input()
result = 0
'''
for i in range(N):
    print(result)
    for j in range(i+1,N):
        if S[i] != S[j]:
            for k in range(j ,N):
                if k- j == j - i:
                    continue
                if S[j] != S[k] and S[i] != S[k]:
                    result +=1
print(result)
'''
r = S.count('R')
g = S.count('G')
b = S.count('B')
target = set('RGB')
result = r * g * b
for i in range(N):
    for j in range(1, min(i, (N - i - 1)) + 1):
        if target == set(S[i] + S[i-j] + S[j + i]):
            result -= 1
print(result)

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]=='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]=='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] =2
    elif S[i]=='B':
       S[i] =4
    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]=='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] =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

Runtime Error

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()
a = s.count("R")
b = s.count("G")
c = s.count("B")
z = a*b*c
if z ==0:
  print(0)
else:
  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)
  x = 0
  for i in R:
    for j in G:
      if (0<= 2*j-i <=n-1 and s[2*j-i] in B) or (0<= 2*i-j <=n-1 and s[2*i-j] in B):
          x += 1
print(z-x)

n = int(input())
s = input()
a = s.count("R")
b = s.count("G")
c = s.count("B")
z = a*b*c
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)
x = 0
for i in R:
  for j in G:
    if 0 <= 2*j-i <= n-1 and s[2*j-i]=="B":
      x+=1
    if 0 <= 2*i-j <= n-1 and s[2*i-j]=="B":
      x+=1
    if (i+j)%2==0 and s[(i+j)//2]=="B":
      x+=1
print(z-x)


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

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

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(1, 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(3,n):
    minus[i+1] = minus[i]+counting(i+1)
  print(int(upper-minus[n]))
else:
  print(int(0))

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 = str(input())
RGB = [0] * 3
for i in range(N):
  if S[i] == "R":
    RGB[0] += 1
  elif S[i] == "G":
    RGB[1] += 1:
  else:
    RGB[2] += 1
    
ans = RGB[0] * RGB[1] * RGB[2]

for i in range(1, 2000):
  for j in range(1, N + 1):
    if (j + 2 * i) <= N:
      if S[j - 1] != S[j + i - 1]:
        if S[j + 2 * i - 1] != S[j + i - 1]:
          if S[j - 1] != S[j + 2 * i - 1]:
            ans -= 1
            
print(max(ans, 0))
  

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] == "G":
    G += 1
  else:
    B += 1
    
ans = R * G * B 

for i in range(1, 2000):
  for j in range(1, N - 2 * i + 1):
    if S[j - 1] != S[j + i - 1]:
      if S[j + 2 * i - 1] != S[j + i - 1]:
        if S[j - 1] != S[j + 2 * i - 1]:
          ans -= 1
            
print(max(ans, 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):
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)

samu = len(R) * len(G) * len(B)

for i in R:
    for j in G:
        k = int(2 * j - i)
        if(0 <= k < n):
            if(s[k] == 'B'):
                samu -= 1
                print(i,j,k)
        k = int(2 * i - j)
        if(0 <= k < n):
            if(s[k] == 'B'):
                samu -= 1
                print(i,j,k)
        if(i % 2 == j % 2):
            k = int((i + j) / 2)
            if(s[k] == 'B'):
                samu -= 1
                print(i,j,k)

print(samu)

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)

samu = len(R) * len(G) * len(B)

for i in R:
    for j in G:
        k = int(2 * j - i)
        if(0 <= k < n):
            if(s[k] == 'B'):
                samu -= 1
        k = int(2 * i - j)
        if(0 <= k < n):
            if(s[k] == 'B'):
                samu -= 1
        if(i % 2 == j % 2):
            k = int((i + j) / 2)
            if(s[k] == 'B'):
                samu -= 1

print(samu)

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 sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n = k()
s = s()
r = s.count("R")
g = s.count("G")
b = s.count("B")
ans = r*g*b
for i in range(n-2):
    for j in range((n-i+1)//2):
        if s[i]!=s[i+j] and s[i+j]!=s[i+2*j] and s[i+2*j]!=s[i]:
            a-=1

print(a)


import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n = k()
s = s()
r = s.count("R")
g = s.count("G")
b = s.count("B")
ans = r*g*b
for i in range(n-2):
    for j in range((n-i+1)//2):
        if s[i]!=s[i+j] and s[i+j]!=s[i+2*j] and s[i+2*j]!=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 = list(input())

a = S[0]
res= 0

for i in range(1, N-2):
    if a == S[i]:
        b = S[i]
        for j in range(j, N-1):
            if i == j:
                continue
            c = S[j]
            if a!=b and b!= c and a!=c:
                res +=1

print(res)

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

cntOne = S.count('R') * S.count('G') * S.count('B')
cntTwo = 0


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

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

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

res = 0
for i in range(N-2):
    for d in range(1, (N-i)//2+1):
        if set(S[i], S[i+d], S[i+2*d]) == {"R", "G", "B"}:
            res += 1
ans -= res
print(ans)


from bisect import bisect_right

def runLength(string):
    
    res = []
    data, count = string[0], 1
    for i in range(1, len(string)):
        if string[i] == data:
            count += 1
        else:
            res.append((data, count, i))
            data, count = string[i], 1
    res.append((data, count, i))
    return res


N = int(input())
S = input()
rl = runLength(S)
keys = [rli[2] for rli in rl]
nrl = len(rl)

ans = 0

for i in range(N-2):
    for j in range(i+1, N-1):
        if S[i] == S[j]:
            continue
        elif set([S[i], S[j]]) == {"R", "G"}:
            if 2*j - i < N and S[2*j - i] == "B":
                ans += sum([rl[x][1] for x in range(bisect_right(keys, j+1), nrl) if rl[x][0] == "B"]) - 1
            else:
                ans += sum([rl[x][1] for x in range(bisect_right(keys, j+1), nrl) if rl[x][0] == "B"])
        elif set([S[i], S[j]]) == {"B", "G"}:
            if 2*j - i < N and S[2*j - i] == "R":
                ans += sum([rl[x][1] for x in range(bisect_right(keys, j+1), nrl) if rl[x][0] == "R"]) - 1
            else:
                ans += sum([rl[x][1] for x in range(bisect_right(keys, j+1), nrl) if rl[x][0] == "R"])
        else:
            if 2*j - i < N and S[2*j - i] == "G":
                ans += sum([rl[x][1] for x in range(bisect_right(keys, j+1), nrl) if rl[x][0] == "G"]) - 1
            else:
                ans += sum([rl[x][1] for x in range(bisect_right(keys, j+1), nrl) if rl[x][0] == "G"])

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+i-1)//2+1):
        if set([S[i], S[j], S[2*j-i]]) == {"R", "G", "B"}:
            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):
from collections import Counter
n=int(input())
s_=input()
s=Counter(s_)
rgb = s['R'] * s['G'] * s['B']
cnt=0
for i in range(len(s_)):
  for j in range(i+1,len(s_)):
    h=j-i+j
    if h<len(s_)-1:
      if s_[i]!=s_[j] and s_[h]!=s_[j] and s_[i]!=s_[h]:
        cnt+=1

print(rgb-cnt)

from collections import Counter
n=int(input())
s_=input()
s=Couter(s_)
rgb = s['R'] * s['G'] * s['B']
cnt=0
for i in range(len(s_)):
  for j in range(i+1,len(s_)):
    h=j-i+j
    if h<n:
      if s_[i]!=s_[j] and s_[h]!=s_[j] and s_[i]!=s_[h]:
        cnt+=1

print(rgb-cnt)
    

from collections import Counter
n=int(input())
s_=input()
s=Counter(s_)
rgb = s['R'] * s['G'] * s['B']
cnt=0
for i in range(len(s_)):
  for j in range(i+1,len(s_)):
    h=j-i+j
    if h<n:
      if s_[i]!=s_[j] and s_[h]!=s_[j] and s_[i]!=s_[h]:
        cnt+=1

print(rgb-cnt)
    

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 numba import jit

@jit
def main():

    N=int(input())
    S=input()
    R=0
    G=0
    B=0
    for i in range(N):
        s=S[i]
        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):
            if 0<=j+j-i<N:
                si=S[i]
                sj=S[j]
                sk=S[2*j-i]
                if si!=sj and sj!=sk and sk!=si:
                    ans-=1
    print(ans)
        
if __name__=="__main__":
    main()

from numba import njit

N=int(input())
S=input()
R=0
G=0
B=0
for i in range(N):
    s=S[i]
    if s=="R":
        R+=1
    elif s=="G":
        G+=1
    else:
        B+=1
ans=R*G*B

@njit
def calc(ans):
    for i in range(N-2):
        for j in range(i+1, N-1):
            if 0<=j+j-i<N:
                si=S[i]
                sj=S[j]
                sk=S[2*j-i]
                if si!=sj and sj!=sk and sk!=si:
                    ans-=1
    return ans
print(calc(ans))


from numba import jit

N=int(input())
S=input()
R=0
G=0
B=0
for i in range(N):
    s=S[i]
    if s=="R":
        R+=1
    elif s=="G":
        G+=1
    else:
        B+=1
ans=R*G*B

@njit
def calc(ans):
    for i in range(N-2):
        for j in range(i+1, N-1):
            if 0<=j+j-i<N:
                si=S[i]
                sj=S[j]
                sk=S[2*j-i]
                if si!=sj and sj!=sk and sk!=si:
                    ans-=1
    return ans
print(calc(ans))


from numba import jit

N=int(input())
S=input()
R=0
G=0
B=0
for i in range(N):
    s=S[i]
    if s=="R":
        R+=1
    elif s=="G":
        G+=1
    else:
        B+=1
ans=R*G*B

@jit
def calc(ans):
    for i in range(N-2):
        for j in range(i+1, N-1):
            if 0<=j+j-i<N:
                si=S[i]
                sj=S[j]
                sk=S[2*j-i]
                if si!=sj and sj!=sk and sk!=si:
                    ans-=1
    return ans
print(calc(ans))


from collections import Counter
N=int(input())
S=input()
C=Counter(S)
nr=C["R"]
ng=C["G"]
nb=C["B"]
ans=nr*ng*nb
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: Time Limit Exceeded

Time Limit Exceeded

Runtime Error

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())
List = list(input())
count = 0
print(List)
for k in range(n - 2):
    for l in range(k + 1, n - 1):
        if List[k] != List[l]:
            for m in range(l + 1, min(2 * l - k, n)):
                if List[k] != List[m] and List[l] != List[m]:
                    count += 1
            for m in range(min(2 * l - k + 1, n), n):
                if List[k] != List[m] and List[l] != List[m]:
                    count += 1
print(count)

n = int(input())
List = list(input())
count = List.count("R") * List.count("G") *List.count("B")
for w in range(1, n // 3 * 3 + 1):
    for s in range(n - 2 * w):
        if List[s] != List[s + w] and List[s] != List[s + w * 2] and List[s + w] != List[s + w * 2]:
            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):


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

cnt = 0

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


print(N-cnt)



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

cnt = 0

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


print(N-cnt)



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

cnt = 0

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


print(N**3-cnt)



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

cnt = S.count('B')*S.count('G')*S.count('R')

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


print(cnt)



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

cnt = S.count('B')*S.count('G')*S.count('R')

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


print(cnt)



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

cnt = 0

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


print(N-cnt)



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

cnt = S.count('B')*S.count('G')*S.count('R')

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


print(cnt)

Verdicts: Wrong Answer

Runtime Error

Runtime Error

Runtime Error

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):
from itertools import product

k = int(input())
s = input()

temp_dict = {
    "R": [],
    "G": [],
    "B": [],
}
for i, c in enumerate(s):
    temp_dict[c].append(i)

ans = 0
temp_list = list(product(temp_dict["R"], temp_dict["G"], temp_dict["B"]))
for temp in temp_list:
    temp.sort()
    if temp[0] - temp[1] != temp[1] - temp[2]:
        ans += 1

print(ans)


temp_dict = {
    "R": [],
    "G": [],
    "B": [],
}
for i, c in enumerate(s):
    temp_dict[c].append(i)

ans = 0
temp_list = list(product(temp_dict["R"], temp_dict["G"], temp_dict["B"]))
for temp in temp_list:
    temp = sorted(list(temp))
    if temp[0] - temp[1] != temp[1] - temp[2]:
        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 + 2, n, 2):
        if s[i] != s[(i + j) >> 1] != s[j] != s[i]:
            ans -= 1
print(ans)

Verdicts: Runtime Error

Runtime Error

Accepted