Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import itertools
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
    
def main():
    k = int(input())
    ans = 0
    for a, b, c in itertools.product(range(1, k+1), range(1, k+1), range(1, k+1)):
        ans += gcd(a, b, c)
    print(ans)
    
main()


Fixed submission:
# coding: utf-8
import itertools
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
    
def main():
    k = int(input())
    array = list(range(1, k+1))
    ans = sum(array)
    for i in range(2, 4):
        for x in itertools.combinations(array, i):
            x = list(x)
            tmp = gcd(*x)
            ans += tmp * 6
    print(ans)
    
main()
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
n = int(input())
a_list = list(map(int,input().split()))
ans_list = []

#a0
ans_flag = 0
first_ans = a_list[0]
for i in range(1,n-1):
    if ans_flag == 1:
        break
    for j in range(i+1,n):
        ans = a_list[i] ^ a_list[j]
        #print(ans)
        if ans == a_list[0]:
            ans_flag = 1
            fin_ans = a_list[j]
            sec_ans = a_list[i]
            a_list.remove(sec_ans)
            a_list.remove(fin_ans)
            a_list.remove(first_ans)
            ans_list.append(first_ans)
            ans_list.append(sec_ans)
            break
        
if ans_flag == 0:
    print("No")
    quit()

for i in range(n-2):
    ans = ans_list[i] ^ ans_list[i+1]
    if i == n-3:
        if ans == fin_ans:
            print("Yes")
            quit()
    
    if ans in a_list:
        ans_list.append(ans)
        a_list.remove(ans)
    else:
        print("No")
        quit()
    

Fixed submission:
# coding: utf-8
import collections
 
n = int(input())
a_list = list(map(int,input().split()))
 
c = collections.Counter(a_list)
 
#print(len(c.keys()))
ans_list = list(c.keys())
count_list = list(c.values())
 
#print(c.keys())
if len(c.keys()) == 1:
    if list(c.keys()) == [0]:
        print("Yes")
        quit()
    else:
        print("No")
        quit()
elif len(c.keys()) == 2:
    if ans_list[0] == ans_list[0]^ans_list[1] and count_list[0]== 2*count_list[1]:
        print("Yes")
        quit()
    elif ans_list[1] == ans_list[0]^ans_list[1] and count_list[1]== 2*count_list[0]:
        print("Yes")
        quit()
    else:
        print("No")
        quit()
        
if len(c.keys()) != 3:
    print("No")
    quit()

count_list.sort()
if ans_list[0] == ans_list[1] ^ ans_list[2]:
    if count_list[0]==count_list[1]==count_list[2]:
        print("Yes")
    else:
        print("No")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))
a = a*2
#a = a.reshape((a.shape[0],1))
#print(n,a)

N = np.zeros((n,n), dtype=int)
for i in range(n):
    N[i,i] = 1
    if i+1 == n:
        N[i,0] = 1
    else:
        N[i,i+1] = 1
#print(N)

ans = np.linalg.solve(N,a)
#ans = ans.reshape((ans.shape[0],))
ans = ans.astype(np.int)
print(*ans)



Fixed submission:
# coding: utf-8
n,a,b = map(int, input().split())
if n*a < b:
    print(n*a)
else:
    print(b)
Buggy python submission (verdict: Runtime Error):
import numpy as np
from collections import deque

n = int(input())
matrix = np.zeros((n,n),dtype="int32")
for i in range(n-1):
    v,w,d = map(int,input().split())
    matrix[v-1,w-1] = d
#print(matrix)

queue = deque([0])
no_check = [i for i in range(1,n)]
ans = np.zeros((n),dtype="int32")

while queue:
    x = queue.popleft()
    #print("x:",x)
    if no_check == []:
        break
    for i in no_check:
        if matrix[x,i]!=0:
            if matrix[x,i]%2==0:
                ans[i] = ans[x]
            else:
                if ans[x]==0:
                    ans[i] = 1
                else:
                    ans[i] = 0
            no_check.remove(i)
            queue.append(i)
        
                
for i in ans:
    print(i)

Fixed submission:
# coding: utf-8
from collections import deque

n = int(input())

