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 = s.count('R')
G = s.count('G')
B = s.count('B')

count = R*G*B
print(count)
cnt = 0
for i in range(len(s)):
    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]:
            count -= 1
print(count)

N = int(input())
s = input()
R = s.count('R')
G = s.count('G')
B = s.count('B')

count = R*G*B
cnt = 0
for i in range(len(s)):
    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]:
            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 = list(input())

arr = []
R = len(list(filter(lambda x:x == 'R', s)))
G = len(list(filter(lambda x:x == 'G', s)))
B = len(list(filter(lambda x:x == 'B', s)))
tot = R*G*B
print(tot)

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

print(tot)

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

arr = []
R = len(list(filter(lambda x:x == 'R', s)))
G = len(list(filter(lambda x:x == 'G', s)))
B = len(list(filter(lambda x:x == 'B', s)))
tot = R*G*B

for i in range(n):
  for j in range(i+1, n):
    k = 2*j-i
    if k > n:
      continue
    if (s[i] != s[j]) & (s[i] != s[k]) & (s[j] != s[k]):
      tot -= 1

print(tot)

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

arr = []
R = len(list(filter(lambda x:x == 'R', s)))
G = len(list(filter(lambda x:x == 'G', s)))
B = len(list(filter(lambda x:x == 'B', s)))
tot = R*G*B

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

print(tot)


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

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

tmp=0

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

ans = ans - tmp
print(ans)

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

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

tmp=0

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

ans = ans - tmp
print(ans)

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

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

tmp=0

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

ans = ans - tmp
print(ans)

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):
import sys
n = int(sys.stdin.readline())
s = sys.stdin.readline()
r = []
g = []
b = []
cnt = 0
i = 0
while i < n:
  if s[i] == "R":
    r.append(i)
  elif s[i] == "G":
    g.append(i)
  else:
    b.append(i)
for j in r:
  for k in g:
    for l in b:
      if l - k != k - j:
        cnt += 1
print(cnt)

import sys

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))


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








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=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)
print(r)
print(g)
print(b)
t=0
for i in range(len(r)):
    for j in range(len(g)):
        p=0
        for k in range(len(b)):
            if p<3:
                if abs(r[i]-g[j])!=abs(b[k]-g[j]) and abs(r[i]-b[k])!=abs(b[k]-g[j]) and abs(r[i]-g[j])!=abs(b[k]-r[i]):
                    t=t+1
                else:
                    p+=1
            else:
                t = t + 1
print(t)

N= int(input())
S=input()
r=[]
g=[]
b=[]
A=0
B=0
C=0
for i in range(N):
    if S[i]=="R":
        r.append(i)
        A+=1
    elif S[i]=="G":
        g.append(i)
        B+=1
    else:
        b.append(i)
        C+=1
k=0
for i in range(N-2):
    for j in range(i+1,N-1):
        t=2*j-i
        if t<N:
            if S[i]!=S[j] and S[i]!=S[t] and S[t]!=S[j] :
                k+=1
                print(i,j,t)
print(k)
print(A*B*C-k)

N= int(input())
S=input()
r=[]
g=[]
b=[]
A=0
B=0
C=0
for i in range(N):
    if S[i]=="R":
        r.append(i)
        A+=1
    elif S[i]=="G":
        g.append(i)
        B+=1
    else:
        b.append(i)
        C+=1
k=0
for i in r:
    x=i
    for j in b:
        y=j
        if 2*x-y in b:
            k+=1
        if 2*y-x in b:
            k+=1
        if (x+y)/2 in b:
            k+=1

print(A*B*C-k)

N= int(input())
S=input()
r=[]
g=[]
b=[]
A=0
B=0
C=0
for i in range(N):
    if S[i]=="R":
        r.append(i)
        A+=1
    elif S[i]=="G":
        g.append(i)
        B+=1
    else:
        b.append(i)
        C+=1
k=0
for i in range(N-2):
    for j in range(i+1,N-1):
        t=2*j-i
        if t<N:
            if S[i]!=S[j] and S[i]!=S[t] and S[t]!=S[j] :
                k+=1

print(A*B*C-k)

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 = list(map(input().split()))

