Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys


def main():
    n, k = [int(x) for x in sys.stdin.readline().rstrip().split(' ')]
    x = [int(x) for x in sys.stdin.readline().rstrip().split(' ')]

    c = 0
    while x[c] < 0 and c<n:
        c += 1


    def getCost(l, r):
        if l<c and c<=r-1:
            return min(-x[l]*2+x[r-1], x[r-1]*2-x[l])
        elif c>r-1:
            return -x[l]
        else:
            return x[r-1]
    cost = getCost(0, k)

    for i in range(1,n-k+1):
        cost = min(cost, getCost(i, i+k))
    
    print(cost)
        

      
if __name__=="__main__":
    main()


Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys


def main():
    n, k = [int(v) for v in sys.stdin.readline().rstrip().split(' ')]
    x = [int(v) for v in sys.stdin.readline().rstrip().split(' ')]

    c = 0
    while c<n and x[c] < 0:
        c += 1


    def getCost(l, r):
        if l<c and c<=r-1:
            return min(-x[l]*2+x[r-1], x[r-1]*2-x[l])
        elif c>r-1:
            return -x[l]
        else:
            return x[r-1]
    cost = getCost(0, k)

    for i in range(1,n-k+1):
        cost = min(cost, getCost(i, i+k))
    
    print(cost)
        

      
if __name__=="__main__":
    main()

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys


def main():
    n, k = [int(x) for x in sys.stdin.readline().rstrip().split(' ')]
    x = [int(x) for x in sys.stdin.readline().rstrip().split(' ')]

    c = 0
    while x[c] < 0 and c<n:
        c += 1


    def getCost(l, r):
        if l<c and c<=r-1:
            return min(-x[l]*2+x[r-1], x[r-1]*2-x[l])
        elif c>r-1:
            return -x[l]
        else:
            return x[r-1]
    cost = getCost(0, k)

    for i in range(1,n-k+1):
        cost = min(cost, getCost(i, i+k))
    
    print(cost)
        

      
if __name__=="__main__":
    main()


Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys


def main():
    n, k = [int(v) for v in sys.stdin.readline().rstrip().split(' ')]
    x = [int(v) for v in sys.stdin.readline().rstrip().split(' ')]

    c = 0
    while c<n and x[c] < 0:
        c += 1


    def getCost(l, r):
        if l<c and c<=r-1:
            return min(-x[l]*2+x[r-1], x[r-1]*2-x[l])
        elif c>r-1:
            return -x[l]
        else:
            return x[r-1]
    cost = getCost(0, k)

    for i in range(1,n-k+1):
        cost = min(cost, getCost(i, i+k))
    
    print(cost)
        

      
if __name__=="__main__":
    main()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3

def main():
    a = int(input().rstrip())
    b = int(input().rstrip())

    print((a-1)*(b-1))
    

if __name__ == '__main__':
    main()

Fixed submission:
#!/usr/bin/env python3
import sys

def main():
    a, b = [int(x) for x in sys.stdin.readline().rstrip().split()]
    print((a-1)*(b-1))
    

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys

def main():
    a = int(sys.stdin.readline().rstrip())
    b = int(sys.stdin.readline().rstrip())

    print((a-1)*(b-1))
    

if __name__ == '__main__':
    main()

Fixed submission:
#!/usr/bin/env python3
import sys

def main():
    a, b = [int(x) for x in sys.stdin.readline().rstrip().split()]
    print((a-1)*(b-1))
    

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import copy
S=list(input())
ans=1
l=S.pop(0)
while len(S)>=1:
    x=S.pop(0)
    if l!=x:
        ans+=1
        l=copy.deepcopy(x)
    else:
        if len(S)>=1:
            ans+=1
            l=copy.deepcopy(x)+S.pop(0)
        else:
            break
print(ans)



