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

ans_lst=[]
for i in range(1,n+1):
    ans_lst.append(str(h.index(i)+1))
print(' '.join(ans_lst))


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

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

ans_lst=[None]*n
for i,h[i] in enumerate(h):
    ans_lst[h[i]-1]=i+1
print(*ans_lst)

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

ans_lst=[]
for i in range(1,n+1):
    ans_lst.append(str(h.index(i)+1))
print(' '.join(ans_lst))


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

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

ans_lst=[None]*n
for i,h[i] in enumerate(h):
    ans_lst[h[i]-1]=i+1
print(*ans_lst)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))

while m>0:
    max_a_ind=a.index(max(a))
    a[max_a_ind]=a[max_a_ind]//2
    m-=1

print(sum(a))


Fixed submission:
from heapq import heappop,heappush,heapify
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7) 
 
n,m = map(int,input().split())
a = [int(x) for x in input().split()]
 
a_minus = [-x for x in a]
heapify(a_minus)
 
pop = lambda: -heappop(a_minus)
push = lambda x: heappush(a_minus,-x)
 
for _ in range(m):
    x = pop()
    push(x//2)
 
print(-sum(a_minus))

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

while m>0:
    max_a_ind=a.index(max(a))
    a[max_a_ind]=a[max_a_ind]//2
    m-=1

print(sum(a))


Fixed submission:
from heapq import heappop,heappush,heapify
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7) 
 
n,m = map(int,input().split())
a = [int(x) for x in input().split()]
 
a_minus = [-x for x in a]
heapify(a_minus)
 
pop = lambda: -heappop(a_minus)
push = lambda x: heappush(a_minus,-x)
 