r_i = [i for i, x in enumerate(s) if x=='R']
g_i = [i for i, x in enumerate(s) if x=='G']
b_i = [i for i, x in enumerate(s) if x=='B']

ans = 0

for i in len(r_i):
    for j in len(g_i):
        for k in len(b_i):
            if r_i[i]!=g_i[j] and g_i[j]!=b_i[k] and b_i[k]!=r_i[i]:
                ans += 1

print(ans)

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

ri = [i for i, x in enumerate(s) if x=='R']
gi = [i for i, x in enumerate(s) if x=='G']
bi = [i for i, x in enumerate(s) if x=='B']

ans = len(ri) * len(gi) * len(bi)

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

print(ans)

n = int(input())
s = list(map(input().split()))

r_i = [i for i, x in enumerate(s) if x=='R']
g_i = [i for i, x in enumerate(s) if x=='G']
b_i = [i for i, x in enumerate(s) if x=='B']

ans = 0

for i in len(r_i):
    for j in len(g_i):
        for k in len(b_i):
            if r_i[i]!=g_i[j] and g_i[j]!=b_i[k] and b_i[k]!=r_i[i]:
                ans += 1

print(ans)

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

ri = [i for i, x in enumerate(s) if x=='R']
gi = [i for i, x in enumerate(s) if x=='G']
bi = [i for i, x in enumerate(s) if x=='B']

ans = len(ri) * len(gi) * len(bi)

for i in range(n):
    for d in range(n):
        j=i+d
        k=i+2*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

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=[]
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 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[i]=s[k]) and (s[j]=s[k]):
                ans-=1
print(ans)

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 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[i]==s[k]) and (s[j]==s[k]):
                ans-=1
print(ans)

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 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[i]!=s[k]) and (s[j]!=s[k]):
                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()
c = 0
RGB = 'RGB'
for i in range(N-2):
  a = S[i]
  for j in range(i+1,N-1):
    if S[j] != a:
      S_ = S[j+1:]
      d = j - i
      S_ = S_[d: d+1]
      RGB = RGB.strip(a).strip(S[j])
      c += S_.count(RGB)
print(c)

N=int(input())
S=input()
A=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:
            if S[i] != S[j] and S[i] != S[2*j-i] and S[j] != S[2*j-i]:
                A-=1
print(A)

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

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

print(tot)


n = int(input())
s = input()
r_num = s.count('R')
g_num = s.count('G')
b_num = s.count('B')
tot = r_num*g_num*b_num
for i in range(n):
    for j in range(i+1,n):
        k = j+(j-i)

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

print(tot)


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):
def S(): return stdin.readline().rstrip()
def I(): return int(stdin.readline().rstrip())


n = I()
s = S()

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

print(ans)

from numba import njit
from sys import stdin
def S(): return stdin.readline().rstrip()
def I(): return int(stdin.readline().rstrip())
 
@njit
def main():
    n = I()
    s = list(S())
    ans = 0
    for i in range(n-2):
        color = {s[i]}
        for j in range(i+1,n-1):
            if not s[j] in color:
                color.add(s[j])
                for k in range(j+1,n):
                    if not s[k] in color:
                        if k-j != j-i:
                            ans += 1
                color = {s[i]}
    
    print(ans)

if __name__ == '__main__':
    main()

from sys import stdin
def S(): return stdin.readline().rstrip()
def I(): return int(stdin.readline().rstrip())
 
n = I()
s = list(S())

r = s.count('R')
g = s.count('G')
b = s.count('B')
 
ans = r*g*b
for i in range(n-1):
    for j in range(1,n):
        if i-j<0 or n<=i+j:
            break
        else:
            if s[i-j]!=s[i] and s[i]!=s[i+j] and s[i-j]!=s[i+j]:
                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 collections