Fixed submission:
from collections import deque
import copy
S=deque(list(input()))
ans=1
l=S.popleft()
while len(S)>=1:
    x=S.popleft()
    if l!=x:
        ans+=1
        l=copy.deepcopy(x)
    else:
        if len(S)>=1:
            ans+=1
            l=copy.deepcopy(x)+S.popleft()
        else:
            break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import copy
S=list(input())
ans=1
l=S.pop(0)
while len(S)>=1:
    x=S.pop(0)
    if l!=x:
        ans+=1
        l=copy.deepcopy(x)
    else:
        if len(S)>=1:
            ans+=1
            l=copy.deepcopy(x)+S.pop(0)
        else:
            break
print(ans)



Fixed submission:
from collections import deque
import copy
S=deque(list(input()))
ans=1
l=S.popleft()
while len(S)>=1:
    x=S.popleft()
    if l!=x:
        ans+=1
        l=copy.deepcopy(x)
    else:
        if len(S)>=1:
            ans+=1
            l=copy.deepcopy(x)+S.popleft()
        else:
            break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import copy
N=int(input())
A=list(int(input()) for _ in range(N))
a=copy.deepcopy(A)
for i in range(N):
    a = copy.deepcopy(A)
    a.pop(i)
    print(max(a))


Fixed submission:
import copy
N=int(input())
A=list(int(input()) for _ in range(N))
a=copy.deepcopy(A)
a.sort(reverse=True)
x=a[0]
y=a[1]

for i in range(N):
    if A[i]==x:
        print(y)
    else:
        print(x)
Buggy python submission (verdict: Runtime Error):
L,R=map(int,input().split())
mod=2019
if R-L>=2020:
    print(0)
    exit()
else:
    l=[]
    for i in range(L,R+1):
        l.append(i%mod)
ans=2018
for i in l:
    for j in l:
        if i!=j:
            ans=min(ans,l[i]*l[j]%mod)
print(ans)

Fixed submission:
L,R=map(int,input().split())
mod=2019
if R-L>=2020:
    print(0)
    exit()
else:
    l=[]
    for i in range(L,R+1):
        l.append(i%mod)
ans=2018
for i in l:
    for j in l:
        if i!=j:
            ans=min(ans,i*j%mod)
print(ans)
Buggy python submission (verdict: Runtime Error):
N,A,B,C,D=map(int,input().split())
S=input()
if C<D and B<C:
    for i in range(A-1,D-2):
        if S[i]=='#' and S[i+1]=='#':
            print('No')
            exit()
    print('Yes')
    exit()
elif C<D and B>C:
    for i in range(A-1,C-2):
        if S[i] == '#' and S[i + 1] == '#':
            print('No')
            exit()
    for p in range(B-1,D-2):
        if S[p] == '#' and S[p + 1] == '#':
            print('No')
            exit()
    print('Yes')
    exit()
elif C>D:
    for j in range(A-1,D-2):
        if S[j]=='#' and S[j+1]=='#':
            print('No')
            exit()
    if any(S[k-1]=='.' and S[k]=='.' and S[k+1]=='.' for k in range(B-1,D-1)):
        print('Yes')
        exit()
        
elif 
print('No')


Fixed submission:
N,A,B,C,D=map(int,input().split())
S=input()
if C<B and B<D:#パターンその1
    for i in range(A-1,C-1):
        if S[i] == '#' and S[i + 1] == '#':
            print('No')
            exit()
    for p in range(B-1,D-1):
        if S[p] == '#' and S[p + 1] == '#':
            print('No')
            exit()
    print('Yes')
    exit()
elif B<C and C<D:#パターンその2
    for i in range(A-1,D-1):
        if S[i]=='#' and S[i+1]=='#':
            print('No')
            exit()
    print('Yes')
    exit()
elif D<C:#パターンその3
    for j in range(A-1,C-1):
        if S[j]=='#' and S[j+1]=='#':
            print('No')
            exit()
    if any(S[k-1]=='.' and S[k]=='.' and S[k+1]=='.' for k in range(B-1,D)):
        print('Yes')
        exit()
