Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

a = sorted(a)
b = sorted(b)
c = sorted(c)

ans = 0

for i in range(n):
    ans1 = 0
    ans2 = 0
    ok = -1
    ng = n
    while abs(ng - ok) > 1:
        mid = (ok + ng) // 2
        if a[mid] < b[i] :
            ok = mid
        else:
            ng = mid
        if abs(ng - ok) == 1:
            ans1 += ok + 1
    ok = n
    ng = -1
    while abs(ng - ok) > 1:
        mid = (ok + ng) // 2
        if b[i] < c[mid]:
            ok = mid
        else:
            ng = mid
        if abs(ng - ok) == 1:
            ans2 += n - ok
    ans += ans1 * ans2
print(ans)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

a = sorted(a)
b = sorted(b)
c = sorted(c)

ans = 0

for i in range(n):
    ans1 = 0
    ans2 = 0
    ok = -1
    ng = n
    while abs(ng - ok) > 1:
        mid = (ok + ng) // 2
        if a[mid] < b[i] :
            ok = mid
        else:
            ng = mid
        if abs(ng - ok) == 1:
            ans1 += ok + 1
    ok = n
    ng = -1
    while abs(ng - ok) > 1:
        mid = (ok + ng) // 2
        if b[i] < c[mid]:
            ok = mid
        else:
            ng = mid
        if abs(ng - ok) == 1:
            ans2 += n - ok
    ans += ans1 * ans2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

a = sorted(a)
b = sorted(b)
c = sorted(c)

ans = 0

for i in range(n):
    ans1 = 0
    ans2 = 0
    ok = -1
    ng = n
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if a[mid] < b[i] :
            ok = mid
        else:
            ng = mid
        if ng - ok == 1:
            ans1 += ok + 1
    ok = n
    ng = -1
    while abs(ng - ok) > 1:
        mid = (ok + ng) // 2
        if b[i] < c[mid]:
            ok = mid
        else:
            ng = mid
        if abs(ng - ok) == 1:
            ans2 += n - ok
    ans += ans1 * ans2
print(ans)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

a = sorted(a)
b = sorted(b)
c = sorted(c)

ans = 0

for i in range(n):
    ans1 = 0
    ans2 = 0
    ok = -1
    ng = n
    while abs(ng - ok) > 1:
        mid = (ok + ng) // 2
        if a[mid] < b[i] :
            ok = mid
        else:
            ng = mid
        if abs(ng - ok) == 1:
            ans1 += ok + 1
    ok = n
    ng = -1
    while abs(ng - ok) > 1:
        mid = (ok + ng) // 2
        if b[i] < c[mid]:
            ok = mid
        else:
            ng = mid
        if abs(ng - ok) == 1:
            ans2 += n - ok
    ans += ans1 * ans2
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
d = list(map(int,input().split()))
m = int(input())
t = list(map(int,input().split()))

count = {}

for i in range(n):
    if d[i] in count.keys():
        count[d[i]] += 1
    else:
        count[d[i]] = 1  

for i in range(m):
    if count[t[i]] == 0:
        print("NO")
        break
    else:
        count[t[i]] -=1
    if i == m-1:
        print("YES")

Fixed submission:
n = int(input())
d = list(map(int,input().split()))
m = int(input())
t = list(map(int,input().split()))

count = {}

for i in range(n):
    if d[i] in count.keys():
        count[d[i]] += 1
    else:
        count[d[i]] = 1  

for i in range(m):
    if t[i] not in count.keys():
        print("NO")
        break
    if count[t[i]] == 0:
        print("NO")
        break
    else:
        if t[i] not in count.keys():
            print("NO")
            break
        else:
            count[t[i]] -=1
    if i == m-1:
        print("YES")
Buggy python submission (verdict: Runtime Error):
s = input()
if s[0] == 'Y' and s[1] == "A" and s[2] == "K" and s[3] == "I" and len(s) >= 4:
    print("Yes")
else:
    print("No")

Fixed submission:
s = input()
if len(s) >=4:
    if s[0] == 'Y' and s[1] == "A" and s[2] == "K" and s[3] == "I":
        print("Yes")
    else:
        print("No")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
s = input()
if s[0] == 'Y' and s[1] == "A" and s[2] == "K" and s[3] == "I":
    print("Yes")
else:
    print("No")

