Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N,W=map(int,input().split())

dp={}
dp_up={}
V_max=0

for i in range(1,N+1):
    w,v=map(int,input().split())

    V_max+=v

    for j in range(v,V_max+1):
        if j==v:
            if j in dp:
                dp_up[j]=min(dp[j],w)
                j_max=j
            else:
                dp_up[j]=w
                j_max=j
        else:
            if j-v in dp and dp[j-v]+w<=W:
                if j in dp:
                    dp_up[j]=min(dp[j],dp[j-v]+w)
                    j_max=j
                else:
                    dp_up[j]=dp[j-v]+w
                    j_max=j
    dp=dp_up.copy()
print(max(dp))    

Fixed submission:
import sys
input = sys.stdin.readline

N,W=map(int,input().split())

dp={}
dp_up={}
V_max=0

for i in range(1,N+1):
    w,v=map(int,input().split())

    V_max+=v

    for j in range(v,V_max+1):
        if j==v:
            if j in dp:
                dp_up[j]=min(dp[j],w)
                j_max=j
            else:
                dp_up[j]=w
                j_max=j
        else:
            if j-v in dp and dp[j-v]+w<=W:
                if j in dp:
                    dp_up[j]=min(dp[j],dp[j-v]+w)
                    j_max=j
                else:
                    dp_up[j]=dp[j-v]+w
                    j_max=j
    dp=dp_up.copy()
print(max(dp))
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict

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

result=0

dic_a=defaultdict(int)
dic_b=defaultdict(int)