for _ in range(m):
    x = pop()
    push(x//2)
 
print(-sum(a_minus))
Buggy python submission (verdict: Runtime Error):
import fractions


def P(n, r):
    return fractions.factorial(n)//fractions.factorial(n-r)

def C(n, r):
    return P(n, r)//fractions.factorial(r)

n = int(input())
str_list = []
for i in range(n):
    str_list.append(list(sorted(input())))
str_list=sorted(str_list)
str_list.append("a")

ans=0
cnt=0
for i in range(n):
    if str_list[i]==str_list[i+1]:
        cnt+=1
    else:
        if cnt==1:
            ans+=1
            cnt = 0
        else:
            ans+=C(cnt+1,2)
            cnt=0

print(ans)


Fixed submission:
from collections import Counter
import sys
input = sys.stdin.readline

n = int(input())
s = [''.join(sorted(input())).strip() for _ in range(n)]
c = Counter(s)
ans=sum(map(lambda x: x*(x-1)//2, c.values()))
print(ans)

Buggy python submission (verdict: Runtime Error):
def fact(n):
    if n == 0 or n == 1:
        return 1
    else:
        return n * fact(n-1)

def P(n, r):
    return fact(n)//fact(n-r)

def C(n, r):
    return P(n, r)//fact(r)

n = int(input())
str_list = []
for i in range(n):
    str_list.append(list(sorted(input())))
str_list=sorted(str_list)
str_list.append("a")

ans=0
cnt=0
for i in range(n):
    if str_list[i]==str_list[i+1]:
        cnt+=1
    else:
        if cnt==1:
            ans+=1
            cnt = 0
        else:
            ans+=C(cnt+1,2)
            cnt=0

print(ans)


Fixed submission:
from collections import Counter
import sys
input = sys.stdin.readline

n = int(input())
s = [''.join(sorted(input())).strip() for _ in range(n)]
c = Counter(s)
ans=sum(map(lambda x: x*(x-1)//2, c.values()))
print(ans)

Buggy python submission (verdict: Runtime Error):
import math


def P(n, r):
    return math.factorial(n)//math.factorial(n-r)

def C(n, r):
    return P(n, r)//math.factorial(r)

n = int(input())
str_list = []
for i in range(n):
    str_list.append(list(sorted(input())))
str_list=sorted(str_list)
str_list.append("a")

ans=0
cnt=0
for i in range(n):
    if str_list[i]==str_list[i+1]:
        cnt+=1
    else:
        if cnt==1:
            ans+=1
            cnt = 0
        else:
            ans+=C(cnt+1,2)
            cnt=0

print(ans)


Fixed submission:
from collections import Counter
import sys
input = sys.stdin.readline

n = int(input())
s = [''.join(sorted(input())).strip() for _ in range(n)]
c = Counter(s)
ans=sum(map(lambda x: x*(x-1)//2, c.values()))
print(ans)
Buggy python submission (verdict: Runtime Error):
s=input()
n=len(s)

def rle(string):
    tmp = string[0]
    cnt = 1
    ans = ''
    for i in range(1, len(string)):
        if tmp == string[i]:
            cnt += 1
        else:
            ans += tmp+str(cnt)
            tmp = string[i]
            cnt = 1
    ans += (tmp+str(cnt))
    return ans


rle_s=list(rle(s))

ans=[0]*n
sum_cnt=0

for i in range(0,len(rle_s),4):
    r_num=int(rle_s[i+1])
    l_num=int(rle_s[i+3])
    odd_num=r_num//2+(l_num+1)//2
    even_num=r_num+l_num-odd_num

    ans[sum_cnt+r_num-1]=even_num
    ans[sum_cnt+r_num]=odd_num

    sum_cnt+=(r_num+l_num)
    # print(r_num, l_num, odd_num, even_num, sum_cnt)

print(*ans)


Fixed submission:
s=input()
n=len(s)

def rle(string):
    tmp = string[0]
    cnt = 1
    ans = []
    for i in range(1, len(string)):
        if tmp == string[i]:
            cnt += 1
        else:
            ans.append(tmp)
            ans.append(cnt)
            tmp = string[i]
            cnt = 1
    ans.append(tmp)
    ans.append(cnt)
    return ans

rle_s=list(rle(s))
# print(rle_s)
ans=[0]*n
sum_cnt=0

for i in range(0,len(rle_s),4):
    r_num=int(rle_s[i+1])
    l_num=int(rle_s[i+3])
    odd_num=r_num//2+(l_num+1)//2
    even_num=r_num+l_num-odd_num

    ans[sum_cnt+r_num-1]=even_num
    ans[sum_cnt+r_num]=odd_num

    sum_cnt+=(r_num+l_num)
    # print(r_num, l_num, odd_num, even_num, sum_cnt)

print(*ans)

Buggy python submission (verdict: Runtime Error):
s=input()
n=len(s)

def rle(s):
    tmp, cnt, ans = s[0], 1, ''
    for i in range(1, len(s)):
        if tmp == s[i]:
            cnt += 1
        else:
            ans += tmp+str(cnt)
            tmp = s[i]
            cnt = 1
    ans += tmp+str(cnt)
    return ans

rle_s=list(rle(s))
ans=[0]*n
sum_cnt=0
for i in range(0,len(rle_s),4):
    r_num=int(rle_s[i+1])
    l_num=int(rle_s[i+3])
    odd_num=(r_num+l_num+1)//2
    even_num=r_num+l_num-odd_num

    if r_num%2==0:
        ans[sum_cnt+r_num-1]=even_num
        ans[sum_cnt+r_num]=odd_num
    else:
        ans[sum_cnt+r_num-1]=odd_num
        ans[sum_cnt+r_num]=even_num

    sum_cnt+=r_num+l_num
    # print(r_num,l_num,odd_num,even_num)

print(*ans)


Fixed submission:
s=input()
n=len(s)

def rle(string):
    tmp = string[0]
    cnt = 1
    ans = []
    for i in range(1, len(string)):
        if tmp == string[i]:
            cnt += 1
        else:
            ans.append(tmp)
            ans.append(cnt)
            tmp = string[i]
            cnt = 1
    ans.append(tmp)
    ans.append(cnt)
    return ans

rle_s=list(rle(s))
# print(rle_s)
ans=[0]*n
sum_cnt=0

for i in range(0,len(rle_s),4):
    r_num=int(rle_s[i+1])
    l_num=int(rle_s[i+3])
    odd_num=r_num//2+(l_num+1)//2
    even_num=r_num+l_num-odd_num

    ans[sum_cnt+r_num-1]=even_num
    ans[sum_cnt+r_num]=odd_num

    sum_cnt+=(r_num+l_num)
    # print(r_num, l_num, odd_num, even_num, sum_cnt)

print(*ans)
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
n=len(s)
mod=10**9+7
dp=[[0]*13 for _ in range(n+1)]
dp[0][0]=1
mul=1

for i in range(n):
    x=s[-(i+1)]  # 後ろから見ていく
    if x=='?':
        for k in range(10):
            for j in range(13):
                dp[i+1][(mul*k+j)%13]+=dp[i][j]
                dp[i+1][(mul*k+j)%13]%=mod
    else:
        k=int(x)
        for j in range(13):
            dp[i+1][(mul*k+j)%13]+=dp[i][j]
            dp[i+1][(mul*k+j)%13]%=mod
    mul=mul*10%13
# print(dp)
print(dp[n][5])


Fixed submission:
s=input()
n=len(s)
mod=10**9+7
dp=[[0]*13 for _ in range(n+1)]
dp[0][0]=1
mul=1

for i in range(n):
    x=s[-(i+1)]  # 後ろから見ていく
    if x=='?':
        for k in range(10):
            for j in range(13):
                dp[i+1][(mul*k+j)%13]+=dp[i][j]
                dp[i+1][(mul*k+j)%13]%=mod
    else:
        k=int(x)
        for j in range(13):
            dp[i+1][(mul*k+j)%13]+=dp[i][j]
            dp[i+1][(mul*k+j)%13]%=mod
    mul=mul*10%13
# print(dp)
print(dp[n][5])
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[int(input()) for _ in range(n)]

m=max(a)
for i in range(n):
    if a[i]==m:
        a_new=a[:i]+a[i+1:]
        print(max(a_new))
    else:
        print(m)


Fixed submission:
n=int(input())
a=[int(input()) for _ in range(n)]

a_s=sorted(a)
m1=a_s[-1]
m2=a_s[-2]

for i in range(n):
    if a[i]==m1:
        print(m2)
    else:
        print(m1)
Buggy python submission (verdict: Runtime Error):
import numpy as np

n,d=map(int,input().split())
x=[list(map(int,input().split())) for _ in range(n)]

cnt=0
for i in range(n-1):
    for j in range(i+1,n):
        dist=0
        for k in range(d):
            dist+=(x[i][k]-x[j][k])**2
        for dist2 in range(int(np.sqrt(dist))+1):
            if dist2**2==dist:
                cnt+=1
print(cnt)


Fixed submission:
import numpy as np

n,d=map(int,input().split())
x=[list(map(int,input().split())) for _ in range(n)]

cnt=0
for i in range(n-1):
    for j in range(i+1,n):
        dist=0
        for k in range(d):
            dist+=(x[i][k]-x[j][k])**2
        for dist2 in range(int(np.sqrt(dist))+1):
            if dist2**2==dist:
                cnt+=1
print(cnt)
Buggy python submission (verdict: Runtime Error):
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n,k=map(int,input().split())
for i in range(1,k+1):
    ans = combinations_count(k-1,i-1)*combinations_count(n-k+1, i)
    print(int(ans%(10**9+7)))


Fixed submission:
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

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

for i in range(1,k+1):
    if n-k+1<i:
        print(0)
    else:
        ans = combinations_count(k-1,i-1)*combinations_count(n-k+1, i)
        print(int(ans%(10**9+7)))

Buggy python submission (verdict: Runtime Error):
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n,k=map(int,input().split())
for i in range(1,k+1):
    ans = combinations_count(k-1,i-1)*combinations_count(n-k+1, i)
    print(int(ans%(10**9+7)))


Fixed submission:
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

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

for i in range(1,k+1):
    if n-k+1<i:
        print(0)
    else:
        ans = combinations_count(k-1,i-1)*combinations_count(n-k+1, i)
        print(int(ans%(10**9+7)))
Buggy python submission (verdict: Runtime Error):
from collections import Counter
n=int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
xy=sorted(xy)
xy_diff=[]

for i in range(0,n-1):
    xy_diff.append(xy[i][0]-xy[i+1][0])

c=Counter(xy_diff)
mode = c.most_common(1)
saihin=mode[0][0]

xy1_diff=[]

for i in range(0,n-1):
    if xy[i][0]-xy[i+1][0]==saihin:
        xy1_diff.append(xy[i][1]-xy[i+1][1])

d=Counter(xy1_diff)
mode = d.most_common(1)
kaisu=mode[0][1]


print(n-kaisu)

Fixed submission:
n=int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
diff={}

for i in range(n):
    for j in range(n):
        if i==j:
            continue
        if ((xy[i][0]-xy[j][0]),(xy[i][1]-xy[j][1])) in diff:
            diff[((xy[i][0]-xy[j][0]), (xy[i][1]-xy[j][1]))]+=1
        else:
            diff[((xy[i][0] - xy[j][0]), (xy[i][1] - xy[j][1]))] = 1

print(n-max(diff.values()) if n!=1 else 1)
Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())

s=[['#']*(w+2)]
for i in range(h):
    s.append(['#']+list(input())+['#'])
s.append([['#']*(w+2)])

l=[[0]*(w+2) for _ in range(h+2)]
r=[[0]*(w+2) for _ in range(h+2)]
u=[[0]*(w+2) for _ in range(h+2)]
d=[[0]*(w+2) for _ in range(h+2)]

for i in range(1, h+1):
    for j in range(1, w+1):
        if s[i][j]=='.':
            l[i][j]=l[i][j-1]+1
            u[i][j]=u[i-1][j]+1
        if s[i][w+1-j]=='.':
            r[i][w+1-j]=r[i][w+2-j]+1
        if s[h+1-i][j]=='.':
            d[h+1-i][j]=d[h+2-i][j]+1

ans=0
for i in range(1, h+1):  # hはy座標
    for j in range(1, w+1):  # wはx座標
        tmp_ans=l[i][j]+r[i][j]+u[i][j]+d[i][j]-3
        ans=max(ans, tmp_ans)
print(ans)


Fixed submission:
h,w=map(int,input().split())

s=[['#']*(w+2)]
for i in range(h):
    s.append(['#']+list(input())+['#'])
s.append([['#']*(w+2)])

l=[[0]*(w+2) for _ in range(h+2)]
r=[[0]*(w+2) for _ in range(h+2)]
u=[[0]*(w+2) for _ in range(h+2)]
d=[[0]*(w+2) for _ in range(h+2)]

for i in range(1, h+1):
    for j in range(1, w+1):
        if s[i][j]=='.':
            l[i][j]=l[i][j-1]+1
            u[i][j]=u[i-1][j]+1
        if s[i][w+1-j]=='.':
            r[i][w+1-j]=r[i][w+2-j]+1
        if s[h+1-i][j]=='.':
            d[h+1-i][j]=d[h+2-i][j]+1

ans=0
for i in range(1, h+1):  # hはy座標
    for j in range(1, w+1):  # wはx座標
        tmp_ans=l[i][j]+r[i][j]+u[i][j]+d[i][j]-3
        ans=max(ans, tmp_ans)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
bc = [list(map(int, input().split())) for _ in range(m)]

[a.extend([bc[i][1]]*bc[i][0]) for i in range(m)]

print(sum(sorted(a,reverse=True)[:n]))


Fixed submission:
n,m=map(int,input().split())
a=list(map(int,input().split()))
bc=[list(map(int, input().split())) for _ in range(m)]

sorted_ab=sorted(bc, reverse=True, key=lambda x: x[1])
new_ab=[]
ans=[]

for i in range(m):
    if len(new_ab)<=n:
        tmp_l=[sorted_ab[i][1]]*sorted_ab[i][0]
        new_ab+=tmp_l
    else:
        break

final_list=a+new_ab
final_list.sort(reverse=True)

print(sum(final_list[:n]))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
bc = [list(map(int, input().split())) for _ in range(m)]

for i in range(m):
    listnum=bc[i][0]
    tplist=[bc[i][1]]
    templist=tplist*listnum
    a.extend(templist)
a=sorted(a,reverse=True)
print(sum(a[:n]))


Fixed submission:
n,m=map(int,input().split())
a=list(map(int,input().split()))
bc=[list(map(int, input().split())) for _ in range(m)]

sorted_ab=sorted(bc, reverse=True, key=lambda x: x[1])
new_ab=[]
ans=[]

for i in range(m):
    if len(new_ab)<=n:
        tmp_l=[sorted_ab[i][1]]*sorted_ab[i][0]
        new_ab+=tmp_l
    else:
        break

final_list=a+new_ab
final_list.sort(reverse=True)

print(sum(final_list[:n]))
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
s=input()
ss=s[k]

print(s[:k]+ss.lower()+s[k+1:])

Fixed submission:
n,k=map(int,input().split())
s=input()
ss=s[k-1]

print(s[:(k-1)]+ss.lower()+s[k:])
Buggy python submission (verdict: Runtime Error):
from collections import Counter

n=int(input())
s=[input() for _ in range(n)]

cnt=0
cnt_a=0
cnt_b=0
cnt_ab=0
for i in range(n):
    if s[i][0]=='B' and s[i][-1]=='A':
        cnt_ab+=1
    elif s[i][0]=='B':
        cnt_b+=1
    elif s[i][-1]=='A':
        cnt_a+=1
    cnt+=s[i].count('AB')
if cnt_ab=0:
    ans=cnt+min(cnt_a,cnt_b)
elif:
    if cnt_a=0 and cnt_b=0:
        ans=cnt+cnt_ab-1
    else:
        ans=cnt+min(cnt_a,cnt_b)

print(ans)


Fixed submission:
from collections import Counter

n=int(input())
s=[input() for _ in range(n)]

cnt=0
cnt_a=0
cnt_b=0
cnt_ab=0
for i in range(n):
    if s[i][0]=='B' and s[i][-1]=='A':
        cnt_ab+=1
    elif s[i][0]=='B':
        cnt_b+=1
    elif s[i][-1]=='A':
        cnt_a+=1
    cnt+=s[i].count('AB')
if cnt_ab==0:
    ans=cnt+min(cnt_a,cnt_b)
else:
    if cnt_a==0 and cnt_b==0:
        ans=cnt+cnt_ab-1
    else:
        ans=cnt+cnt_ab+min(cnt_a,cnt_b)

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.read


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

abslsta=[abs(v) for v in lsta]
min_index=abslsta.index(min(abslsta))

for i in range(n-1):
    if lsta[i]<0:
        lsta[i]=lsta[i]*(-1)
        lsta[i+1]=lsta[i+1]*(-1)

if lsta[n-1]<0:
    if min_index==n-1:
        print(sum(lsta))

    else:
        print(sum(lsta)-lsta[n-1]*2-lsta[min_index]*2)

else:
    print(sum(lsta))

Fixed submission:
#import sys
#input = sys.stdin.read

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

abslsta=[abs(v) for v in lsta]
min_index=abslsta.index(min(abslsta))

for i in range(n-1):
    if lsta[i]<0:
        lsta[i]=lsta[i]*(-1)
        lsta[i+1]=lsta[i+1]*(-1)

if lsta[n-1]<0:
    if min_index==n-1:
        print(sum(lsta))

    else:
        print(sum(lsta)-lsta[n-1]*2-lsta[min_index]*2)

else:
    print(sum(lsta))

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.read

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

abslsta=[abs(v) for v in lsta]
min_index=abslsta.index(min(abslsta))

for i in range(n-1):
    if lsta[i]<0:
        lsta[i]=lsta[i]*(-1)
        lsta[i+1]=lsta[i+1]*(-1)
        print(lsta)


if lsta[n-1]<0:
    if min_index==n-1:
        print(sum(lsta))

    else:
        print(sum(lsta)-lsta[n-1]*2-lsta[min_index]*2)

else:
    print(sum(lsta))

Fixed submission:
#import sys
#input = sys.stdin.read

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

abslsta=[abs(v) for v in lsta]
min_index=abslsta.index(min(abslsta))

for i in range(n-1):
    if lsta[i]<0:
        lsta[i]=lsta[i]*(-1)
        lsta[i+1]=lsta[i+1]*(-1)

if lsta[n-1]<0:
    if min_index==n-1:
        print(sum(lsta))

    else:
        print(sum(lsta)-lsta[n-1]*2-lsta[min_index]*2)

else:
    print(sum(lsta))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()

ans=1145141919
for i in range(n+1):
    ans = min(ans, (s[:i].count("#")+s[i:].count(".")))
print(ans)


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

white=s.count(".")
black=0
ans=white

for s_i in s:
    if s_i == "#":
        black+=1
    else:
        white-=1
    ans = min(ans, white+black)
print(ans)

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

ans=1145141919
for i in range(n+1):
    ans = min(ans, (s[:i].count("#")+s[i:].count(".")))
print(ans)


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

white=s.count(".")
black=0
ans=white

for s_i in s:
    if s_i == "#":
        black+=1
    else:
        white-=1
    ans = min(ans, white+black)
print(ans)
Buggy python submission (verdict: Runtime Error):
lst=[int(input()) for _ in range(5)]

c=[]
for i in range(5):
    if lst[i]%10!=0:
        c.append(lst[i]%10)
        lst[i]=(lst[i]//10+1)*10


print(sum(lst)-10+min(c))

Fixed submission:
lst=[int(input()) for _ in range(5)]

c=[]
for i in range(5):
    if lst[i]%10!=0:
        c.append(lst[i]%10)
        lst[i]=(lst[i]//10+1)*10

if not c:
    print(sum(lst))
else:
    print(sum(lst)+min(c)-10)
Buggy python submission (verdict: Time Limit Exceeded):
x,y,z,k=map(int, input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
c=list(map(int, input().split()))

ab=[]
for i in range(x):
    for j in range(y):
        ab.append(a[i]+b[j])

if len(ab)>k:
    ab.sort(reverse=True)
    ab=ab[:k]
else:
    ab.sort(reverse=True)

ans=[]
for i in range(len(ab)):
    for j in range(z):
        ans.append(ab[i]+c[j])
ans.sort(reverse=True)

for i in range(k):
    print(ans[i])



Fixed submission:
x,y,z,k=map(int, input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
c=list(map(int, input().split()))

ab=[]
for i in range(x):
    for j in range(y):
        ab.append(a[i]+b[j])

if len(ab)>k:
    ab.sort(reverse=True)
    ab=ab[:k]
else:
    ab.sort(reverse=True)

ans=[]
for i in range(len(ab)):
    for j in range(z):
        ans.append(ab[i]+c[j])
ans.sort(reverse=True)

for i in range(k):
    print(ans[i])
Buggy python submission (verdict: Runtime Error):
a,b,k=map(int,input().split())
numlst=[]
for i in range(1,max(a,b)):
    if a%i==0 and b%i==0:
        numlst.append(i)

print(numlst[k-1])

Fixed submission:
a,b,k=map(int,input().split())
numlst=[]
for i in range(max(a,b)):
    if a%(i+1)==0 and b%(i+1)==0:
        numlst.append(i+1)

print(numlst[len(numlst)-k])
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**7)

n, m = map(int, input().split())

par = [i for i in range(n+1)]
rank = [0]*(n+1)
size = [1]*(n+1)

def root(x):
    if par[x] == x:
        return x
    else:
        par[x] = root(par[x])
        return par[x]

def same(x, y):
    return root(x) == root(y)

def unite(x, y):
    xx = root(x)
    yy = root(y)
    if xx == yy:
        return
    if rank[xx] < rank[yy]:
        par[xx] = yy
        size[yy] += size[xx]
    else:
        par[yy] = xx
        size[xx] += size[yy]
        if rank[xx] == rank[yy]:
            rank[yy] += 1

ab=[list(map(int, input().split())) for _ in range(m)]

ans=[0]*m
ans[m-1]=n*(n-1)//2

for i in range(M-1, 0, -1):
    a = ab[i][0]
    b = ab[i][1]
    if root(a) != root(b):
        ans[i-1] = ans[i] - size[root(a)]*size[root(b)]
    else:
        ans[i-1] = ans[i]
    unite(a,b)

for ans_i in ans:
    print(ans_i)


Fixed submission:
import sys
# sys.setrecursionlimit(10**7)


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1]*n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


n, m = map(int, input().split())
ab=[list(map(int, input().split())) for _ in range(m)]

uf = UnionFind(n)
tmp_ans = n*(n-1)//2
ans = []
for i in range(m):
    ans.append(tmp_ans)
    a=ab[m-1-i][0]
    b=ab[m-1-i][1]
    a-=1
    b-=1
    if not uf.is_same(a,b):
        tmp_ans-=uf.size(a)*uf.size(b)
    uf.union(a,b)

ans.reverse()
for i in ans:
    print(i)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())

listA=[]
for i in range(n):
    listA.append(list(map(int,input().split())))

for i in range(n):
    popped_item1=listA[i].pop(0)

listB=[]
for i in listA:
    for j in i:
        listB.append(j)

cnt=0
for i in range(m+1):
    if listB.count(i)==n:
        cnt+=1
print(cnt)

Fixed submission:
n=int(input())
listL = list(map(int, input().split()))
if max(listL)<(sum(listL)-max(listL)):
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

INF=float('inf')
n, k = map(int,input().split())
h = list(map(int, input().split()))
dp=[0]+[INF]*(n-1)
for i in range(1,n):
    for j in range(1,min(i+1,k+1)):
        dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
print(dp[-1])


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

INF=float('inf')
n, k = map(int,input().split())
h = list(map(int, input().split()))
dp=[0]+[INF]*(n-1)
for i in range(1,n):
    for j in range(1,min(i+1,k+1)):
        dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
print(dp[-1])