lw = [[] for _ in range(n+1)]
for i in range(n-1):
    u,v,w = map(int,input().split())
    lw[u].append((v,w))
    lw[v].append((u,w))

#print(lw)

ans = [-1] * (n+1)
q = deque()
ans[1] = 0
q.append(1)
while q:
    r = q.popleft()
    prev = ans[r]
    
    for x in lw[r]:
        #print(x)
        y = x[0]
        if ans[y] >= 0:
            continue
        q.append(y)
        if x[1]%2==0:
            ans[y] = ans[r]
        else:
            ans[y] = 1 - ans[r]

for x in ans[1:]:
    print(x)

Buggy python submission (verdict: Runtime Error):
import numpy as np
from collections import deque

n = int(input())
matrix = np.zeros((n,n),dtype="int32")
for i in range(n-1):
    v,w,d = map(int,input().split())
    matrix[v-1,w-1] = d
#print(matrix)

queue = deque([0])
check = [0]
ans = np.zeros((n),dtype="int32")

while queue:
    x = queue.popleft()
    #print("x:",x)
    for i in range(n):
        #print("i:",i,"check:",check)
        if i not in check:
            if matrix[x,i] != 0:
                #print("d:",matrix[x,i])
                if matrix[x,i]%2==0:
                    #print("even")
                    ans[i] = ans[x]
                else:
                    #print("odd")
                    if ans[x] == 0:
                        ans[i] = 1
                    else:
                        ans[i] = 0
                check.append(i)
                queue.append(i)
                #print("APPEND check:",check,"queue:",queue)
                
for i in ans:
    print(i)

Fixed submission:
# coding: utf-8
from collections import deque

n = int(input())

lw = [[] for _ in range(n+1)]
for i in range(n-1):
    u,v,w = map(int,input().split())
    lw[u].append((v,w))
    lw[v].append((u,w))

#print(lw)

ans = [-1] * (n+1)
q = deque()
ans[1] = 0
q.append(1)
while q:
    r = q.popleft()
    prev = ans[r]
    
    for x in lw[r]:
        #print(x)
        y = x[0]
        if ans[y] >= 0:
            continue
        q.append(y)
        if x[1]%2==0:
            ans[y] = ans[r]
        else:
            ans[y] = 1 - ans[r]

for x in ans[1:]:
    print(x)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
import math

n = int(input())
h_list = list(map(int, input().split()))

inf = math.inf
ans_list = [inf for _ in range(n)]
# ans_list = [0, 1, 2,..., n-1]
# h_list = [0, 1, 2,..., n-1]

def cmin(a, b):
    if a<b:
        return a
    else:
        return b

ans_list[0] = 0
ans_list[1] = abs(h_list[1] - h_list[0])
for i in range(2, n):
    ans_list[i] = cmin(ans_list[i], ans_list[i-1]+abs(h_list[i]-h_list[i-1]))
    ans_list[i] = cmin(ans_list[i], ans_list[i-2]+abs(h_list[i]-h_list[i-2]))

print(ans_list[-1])

Fixed submission:
# coding: utf-8

n = int(input())
h_list = list(map(int, input().split()))

inf = float('inf')
ans_list = [inf for _ in range(n)]
# ans_list = [0, 1, 2,..., n-1]
# h_list = [0, 1, 2,..., n-1]

def cmin(a, b):
    if a<b:
        return a
    else:
        return b

ans_list[0] = 0
ans_list[1] = abs(h_list[1] - h_list[0])
for i in range(2, n):
    ans_list[i] = cmin(ans_list[i], ans_list[i-1]+abs(h_list[i]-h_list[i-1]))
    ans_list[i] = cmin(ans_list[i], ans_list[i-2]+abs(h_list[i]-h_list[i-2]))

print(ans_list[-1])
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8

n, k = map(int, input().split())
h_list = list(map(int, input().split()))


ans = [float("inf")]*(n)

ans[0] = 0
ans[1] = abs(h_list[1]-h_list[0])

for i in range(n):
    for j in range(1,k+1):
        if i+j > n-1:
            break
        ans[i+j] = min(ans[i+j], ans[i]+abs(h_list[i+j]-h_list[i]))
        
# print(ans)
print(ans[-1])

Fixed submission:
# coding: utf-8
import numpy as np

