Problem:


Score : 400 points

Problem Statement

We have a string S of length N consisting of R, G, and B.

Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions:

S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k.

j - i \neq k - j.

Constraints

1 \leq N \leq 4000

S is a string of length N consisting of R, G, and B.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the number of triplets in question.

Sample Input 1

4
RRGB

Sample Output 1

1

Only the triplet (1,~3,~4) satisfies both conditions. The triplet (2,~3,~4) satisfies the first condition but not the second, so it does not count.

Sample Input 2

39
RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB

Sample Output 2

1800



Sample input:
4
RRGB


Sample output:
1

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

r = [0] * (n+1)
g = [0] * (n+1)
b = [0] * (n+1)
for i, c in enumerate(reversed(s), 1):
    if c == 'R':
        r[i] += r[i-1] + 1
    else:
        r[i] += r[i-1]
    
    if c == 'G':
        g[i] += g[i-1] + 1
    else:
        g[i] += g[i-1]
    
    if c == 'B':
        b[i] += b[i-1] + 1
    else:
        b[i] += b[i-1]

# print(r[:-1][::-1])
# print(g[:-1][::-1])
# print(b[:-1][::-1])

ans=0
for i in range(n-2):
    for j in range(i+1, n-1):
        if s[i] == s[j]:
            continue
        se = set('RGB') - set(s[i] + s[j])
        c = se.pop()
        print('i=',i,'j=',j,'c=',c)
        if c == 'R':
            ans += r[j]
            if 2*j-i < n and s[2*j-i] == 'R':
                ans -= 1
        elif c == 'G':
            ans += g[j]
            if 2*j-i < n and s[2*j-i] == 'G':
                ans -= 1
        elif c == 'B':
            ans += b[j]
            if 2*j-i < n and s[2*j-i] == 'B':
                ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
C = {"R", "G", "B"}
cumsum = {c:[0 for i in range(N)] for c in C}

for i in range(N):
  s = S[i]
  cumsum[s][i] = 1
for i in range(2, N+1):
  for c in C:
    cumsum[c][-i] = cumsum[c][-i] + cumsum[c][-(i-1)]
#print(cumsum)
ans = 0
for i in range(N):
  s = S[i]
  a, b = C - {s}
  ans += cumsum[a][i]*cumsum[b][i]

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

def inp():
    return int(input())
def inps():
    return input().rstrip()
def inpl():
    return list(map(int, input().split()))
def _debug(obj):
    print(obj, file=sys.stderr)

# import decimal
# from decimal import Decimal
# decimal.getcontext().prec = 10

# from heapq import heappush, heappop, heapify
# import math
# from math import gcd
# import itertools as it
# import collections
# from collections import deque 

# ---------------------------------------

N = inp()
S = inps()

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

for i in range(N):
    if S[i] == "R":
        r.append(i)
    if S[i] == "G":
        g.append(i)
    if S[i] == "B":
        b.append(i)