Fixed submission:
s = input()
if len(s) >=4:
    if s[0] == 'Y' and s[1] == "A" and s[2] == "K" and s[3] == "I":
        print("Yes")
    else:
        print("No")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
a = []
b = []
ans = ""
for i in range(m):
    tmp1,tmp2 = map(int,input().split())
    a.append(tmp1)
    b.append(tmp2)

xton = []
#nへ向かう便が出てる島を確認する
for i in range(m):
    if b[i] == n:
        xton.append(a[i])
#nへ向かう便が出ている島へ1から向かう便があるか確認する
for i in range(m):
    if a[i] == 1 and b[i] in xton:
        ans = "POSSIBLE"
        break
    else:
        ans = "IMPOSSIBLE"
print(ans)

Fixed submission:
n,m = map(int,input().split())
a = []
b = []
ans = ""
for i in range(m):
    tmp1,tmp2 = map(int,input().split())
    a.append(tmp1)
    b.append(tmp2)

xton = set()
#nへ向かう便が出てる島を確認する
for i in range(m):
    if b[i] == n:
        xton.add(a[i])
#nへ向かう便が出ている島へ1から向かう便があるか確認する
for i in range(m):
    if a[i] == 1 and b[i] in xton:
        ans = "POSSIBLE"
        break
    else:
        ans = "IMPOSSIBLE"
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
a = []
b = []
ans = ""
for i in range(m):
    tmp1,tmp2 = map(int,input().split())
    a.append(tmp1)
    b.append(tmp2)

xton = []
#nへ向かう便が出てる島を確認する
for i in range(m):
    if b[i] == n:
        xton.append(a[i])
#nへ向かう便が出ている島へ1から向かう便があるか確認する
for i in range(m):
    if a[i] == 1 and b[i] in xton:
        ans = "POSSIBLE"
        break
    else:
        ans = "IMPOSSIBLE"
print(ans)

Fixed submission:
n,m = map(int,input().split())
a = []
b = []
ans = ""
for i in range(m):
    tmp1,tmp2 = map(int,input().split())
    a.append(tmp1)
    b.append(tmp2)

xton = set()
#nへ向かう便が出てる島を確認する
for i in range(m):
    if b[i] == n:
        xton.add(a[i])
#nへ向かう便が出ている島へ1から向かう便があるか確認する
for i in range(m):
    if a[i] == 1 and b[i] in xton:
        ans = "POSSIBLE"
        break
    else:
        ans = "IMPOSSIBLE"
print(ans)
Buggy python submission (verdict: Runtime Error):
if a >= b :
    print("delicious")
elif b - a <= x:
    print("safe")
else:
    print("dangerous")

Fixed submission:
x,a,b = map(int,input().split())

if a >= b :
    print("delicious")
elif b - a <= x:
    print("safe")
else:
    print("dangerous")
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = []
for i in range(n):
    tmp = int(input())
    s.append(tmp)
sorted(s)
max_s = sum(s)

if max_s % 10 != 0:
    print(max_s)
else:
    for j in range(n):
        if s[j] % 10 != 0:
            print(max_s - s[j])
            break
if j == n-1:
    print(0)

Fixed submission:
n = int(input())
s = []
for i in range(n):
    tmp = int(input())
    s.append(tmp)
s = sorted(s)
max_s = sum(s)
if max_s % 10 != 0:
    print(max_s)
else:
    for j in range(n):
        if s[j] % 10 != 0:
            print(max_s - s[j])
            break
        elif j == n-1:
            print(0)
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = []
b = []
for i in range(n):
    tmp1,tmp2 = map(int,input().split())
    a.append(tmp1)
    b.append(tmp2)
counter = k-1
for i in range(n):
    counter = counter - b[i]
    if counter <= 0:
        print(a[i])
        break

Fixed submission:
a,b,c = map(int,input().split())
if c >= a and c <=b:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
a,b,c = map(int,input().split())

if a == b and b == c and c == a:
    print(-1)
else:
    for i in range(10**9):
        ans = i
        if a % 2 ==1:
            break
        else:
            a = b/2 + c/2
        if b % 2 == 1:
            break
        else:
            b = c/2 + a/2
        if c % 2 == 1:
            break
        else:
            c = a/2 + b/2
print(ans)

Fixed submission:
a,b,c = map(int,input().split())