N=int(input())
S=input()
lis=list(S)
C= collections.Counter(lis)
count=list(C.values())
c=0
for i in range(N):
    print(i)
    for j in range(i,(N+i-1) // 2+1):
        if(lis[i]!=lis[j]):
            if(lis[j]!=lis[2*j-i]):
                if(lis[i]!=lis[2*j-i]):
                    c+=1
if(len(count)==3):
    print(count[0]*count[1]*count[2]-c)
else:
    print(0)


import collections
N=int(input())
S=input()
lis=list(S)
C= collections.Counter(lis)
count=list(C.values())
c=0
for i in range(N):
    print(i)
    for j in range(i,(N+i-1) // 2+1):
        if(lis[i]!=lis[j]):
            if(lis[j]!=lis[2*j-i]):
                if(lis[i]!=lis[2*j-i]):
                    c+=1
print(count[0]*count[1]*count[2]-c)


import collections
N=int(input())
S=input()
lis=list(S)
C= collections.Counter(lis)
count=list(C.values())
c=0
for i in range(N):
    for j in range(i,(N+i-1) // 2+1):
        if(lis[i]!=lis[j]):
            if(lis[j]!=lis[2*j-i]):
                if(lis[i]!=lis[2*j-i]):
                    c+=1
if(len(count)==3):
    print(count[0]*count[1]*count[2]-c)
else:
    print(0)


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())
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)
def func(a,b,c):
    ans = 0
    for i in a:
        for k in [num1 for num1 in b if num1 > i+1]:
            if (k + i) // 2 in j:
                    ans -= 1
    return ans
print(ans + func(r,g,b) + func(r,b,g) + func(g,r,b) + func(g,b,r) + func(b,g,r) + func(b,r,g))

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:
            break
        elif 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 = S.count("R")
G = S.count("G")
B = S.count("B")

RGB = [R,G,B]
RGB.sort()
ans = min(RGB) * (max(RGB)+1) * (RGB[1]-1)
print(ans)


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


x = 0
for i in R:
  for j in G:
    if (i - j) % 2 == 0 and (i + j) // 2 in B:
      x -= 1
    if 2 * j - i in B:
      x -= 1
    if 2 * i - j in B:
      x -= 1
    # print(i,j,x)
x += len(R) * len(B) * len(G)
print(x)


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):
ans=0
n=int(input())
k=str(input())
r=k.count("R")
b=k.count("B")
g=k.count("G")
ans+=r*b*g
    