ans = 0
for m in r:
    for n in g:
        if m > n:
            m, n = n, m
        sa = abs(m - n)
        ans += len(b)
        if m - sa >= 0 and S[m - sa] == "B":
            ans -= 1
        if n + sa < N and S[n + sa] == "B":
            ans -= 1
        if sa % 2 == 0 and S[m + sa//2] == "B":
            ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

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

r = []
g = []
b = []
cnt = -1

for i in s:
	cnt += 1
	if i == 'R':
		r.append(cnt)
	elif i == 'G':
		g.append(cnt)
	else:
		b.append(cnt)

ans = 0		
						
for i in r:
	for j in g:
		for t in b:
			l = (i,j,t)
			total = sum(l)
			m, M = min(l), max(l)
			middle = total - m - M
			if middle - m != M - middle:
				ans += 1
	
print(ans)

Submission status: Wrong Answer

Solution code:
# author:  Taichicchi
# created: 19.09.2020 00:14:21

from collections import Counter
import sys
from math import prod

N = int(input())

S = input()


c = Counter(S)

ans = prod(list(c.values()))

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

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n=int(input())
s=input()
c=Counter(s)

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

lim=n//2
for i in range(1,n//2):
  for j in range(i,n-i):
    l=s[j-i]
    m=s[j]
    r=s[j+i]
    if l!=m and m!=r and r!=l:
      ans-=1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
r,g,b = [],[],[]
ans = 0
for i in range(n):
    if s[i] == "R":
        r.append(i)
    elif s[i] == "G":
        g.append(i)
    else:
        b.append(i)

lr,lg,lb = len(r),len(g),len(b)

for i in r:
    for j in g:
        if 2*j-i in set(b):
            ans += lb-1
        else:
            ans += lb

print(ans)

Submission status: Wrong Answer

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

from collections import Counter

c=Counter(s)

ans = 1
for i in list(c.values()):
    ans*=i

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

print(ans-cnt)

Submission status: Wrong Answer

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

from collections import Counter

c=Counter(s)

ans = 1
for i in list(c.values()):
    ans*=i

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


print(ans)

Submission status: Wrong Answer

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

from collections import Counter

c=Counter(s)

ans = 1
for i in list(c.values()):
    ans*=i

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


print(ans)

Submission status: Wrong Answer

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

from collections import Counter

c=Counter(s)

ans = 1
for i in list(c.values()):
    ans*=i

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


print(ans)

Submission status: Wrong Answer

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

from collections import Counter

c=Counter(s)

ans = 1
for i in list(c.values()):
    ans*=i

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


print(ans)

Submission status: Wrong Answer

Solution code:
def inN():
    return int(input())
def inL():
    return list(map(int,input().split()))
def inNL(n):
    return [list(map(int,input().split())) for i in range(n)]


n = inN()
s = input()


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

#print(r,b,g,r*b*g)
print(r*b*g - min(b,g)**2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

cnt = len(r)*len(g)*len(b)
for i in range(len(r)):
  for j in range(len(g)):
    if min(r[i],g[j]) - abs(r[i]-g[j]) in b:
      cnt -= 1
    if (r[i]+g[j]) / 2 in b:
      cnt -= 1
    if max(r[i],g[j]) + abs(r[i]-g[j]) in b:
      cnt -= 1
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
s = input()
c = Counter(s)
total = 1
for v in c.values():
  total *= v
for i in range(1, n - 1):
  for j in range(1, min(i + 1, n - i)):
    if s[i] != s[i - j] and s[i - j] != s[i + j] and s[i] != s[i + j]:
      total -= 1
print(total)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
s = input()
c = Counter(s)
total = 1
for v in c.values():
  total *= v

for i in range(1, n - 1):
  l = i - 1
  r = i + 1
  for j in range(min(l + 1, n - r)):
    if s[i] != s[l - j] and s[l - j] != s[r + j] and s[i] != s[r + j]:
      total -= 1
print(total)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

if N in [1,2]:
    print(0)
else:   
    for j in range(1,N-1):
        i,k = j-1, j+1
        while(i!=-1 and k!=N):
            if S[i] != S[k] and S[i] != S[j] and S[j] != S[k]:
                cnt += 1
            i -= 1
            k += 1
    ans = 1
    for v in S_cnt.values():
        ans *= v
    print(ans-cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

for j in range(1,N-1):
    i,k = j-1, j+1
    while(i!=-1 and k!=N):
        if S[i] != S[k] and S[i] != S[j] and S[j] != S[k]:
            cnt += 1
        i -= 1
        k += 1
ans = 1
for v in S_cnt.values():
    ans *= v
print(ans-cnt)

Submission status: Wrong Answer

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

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
from math import ceil as C, floor as F, sqrt, gcd as G
from collections import defaultdict as D, Counter as CNT
from functools import reduce as R
import heapq as HQ
from operator import mul

class Heap:
  def __init__(self, data, reverse=False):
    self.reverse = -1 if reverse else 1
    self.data = [self.reverse * d for d in data]
    HQ.heapify(self.data)
  def push(self, x): return HQ.heappush(self.data, self.reverse * x)
  def pop(self): return self.reverse * HQ.heappop(self.data) 

ALP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
alp = 'abcdefghijklmnopqrstuvwxyz'
def prod(list): return R(mul, list, 1)
def _X(): return sys.stdin.readline().rstrip().split(' ')
def _S(ss): return tuple(ss) if len(ss) > 1 else ss[0]
def S(): return _S(_X())
def Ss(): return list(S())
def _I(ss): return tuple([int(s) for s in ss]) if isinstance(ss, tuple) else int(ss)
def I(): return _I(S())
def _Is(ss): return list(ss) if isinstance(ss, tuple) else [ss]
def Is(): return _Is(I())

n = I()
rgb = S()

ans = prod([c for _, c in CNT(list(rgb)).items()])

for i, r in enumerate(rgb):
    for j, g in enumerate(rgb[i+1:], start=i+1):
        k = j + (j - i)
        if k < len(rgb):
            if r != g and g != rgb[k] and r != rgb[k]:
                ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from math import ceil as C, floor as F, sqrt, gcd as G
from collections import defaultdict as D, Counter as CNT
from functools import reduce as R
import heapq as HQ
from operator import mul

class Heap:
  def __init__(self, data, reverse=False):
    self.reverse = -1 if reverse else 1
    self.data = [self.reverse * d for d in data]
    HQ.heapify(self.data)
  def push(self, x): return HQ.heappush(self.data, self.reverse * x)
  def pop(self): return self.reverse * HQ.heappop(self.data) 

ALP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
alp = 'abcdefghijklmnopqrstuvwxyz'
def prod(list): return R(mul, list, 1)
def _X(): return sys.stdin.readline().rstrip().split(' ')
def _S(ss): return tuple(ss) if len(ss) > 1 else ss[0]
def S(): return _S(_X())
def Ss(): return list(S())
def _I(ss): return tuple([int(s) for s in ss]) if isinstance(ss, tuple) else int(ss)
def I(): return _I(S())
def _Is(ss): return list(ss) if isinstance(ss, tuple) else [ss]
def Is(): return _Is(I())

n = I()
rgb = S()

ans = prod([c for _, c in CNT(list(rgb)).items()])

for i, r in enumerate(rgb):
    for j, g in enumerate(rgb[i+1:], start=i+1):
        k = j + (j - i)
        if k < len(rgb):
            if r != g and g != rgb[k] and r != rgb[k]:
                print(i, j, k)
                ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from math import ceil as C, floor as F, sqrt, gcd as G
from collections import defaultdict as D, Counter as CNT
from functools import reduce as R
import heapq as HQ
from operator import mul

class Heap:
  def __init__(self, data, reverse=False):
    self.reverse = -1 if reverse else 1
    self.data = [self.reverse * d for d in data]
    HQ.heapify(self.data)
  def push(self, x): return HQ.heappush(self.data, self.reverse * x)
  def pop(self): return self.reverse * HQ.heappop(self.data) 

ALP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
alp = 'abcdefghijklmnopqrstuvwxyz'
def prod(list): return R(mul, list, 1)
def _X(): return sys.stdin.readline().rstrip().split(' ')
def _S(ss): return tuple(ss) if len(ss) > 1 else ss[0]
def S(): return _S(_X())
def Ss(): return list(S())
def _I(ss): return tuple([int(s) for s in ss]) if isinstance(ss, tuple) else int(ss)
def I(): return _I(S())
def _Is(ss): return list(ss) if isinstance(ss, tuple) else [ss]
def Is(): return _Is(I())

n = I()
rgb = S()

ans = prod([c for _, c in CNT(list(rgb)).items()])
for i, r in enumerate(rgb):
    for j, g in enumerate(rgb[i+1:], start=i+1):
        k = j + (j - i)
        if k < len(rgb):
            if r != g and g != rgb[k] and r != rgb[k]:
                ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
	N = int(input())
	S = list(input())
	R = []
	G = []
	B = []
	cnt = 0
	for i in range(len(S)):
		if S[i] == "R":
			R.append(i)
		elif S[i] == "G":
			G.append(i)
		elif S[i] == "B":
			B.append(i)
	l = len(B)
	for i in range(len(R)):
		r = R[i]
		for j in range(len(G)):
			g = G[j]
			if g > r:
				M = g
				m = r
			elif r > g:
				M = r
				m = g
			d = M - m
			if (M + d < N and S[M + d] == "B") and (m - d >= 0 and S[m - d] == "B"):
				cnt += l - 2
			elif (M + d < N and S[M + d] == "B") or (m - d >= 0 and S[m - d] == "B"):
				cnt += l - 1
			else:
				cnt += l
	print(cnt)

main()

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
S = input()
D = Counter(S)
ans = 1
for d in D.values():
    ans *= d

for i in range(N):
    for x in range(1, (N-i+1)//2):
        if S[i] != S[i+x] and S[i+x] != S[i+2*x] and S[i+2*x] != S[i]:
            ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
k=int(input())
import math
s=0
result=0
for a in range(1,k+1,1):
    for b in range(a,k+1,1):
        for c in range(b,k+1,1):
            gcd=math.gcd(math.gcd(a,b),math.gcd(b,c))
            if a==b==c:
                pass
            elif (a==b and b!=c) or (b==c and b!=a) or (a==c and a!=c):
                gcd=3*gcd
            else:
                gcd=6*gcd
            
            result+=gcd
print(result)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=[str(i) for i in input()]
cnt=0
for i in range(n):
    for j in range(i+1,n,1):
        for k in range(j+1,n,1):
            if j-i!=k-j:
                if  s[i]!=s[j] :
                    if s[k]!=s[i] :
                        if s[i]!=s[j]:
                            cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:

def solve(N, S):
    ans = 0
    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
    print(R, G, B, R*G*B)
    ans = R * G * B

    dif = 1
    while dif <= N//2+1:
        idx = 0
        while idx + dif + dif < N:
            if S[idx] != S[idx + dif] and S[idx+dif] != S[idx+2*dif] and S[idx+2*dif] != S[idx]:
                ans -= 1
            idx += 1
        dif += 1
    print(ans)
if __name__ == '__main__':
    # N = 4000
    # S = 'RGBR' * 1000
    N = int(input())
    S = input()

    solve(N, S)

Submission status: Wrong Answer

Solution code:

def solve(N, S):
    ans = 0
    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

    idx = 0
    dif = 1
    while dif <= N//2+1:
        while idx + dif + dif < N:
            if S[idx] != S[idx + dif] and S[idx+dif] != S[idx+2*dif] and S[idx+2*dif] != S[idx]:
                ans -= 1
            idx += 1
        dif += 1
    print(ans)
if __name__ == '__main__':
    # N = 4000
    # S = 'RGBR' * 1000
    N = int(input())
    S = input()

    solve(N, S)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

r = [i+1 for i, x in enumerate(s) if x == 'R']
g = [i+1 for i, x in enumerate(s) if x == 'G']
b = [i+1 for i, x in enumerate(s) if x == 'B']
    
c = 0
for i in range(1,n//2):
    for j in range(1,n-2*i+1):
        if j in r and j+i in g and j+2*i in b:
            c += 1
        if j in r and j+i in b and j+2*i in g:
            c += 1
        if j in g and j+i in b and j+2*i in r:
            c += 1
        if j in g and j+i in r and j+2*i in b:
            c += 1
        if j in b and j+i in r and j+2*i in g:
            c += 1
        if j in b and j+i in g and j+2*i in r:
            c += 1

ans = (len(r)*len(g)*len(b) - c)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
cnt=0
for i in range(n):
    if s[i]=="R" or "G" or "B":
        for j in range(n):
            if i<j:
                if s[j]!=s[i]:
                    for k in range(n):   
                        if s[k]!=s[i] and s[k]!=s[i]:
                            if j<k: 
                                if s[i]!=s[k]: 
                                    if j-i!=k-j:
                                        # print(i,j,k)
                                        cnt+=1
            
print(cnt)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
R=[]
G=[]
B=[]
count=1
for i in S:
    if i=="R":
        R.append(count)
    if i=="G":
        G.append(count)
    if i=="B":
        B.append(count)
    count+=1
ans=0
x=len(B)
for j in R:
    for k in G:
        if 2*j-k in B:
            x-=1
        if 2*k-j in B:
            x-=1
        if (k+j)/2==(k+j)//2 and (k+j)//2 in B:
            x-=1
        ans+=x
print(ans)

Submission status: Wrong Answer

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

c = collections.Counter(S)

total = 1

for k, v in c.items():
    total *= v
    
cnt = 0

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

print(total-cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
s=str(input())
R,G,B=[],[],[]
i=0
for ch in s:
    if ch=='R':
        R.append(i)
    elif ch=='G':
        G.append(i)
    else:
        B.append(i)
    i+=1
lr,lg,lb=len(R),len(G),len(B)
B=Counter(B)
ans=lr*lg*lb
for i in R:
    for j in G:
        if B[j+j-i]>=1:
            ans-=1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
input = sys.stdin.readline
n = int(input())
s = list(input())

num = 0

now_color = {'R':0,'G':0,'B':0}
c  = Counter(s)  
all_color = {'R':c['R'],'G':c['G'],'B':c['B']}

for i in range(n):
    now_color[s[i]] += 1
    alist = []
    for m in ['R','G','B']:
        if m != s[i]:
            alist.append(all_color[m]-now_color[m])
    num += alist[0]*alist[1]

# print(num)

for j in range(n):
    for d in range(1,min(j,n-j-1)+1):
        i = j-d
        k = j+d
        if s[i] == s[j] or s[j] == s[k] or s[k] == s[i]:
            num -= 1
            # print(i,j,k)

print(num)

Submission status: Wrong Answer

Solution code:
import sys
import functools
import collections
import operator


def resolve(in_):
    n = int(next(in_))
    s = next(in_)

    c = collections.Counter(s)
    c['R']
    c['G']
    c['B']
    ans = functools.reduce(operator.mul, collections.Counter(s).values())
    for i in range(1, n + 1):
        for j in range(i, n + 1):
            k = j * 2 - i
            if k - 1 >= n:
                break
            si = s[i - 1]
            sj = s[j - 1]
            sk = s[k - 1]
            if si != sj and sj != sk and sk != si:
                ans -= 1
    return ans


def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import functools
import collections
import operator


def resolve(in_):
    n = int(next(in_))
    s = next(in_)

    ans = functools.reduce(operator.mul, collections.Counter(s).values())
    for i in range(1, n + 1):
        for j in range(i, n + 1):
            k = j * 2 - i
            if k - 1 >= n:
                break
            si = s[i - 1]
            sj = s[j - 1]
            sk = s[k - 1]
            if si != sj and sj != sk and sk != si:
                ans -= 1
    return ans


def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import itertools

def f1(v):
    i, j, k = v
    return j - i != k - j


s = b''
def f2(v):
    i, j, k = v
    return s[i - 1] != s[j - 1] != s[k - 1]


def resolve(in_):
    n = int(next(in_))
    global s
    s = next(in_)

    
    it = ((i, j, k) for i in range(1, n + 1) for j in range(i, n + 1) for k in range(j, n + 1))
    it = filter(f1, it)
    it = filter(f2, it)
    ans = sum(1 for _ in it)

    return ans


def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
s = input()

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

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

for i in range(1,n // 2):
    for j in range(n - 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

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
d={'R':0,'G':0,'B':0}
for i in s:
  d[i]+=1
ans=1
for i in d:
  ans*=d[i]
for k in range(n//2):
  for i in range(n-2*k):
    if len(set([s[i],s[i+k],s[i+2*k]]))==3:ans-=1
print(ans)

Submission status: Wrong Answer

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

count=0

for i in range (N):
    if S[i]=="R":
        for j in range(N-i):
            if S[i+j]=="G":
                for k in range(N-i-j):
                    if S[i+j+k]=="G" and abs(j-i) != abs(k-j):
                        count+=1
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
out = 0
ls = []
RGB = ['R','G','B']
for i in RGB:
    ls.append([j for j, x in enumerate(S) if x == i])

for i in ls:
    print(i)
# flg = [[[0 for i in range(N)] for j in range(N)] for k in range(N)]
for i in ls[0]:
    for j in ls[1]:
        for k in ls[2]:
            tmp = [i,j,k]
            tmp.sort()
            [l,m,n] = tmp
            if m-l != n-m:
                out += 1

print(out)

Submission status: Wrong Answer

Solution code:
# D - RGB Triplets
from collections import defaultdict
from functools import reduce
from operator import mul


def main():
    _, S = open(0).read().split()
    indices, doubled_indices = defaultdict(list), defaultdict(set)
    for i, c in enumerate(S):
        indices[c].append(i)
        doubled_indices[c].add(2 * i)

    cnt = reduce(mul, [len(i) for i in indices.values()])
    for x, y, z in ("RGB", "RBG", "BGR"):
        cnt -= sum(i + j in doubled_indices[z] for i in indices[x] for j in indices[y])
    print(cnt)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
S = list(input())
cnt = Counter(S)
ans = 1
for v in cnt.values():
    ans *= v

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
S = list(input())
cnt = Counter(S)
ans = 1
for v in cnt.values():
    ans *= v

for dif in range(1, N // 2 - (N % 2 == 0) + 1):
    i = 0
    while 1:
        if (S[i] != S[i + dif])\
         & (S[i] != S[i + 2*dif])\
         & (S[i + dif] != S[i + 2*dif]):
            ans -= 1
        i += 1
        if i + 2*dif >= N:
            break
print(ans)

Submission status: Wrong Answer

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

r,g,b=[],[],[]
for i in range(N):
  s = S[i]
  if s=='R':r.append(i)
  elif s=='G':g.append(i)
  else:b.append(i)

count = 0
for i in r:
  for j in g:
    x,y,z = i+j, (i+j)/2, min(i,j)-abs(i-j)
    c = 0
    if x in b:c+=1
    if y in b:c+=1
    if z in b:c+=1
    count += len(b)-c
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
l = [1] * N
i = 0
d = {1:0,2:0,3:0}
for s in input():
    n = 1
    if s == "G":
        n = 2
    elif s == "B":
        n = 3
    l[i] = n
    d[n] += 1
    i += 1
cnt = d[1] * d[2] * d[3]
for j in range(1,(N - 1) // 2):
    for k in range(N - (2 * j)):
        if l[k] * l[k+j] * l[k+j+j] == 6:
            cnt -= 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def main():
    n= int(input())
    s = str(input().rstrip())
    r= s.count('R')
    g=s.count('G')
    b = s.count('B')
    ans = 0
    for i in range(2):
        for j in range(i+1, (n+i+1)//2):
            k = 2*j-i
            t = {s[i], s[j], s[k]}
            if len(t) ==3:
                ans +=1
    print(r*g*b-ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce
from collections import Counter

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

c = Counter(s)

ans = reduce(mul, c.values())

for i in range(n - 1):
    x, y, z = i, i + 1, i + 2
    while z <= n - 1:
        if s[x] != s[y] and s[x] != s[z] and s[y] != s[z]:
            ans -= 1
        y += 1
        z += 2

print(ans)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
S=input()
c=collections.Counter(S)
v=c.values()
ans=1
for vv in v:
  ans*=vv
hiku=0
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)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
S=input()
c=collections.Counter(S)
v=c.values()
ans=1
for vv in v:
  ans*=vv
hiku=0
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]:
          hiku+=1
print(ans-hiku)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
s=input()
c=collections.Counter(s)
v=c.values()
ans=1
for vv in v:
  ans*=vv
hiku=0

k=(n-3)//2
for kk in range(0,k+1):
  i=0
  while i+2*kk+2<=n-1:
    if len(set([s[i],s[i+kk+1],s[i+2*kk+2]]))==3:
      hiku+=1
    i+=1
print(ans-hiku)

Submission status: Wrong Answer

Solution code:
import collections
s=input()
c=collections.Counter(s)
v=c.values()
ans=1
for vv in v:
  ans*=vv
hiku=0
n=len(s)
k=(n-3)//2
for kk in range(0,k+1):
  i=0
  while i+2*kk+2<=n-1:
    if len(set([s[i],s[i+kk+1],s[i+2*kk+2]]))==3:
      hiku+=1
    i+=1
print(ans-hiku)

Submission status: Wrong Answer

Solution code:
import collections
s=input()
c=collections.Counter(s)
v=c.values()
ans=1
for vv in v:
  ans*=vv
hiku=0
n=len(s)
k=(n-3)//2
for kk in range(0,k+1):
  i=0
  while i+2*k+2<=n-1:
    if len(set([s[i],s[i+k+1],s[i+2*k+2]]))==3:
      hiku+=1
    i+=1
print(ans-hiku)