if a%2 == 1 or b%2 == 1 or c%2==1:
    print(0)
elif a==b and b==c and c==a:
    print(-1)
else:
    for i in range(10**9):
        ans = i
        if a % 2 == 1:
            break
        else:
            tmpa = b/2 + c/2
        if b % 2 == 1:
            break
        else:
            tmpb = c/2 + a/2
        if c % 2 == 1:
            break
        else:
            tmpc = a/2 + b/2
        a = tmpa
        b = tmpb
        c = tmpc
    print(ans)
Buggy python submission (verdict: Runtime Error):
n,c,k = map(int,input().split())
t = []
for i in range(n):
    t.append(int(input()))
    
t = sorted(t)
bus = []
ans = 1
for i in range(n):
    if len(bus) < c: #バスの定員に余裕があるとき
        if not bus:　#バスに誰も乗っていなかったらバスに人を乗せる
            bus.append(t[i])
        elif t[i] <= bus[0] + k:#バスに初めて人が乗った時刻にkを足して、それよりt[i]が小さければバスに乗せる
            bus.append(t[i])
        else:#上記のelifを満たさない場合（
            ans +=1
            bus = []
            bus.append(t[i])
    elif len(bus) == c:
        ans +=1
        bus = []
        bus.append(t[i])
    else:
        ans +=1
        bus = []
print(ans)

Fixed submission:
n,c,k = map(int,input().split())
t = []
for i in range(n):
    t.append(int(input()))
    
t = sorted(t)
bus = []
ans = 1
for i in range(n):
    if len(bus) < c: #バスの定員に余裕があるとき
        if not bus:#バスに誰も乗っていなかったらバスに人を乗せる
            bus.append(t[i])
        elif t[i] <= bus[0] + k:#バスに初めて人が乗った時刻にkを足して、それよりt[i]が小さければバスに乗せる
            bus.append(t[i])
        else:#上記のelifを満たさない場合
            ans +=1
            bus = []
            bus.append(t[i])
    elif len(bus) == c:
        ans +=1
        bus = []
        bus.append(t[i])
    else:
        ans +=1
        bus = []
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
tmp = 1
ans = 0
for i in range(1,n+1):
    tmp = tmp*i
print(tmp%(1000000000 + 7))

Fixed submission:
import math
n = int(input())
print(math.factorial(n)%1000000007)
Buggy python submission (verdict: Time Limit Exceeded):
k,s = map(int,input().split())
ans = 0
for x in range(k+1):
    for y in range(k+1):
        for z in range(k+1):
            if x+y+z == s:
                ans += 1
print(ans)

Fixed submission:
k,s = map(int,input().split())
ans = 0
for x in range(k+1):
    for y in range(k+1):
        z = s - x - y
        if 0 <= z and z <= k:
            ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
t = list(map(int,input().split()))
m = int(input())
p = []
x = []
for i in range(m):
    t1,t2 = map(int,input().split())
    p.append(t1)
    x.append(t2)
sum_t = sum(t)
for i in range(m):
    print(sum_t - (t[i] -x[i]))

Fixed submission:
n = int(input())
t = list(map(int,input().split()))
m = int(input())
p = []
x = []
for i in range(m):
    t1,t2 = map(int,input().split())
    p.append(t1)
    x.append(t2)
sum_t = sum(t)
for i in range(m):
    sa = t[p[i] - 1] - x[i]
    print(sum_t-sa)