for i in range(n-2):
  ii=k[i]
  for j in range(i+1,(n-i)//2):
    jj=k[j]
    l=j+(j-i)
    #print(l)
    if jj!=ii and l<n:
      #print(i,j)
      ll=k[l]
      if ii!=ll and jj!=ll:
        ans-=1
          #print(i,j,l)
print(ans)

ans=0
n=int(input())
k=str(input())
r=k.count("R")
b=k.count("B")
g=k.count("G")
ans+=r*b*g
    
for i in range(n-2):
  ii=k[i]
  for j in range(i+1,(n-i)//2+1+i):
    jj=k[j]
    l=j+(j-i)
    #print(l)
    if jj!=ii and l<n:
      #print(i,j)
      ll=k[l]
      if ii!=ll and jj!=ll:
        ans-=1
          #print(i,j,l)
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

for i in range(n-3):
    for j in range(i+1, n-2):
        if s[i] == s[j]:
            continue
        for k in range(j+1, n-1):
            if s[i] == s[k] or s[j] == s[k]:
                continue
            else:
                if j - i == k - j:
                    continue
                else:
                    count += 1

print(count)


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

nr = s.count("R")
ng = s.count("G")
nb = s.count("B")

count = nr * ng * nb

for i in range(n-3):
    for j in range(i+1, (n+i+1)//2):
        if s[i] == s[j]:continue
        else:
            k = 2*j - i 
            if s[i] == s[k]:continue
            if s[j] == s[k]:continue
            count -= 1

print(count)


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

nr = s.count("R")
ng = s.count("G")
nb = s.count("B")

count = nr * ng * nb

for i in range(n-3):
    for j in range(i+1, n-1):
        if s[i] == s[j]:continue
        else:
            k = 2*j - i 
            if k > n - 1:continue
            if s[i] == s[k]:continue
            if s[j] == s[k]:continue
            count -= 1

print(count)


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

nr = s.count("R")
ng = s.count("G")
nb = s.count("B")

count = nr * ng * nb

for i in range(n-2):
    for j in range(i+1, (n+i+1)//2):
        if s[i] == s[j]:continue
        else:
            k = 2*j - i 
            if s[i] == s[k]:continue
            if s[j] == s[k]:continue
            count -= 1

print(count)


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=[]
ans=0
x=0
a=0
b=0
c=0
for i in S:
    if i=="R":
        R.append(x)
    if i=="G":
        G.append(x)
    if i=="B":
        B.append(x)
    x+=1
for j in R:
    for k in G:
        if 2*k-j in B:
            B.pop(B.index(2*k-j))
            a+=1
        if 2*j-k in B:
            B.pop(B.index(2*j-k))   
            b+=1
        if (j+k)/2 in B:
            B.pop(B.index((j+k)/2))
            c+=1
        count+=len(B)
        if a!=0:
            B.append(2*k-j)
            a=0
        if b!=0:
            B.append(2*j-k)
            b=0
        if c!=0:
            B.append((j+k)/2)
            c=0
print(ans)

N=int(input())
S=list(input())
S.insert(0,0)
R=S.count("R")
G=S.count("G")
B=S.count("B")
ans=R*G*B
for i in range(1,N-1):
    for j in range(i+1,N):
        k=2*j-i
        if k<N+1 and S[i]!=S[j] and S[j]!=S[k] and S[k]!=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 itertools

N = int(input())
S = input()
out = S.count('R') * S.count('G') * S.count('B')
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()
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: 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):
_input = input
#'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''




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

RGB_num=[0]*3

for c in S:
	if c=='R':
		RGB_num[0] += 1
	elif c=='G':
		RGB_num[1] += 1
	else:
		RGB_num[2] += 1

#print(RGB_num)
joken2=0

print(S[0])
for i in range(N-2):
	#print("i",i,S[i+1])
	for j in range(min(i+1,N-i-2)):
		if S[i+1] != S[i-j] and S[i+1] != S[i+j+2] and S[i-j] != S[i+j+2]:
			joken2 += 1
			#print(i,j,S[i-j]+S[i+1]+S[i+j+2],"j2")
		#else:
			#print(i,j,S[i-j]+S[i+1]+S[i+j+2])

joken1=RGB_num[0]*RGB_num[1]*RGB_num[2]

print(joken1-joken2)

input = _input


_input = input
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''




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

RGB_num=[0]*3

for c in S:
	if c=='R':
		RGB_num[0] += 1
	elif c=='G':
		RGB_num[1] += 1
	else:
		RGB_num[2] += 1

#print(RGB_num)
joken2=0

print(S[0])
for i in range(N-2):
	#print("i",i,S[i+1])
	for j in range(min(i+1,N-i-2)):
		if S[i+1] != S[i-j] and S[i+1] != S[i+j+2] and S[i-j] != S[i+j+2]:
			joken2 += 1
			#print(i,j,S[i-j]+S[i+1]+S[i+j+2],"j2")
		#else:
			#print(i,j,S[i-j]+S[i+1]+S[i+j+2])

joken1=RGB_num[0]*RGB_num[1]*RGB_num[2]

print(joken1-joken2)

input = _input



_input = input
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''




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

RGB_num=[0]*3

for c in S:
	if c=='R':
		RGB_num[0] += 1
	elif c=='G':
		RGB_num[1] += 1
	else:
		RGB_num[2] += 1

#print(RGB_num)
joken2=0

print(S[0])
for i in range(N-2):
	#print("i",i,S[i+1])
	for j in range(min(i+1,N-i-2)):
		if S[i+1] != S[i-j] and S[i+1] != S[i+j+2] and S[i-j] != S[i+j+2]:
			joken2 += 1
			#print(i,j,S[i-j]+S[i+1]+S[i+j+2],"j2")
		#else:
			#print(i,j,S[i-j]+S[i+1]+S[i+j+2])

joken1=RGB_num[0]*RGB_num[1]*RGB_num[2]

print(joken1-joken2)

input = _input


_input = input
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''




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

RGB_num=[0]*3

for c in S:
	if c=='R':
		RGB_num[0] += 1
	elif c=='G':
		RGB_num[1] += 1
	else:
		RGB_num[2] += 1

#print(RGB_num)
joken2=0

for i in range(N-2):
	#print("i",i,S[i+1])
	for j in range(min(i+1,N-i-2)):
		if S[i+1] != S[i-j] and S[i+1] != S[i+j+2] and S[i-j] != S[i+j+2]:
			joken2 += 1
			#print(i,j,S[i-j]+S[i+1]+S[i+j+2],"j2")
		#else:
			#print(i,j,S[i-j]+S[i+1]+S[i+j+2])

joken1=RGB_num[0]*RGB_num[1]*RGB_num[2]

print(joken1-joken2)

input = _input


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):
n = int(input())
s = input()
r = 0
g = 0 
for i in range(s):
  if i == 'R':
    r += 1
  elif i == 'G':
    g += 1
  
c = r*g*(n-r-g)
for j in range(1, n):
  for i in range(1, min(j, n - j -1) + 1):
    if s[j] != s[j + i] and s[j] != s[j - i] and s[j - i] != s[j + 1]:
      c -= 1
print(c)
  

n = int(input())
s = input()
r = 0
g = 0 
for i in s:
  if i == 'R':
    r += 1
  elif i == 'G':
    g += 1
  
c = r*g*(n-r-g)
for j in range(1, n-1):
  for i in range(1, min(j, n - j -1) + 1):
    if (s[j] != s[j + i] ) and (s[j] != s[j - i]) and (s[j - i] != s[j + i]):
      c -= 1
print(c)

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

R = []
G = []
B = []
ans = 0

for i, x in enumerate(S):
  if x == 'R':
    R.append(i)
  elif x == 'G':
    G.append(i)
  else:
    B.append(i)

def calc(a, b, c):
  lis = sorted([a, b, c])
  if lis[1] * 2 != lis[0] + lis[2]:
    return 1
  else:
    return 0
        
lis = [calc(r, g, b) for r in R for g in G for b in B]
print(sum(lis))

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: 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-2):
  for j in range(i+1,n-1):
    k = j+1
    if k < n and 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-2):
    for j in range(i+1,N-1):
        k = j-i + j
        if k < N and S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
            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=str(input())