n, k = map(int, input().split())
h_list = np.array([int(x) for x in input().split()])

ans = np.zeros(n, dtype=int)

for i in range(1, n):
    start = max(i-k, 0)
    ans[i] = np.min(ans[start:i] + np.abs(h_list[start:i] - h_list[i]))
        
# print(ans)
print(ans[-1])

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8

n, k = map(int, input().split())
h_list = list(map(int, input().split()))


def cmin(a, b):
    if a<b:
        return a
    else:
        return b

ans = [float("inf")]*(n)

ans[0] = 0
ans[1] = abs(h_list[1]-h_list[0])

for i in range(n):
    for j in range(1,k+1):
        if i+j > n-1:
            break
        ans[i+j] = cmin(ans[i+j], ans[i]+abs(h_list[i+j]-h_list[i]))
        
# print(ans)
print(ans[-1])

Fixed submission:
# coding: utf-8
import numpy as np

n, k = map(int, input().split())
h_list = np.array([int(x) for x in input().split()])

ans = np.zeros(n, dtype=int)

for i in range(1, n):
    start = max(i-k, 0)
    ans[i] = np.min(ans[start:i] + np.abs(h_list[start:i] - h_list[i]))
        
# print(ans)
print(ans[-1])
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
import numpy as np

def main():
    N, W = map(int, input().split())
    V = 10**3 * 100
    
    dp = np.full(V, V+100)
    # print(len(dp))
    dp[0] = 0
    
    for _ in range(N):
        w, v = map(int, input().split())
        dp[v:] = np.minimum(dp[v:], dp[:-v]+w)

# print(dp)
print(np.max(np.where(dp<=W)))
    
if __name__ == "__main__":
    main()

Fixed submission:
import numpy as np
N, W = map(int, input().split())
 
items = [tuple(map(int, input().split())) for _ in range(N)]
 
dp = np.full(N*1000 +1, W+1) #横軸を価値の値に変換する
dp[0] = 0
 
for i, (w, v) in enumerate(items):
    dp[v:] = np.minimum(dp[v:], dp[:-v]+w)
 
print(np.max(np.where(dp <= W)))

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
def main():
    N, W = map(int, input().split())
    V = 10**3 * 100
    
    f_inf = float("inf")
    dp = [f_inf] * (V+1)
    dp[0] = 0
    
    for _ in range(N):
        w, v = map(int, input().split())
        for i in range(V-v, -1, -1):
            if dp[i] == -1:
                continue
            dp[i+v] = min(dp[i+v], dp[i] + w)

    # print(dp)
    ans = 0
    for i in range(len(dp)):
        if dp[i] <= W and i >= ans:
            ans = i

    print(ans)
    
if __name__ == "__main__":
    main()

Fixed submission:
import numpy as np
N, W = map(int, input().split())
 
items = [tuple(map(int, input().split())) for _ in range(N)]
 
dp = np.full(N*1000 +1, W+1) #横軸を価値の値に変換する
dp[0] = 0
 
for i, (w, v) in enumerate(items):
    dp[v:] = np.minimum(dp[v:], dp[:-v]+w)
 
print(np.max(np.where(dp <= W)))

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
def main():
    N, W = map(int, input().split())
    V = 10**3 * 100
    
    dp = [[float("inf")]*(V) for _ in range(N+1)]
    dp[0][0] = 0
    
    for i in range(1, N+1):
        w, v = map(int, input().split())
        for j in range(V):
            if j-v >= 0:
                dp[i][j] = min(dp[i][j], dp[i-1][j-v]+w)
            dp[i][j] = min(dp[i][j], dp[i-1][j])
        
    ans = 0
    for i in range(len(dp[N])):
        if dp[N][i] > W:
            continue
        if i >= ans:
            ans = i
            
    # print(dp)
    print(ans)
    
if __name__ == "__main__":
    main()

Fixed submission:
import numpy as np
N, W = map(int, input().split())
 
items = [tuple(map(int, input().split())) for _ in range(N)]
 
dp = np.full(N*1000 +1, W+1) #横軸を価値の値に変換する
dp[0] = 0
 
for i, (w, v) in enumerate(items):
    dp[v:] = np.minimum(dp[v:], dp[:-v]+w)
 