print('No')
Buggy python submission (verdict: Time Limit Exceeded):
import sys 
sys.setrecursionlimit(500000)
s=input()
ans=0
def dfs(v):#vはインデックス
    if 0<=v+1<=len(s)-1 and s[v+1]=='A':
        dfs(v+1)
    elif 0<=v+2<=len(s)-1 and s[v+1]=='B' and s[v+2]=='C':
        global ans
        ans+=1
        dfs(v+2)
    else:
        return
L=[]
for i,I in enumerate(s):
    if I=='A':
        L.append(i)
for l in L:
    dfs(l)
print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(500000)
s=list(input())
ans=0
cA=1
L=[]
def dfs(v):#vはインデックス
    if 0<=v+1<=len(s)-1 and s[v+1]=='A':
        s[v+1]='#'
        global cA
        cA+=1
        dfs(v+1)
    elif 0<=v+2<=len(s)-1 and s[v+1]=='B' and s[v+2]=='C':
        global ans
        ans+=cA
        dfs(v+2)
    else:
        cA=1
        return

for i,I in enumerate(s):
    if I=='A':
        L.append(i)
for l in L:
    if (0<=l+1<=len(s)-1 and s[l]=='A'and s[l+1]=='A'):
        dfs(l)
    elif (0<=l+2<=len(s)-1 and s[l]=='A'and s[l+1]=='B'and s[l+2]=='C'):
        dfs(l)
    else:
        cA=1
print(ans)

Buggy python submission (verdict: Runtime Error):
s=input()
ans=0
def dfs(v):#vはインデックス
    if 0<=v+1<=len(s)-1 and s[v+1]=='A':
        dfs(v+1)
    elif 0<=v+2<=len(s)-1 and s[v+1]=='B' and s[v+2]=='C':
        global ans
        ans+=1
        dfs(v+2)
    else:
        return
L=[]
for i,I in enumerate(s):
    if I=='A':
        L.append(i)
for l in L:
    dfs(l)
print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(500000)
s=list(input())
ans=0
cA=1
L=[]
def dfs(v):#vはインデックス
    if 0<=v+1<=len(s)-1 and s[v+1]=='A':
        s[v+1]='#'
        global cA
        cA+=1
        dfs(v+1)
    elif 0<=v+2<=len(s)-1 and s[v+1]=='B' and s[v+2]=='C':
        global ans
        ans+=cA
        dfs(v+2)
    else:
        cA=1
        return

for i,I in enumerate(s):
    if I=='A':
        L.append(i)
for l in L:
    if (0<=l+1<=len(s)-1 and s[l]=='A'and s[l+1]=='A'):
        dfs(l)
    elif (0<=l+2<=len(s)-1 and s[l]=='A'and s[l+1]=='B'and s[l+2]=='C'):
        dfs(l)
    else:
        cA=1
print(ans)
Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
V=list(map(int,input().split()))
R=min(N,K)
L=[]
for r in range(R+1):
    for A in range(R -r + 1):
        B = R - r-A
        I = sorted((V[:A] + V[::-1][:B]))
        p=K-A-B
        for i in range(len(I)):
            if I[i] >= 0:
                p = i
                break
        for ii in range(min(p,K-A-B)):
            if len(I)>0:
                I.pop(0)
            else:break
            L.append(sum(I))
print(max(L))








Fixed submission:
N,K=map(int,input().split())
V=list(map(int,input().split()))
R=min(N,K)
L=[]
for r in range(R+1):
    for A in range(R -r + 1):
        B = R - r-A
        I = sorted((V[:A] + V[::-1][:B]))
        p=K-A-B
        for i in range(len(I)):
            if I[i] >= 0:
                p = i
                break
        for ii in range(min(p,K-A-B)):
            if len(I)>0:
                I.pop(0)
            else:break
        L.append(sum(I))