Buggy python submission (verdict: Runtime Error):
a,b,c = input().split()
print(a[0]+b[0]+c[0]

Fixed submission:
a,b,c = input().split()
print(a[0]+b[0]+c[0])
Buggy python submission (verdict: Runtime Error):
import heapq as hp
n = int(input())
if n%2 ==0:
    m = n//2 + 1
else:
    m = (n+1) //2
a,b = [],[]
for i in range(0,n):
    c = list(map(int, input().split()))
    a.append(c[0])
    b.append(c[1])
la = hp.nlargest(m,a)
lb = hp.nlargest(m,b)
if n%2 == 0:
    c = la[-1] + la[-2] 
    d = lb[-1] + lb[-2] 
    print(d-c+1)
else:
    print(lb[-1]-la[-1]+1)



Fixed submission:
a,b = map(int, input().split())
print(a*b)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a=list(map(int, input().split()))
ans = 1
for i in a:
    ans = ans * i
    if ans == 0:
        print(0)
        exit()
if ans > 10**18:
    print(-1)
else:
    print(ans)


Fixed submission:
a,b = map(int, input().split())
print(a*b)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a=list(map(int, input().split()))
ans = 1
for i in a:
    ans = ans * i
    if ans == 0:
        print(0)
        exit()
if ans > 10**18:
    print(-1)
else:
    print(ans)

Fixed submission:
n = int(input())
a=list(map(int, input().split()))
ans = 1
if a.count(0) > 0:
    print(0)
    exit()
for i in a:
    ans = ans * i
    if ans > 10**18:
        print(-1)
        exit()
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
a,b = map(float, input().split())
print(math_floor(a*b,2))

Fixed submission:
from decimal import Decimal
import math
a,b = map(str, input().split())
b = Decimal(b)
a = int(a)
print(int(a*b))
Buggy python submission (verdict: Runtime Error):
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append(cnt)

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

m = int(input())
a = factorization(m)
ans = 0
for i in a:
    j = 1
    while j *(j+1) //2 <= i:
        j += 1
    ans += j-1
print(ans)


Fixed submission:
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

m = int(input())
if m == 1:
  print(0)
  exit()
a = factorization(m)
b = []
ans = 0
for i in a:
    j = 1
    while j *(j+1) //2 <= i[1]:
        j += 1
    ans += j-1
print(ans)
Buggy python submission (verdict: Runtime Error):
def solv_quadratic_equation(a, b, c):
    D = (b**2 - 4*a*c) ** (1/2)
    if isinstance(D, float) == True:
      x_1 = (-b + D) / (2 * a)
      x_2 = (-b - D) / (2 * a)
      return x_1,x_2
    else:
      return 0.1,0.1

n = int(input())
a,ch = n // 10,0
while ch == 0:
    s,t,u = a,-pow(a,3),(pow(a,5) -n)/5
    v,w = solv_quadratic_equation(s,t,u)
    if v.is_integer() == True:
        e,f = solv_quadratic_equation(1,-a,v)
        if e.is_integer() == True & f.is_integer() == True:
            if abs(int(e)) >= abs(int(f)):
                print(int(e),int(-f))
            else:
                print(int(f),int(-e))
            ch = 1
    if w.is_integer() == True:
        e,f = solv_quadratic_equation(1,-a,w)
        if e.is_integer() == True & f.is_integer() == True:
            if abs(int(e)) >= abs(int(f)):
                print(int(e),int(-f))
            else:
                print(int(f),int(-e))
            ch = 1
    a += 10

Fixed submission:
def check(a, b):
    return pow(a,5) - pow(b,5)

n = int(input())
a = 0
for i in range(0,120):
    for j in range(-119,i):
      if a == 0:
        if n == check(i,j):
          print(i,j)
          a = 1

Buggy python submission (verdict: Runtime Error):
def solv_quadratic_equation(a, b, c):
    D = (b**2 - 4*a*c) ** (1/2)
    if isinstance(D, float) == True:
      x_1 = (-b + D) / (2 * a)
      x_2 = (-b - D) / (2 * a)
      return x_1,x_2
    else:
      return 0.1,0.1

n = int(input())
a,ch = n // 10,0
while ch == 0:
    s,t,u = a,pow(a,3),(pow(a,5) -n)/5
    v,w = solv_quadratic_equation(s,t,u)
    if v.is_integer() == True:
        e,f = solv_quadratic_equation(1,-a,-v)
        if e.is_integer() == True & f.is_integer() == True:
            print(int(max(e,f)),int(min(e,f)))
            ch = 1
    elif w.is_integer() == True:
        e,f = solv_quadratic_equation(1,-a,-w)
        if e.is_integer() == True & f.is_integer() == True & ch == 0:
            print(int(max(e,f)),int(min(e,f)))
            ch = 1
    a += 10

Fixed submission:
def check(a, b):
    return pow(a,5) - pow(b,5)

n = int(input())
a = 0
for i in range(0,120):
    for j in range(-119,i):
      if a == 0:
        if n == check(i,j):
          print(i,j)
          a = 1
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a,b,c,d,e,v,w,x,y,z = [],[],[],[],[],[],[],[],[],[]
for i in range(0,n):
    s = str(input())
    t = len(s)
    if t == 1:
        m = 0
        for j in range(0,len(a)):
            if s == a[j]:
                m = 1
                break
        if m == 0:
            a.append(s)
    elif t == 2:
        m = 0
        for j in range(0,len(b)):
            if s == b[j]:
                m = 1
                break
        if m == 0:
            b.append(s)
    elif t == 3:
        m = 0
        for j in range(0,len(c)):
            if s == c[j]:
                m = 1
                break
        if m == 0:
            c.append(s)
    elif t == 4:
        m = 0
        for j in range(0,len(d)):
            if s == d[j]:
                m = 1
                break
        if m == 0:
            d.append(s)
    elif t == 5:
        m = 0
        for j in range(0,len(e)):
            if s == e[j]:
                m = 1
                break
        if m == 0:
            e.append(s)
    elif t == 6:
        m = 0
        for j in range(0,len(v)):
            if s == v[j]:
                m = 1
                break
        if m == 0:
            v.append(s)
    elif t == 7:
        m = 0
        for j in range(0,len(w)):
            if s == w[j]:
                m = 1
                break
        if m == 0:
            w.append(s)
    elif t == 8:
        m = 0
        for j in range(0,len(x)):
            if s == x[j]:
                m = 1
                break
        if m == 0:
            x.append(s)
    elif t == 9:
        m = 0
        for j in range(0,len(y)):
            if s == y[j]:
                m = 1
                break
        if m == 0:
            y.append(s)
    else:
        m = 0
        for j in range(0,len(z)):
            if s == z[j]:
                m = 1
                break
        if m == 0:
            z.append(s)
ans = len(a)+len(b)+len(c)+len(d)+len(e)+len(v)+len(w)+len(x)+len(y)+len(z)
print(ans)

Fixed submission:
n = int(input())
a = []
for i in range(0,n):
    s = str(input())
    a.append(s)
ans = set(a)
print(len(ans))
Buggy python submission (verdict: Time Limit Exceeded):
import collections
n = str(input())
ans= 0
t=[0]*2019
t[0]=1
for i in range(0,len(n)):
        k = int(n[i:len(n)]) % 2019
        t[k] +=1
for i in t:
    ans += i *(i-1) /2
print(int(ans))


Fixed submission:
import collections
n = str(input())
ans,m,div = 0,0,[]
for i,j in enumerate(reversed(n)):
    m=(m+int(j)*pow(10,i,2019))%2019
    div.append(m)
div.append(0)
c = collections.Counter(div)
values, counts = zip(*c.most_common())
for i in range(0,len(counts)):
    ans += counts[i] *(counts[i]-1) /2
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
import collections
n = str(input())
ans,div = 0,[]
for i in range(0,len(n)):
        k = int(n[i:len(n)])
        div.append(k % 2019)
div.append(0)
c = collections.Counter(div)
values, counts = zip(*c.most_common())
for i in range(0,len(counts)):
    ans += counts[i] *(counts[i]-1) /2
print(int(ans))

Fixed submission:
import collections
n = str(input())
ans,m,div = 0,0,[]
for i,j in enumerate(reversed(n)):
    m=(m+int(j)*pow(10,i,2019))%2019
    div.append(m)
div.append(0)
c = collections.Counter(div)
values, counts = zip(*c.most_common())
for i in range(0,len(counts)):
    ans += counts[i] *(counts[i]-1) /2
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
n = str(input())
ans,div = 0,[]
for i in range(0,len(n)):
        k = int(n[i:len(n)])
        div.append(k % 2019)
div.append(0)
for i in range(0,len(n)):
    for j in range(i+1,len(n)+1):
        if div[i] == div[j]:
            ans += 1
print(ans)

Fixed submission:
import collections
n = str(input())
ans,m,div = 0,0,[]
for i,j in enumerate(reversed(n)):
    m=(m+int(j)*pow(10,i,2019))%2019
    div.append(m)
div.append(0)
c = collections.Counter(div)
values, counts = zip(*c.most_common())
for i in range(0,len(counts)):
    ans += counts[i] *(counts[i]-1) /2
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
n = str(input())
ans = 0
m = len(str(n))
for i in range(0,m-4):
    for j in range(i+5,m+1):
        k = n[i:j]
        if int(k) % 2019 == 0:
             ans += 1
print(ans)

Fixed submission:
import collections
n = str(input())
ans,m,div = 0,0,[]
for i,j in enumerate(reversed(n)):
    m=(m+int(j)*pow(10,i,2019))%2019
    div.append(m)
div.append(0)
c = collections.Counter(div)
values, counts = zip(*c.most_common())
for i in range(0,len(counts)):
    ans += counts[i] *(counts[i]-1) /2
print(int(ans))
Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a, b, c):
    while b:
        a, b = b, a % b
    while c:
        a, c = c, a % c
    return a