print(np.max(np.where(dp <= W)))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
n,x,m = list(map(int,input().split()))

def fact(n):
    freq = defaultdict(int)
    if n==0:
        return freq
    while n%2==0:
        freq[2]+=1
        n = n//2
    for i in range(3,int(n**0.5)+1):
        if n%i==0:
            freq[i]+=1
            n = n//i
    if n>1:
        freq[n]+=1
    return freq

can = True
freqx = fact(x)
freqm = fact(m)

for pf in freqm:
    if freqx[pf]!=0:
        can = False

if can or n<=m:
    s = x%m
    op = 1
    while op<n:
        rem = x%m
        rem = (rem*rem)%m
        if(rem==0):
            break
        s+=rem
        x = rem
        op+=1
    print(s)
else:
    x = x%m
    lo = [-1 for i in range(m)]
    series = [x]
    lo[x] = 0
    rep = -1
    for i in range(1,m+5):
        rem = (x*x)%m
        if lo[rem]>=0:
            rep = i-lo[rem]
            break
        else:
            series.append(rem)
            lo[rem] = i
        x = rem
    if rep>=0:
        st = len(series)-rep
        n-=st
        mul = n//rep
        ex = n%rep
        s = 0
        for i in range(st):
            s+=series[i]
        for i in range(st,len(series)):
            s+=(mul*series[i])
        for i in range(ex):
            s+=series[st+i]
    print(s)


Fixed submission:
from collections import defaultdict
n,x,m = list(map(int,input().split()))

def fact(n):
    freq = defaultdict(int)
    if n==0:
        return freq
    while n%2==0:
        freq[2]+=1
        n = n//2
    for i in range(3,int(n**0.5)+1):
        if n%i==0:
            freq[i]+=1
            n = n//i
    if n>1:
        freq[n]+=1
    return freq

can = True
freqx = fact(x)
freqm = fact(m)

for pf in freqm:
    if freqx[pf]==0:
        can = False

if can or n<=m:
    s = x%m
    op = 1
    while op<n:
        rem = x%m
        rem = (rem*rem)%m
        if(rem==0):
            break
        s+=rem
        x = rem
        op+=1
    print(s)
else:
    x = x%m
    lo = [-1 for i in range(m)]
    series = [x]
    lo[x] = 0
    rep = -1
    for i in range(1,m+5):
        rem = (x*x)%m
        if lo[rem]>=0:
            rep = i-lo[rem]
            break
        else:
            series.append(rem)
            lo[rem] = i
        x = rem
    if rep>=0:
        st = len(series)-rep
        n-=st
        mul = n//rep
        ex = n%rep
        s = 0
        for i in range(st):
            s+=series[i]
        for i in range(st,len(series)):
            s+=(mul*series[i])
        for i in range(ex):
            s+=series[st+i]
    print(s)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = list(map(int,input().split()))
arr = list(map(int,input().split()))
lo = 1
hi = 10**18
ans = max(arr)
while lo<=hi:
    t = 0
    m = (hi+lo)//2
    for i in range(n):
        if arr[i]>m:
            req = arr[i]//m
        else:
            req=  0
        t+=req
    if t<=k:
        ans = m
        hi = m-1
    else:
        lo = m+1
print(ans)

Fixed submission:
n,k = list(map(int,input().split()))
arr = list(map(int,input().split()))
lo = 1
hi = 10**12
ans = max(arr)
while lo<=hi:
    t = 0
    m = (hi+lo)//2
    for i in range(n):
        if arr[i]>m:
            req = arr[i]//m
        else:
            req=  0
        t+=req
    if t<=k:
        ans = m
        hi = m-1
    else:
        lo = m+1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
dp = [0 for i in range(n+1)]
maxn = 201
for x in range(1,maxn):
    for y in range(1,maxn):
        for z in range(1,maxn):
            p = (x+y+z)**2
            p-=(x*y + y*z + z*x)
            if p<=n:
                dp[p]+=1
for i in dp[1::]:
    print(i)