print(max(L))

Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
V=list(map(int,input().split()))
R=min(N,K)
L=[]
for r in range(R+1):
    for A in range(R -r + 1):
        B = R - r-A
        I = sorted((V[:A] + V[::-1][:B]))
        for i in range(len(I)):
            p=K-A-B
            if I[i] >= 0:
                p = i
                break
        for ii in range(min(p,K-A-B)):
            while len(I)>0:
                I.pop(0)
            L.append(sum(I))
print(max(L))








Fixed submission:
N,K=map(int,input().split())
V=list(map(int,input().split()))
R=min(N,K)
L=[]
for r in range(R+1):
    for A in range(R -r + 1):
        B = R - r-A
        I = sorted((V[:A] + V[::-1][:B]))
        p=K-A-B
        for i in range(len(I)):
            if I[i] >= 0:
                p = i
                break
        for ii in range(min(p,K-A-B)):
            if len(I)>0:
                I.pop(0)
            else:break
        L.append(sum(I))
print(max(L))
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
LR=list(map(int,input().split()) for _ in range(M) )
L=1
R=N
for i in range(M):
    L=max(L,LR[i][0])
    R=min(R,LR[i][1])
print(R-L+1 if R<=L else 0)

Fixed submission:
N,M=map(int,input().split())
LR=list(list(map(int,input().split())) for _ in range(M))
L=1
R=N
for i in range(M):
    L=max(L,LR[i][0])
    R=min(R,LR[i][1])
print(R-L+1 if L<=R else 0)

Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
LR=list(map(int,input().split()) for _ in range(M) )
L=0
R=N
for i in range(M):
    L=max(L,LR[i][0])
    R=min(R,LR[i][1])
print(R-L+1 if R<=L else 0)

Fixed submission:
N,M=map(int,input().split())
LR=list(list(map(int,input().split())) for _ in range(M))
L=1
R=N
for i in range(M):
    L=max(L,LR[i][0])
    R=min(R,LR[i][1])
print(R-L+1 if L<=R else 0)

Buggy python submission (verdict: Time Limit Exceeded):
import copy
N,M=map(int,input().split())
D=[]
for _ in range(M):
    if _==0:
        LR=list(map(int,input().split()))
        for u in range(LR[0],LR[1]+1):
            D.append(u)
    else:
        LR=list(map(int,input().split()))
        DD=copy.deepcopy(D)
        for v in DD:
            if v not in range(LR[0],LR[1]+1):
                D.remove(v)
print(len(D))

Fixed submission:
N,M=map(int,input().split())
LR=list(list(map(int,input().split())) for _ in range(M))
L=1
R=N
for i in range(M):
    L=max(L,LR[i][0])
    R=min(R,LR[i][1])
print(R-L+1 if L<=R else 0)

Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
C={i for i in range(1,N+1)}

for _ in range(M):
    LR=list(map(int,input().split()))
    C=C&{k for k in range(max(LR[0],min(C)),min(LR[1]+1,max(C)+1))}
print(len(C))

Fixed submission:
N,M=map(int,input().split())
LR=list(list(map(int,input().split())) for _ in range(M))
L=1
R=N
for i in range(M):
    L=max(L,LR[i][0])
    R=min(R,LR[i][1])
print(R-L+1 if L<=R else 0)

Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
C={i for i in range(1,N+1)}

for _ in range(M):
    LR=list(map(int,input().split()))
    C=C&{k for k in range(LR[0],LR[1]+1)}
print(len(C))

Fixed submission:
N,M=map(int,input().split())
LR=list(list(map(int,input().split())) for _ in range(M))
L=1
R=N
for i in range(M):
    L=max(L,LR[i][0])
    R=min(R,LR[i][1])