t=len(s)

r=set()
g=set()
b=set()
a=0
for i in range(n):
    if s[i]=='R':
        r.add(i)
    if s[i]=='G':
        g.add(i)
    if s[i]=='B':
        b.add(i)
d=len(r)*len(g)*len(b)
for ri in r:
    for gi in g:
        if 2ri-gi in b:
            d-=1
        if 2gi-ri in b:
            d-=1
        if (gi+ri)/2 in b:
            d-=1

print(d)

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

r=set()
g=set()
b=set()
a=0
for i in range(n):
    if s[i]=='R':
        r.add(i)
    if s[i]=='G':
        g.add(i)
    if s[i]=='B':
        b.add(i)
d=len(r)*len(g)*len(b)
for ri in r:
    for gi in g:
        if 2*ri-gi in b:
            d-=1
        if 2*gi-ri in b:
            d-=1
        if (gi+ri)/2 in b:
            d-=1

print(d)

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


def main():
    for i in range(N):
        first_s = S[i]
        for j in range(i+1, N):
            if S[j] != first_s:
                second_s = S[j]
                for k in range(j+1, N):
                    if (S[k] != first_s) and (S[k] != second_s):
                        if k == 2*j-i:
                            continue
                        ans += 1
    print(ans)


if __name__ == '__main__':
    main()


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