for i in range(n//2):
    dic_a[v[i*2]]+=1
    dic_b[v[i*2+1]]+=1


#それぞれの最大値を取得
max_a=max(dic_a.items(),key=lambda x:[1])
max_b=max(dic_b.items(),key=lambda x:[1])

if max_a[0] != max_b[0]:
    result=n-max_a[1]-max_b[1]

elif len(dic_a)==1 and len(dic_b)==1:
    result=n//2

elif len(dic_a)==1:
    dic_b.pop(max_b[0])
    max_b=max(dic_b.items(),key=lambda x:[1])
    result=n-max_a[1]-max_b[1]

elif len(dic_b)==1:
    dic_a.pop(max_a[0])
    max_a=max(dic_a.items(),key=lambda x:[1])
    result=n-max_a[1]-max_b[1]

else:
    dic_a.pop(max_a[0])
    max_a2=max(dic_a.items(),key=lambda x:[1])

    dic_b.pop(max_b[0])
    max_b2=max(dic_b.items(),key=lambda x:[1])

    if max_a2>max_b2:
        result=n-max_a2-max_b
    else:
        result=n-max_a-max_b2

print(result)

Fixed submission:
from collections import defaultdict

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

result=0

dic_a=defaultdict(int)
dic_b=defaultdict(int)

for i in range(n//2):
    dic_a[v[i*2]]+=1
    dic_b[v[i*2+1]]+=1


#それぞれの最大値を取得
max_a=max(dic_a.items(),key=lambda x:x[1])
max_b=max(dic_b.items(),key=lambda x:x[1])

if max_a[0] != max_b[0]:
    result=n-max_a[1]-max_b[1]

elif len(dic_a)==1 and len(dic_b)==1:
    result=n//2

else:
    dic_a.pop(max_a[0])
    max_a2=max(dic_a.items(),key=lambda x:x[1])

    dic_b.pop(max_b[0])
    max_b2=max(dic_b.items(),key=lambda x:x[1])

    result=min(n-max_a2[1]-max_b[1],n-max_a[1]-max_b2[1])

print(int(result))
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
K=int(input())

N=len(s)
ln=0
siki_sub=''
result={}

for i in range(N):
    for j in range(N-i):
        if ln<K:
            if s[i:i+j+1] not in result:
                result[s[i:i+j+1]]=1
                siki_sub=max(result)
                ln+=1
        else:
            if siki_sub>s[i:i+j+1] and s[i:i+j+1] not in result:
                del result[siki_sub]
                result[s[i:i+j+1]]=1
                siki_sub=max(result)

print(siki_sub)




        

Fixed submission:
s=input()
K=int(input())

N=len(s)
ln=0
siki_sub=''
result={}

for i in range(N):
    for j in range(min(N-i,K+1)):
        if ln<K:
            if s[i:i+j+1] not in result:
                result[s[i:i+j+1]]=1
                siki_sub=max(result)
                ln+=1
        else:
            if siki_sub>s[i:i+j+1] and s[i:i+j+1] not in result:
                del result[siki_sub]
                result[s[i:i+j+1]]=1
                siki_sub=max(result)

print(siki_sub)
Buggy python submission (verdict: Runtime Error):
l=list(map(int,input()))
print(l.index(0))

Fixed submission:
l=list(map(int,input().split()))
print(l.index(0)+1)
Buggy python submission (verdict: Runtime Error):
l=list(map(int,input().split()))
n=l[0]
legs=l[1]
(2*a)+(2*(n-a))==legs
if(l[1]%2!=0):
    print("No")
if(l[1]%2==0 and l[0]*4>=l[1]):
    print("Yes")
else:
    print("No")

Fixed submission:
l=list(map(int,input().split()))
n=l[0]
legs=l[1]
if(n==0 and legs==0):
    print("Yes")
if(legs%2==0 and l[0]*4>=l[1] and l[0]*2<=l[1]):
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
n=int(input())
a = list(map(int,input().split()))
a = a.sort(reverse=True)
ans = 1
for i in range(n):
    ans *= a[i]
    if ans > 1000000000000000000:
        ans = -1
        break
print(ans)

Fixed submission:
n=int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
ans = 1
for i in range(n):
    ans *= a[i]
    if ans > 1000000000000000000:
        if a[n-1] == 0:
            ans = 0
        else:
            ans = -1
        break

print(ans)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a = list(map(int,input().split()))
a = a.sort(reverse=true)
ans = 1
for i in range(n):
    ans *= a[i]
    if ans > 1000000000000000000:
        ans = -1
        break
print(ans)

Fixed submission:
n=int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
ans = 1
for i in range(n):
    ans *= a[i]
    if ans > 1000000000000000000:
        if a[n-1] == 0:
            ans = 0
        else:
            ans = -1
        break

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a = list(map(int,input().split()))
ans = 1
for i in range(n):
    ans *= a[i]
if ans > 1000000000000000000:
    print(-1)
else:
    print(ans)

Fixed submission:
n=int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
ans = 1
for i in range(n):
    ans *= a[i]
    if ans > 1000000000000000000:
        if a[n-1] == 0:
            ans = 0
        else:
            ans = -1
        break

print(ans)
Buggy python submission (verdict: Runtime Error):
def prime_sieve(n):
    if n == 1:
        return []
    else:
        x = list(range(2,n+1))
        y = []
        while x[0]<pow(n,1/2):
            y += [x[0]]
            a = x[0]
            for i in x:
                if i % a == 0:
                    del x[x.index(i)]
        for i in x:
            y += [i]
        return y

n = int(input())
ans = 0
for i in prime_sieve(n):
    count = 1
    while n%i == 0:
        n /= i
        count -= 1
        loop = 1
        if count == 0:
            ans += 1
            loop += 1
            count = loop


print(ans)

Fixed submission:
n = int(input())

ans = 0
for i in range(2,int(n**0.5)+1):
    count = 1
    loop = 1
    while n % i == 0:
        n = int(n/i)
        count -= 1
        if count == 0:
            ans += 1
            loop += 1
            count = loop

if n > 1:
    ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
path = [[]for i in range(n)]
for i in range(m):
    a,b = map(lambda x: int(x)-1,input().split())
    path[a] += [b]
    path[b] += [a]
ans = [-1 for i in range(n)]
count = [[] for i in range(n)]
c=1
ans[0] = -2

for i in path[0]:
    ans[i] = 1
    count[1] += [i]
while -1 in ans:
    for i in count[c]:
        for j in path[i]:
            if ans[j]==-1:
                ans[j]=i+1
                count[c]+=[i]
        c+=1
print("Yes")
for i in range(1,n):
    print(ans[i])

Fixed submission:
n,m = map(int,input().split())
path = [[]for i in range(n)]
for i in range(m):
    a,b = map(lambda x: int(x)-1,input().split())
    path[a] += [b]
    path[b] += [a]
ans = [-1 for i in range(n)]
depth = [[] for i in range(n)]
visited = [False for i in range(n)]
d=0
ans[0] = -2
depth[0]+=[0]
visited[0]=True
while False in visited:
    for i in depth[d]:
        for j in path[i]:
            if not visited[j]:
                ans[j] = i+1
                depth[d+1] += [j]
                visited[j] = True
    d += 1
print("Yes")
for i in range(1,n):
    print(ans[i])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
l = {}
r = {}
for i in range(n):
    p = i+a[i]
    q = i-a[i]
    if p < n:
        if p in l:
            l[p] = l[p]+[i]
        else:
            l[p] = [i]
    if q > 0:
        if q in r:
            r[q] = r[q]+[i]
        else:
            r[q] = [i]
ans = 0
for i in l:
    if i in r:
        ans+= len(l[i])*len(r[i])
print(ans)



Fixed submission:
n = int(input())
a = list(map(int,input().split()))
l = {}
r = {}
for i in range(n):
    p = i+a[i]
    q = i-a[i]
    if p < n:
        if p in l:
            l[p] = l[p]+1
        else:
            l[p] = 1
    if q > 0:
        if q in r:
            r[q] = r[q]+1
        else:
            r[q] = 1
ans = 0
for i in l:
    if i in r:
        ans+= l[i]*r[i]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
l = {}
r = {}
for i in range(n):
    p = i+a[i]
    q = i-a[i]
    if p in l:
        l[p] = l[p]+[i]
    else:
        l[p] = [i]
    if q in r:
        r[q] = r[q]+[i]
    else:
        r[q] = [i]
ans = 0
for i in l:
    if i in r:
        ans+= len(l[i])*len(r[i])
print(ans)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
l = {}
r = {}
for i in range(n):
    p = i+a[i]
    q = i-a[i]
    if p < n:
        if p in l:
            l[p] = l[p]+1
        else:
            l[p] = 1
    if q > 0:
        if q in r:
            r[q] = r[q]+1
        else:
            r[q] = 1
ans = 0
for i in l:
    if i in r:
        ans+= l[i]*r[i]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
l = []
r = []
for i in range(n):
    l += [i+a[i]]
    r += [i-a[i]]
ans = 0
for i in range(n):
    ans+=r.count(l[i])
print(ans)


Fixed submission:
n = int(input())
a = list(map(int,input().split()))
l = {}
r = {}
for i in range(n):
    p = i+a[i]
    q = i-a[i]
    if p < n:
        if p in l:
            l[p] = l[p]+1
        else:
            l[p] = 1
    if q > 0:
        if q in r:
            r[q] = r[q]+1
        else:
            r[q] = 1
ans = 0
for i in l:
    if i in r:
        ans+= l[i]*r[i]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
ans = 0
for i in range(n-1):
    if i+a[i]+1 < n:
        for j in range(i+a[i]+1,n):
            if j-i == a[i]+a[j]:
                ans+=1
print(ans)



Fixed submission:
n = int(input())
a = list(map(int,input().split()))
l = {}
r = {}
for i in range(n):
    p = i+a[i]
    q = i-a[i]
    if p < n:
        if p in l:
            l[p] = l[p]+1
        else:
            l[p] = 1
    if q > 0:
        if q in r:
            r[q] = r[q]+1
        else:
            r[q] = 1
ans = 0
for i in l:
    if i in r:
        ans+= l[i]*r[i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = []
ans = 0
for i in range(n):
    b = input()
    if b not in a:
        a += [b]
        ans += 1
print(ans)

Fixed submission:
n = int(input())
a = []
ans = 0
for i in range(n):
    b = input()
    a+=[b]
c = sorted(a)
b = 0
for i in range(n-1):
    if c[i] == c[i+1]:
        b += 1

print(n-b)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [[""for i in range(10)]for j in range(26)]
dic = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
ans = 0
for i in range(n):
    b = input()
    p = dic.index(b[0])
    q = len(b)
    if b not in a[p][q]:
        a[p][q] += b
        ans += 1
print(ans)

Fixed submission:
n = int(input())
a = []
ans = 0
for i in range(n):
    b = input()
    a+=[b]
c = sorted(a)
b = 0
for i in range(n-1):
    if c[i] == c[i+1]:
        b += 1

print(n-b)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = []
for i in range(n):
    b = input()
    if b not in a:
        a += [b]
print(len(a))

Fixed submission:
n = int(input())
a = []
ans = 0
for i in range(n):
    b = input()
    a+=[b]
c = sorted(a)
b = 0
for i in range(n-1):
    if c[i] == c[i+1]:
        b += 1

print(n-b)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [0]
a += list(map(int,input().split()))
b = [0]*n
for i in range(n):
    print(a.count(i+1))


Fixed submission:
n = int(input())
a = [0]
a += list(map(int,input().split()))
b = [0]*n
for i in range(n-1,0,-1):
    b[a[i]-1] += 1
for i in b:
    print(i)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
b = sorted(a)
aj = [a[0]]
for i in range(1,n-1):
    if a.index(b[i]) < n/2:
        aj += [b[i]]
    else:
        aj = [b[i]]+aj
if aj[0] == b[n-1]:
    aj += [b[n]]
else:
    aj = [b[n]]+aj

ans = 0
for i in range(n):


print(ans)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
ans = 0
place = [0]*n
active = sorted(a,reverse=True)
for i in range(n):
    place[i] = a.index(active[i])
    a[a.index(active[i])] = -1

#dp[x][y] x,y:0~n+1 (x[-1]=x[n+1]=0にすることで端の処理を楽にする)
dp = [[0 for i in range(n+2)]for j in range(n+2)]

for i in range(n):
    dp[0][i+1] = dp[0][i]+active[i]*abs(n-i-1-place[i])
    dp[i+1][0] = dp[i][0]+active[i]*abs(place[i]-i)



def check(mat):
    for i in range(len(mat)):
        print(mat[i])
    print("\n")


for i in range(n):
    for x in range(i+2):
        y = i+1 - x
        if x != 0 and y != 0:
            dp[x][y] = max(dp[x-1][y]+active[i]*abs(place[i]-x+1),dp[x][y-1]+active[i]*abs(n-y-place[i]))
            if i == n-1:
                ans = max(ans,dp[x][y])

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
ans = 0

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

print(ans)

Fixed submission:
n = int(input())
s = input()
ans = s.count("R")*s.count("G")*s.count("B")


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

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())
ans = 0

def lunlun(ans):
    a = True
    c = len(str(ans))
    for i in range(c-1):
        r1 = ans % 10
        ans = int(ans/10)
        r2 = ans % 10
        if abs(r1-r2) > 1:
            a = False
    return a

while k > 0:
    ans += 1
    if lunlun(ans):
        k -= 1

print(ans)

Fixed submission:
k = int(input())
ans = 0
import queue

q = queue.Queue()
for i in range(1,10):
    q.put(i)

for i in range(k):
    ans = q.get()
    if ans%10 != 0:
        x = 10*ans + ans%10 - 1
        q.put(x)
    y = 10*ans + ans%10
    q.put(y)
    if ans%10 != 9:
        z = 10*ans + ans%10 + 1
        q.put(z)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(lambda x:int(x)-1,input().split()))
count = [0]*n
for i in a:
    count[i]+=1
for i in a:
    ans = 0
    for j in range(n):
        k = count[j]
        if j == i:
            k -= 1
        ans += k*(k-1)//2
    print(ans)

Fixed submission:
n = int(input())
a = list(map(lambda x:int(x)-1,input().split()))
count = [0]*n
for i in a:
    count[i]+=1
sum=0
for i in count:
    sum += i*(i-1)//2

for i in a:
    ans = sum-count[i]+1
    print(ans)
Buggy python submission (verdict: Runtime Error):
n = input()
ans = 0

if n % 2 == 0:
    ans = n/2
else:
    ans = int(n/2) + 1

print(ans)


Fixed submission:
n = int(input())+1
ans = int(n/2)
print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np
n,k = map(int,input().split())
h = list(map(int,input().split()))

dp = np.full
dp[0] = 0

for i in range(n):
    for j in range(k+1):
        if i+j<n:
            dp[i + j] = min(dp[i] + abs(h[i] - h[i + j]), dp[i + j])
print(dp[n-1])

Fixed submission:
n,k = map(int,input().split())
h = list(map(int,input().split()))

dp = [1000000000 for i in range(n)]
dp[0] = 0

for i in range(n):
    for j in range(k+1):
        if i+j<n:
            dp[i + j] = min(dp[i] + abs(h[i] - h[i + j]), dp[i + j])
print(dp[n-1])

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

dp = [[100000 for i in range(n)]for j in range(n)]

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

Fixed submission:
n,k = map(int,input().split())
h = list(map(int,input().split()))

dp = [1000000000 for i in range(n)]
dp[0] = 0

for i in range(n):
    for j in range(k+1):
        if i+j<n:
            dp[i + j] = min(dp[i] + abs(h[i] - h[i + j]), dp[i + j])
print(dp[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
n,w = map(int,input().split())
dp = [[0 for i in range(w+1)]for j in range(n+1)]

for i in range(n):
    weight,value = map(int,input().split())
    for j in range(w+1):
        if j >= weight:
            dp[i+1][j] = max(dp[i][j-weight]+value,dp[i][j])
        else:
            dp[i+1][j] = dp[i][j]

print(dp[n][w])

Fixed submission:
n,w = map(int,input().split())
weight = [0]*n
value = [0]*n
for i in range(n):
    weight[i],value[i] = map(int,input().split())
dp = [[1000000001 for i in range(max(value)*n+1)]for j in range(n+1)]
dp[0][0] = 0

for i in range(n):
    for j in range(len(dp[0])):
        if j >= value[i]:
            dp[i+1][j] = min(dp[i][j-value[i]]+weight[i],dp[i][j])
        else:
            dp[i+1][j] = dp[i][j]

ans = 0
for i,j in enumerate(dp[n]):
    if j <= w:
        ans = max(ans,i)

print(ans)
Buggy python submission (verdict: Runtime Error):
c=list(map(int, input().split()))
c = str(c)
c = c.find(0)
print(c)

Fixed submission:
c=list(map(int, input().split()))
for i in range(len(c)):
    if(c[i]==0):
        a = i+1
        print(a)

Buggy python submission (verdict: Runtime Error):
c=list(map(int, input().split()))
print(c.find(0))

Fixed submission:
c=list(map(int, input().split()))
for i in range(len(c)):
    if(c[i]==0):
        a = i+1
        print(a)

Buggy python submission (verdict: Runtime Error):
a=list(map(int, input().split()))

index = a.find(0)
print(index)

Fixed submission:
c=list(map(int, input().split()))
for i in range(len(c)):
    if(c[i]==0):
        a = i+1
        print(a)

Buggy python submission (verdict: Runtime Error):
a=list(map(int, input().split()))
index = input.a(0)
print(a)

Fixed submission:
c=list(map(int, input().split()))
for i in range(len(c)):
    if(c[i]==0):
        a = i+1
        print(a)
Buggy python submission (verdict: Runtime Error):
#a,b=map(int, input().split()) 

for i in range(a):
    if (a-i)*2+(i)*4 == b:
        print('Yes')
        break
if i==a-1:
    print('No')

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

for i in range(a+1):
    if (a-i)*2+(i)*4 == b:
        print('Yes')
        break
    if i==a:
        print('No')

Buggy python submission (verdict: Runtime Error):
#a,b=map(int, input().split()) 

for i in range(a):
    if (a-i)*2+(i)*4 == b:
        print('Yes')
        break
  
 print('No')

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

for i in range(a+1):
    if (a-i)*2+(i)*4 == b:
        print('Yes')
        break
    if i==a:
        print('No')

Buggy python submission (verdict: Runtime Error):
a,b=map(int, input().split()) 
if i in range(a):
    if((a-i)*2 + (i)*4 == b):
        print('Yes')
    else:
        print('No')
            

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

for i in range(a+1):
    if (a-i)*2+(i)*4 == b:
        print('Yes')
        break
    if i==a:
        print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split()]
ans = a[0]
for i in range(n-1):
    ans *= a[i+1]

if ans > 10 ** 18:
    print('-1')

else:
    print(ans)


Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]


if 0 in a:
    print(0)
else:
    is_true = True
    ans = a[0]
    key = 10 ** 18
    for i in range(n-1):
        ans *= int(a[i+1])
        if ans > key:
            is_true = False
            break
    if is_true:
        print(ans)
    else:
        print('-1')
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
N, K = map(int, input().split())
# mod = 1000000007
Ns = []
for n in range(N+1):
    Ns.append(n)

# print(Ns)

count = 0
# Kこ以上とる組み合わせを作る
for k in range(K, N+2):
    ans = set()
    nums = itertools.combinations(Ns, k)
    # 重複を避けてカウント
    for num in nums:
        ans.add(sum(list(num)))
    count += len(ans)

print(count)


Fixed submission:
N, K = map(int, input().split())
mod = 10 ** 9 + 7

ans = 0
for k in range(K, N+2):
    upper = k * ((N-k+1)+N) // 2
    lower = k * (k-1) // 2
    ans += upper - lower + 1
    ans %= mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
N, K = map(int, input().split())

Ns = []
for n in range(N+1):
    Ns.append(n)

# print(Ns)

ans = set()
for k in range(K, N+2):
    nums = itertools.combinations(Ns, k)
    # print(list(nums))
    for num in nums:
        tmp = f'{str(sum(list(num)))} + {str(k)}'
        ans.add(tmp)
print((len(ans)))


Fixed submission:
N, K = map(int, input().split())
mod = 10 ** 9 + 7

ans = 0
for k in range(K, N+2):
    upper = k * ((N-k+1)+N) // 2
    lower = k * (k-1) // 2
    ans += upper - lower + 1
    ans %= mod
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce


def gcd(*numbers):
    return reduce(math.gcd, numbers)


def gcd_list(numbers):
    return reduce(math.gcd, numbers)


K = int(input())

sums = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            sums += gcd(a, b, c)

print(sums)

Fixed submission:
import math
import itertools
from functools import reduce


def gcd(*numbers):
    return reduce(math.gcd, numbers)


def gcd_list(numbers):
    return reduce(math.gcd, numbers)


K = int(input())

sums = 0
# for a, b, c in itertools.permutations(range(1, K+1), 3):
for a, b, c in itertools.product(range(1, K+1), repeat=3):
    sums += gcd(a, b, c)
# for a in range(1, K+1):
#     for b in range(1, K+1):
#         for c in range(1, K+1):
#             sums += gcd(a, b, c)

print(sums)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

ls = []
for s in S:
    ls += list(s)

ans = 0
for i in range(N-2):
    for j in range(i, N-1):
        for k in range(j, N):
            if ls[i] == ls[j]:
                continue
            elif ls[j] == ls[k]:
                continue
            elif ls[i] == ls[k]:
                continue
            else:
                if k-j == j-i:
                    continue
                else:
                    ans += 1

print(ans)


Fixed submission:
n = int(input())
s = input()
c = s.count

# 文字列からR,G,Bをひとつずつを選んだときの組み合わせ総数をカウントする
ans = c("R")*c("G")*c("B")

for a in range(n-2):  # 基準
    for j in range((n-a+1)//2):  # 文字の距離
        # 全ての組み合わせから距離の等しい組み合わせを排除する
        # 距離の等しい組み合わせは、a,b,cの組み合わせのうち、
        # aを固定、a-bの距離をjで固定したとき,b=a+j, c=a+2*jと表せる
        if s[a] != s[a+j] and s[a+j] != s[a+2*j] and s[a+2*j] != s[a]:
            ans -= 1
print(ans)