print(R-L+1 if L<=R else 0)
Buggy python submission (verdict: Time Limit Exceeded):
R,G,B,N=list(map(int,input().split()))
ans=0
for r in range(0,N//R+1):
    for g in range(0,N//G+1):
        if 0<= (N-(R*r+G*g))//B<=N/B and (N-(R*r+G*g))%B==0 :
            ans+=1
print(ans)

Fixed submission:
R,G,B,N=list(map(int,input().split()))
ans=0
for r in range(0,N//R+1):
    for g in range(0,N//G+1):
        if 0<= (N-(R*r+G*g))//B<=N/B and (N-(R*r+G*g))%B==0 :
            ans+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

N=int(input())
s=list(input() for _ in range(N))
L=list(itertools.permutations(s))
c=0
for i in L:
    if c<''.join(i).count('AB'):
        c=''.join(i).count('AB')
print(c)

Fixed submission:
N=int(input())
s=list(input() for _ in range(N))
ans=0
count=0
a_count=0
b_count=0
ab_count=0
for i in s:
    ans+=i.count('AB')
    if i[0]=='B'and i[-1]=='A':
        ab_count+=1
    elif i[0]=='B':
        b_count+=1
    elif i[-1]=='A':
        a_count+=1
print(ans+min(a_count,b_count)+ab_count if a_count+b_count!=0 else ans+max(ab_count-1,0))

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

N=int(input())
s=list(input() for _ in range(N))
L=list(itertools.permutations(s))
c=0
for i in L:
    if c<''.join(i).count('AB'):
        c=''.join(i).count('AB')
print(c)

Fixed submission:
N=int(input())
s=list(input() for _ in range(N))
ans=0
count=0
a_count=0
b_count=0
ab_count=0
for i in s:
    ans+=i.count('AB')
    if i[0]=='B'and i[-1]=='A':
        ab_count+=1
    elif i[0]=='B':
        b_count+=1
    elif i[-1]=='A':
        a_count+=1
print(ans+min(a_count,b_count)+ab_count if a_count+b_count!=0 else ans+max(ab_count-1,0))

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

N=int(input())
s=list(input() for _ in range(N))
L=list(itertools.permutations(s))
c=0
for i in L:
    if c<''.join(i).count('AB'):
        c=''.join(i).count('AB')
print(c)

Fixed submission:
N=int(input())
s=list(input() for _ in range(N))
ans=0
count=0
a_count=0
b_count=0
ab_count=0
for i in s:
    ans+=i.count('AB')
    if i[0]=='B'and i[-1]=='A':
        ab_count+=1
    elif i[0]=='B':
        b_count+=1
    elif i[-1]=='A':
        a_count+=1
print(ans+min(a_count,b_count)+ab_count if a_count+b_count!=0 else ans+max(ab_count-1,0))
Buggy python submission (verdict: Runtime Error):
m=int(input())
pf={m:1}
a=[0]
for i in range(2,int(m**0.5)+1):
    pf[i]=pf.get(i,0)+1
    if i!=m//i:
        pf[m//i]=pf.get(m//i,0)+1
for i in pf:
    if m//(i-1)==m%(i-1):
        a.append(a[-1]+i-1)
print(a[-1])


Fixed submission:
m=int(input())
pf={m:1}
a=[0]
for i in range(2,int(m**0.5)+1):
    if m ==1:
        break
    pf[i]=pf.get(i,0)+1
    if i!=m//i:
        pf[m//i]=pf.get(m//i,0)+1
for i in pf:
    if m!=1and m//(i-1)==m%(i-1):
        a.append(a[-1]+i-1)
print(a[-1])

Buggy python submission (verdict: Runtime Error):
N=int(input())
s=list(input() for _ in range(N))
ans=0
count=0
a_count=0
b_count=0
ab_count=0
for i in s:
    ans+=i.count('AB')
    if i[0]=='B'and i[-1]=='A':
        ab_count+=1
    elif i[0]=='B':
        b_count+=1
    elif i[-1]=='A':
        a_count+=1
print(ans+min(a_count,b_count)+ab_count if a_count+b_count!=0 else ans+max(ab_count-1,0))

Fixed submission:
m=int(input())
pf={m:1}
a=[0]
for i in range(2,int(m**0.5)+1):
    if m ==1:
        break
    pf[i]=pf.get(i,0)+1
    if i!=m//i:
        pf[m//i]=pf.get(m//i,0)+1
for i in pf:
    if m!=1and m//(i-1)==m%(i-1):
        a.append(a[-1]+i-1)
print(a[-1])
Buggy python submission (verdict: Runtime Error):
import math
lists=list(int(input()) for i in range(5))
modlists=list(lists[j]%10 for j in range(5))
x=set(modlists)
if 0 in x:
      x.remove(0)
else:
      x=set(modlists)
            
#a=list(set(modlists).remove(0) if 0 in modlists else set(modlists))
k=modlists.index(min(x))

b=0
for m in range(5):
      b+=math.ceil(lists[m]/10)*10
print(b-math.ceil(lists[k]/10)*10+lists[k])


Fixed submission:
import math
lists=list(int(input()) for i in range(5))
modlists=list(lists[j]%10 for j in range(5))
x=set(modlists)
if 0 in x :
      x.remove(0)

      
else:
      x=set(modlists)
            
#a=list(set(modlists).remove(0) if 0 in modlists else set(modlists))
k=modlists.index(min(x)) if x else 0


b=0
for m in range(5):
      b+=math.ceil(lists[m]/10)*10
print(b-math.ceil(lists[k]/10)*10+lists[k])

Buggy python submission (verdict: Runtime Error):
import math
lists=list(int(input()) for i in range(5))
modlists=list(lists[j]%10 for j in range(5))
a=set(modlists)
if 0 in modlists:
      a.remove(0)
else:
      a=set(modlists)
            
#a=list(set(modlists).remove(0) if 0 in modlists else set(modlists))
k=modlists.index(min(a))

b=0
for m in range(5):
      b+=math.ceil(lists[m]/10)*10
print(b-math.ceil(lists[k]/10)*10+lists[k])


Fixed submission:
import math
lists=list(int(input()) for i in range(5))
modlists=list(lists[j]%10 for j in range(5))
x=set(modlists)
if 0 in x :
      x.remove(0)

      
else:
      x=set(modlists)
            
#a=list(set(modlists).remove(0) if 0 in modlists else set(modlists))
k=modlists.index(min(x)) if x else 0


b=0
for m in range(5):
      b+=math.ceil(lists[m]/10)*10
print(b-math.ceil(lists[k]/10)*10+lists[k])

Buggy python submission (verdict: Runtime Error):
import math
lists=list(int(input()) for i in range(5))
modlists=list(lists[j]%10 for j in range(5))
a=set(modlists)
if 0 in modlists:
      a.remove(0)
            
#a=list(set(modlists).remove(0) if 0 in modlists else set(modlists))
k=modlists.index(min(a))

b=0
for m in range(5):
      b+=math.ceil(lists[m]/10)*10
print(b-math.ceil(lists[k]/10)*10+lists[k])


Fixed submission:
import math
lists=list(int(input()) for i in range(5))
modlists=list(lists[j]%10 for j in range(5))
x=set(modlists)
if 0 in x :
      x.remove(0)

      
else:
      x=set(modlists)
            
#a=list(set(modlists).remove(0) if 0 in modlists else set(modlists))
k=modlists.index(min(x)) if x else 0


b=0
for m in range(5):
      b+=math.ceil(lists[m]/10)*10
print(b-math.ceil(lists[k]/10)*10+lists[k])
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()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
T=min(A[min(K,len(A)-1)],B[min(K,len(B))-1],C[min(K,len(C)-1)])

L=[]
for i in range(min(K,len(A))):
    if A[i]<T:continue
    for j in range(min(K,len(B))):
        if B[i]<T:continue
        for k in range(min(K,len(C))):
            if C[i]<T:continue
            L.append(A[i]+B[j]+C[k])
L.sort(reverse=True)
for p in range(K):
    print(L[p])

Fixed submission:
import heapq
def hq(x,y,z):
    return (-A[x-1]-B[y-1]-C[z-1],x,y,z)
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()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

visited=[hq(1,1,1)]
q=[]
heapq.heappush(q,hq(1,1,1))
for _ in range(K):
    e,x,y,z=heapq.heappop(q)
    if x+1<=X and hq(x+1,y,z) not in visited:
        heapq.heappush(q,hq(x+1,y,z))
        visited.append(hq(x+1,y,z))
    if y+1<=Y and hq(x,y+1,z) not in visited:
        heapq.heappush(q,hq(x,y+1,z))
        visited.append(hq(x, y+1, z))
    if z+1<=Z and hq(x,y,z+1) not in visited:
        heapq.heappush(q,hq(x,y,z+1))
        visited.append(hq(x, y, z+1))
visited.sort()
for i in visited[0:K]:
    print(-i[0])

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()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
L=[]
for i in range(min(3002,len(A))):
    for j in range(min(3002,len(B))):
        for k in range(min(3002,len(C))):
            L.append(A[i]+B[j]+C[k])
L.sort(reverse=True)
for p in range(K):
    print(L[p])

Fixed submission:
import heapq
def hq(x,y,z):
    return (-A[x-1]-B[y-1]-C[z-1],x,y,z)
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()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

visited=[hq(1,1,1)]
q=[]
heapq.heappush(q,hq(1,1,1))
for _ in range(K):
    e,x,y,z=heapq.heappop(q)
    if x+1<=X and hq(x+1,y,z) not in visited:
        heapq.heappush(q,hq(x+1,y,z))
        visited.append(hq(x+1,y,z))
    if y+1<=Y and hq(x,y+1,z) not in visited:
        heapq.heappush(q,hq(x,y+1,z))
        visited.append(hq(x, y+1, z))
    if z+1<=Z and hq(x,y,z+1) not in visited:
        heapq.heappush(q,hq(x,y,z+1))
        visited.append(hq(x, y, z+1))
visited.sort()
for i in visited[0:K]:
    print(-i[0])
Buggy python submission (verdict: Runtime Error):
N,Q=map(int,input().split())
S=input()
Sum=[0,0]
for i in range(1,N+1):
    if S[i-1]=='A'and S[i]=='C':
        Sum.append(Sum[-1]+1)
    else:
        Sum.append(Sum[-1])
for i in range(Q):
    l,r=map(int,input().split())
    print(Sum[r]-Sum[l])

Fixed submission:
N,Q=map(int,input().split())
S=input()
Sum=[0,0]
for i in range(1,N):
    if S[i-1]=='A'and S[i]=='C':
        Sum.append(Sum[-1]+1)
    else:
        Sum.append(Sum[-1])
for i in range(Q):
    l,r=map(int,input().split())
    print(Sum[r]-Sum[l])

Buggy python submission (verdict: Runtime Error):
N,Q=map(int,input().split())
S=input()
Sum=['']
for i in range(N):
    g=0 if i==0 else 1
    Sum.append(Sum[i]+S[i])
for i in range(Q):
    l,r=map(int,input().split())
    print(Sum[-1][l-1:r].count('AC'))

Fixed submission:
N,Q=map(int,input().split())
S=input()
Sum=[0,0]
for i in range(1,N):
    if S[i-1]=='A'and S[i]=='C':
        Sum.append(Sum[-1]+1)
    else:
        Sum.append(Sum[-1])
for i in range(Q):
    l,r=map(int,input().split())
    print(Sum[r]-Sum[l])
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
AB=list(list(map(int,input().split())) for _ in range(N))
AB.sort(key=lambda x:x[0])
cost=0
for ab in AB:
    for i in range(ab[1]):
        if M>0:
            M-=1
            cost+=ab[0]
print(cost)

Fixed submission:
N,M=map(int,input().split())
AB=list(list(map(int,input().split())) for _ in range(N))
AB.sort(key=lambda x:x[0])
cost=0
for ab in AB:
    if M>=ab[1]:
        M-=ab[1]
        cost+=ab[0]*ab[1]
    else:
        cost+=ab[0]*M
        break
print(cost)