Fixed submission:
n = int(input())
dp = [0 for i in range(n+1)]
maxn = n**0.5
maxn = int(maxn)+1
for x in range(1,maxn):
    for y in range(1,maxn):
        for z in range(1,maxn):
            p = x*x + y*y + z*z + x*y + y*z +z*x
            if p<=n:
                dp[p]+=1
for i in dp[1::]:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())
s = input()
mod = 10**9+7
maxn = 2000005
fact = [0 for i in range(maxn)]
fact[0] = 1
for i in range(1,maxn):
	fact[i] = (i*fact[i-1])%mod
n = len(s)
ans = pow(26,n+k,mod)
for m in range(n):
	calc = (fact[n+k]%mod * pow(fact[m],mod-2,mod))%mod
	calc = (calc * pow(fact[n+k-m],mod-2,mod))%mod
	p = pow(25,n+k-m,mod)
	val = (calc*p)%mod
	ans = (ans-val)%mod
print(ans%mod)

Fixed submission:
k = int(input())
s = input()
mod = 10**9+7
maxn = 2000005
fact = [0 for i in range(maxn)]
fact[0] = 1
for i in range(1,maxn):
	fact[i] = (i*fact[i-1])%mod
n = len(s)
ans = pow(26,n+k,mod)
for m in range(n):
	calc = (fact[n+k]%mod * pow(fact[m],mod-2,mod))%mod
	calc = (calc * pow(fact[n+k-m],mod-2,mod))%mod
	p = pow(25,n+k-m,mod)
	val = (calc*p)%mod
	ans = (ans-val)%mod
print(ans%mod)
Buggy python submission (verdict: Runtime Error):
x = int(input())
x = i
if x>90:
    x = x-90
ans = 0
a = 360
while True:
    if a%x==0:
        ans+=a//x
        break
    else:
        rem = a%x
        ans+=a//x
        a-=rem
print(ans)