r, g, b = 0, 0, 0
ans = 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(N):
    for j in range(i+1, N):
        if 2*j-i < N:
            if (S[i] != S[j]) and (S[j] != S[2*j-i]) and (S[i] != S[2*j-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 = []
for idx, i in enumerate(S, 1):
    if i == 'R':
        r.append(idx)
    elif i == 'G':
        g.append(idx)
    else:
        b.append(idx)

b = set(b)
cnt = len(b) * len(r) * len(g)
print(r)
print(g)
for i in r:
    original = i
    for j in g:
        i = original
        if i > j:
            i, j = j, i
        d = j - i
        if j + d in b:
            cnt -= 1
        if i - d in b:
            cnt -= 1
        if d % 2 == 0 and (i + j) // 2 in b:
            cnt -= 1
print(cnt)


N = int(input())
S = input()
r = []
g = []
b = []
for idx, i in enumerate(S, 1):
    if i == 'R':
        r.append(idx)
    elif i == 'G':
        g.append(idx)
    else:
        b.append(idx)

b = set(b)
cnt = len(b) * len(r) * len(g)
for i in r:
    original = i
    for j in g:
        i = original
        if i > j:
            i, j = j, i
        d = j - i
        if j + d in b:
            cnt -= 1
        if i - d in b:
            cnt -= 1
        if d % 2 == 0 and (i + j) // 2 in b:
            cnt -= 1
print(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())
str=input()
count=str.count("R")*str.count("G")*str.count("B")
count0=0
for i in range(0,n-2):
    for j in range(i+1,(n+i)/2):
        k=2*j-i
        if str[k]!=str[i] and str[k]!=str[j] and str[i]!=str[j]:
            count0=count0+1
print(count-count0)

n=int(input())
str=input()
count=str.count("R")*str.count("G")*str.count("B")
count0=0
for i in range(0,n-2):
    for j in range(i+1,int((n+i-1)/2)+1):
        k=2*j-i
        if str[k]!=str[i] and str[k]!=str[j] and str[i]!=str[j]:
            count0=count0+1
print(count-count0)

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= list(input())
count=0
rr,bb,gg=0,0,0
for i in range(0,n):
    if s_list[i]=="R":
        rr=rr+1
    elif s_list[i]=="G":
        gg=gg+1
    else:
        bb=bb+1
sum=rr*gg*bb

for p in range(0,n-2):
    for q in range(p+1,n-1):
        if s_list[p] == s_list[q]:
            break
        else:
            for r in range(q+1,n):
                if s_list[r]==s_list[p] or s_list[r]==s_list[q] :
                    break
                elif r-q==q-p:
                    count = count+1
                    print(p,q,r)
print(sum-count)

n= int(input())
s_list= list(input())
r_list=[]
g_list=[]
b_list=[]
count=0
for i in range(0,n):
    if s_list[i]=="R":
        r_list.append(i)
    elif s_list[i]=="G":
        g_list.append(i)
    else:
        b_list.append(i)
print(r_list)
print(b_list)
print(g_list)
for pp in r_list:
    for qq in g_list:
        count=count+len(b_list)
        if (pp+qq)/2 in b_list:
            count=count-1
        elif 2*pp-qq in b_list:
            count=count-1
        elif 2*qq-pp in b_list:
            count=count-1
print(count)

n= int(input())
s_list= list(input())
count=0
rr,bb,gg=0,0,0
for i in range(0,n):
    if s_list[i]=="R":
        rr=rr+1
    elif s_list[i]=="G":
        gg=gg+1
    else:
        bb=bb+1
sum=rr*gg*bb

for p in range(0,n-2):
    for q in range(p+1,n-1):
        if s_list[p] == s_list[q]:
            continue
        elif 2*q-p<n and s_list[2*q-p]!=s_list[p] and s_list[2*q-p]!=s_list[q]:
            count= count+1
print(sum-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())
S = input()

idxs = [i for i in range(N)]

ris = [i for i, s in enumerate(S) if s == "R"]
gis = [i for i, s in enumerate(S) if s == "G"]
bis = [i for i, s in enumerate(S) if s == "B"]

ans = 0
for ri in ris:
    for gi in gis:
        for bi in bis:
            i, j, k = sorted([ri, gi, bi])
            if k - j != j - i:
                ans += 1



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

ris = [i for i, s in enumerate(S) if s == "R"]
gis = [i for i, s in enumerate(S) if s == "G"]
bis = [i for i, s in enumerate(S) if s == "B"]

all = len(ris) * len(gis) * len(bis)

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

ans = all - cnt


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

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):
        j = i + d
        k = j + d
        if k > n:
            break
        if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
            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(1, n):
        j = i + d
        k = j + d
        if k >= n:
            break
        if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
            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 = []
for i in range(n):
  if s[i] == 'R':
    r.append(i)
  elif s[i] == 'G':
    g.append(i)
  else:
    b.append(i)
res = 0
for i in range(len(r)):
  for j in range(len(b)):
    if (i + j) / 2 in g:
      res += len(g) - 1
    else:
      res += len(g)
print(res)

n=int(input())
s=input()
R=[]
G={}
B=[]
for i in range(n):
  if s[i]=='R':
    R.append(i+1)
  elif s[i]=='G':
    G[i+1]=G.get(i+1,0)+1
  else:
    B.append(i+1)
res=len(R)*len(G)*len(B)
for i in R:
  for j in B:
    if ((i+j)%2==0 and G.get((i+j)//2,0)==1):
      res-=1
    if G.get(2*max(i,j)-min(i,j),0)==1:
      res-=1
    if G.get(2*min(i,j)-max(i,j),0)==1:
      res-=1
print(res)

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

c = Counter(list(s))
ans = 1
for i in list(c.values):
    ans *= i
for i in range(n-2):
    for j in range(i+1, n-1):
        k = j + (j-i)
        if k >= n:
            break
        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            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):
        k = 2*j-i
        if k < n:
            if s[k] != s[i] and s[k] != s[j] and s[i] != s[j]:
                ans -= 1
        else:
            break
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
from collections import Counter


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    N = int(input())
    S = input()
    C = Counter(S)
    r = C.get("R")
    g = C.get("G")
    b = C.get("B")
    answer = r * g * b
    for left in range(N):
        for mid in range(left + 1, N):
            right = mid * 2 - left
            if right < N:
                if S[right] != S[mid] and S[mid] != S[left] and S[right] != S[left]:
                    answer = -1
    print(answer)


if __name__ == "__main__":
    main()


import sys
from collections import Counter


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    N = int(input())
    S = input()
    C = Counter(S)
    r = C.get("R",0)
    g = C.get("G",0)
    b = C.get("B",0)
    answer = r * g * b
    for left in range(N):
        for mid in range(left + 1, N):
            right = mid * 2 - left
            if right < N:
                if S[right] != S[mid] and S[mid] != S[left] and S[right] != S[left]:
                    answer -= 1
    print(answer)


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):
from numba import jit

n=int(input())
s=input()
R=[]
G=[]
B=[]

@jit
def f():
  for i in range(n):
    if s[i]=="R":
      R.append(i)
    elif s[i]=="G":
      G.append(i)
    else:
      B.append(i)
  r=len(R)
  g=len(G)
  b=len(B)
  if r==0 or g==0 or b==0:
    return 0
  else:
    ans=r*g*b
    m=0
    for j in range(1,n-1):
      for k in range(1,min(j,n-1-j)+1):
        lt=s[j-k]
        md=s[j]
        rt=s[j+k]
        if lt!=md and md!=rt and rt!=lt:
          m+=1
    return ans-m
print(f())

n=int(input())
s=input()
R=[]
G=[]
B=[]
def f():
  for i in range(n):
    if s[i]=="R":
      R.append(i)
    elif s[i]=="G":
      G.append(i)
    else:
      B.append(i)
  r=len(R)
  g=len(G)
  b=len(B)
  if r==0 or g==0 or b==0:
    return 0
  else:
    ans=r*g*b
    m=0
    for j in range(1,n-1):
      for k in range(1,min(j,n-1-j)+1):
        lt=s[j-k]
        md=s[j]
        rt=s[j+k]
        if lt!=md and md!=rt and rt!=lt:
          m+=1
    return ans-m
print(f())

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 = input()
D = {"R": [], "G": [], "B": []}
for i in range(N):
  D[S[i]].append(i)
print(D)
p = 1
for i in D:
  p *= len(D[i])
cnt = 0
for i in range(N):
  for j in range(i+1, N):
    if 2 * j - i < N:
      if S[i] != S[j] and S[j] != S[2*j-i] and S[2*j-i] != S[i]:
        cnt += 1
print(p-cnt)

N = int(input())
S = input()
D = {"R": [], "G": [], "B": []}
for i in range(N):
  D[S[i]].append(i)
p = 1
for i in D:
  p *= len(D[i])
cnt = 0
for i in range(N):
  for j in range(i+1, N):
    if 2 * j - i < N:
      if S[i] != S[j] and S[j] != S[2*j-i] and S[2*j-i] != S[i]:
        cnt += 1
print(p-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):
import math
from functools import reduce

n = int(input())
ans = 0

def gcd(*numbers):
    return reduce(math.gcd, numbers)

for a in range(1,n+1):
    for b in range(1,n+1):
        for c in range(1,n+1):
            ans += gcd(a,b,c)
print(ans)

n = int(input())
s = input()
count = 0

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

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

Verdicts: Wrong Answer

Accepted
Problem: Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive).  There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them.  Since this sum can be enormous, print the value modulo (10^9+7).  Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N.