n = int(input())
ans = 0
for i in range(1,n+1):
    for j in range(1,n+1):
        for k in range(1,n+1):
            ans += gcd(i,j,k)
print(ans)    

Fixed submission:
def gccd(a, b, c):
    while b:
        a, b = b, a % b
    while c:
        a, c = c, a % c
    return a

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

n = int(input())
ans = n * (n+1) //2
for i in range(1,n+1):
    for j in range(i+1,n+1):
        ans += gcd(i,j) * 6
if n >2:
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            for k in range(j+1,n+1):
                ans += gccd(i,j,k) * 6
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = str(input())
ans = 0
rr,gg,bb = [],[],[]
for i in range(0,len(s)):
    if s[i] == "R":
        rr.append(i)
    elif s[i] == "G":
        gg.append(i)

bb = len(s) -len(rr) -len(gg)
ans = len(rr) * len(gg) * bb
for i in range(0,len(rr)):
    for j in range(0,len(gg)):
        che = 0
        a = rr[i] + gg[j]
        if a % 2 == 0:
            if s[a//2] == "B":
                che += -1
        b = min(rr[i],gg[j]) - abs(rr[i]-gg[j])
        if b >= 0:
            if s[b] == "B":
                che += -1
        c = max(rr[i],gg[j]) + abs(rr[i]-gg[j])
        if c < n:
            if s[c] == "B":
                che += -1
        ans += che

print(ans)

Fixed submission:
n = int(input())
s = str(input())
rr,gg = [],[]
for i in range(0,len(s)):
    if s[i] == "R":
        rr.append(i)
    elif s[i] == "G":
        gg.append(i)

bb = len(s) -len(rr) -len(gg)
ans = len(rr) * len(gg) * bb
for i in range(0,len(rr)):
    for j in range(0,len(gg)):
        che = 0
        a = rr[i] + gg[j]
        if a % 2 == 0:
            if s[a//2] == "B":
                che += -1
        b = min(rr[i],gg[j]) - abs(rr[i]-gg[j])
        if b >= 0:
            if s[b] == "B":
                che += -1
        c = a - b
        if c < n:
            if s[c] == "B":
                che += -1
        ans += che

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = str(input())
ans = 0
rr,gg,bb = [],[],[]
for i in range(0,len(s)):
    if s[i] == "R":
        rr.append(i)
    elif s[i] == "G":
        gg.append(i)
    else:
        bb.append(i)

for i in range(0,len(rr)):
    for j in range(0,len(gg)):
        che = 0
        a = rr[i] + gg[j]
        if a % 2 == 0:
            if s[a//2] == "B":
                che += -1
        b = min(rr[i],gg[j]) - abs(rr[i]-gg[j])
        if b >= 0:
            if s[b] == "B":
                che += -1
        c = max(rr[i],gg[j]) + abs(rr[i]-gg[j])
        if c < n:
            if s[c] == "B":
                che += -1
        ans += len(bb)
        ans += che

print(ans)

Fixed submission:
n = int(input())
s = str(input())
rr,gg = [],[]
for i in range(0,len(s)):
    if s[i] == "R":
        rr.append(i)
    elif s[i] == "G":
        gg.append(i)

bb = len(s) -len(rr) -len(gg)
ans = len(rr) * len(gg) * bb
for i in range(0,len(rr)):
    for j in range(0,len(gg)):
        che = 0
        a = rr[i] + gg[j]
        if a % 2 == 0:
            if s[a//2] == "B":
                che += -1
        b = min(rr[i],gg[j]) - abs(rr[i]-gg[j])
        if b >= 0:
            if s[b] == "B":
                che += -1
        c = a - b
        if c < n:
            if s[c] == "B":
                che += -1
        ans += che

print(ans)