Problem p02714 (python)

Fixed submission:
a=int(input())
moji=input()
r=[]
g=[]
b=[]
for i in range(a):
    if moji[i]=="R":
        r.append(i)
    elif moji[i]=="G":
        g.append(i)
    else:
        b.append(i)
res=len(r)*len(g)*len(b)
if len(r)==0 or len(g)==0 or len(b)==0:
    print(0)
else:
    for i in range(0,a-2):
      for j in range(i+1,a-1):
        if 2*j-i<a and moji[i]!=moji[j] and moji[j]!=moji[2*j-i] and moji[2*j-i]!=moji[i]:
          res-=1
    print(res)

Buggy submission (verdict: Runtime Error):
a=int(input())
moji=input()
r=[]
g=[]
b=[]
for i in range(a):
    if moji[i]=="R":
        r.append(i)
    elif moji[i]=="G":
        g.append(i)
    elif moji[i]=="B":
        b.append(i)
res=len(r)*len(g)*len(b)
if len(r)==0 or len(g)==0 or len(b)==0:
    print(0)
else:
    min_len={r:0,g:1,b:2}
    if len(r)>len(g):
        tmp=min_len[r]
        min_len[r]=min_len[g]
        min_len[g]=tmp
    if len(g)>len(b):
        tmp=min_len[g]
        min_len[g]=min_len[b]
        min_len[b]=tmp
    if len(b)>len(r):
        tmp=min_len[b]
        min_len[b]=min_len[r]
        min_len[r]=tmp
    
    for key,value in min_len.items():
        if value==0:
            a1=key
        elif value==1:
            a2=key
        elif value==2:
            a3=key
    
    for i in a1:
        for j in a2:
            if -abs(i-j)+min(i,j) in a3:
                res-=1
            if abs(i-j)+max(i,j) in a3:
                res-=1
            if abs(i-j)%2==0 and  int(abs(i-j)/2)+min(i,j) in a3:
                res-=1
    print(res)

Buggy submission (verdict: Runtime Error):

a=int(input())
moji=input()
r=[]
g=[]
b=[]
for i in range(a):
    if moji[i]=="R":
        r.append(i)
    elif moji[i]=="G":
        g.append(i)
    elif moji[i]=="B":
        b.append(i)
res=len(r)*len(g)*len(b)
if len(r)==0 or len(g)==0 or len(b)==0:
    print(0)
else:
    min_len={len(r):r,len(g):g,len(b):b}
    tmp=sorted(min_len.keys())
    r=min_len[tmp[0]]
    g=min_len[tmp[1]]
    b=min_len[tmp[2]]
    for i in r:
        for j in g:
            if -abs(i-j)+min(i,j) in b:
                res-=1
            if abs(i-j)+max(i,j) in b:
                res-=1
            if abs(i-j)%2==0 and  int(abs(i-j)/2)+min(i,j) in b:
                res-=1
    print(res)

Buggy submission (verdict: Runtime Error):

a=int(input())
moji=input()
r=[]
g=[]
b=[]
for i in range(a):
    if moji[i]=="R":
        r.append(i)
    elif moji[i]=="G":
        g.append(i)
    elif moji[i]=="B":
        b.append(i)
res=len(r)*len(g)*len(b)
if len(r)==0 or len(g)==0 or len(b)==0:
    print(0)
else:
    min_len={len(r):r,len(g):g,len(b):b}
    tmp=sorted(min_len.keys())
    r=min_len[tmp[0]]
    g=min_len[tmp[1]]
    b=min_len[tmp[2]]
    for i in r:
        for j in g:
            if -abs(i-j)+min(i,j) in b:
                res-=1
            if abs(i-j)+max(i,j) in b:
                res-=1
            if abs(i-j)%2==0 and  int(abs(i-j)/2)+min(i,j) in b:
                res-=1
    print(res)

Buggy submission (verdict: Runtime Error):

a=int(input())
moji=input()
r=[]
g=[]
b=[]
for i in range(a):
    if moji[i]=="R":
        r.append(i)
    elif moji[i]=="G":
        g.append(i)
    elif moji[i]=="B":
        b.append(i)
res=len(r)*len(g)*len(b)
if len(r)==0 or len(g)==0 or len(b)==0:
    print(0)
else:
    min_len={len(r):r,len(g):g,len(b):b}
    tmp=list(min_len.keys()).sort()
    r=min_len[tmp[0]]
    g=min_len[tmp[1]]
    b=min_len[tmp[2]]
    for i in r:
        for j in g:
            if -abs(i-j)+min(i,j) in b:
                res-=1
            if abs(i-j)+max(i,j) in b:
                res-=1
            if abs(i-j)%2==0 and  int(abs(i-j)/2)+min(i,j) in b:
                res-=1
    print(res)

Buggy submission (verdict: Runtime Error):
a=int(input())
moji=input()
r=[]
g=[]
b=[]
for i in range(a):
    if moji[i]=="R":
        r.append(i)
    elif moji[i]=="G":
        g.append(i)
    elif moji[i]=="B":
        b.append(i)
res=len(r)*len(g)*len(b)
if len(r)==0 or len(g)==0 or len(b)==0:
    print(0)
else:
    min_len={len(r):r,len(g):g,len(b):b}
    tmp=list(min_len.keys()).sort()
    r=min_len[tmp[0]]
    g=min_len[tmp[1]]
    b=min_len[tmp[2]]
    for i in r:
        for j in g:
            if -abs(i-j)+min(i,j) in b:
                res-=1
            if abs(i-j)+max(i,j) in b:
                res-=1
            if abs(i-j)%2==0 and  int(abs(i-j)/2)+min(i,j) in b:
                res-=1
    print(res)