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):
x1 = input()
x2 = input()
RGB = {"R", "G", "B"}
_sum = 0
for i, rgb in zip(itertools.combinations(range(x1), 3), itertools.combinations(x2, 3)):
    if set(rgb) == RGB and (i[1] - i[0]) != (i[2] - i[1]):
        _sum += 1
print(_sum)

from itertools import product

x1 = int(input())
x2 = input()

R_i = [i for i, x in enumerate(x2) if x == "R"]
G_i = [i for i, x in enumerate(x2) if x == "G"]
B_i = {i for i, x in enumerate(x2) if x == "B"}

R = len(R_i)
G = len(G_i)
# B = len(B_i)

xs = map(sorted, product(R_i, G_i))

s = 0
for a in xs:
    k = a[1]*2 - a[0]  # 2j-i
    if k in B_i:
        s +=1
    i = a[0]*2 - a[1]  # 2j-k
    if i in B_i:
        s +=1
    j = (a[0] + a[1]) / 2
    if j.is_integer():
        j = int(j)
        if j in B_i:
            s +=1
print(R*G*B - s)

import itertools

x1 = input()
x2 = input()
RGB = {"R", "G", "B"}
_sum = 0
for i, rgb in zip(itertools.combinations(range(x1), 3), itertools.combinations(x2, 3)):
    if set(rgb) == RGB and (i[1] - i[0]) != (i[2] - i[1]):
        _sum += 1
print(_sum)

from itertools import product

x1 = int(input())
x2 = input()

R_i = [i for i, x in enumerate(x2) if x == "R"]
G_i = [i for i, x in enumerate(x2) if x == "G"]
B_i = {i for i, x in enumerate(x2) if x == "B"}

R = len(R_i)
G = len(G_i)
# B = len(B_i)

xs = map(sorted, product(R_i, G_i))

s = 0
for a in xs:
    k = a[1]*2 - a[0]  # 2j-i
    if k in B_i:
        s +=1
    i = a[0]*2 - a[1]  # 2j-k
    if i in B_i:
        s +=1
    j = (a[0] + a[1]) / 2
    if j.is_integer():
        j = int(j)
        if j in B_i:
            s +=1
print(R*G*B - s)

x1 = int(input())
x2 = input()

R_i = [i for i, x in enumerate(x2) if x == "R"]
G_i = [i for i, x in enumerate(x2) if x == "G"]
B_i = [i for i, x in enumerate(x2) if x == "B"]

R = len(R_i)
G = len(G_i)
B = len(B_i)

xs = map(sorted, product(R_i, G_i))

s = 0
for a in xs:
    k = a[1]*2 - a[0]  # 2j-i
    if k in B_i:
        s +=1
    i = a[0]*2 - a[1]  # 2j-k
    if i in B_i:
        s +=1
    j = (a[0] + a[1]) / 2
    if j.is_integer():
        j = int(j)
        if j in B_i:
            s +=1
print(R*G*B - s)

import itertools

x1 = 39
x2 = "RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB"
RGB = {"R", "G", "B"}
_sum = 0
for i, rgb in zip(itertools.combinations(range(x1), 3), itertools.combinations(x2, 3)):
    if set(rgb) == RGB and (i[1] - i[0]) != (i[2] - i[1]):
        _sum += 1
print(_sum)

from itertools import product  


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

R_i = [i for i, s in enumerate(S) if s == "R"]  
G_i = [i for i, s in enumerate(S) if s == "G"]  
B_i = {i for i, s in enumerate(S) if s == "B"}  

R = len(R_i)  
G = len(G_i)  
B = len(B_i)  

xs = map(sorted, product(R_i, G_i))  

s = 0  
for x in xs:  
    k = 2 * x[1] - x[0]  # 2j-i  
    if k in B_i:  
        s += 1  
    i = 2 * x[0] - x[1]  # 2j-k  
    if i in B_i:  
        s += 1  
    j = (x[0] + x[1]) / 2  # (i+k)/2  
    if j in B_i:  
        s += 1  

print(R * G * B - s)  

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Accepted