Fixed submission:
x = int(input())
ans = 0
for i in range(1,361):
    num = 360*i
    if num%x==0:
        print(num//x)
        exit()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
n,k = list(map(int,sys.stdin.readline().split()))
arr = list(map(int,sys.stdin.readline().split()))

dp = [sys.maxsize for i in range(n)]
dp[0] = 0
for i in range(n):
	for j in range(i+1,i+k+1):
		if j<n:
			dp[j] = min(dp[j],dp[i]+abs(arr[i]-arr[j]))
sys.stdout.write(str(dp[-1])+'\n')

Fixed submission:
import sys
n,k = list(map(int,input().split()))
arr = list(map(int,input().split()))

dp = [sys.maxsize for i in range(n)]
dp[0] = 0
for i in range(n):
	for j in range(i+1,i+k+1):
		if j<n:
			dp[j] = min(dp[j],dp[i]+abs(arr[i]-arr[j]))
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
import sys
n,k = list(map(int,sys.stdin.readline().split()))
arr = list(map(int,sys.stdin.readline().split()))

dp = [sys.maxsize for i in range(n)]
dp[0] = 0
for i in range(n):
	for j in range(i+1,i+k+1):
		if j<n:
			dp[j] = min(dp[j],dp[i]+abs(arr[i]-arr[j]))
sys.stdout.write(str(dp[-1]+'\n'))

Fixed submission:
import sys
n,k = list(map(int,input().split()))
arr = list(map(int,input().split()))

dp = [sys.maxsize for i in range(n)]
dp[0] = 0
for i in range(n):
	for j in range(i+1,i+k+1):
		if j<n:
			dp[j] = min(dp[j],dp[i]+abs(arr[i]-arr[j]))
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
n,k = list(map(int,input().split()))
arr = list(map(int,input().split()))

dp = [sys.maxsize for i in range(n)]
dp[0] = 0
for i in range(n):
	for j in range(i+1,i+k+1):
		if j<n:
			dp[j] = min(dp[j],dp[i]+abs(arr[i]-arr[j]))
print(dp[-1])

Fixed submission:
import sys
n,k = list(map(int,input().split()))
arr = list(map(int,input().split()))

dp = [sys.maxsize for i in range(n)]
dp[0] = 0
for i in range(n):
	for j in range(i+1,i+k+1):
		if j<n:
			dp[j] = min(dp[j],dp[i]+abs(arr[i]-arr[j]))
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
import sys
n,k = list(map(int,input().split()))
arr = list(map(int,input().split()))

dp = [sys.maxsize for i in range(n)]
dp[0] = [0]
for i in range(n):
	for j in range(i+1,i+k+1):
		if j<n:
			dp[j] = min(dp[j],dp[i]+abs(arr[i]-arr[j]))
print(dp[-1])

Fixed submission:
import sys
n,k = list(map(int,input().split()))
arr = list(map(int,input().split()))

dp = [sys.maxsize for i in range(n)]
dp[0] = 0
for i in range(n):
	for j in range(i+1,i+k+1):
		if j<n:
			dp[j] = min(dp[j],dp[i]+abs(arr[i]-arr[j]))
print(dp[-1])
Buggy python submission (verdict: Runtime Error):
x, n = map(int, input().split())
p = list(map(int, input().split()))

table = [0 for i in range(100)]
for i in p:
    table[i-1] = 1

mx = 10000
ans = mx
dis = mx
for i in range(len(table)):
    idx = 99-i
    if (table[idx] == 0) and (dis >= abs(idx+1-x)):
        ans = idx+1
        dis = abs(idx+1-x)
if ans == mx:
    if 50 >= x
        print(0)
    else:
        print(101)
else:
    print(ans)


Fixed submission:
x, n = map(int, input().split())
p = list(map(int, input().split()))

table = [0 for i in range(102)]
for i in p:
    table[i] = 1

mx = 10000
ans = mx
dis = mx
for i in range(len(table)):
    idx = 101-i
    if (table[idx] == 0) and (dis >= abs(idx-x)):
        ans = idx
        dis = abs(idx-x)
print(ans)
Buggy python submission (verdict: Runtime Error):
n, m, x = map(int, input().split())
prace = []
know = []
for i in range(n):
    acc = list(map(int, input().split()))
    prace.append(acc[0])
    know.append(acc[1:])

ans = 10**10
for i in range(2**n):
    und = [0 for i in range(m)]
    f = "{:b}".format(i)
    s = f.zfill(m)
    mm = 0
    for j in range(len(s)):
        if s[j] == '1':
            for k in range(m):
                und[k] += know[j][k]
            mm += prace[j]
    for j in range(m):
        if und[j] < x:
            break
    else:
        ans = min(ans, mm)
if ans == 10**10:
    print(-1)
else:
    print(ans)


Fixed submission:
n, m, x = map(int, input().split())
prace = []
know = []
for i in range(n):
    acc = list(map(int, input().split()))
    prace.append(acc[0])
    know.append(acc[1:])

ans = 10**10
for i in range(2**n):
    und = [0 for i in range(m)]
    f = "{:b}".format(i)
    s = f.zfill(n)
    mm = 0
    for j in range(len(s)):
        if s[j] == '1':
            for k in range(m):
                und[k] += know[j][k]
            mm += prace[j]
    for j in range(m):
        if und[j] < x:
            break
    else:
        ans = min(ans, mm)
if ans == 10**10:
    print(-1)
else:
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
r, g, b = 0, 0, 0
for i in s:
    if i == 'R':
        r += 1
    elif i == 'G':
        g += 1
    else:
        b += 1
bad = 0
for i in range(n):
    gap = 0
    while i+(gap+1)*2 <= n-1:
        if s[i] != s[i+gap+1] and s[i+gap+1] != s[i+(gap+1)*2]\
                and s[i] != s[i+(gap+1)*2]:
            bad += 1
        gap += 1
print(r*g*b-bad) 


Fixed submission:
n = int(input())
s = input()
r, g, b = 0, 0, 0
for i in s:
    if i == 'R':
        r += 1
    elif i == 'G':
        g += 1
    else:
        b += 1
bad = 0
for i in range(n):
    gap = 0
    while i+(gap+1)*2 <= n-1:
        if s[i] != s[i+gap+1] and s[i+gap+1] != s[i+(gap+1)*2]\
                and s[i] != s[i+(gap+1)*2]:
            bad += 1
        gap += 1
print(r*g*b-bad)
Buggy python submission (verdict: Runtime Error):
x, y, z = input().split()
print(f"{z} {x} {y}")


Fixed submission:
x, y, z = input().split()
print(z, x, y)