Submission attempts (in order):
N, K = map(int, input().split())
mod = 10 ** 9 + 7

s = 0
tmp = 1
for _ in range(N):
    tmp *= K
    tmp %= mod
s = tmp
for i in range(K+1):
    baisuu = K % i
    tmp = 1
    for _ in range(N):
        tmp *= baisuu
        tmp %= mod
    s += tmp * (i - 1)

print(s)

N, K = map(int, input().split())
mod = 10 ** 9 + 7

s = 0
tmp = 1
for _ in range(N)
    tmp *= K
    tmp %= mod
s = tmp
for i in range(K+1):
    baisuu = K % i
    tmp = 1
    for _ in range(N)
        tmp *= baisuu
        tmp %= mod
    s += tmp * (i - 1)

print(s)

N, K = map(int, input().split())
mod = 10 ** 9 + 7

s = 0
tmp = 1
for _ in range(N):
    tmp *= K
    tmp %= mod
s = tmp
for i in range(2, K+1):
    baisuu = K % i
    tmp = 1
    for _ in range(N):
        tmp *= baisuu
        tmp %= mod
    s += tmp * (i - 1)

print(s)

from functools import lru_cache


mod = 10 ** 9 + 7
N, K = map(int, input().split())

@lru_cache
def gcd1_tuples(k):
    if k == 1:
        return 1
    tmp = pow(k, N, mod)
    for j in range(2, k+1):
        tmp -= gcd1_tuples(k//j)
        tmp %= mod
    return tmp

s = 0
for i in range(1, K+1):
    s += gcd1_tuples(K//i) * i
    s %= mod

print(s)




Verdicts: Runtime Error

Runtime Error

Wrong Answer

Accepted
Problem: Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive).  There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them.  Since this sum can be enormous, print the value modulo (10^9+7).  Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N.

Submission attempts (in order):
# encoding:utf-8
import copy
import random
import bisect 
import fractions 
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) 

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N, K = LI()




x_cnt = [0 for i in range(K + 1)]
for x in range(N, 0, -1):
    # print(x)
    tmp = pow(K // x, N, mod)
    for x_n in range(x + x, N+1, x):
        tmp -= x_cnt[x_n]
    x_cnt[x] = tmp % mod

ans = 0
for i in range(1,K+1):
    ans += i * x_cnt[i]
    ans %= mod
print(ans)


    



# encoding:utf-8
import copy
import random
import bisect 
import fractions 
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) 

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N, K = LI()




x_cnt = [0] * (K + 1)
for x in range(K, 0, -1):
    # print(x)
    tmp = pow(K // x, N, mod)
    for j in range(x + x, K+1, x):
        tmp -= x_cnt[j]
    x_cnt[x] = tmp

ans = 0
for i in range(1,K+1):
    ans += i * x_cnt[i]
    ans %= mod
print(ans)


    



Verdicts: Runtime Error

Accepted
Problem: Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive).  There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them.  Since this sum can be enormous, print the value modulo (10^9+7).  Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N.

Submission attempts (in order):
import bisect
import copy
import heapq
import sys
import itertools
import queue
input = sys.stdin.readline
sys.setrecursionlimit(100000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n) 


def main():
    N, K = read_values()
    C = [0] * (K + 1)

    for k in range(K, 0, -1):
        M = K // k
        C[k] = pow(M, N, mod)
        for r in range(2 * k, K, k):
            C[k] -= C[r]
            C[k] %= mod
    print(sum(i * k for i, k in enumerate(C)) % mod)


if __name__ == "__main__":
    main()


import bisect
import copy
import heapq
import sys
import itertools
import queue
input = sys.stdin.readline
sys.setrecursionlimit(100000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n) 


def main():
    N, K = read_values()
    C = [0] * (K + 1)

    for M in range(K, 1, -1):
        c = K // M
        C[M] = pow(c, N, mod)
        for r in range(2 * M, K + 1, M):
            C[M] -= C[r]
            C[M] %= mod

    C[1] = pow(K, N, mod) - sum(C) % mod
    C[1] %= mod
    print(sum(i * k for i, k in enumerate(C)) % mod) 


if __name__ == "__main__":
    main()


Verdicts: Wrong Answer

Accepted