Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
array = []
for i in range(N):
    s = input()
    dict = {}
    for j in range(len(s)):
        if s[j] not in dict:
            dict[s[j]] = 1
        else:
            dict[s[j]] += 1
    array.append(dict)

d = 0
for i in range(N):
    c=0
    for j in range(N):
        if i < j:
            if array[i] == array[j] and array[i] != 0:
                c += 1
                array[j] = 0
    if c != 0:
        d += int((c+1)*c/2)
print(d)

Fixed submission:
import collections
N = int(input())
array = []
for i in range(N):
    s = input()
    dict = {}
    for j in range(len(s)):
        if s[j] not in dict:
            dict[s[j]] = 1
        else:
            dict[s[j]] += 1
    dict = sorted(dict.items())

    array.append(str(dict))
sum = 0
c = collections.Counter(array)
for v in c.values():
    sum += int(v*(v-1)/2)
print(sum)
Buggy python submission (verdict: Runtime Error):
A,B,C = map(int,input())
print(C-(A-B))

Fixed submission:
A,B,C = map(int,input().split())
if C-(A-B) >= 0:
  print(C-(A-B))
else:
  print(0)
Buggy python submission (verdict: Runtime Error):
A,B = map(int,input().split())
if (A+B)%2 == 0:
  pint(int((A+B)//2))
else:
  print('IMPOSSIBLE')

Fixed submission:
A,B = map(int,input().split())
if (A+B)%2 == 0:
  print(int((A+B)//2))
else:
  print('IMPOSSIBLE')

Buggy python submission (verdict: Runtime Error):
A,B = map(int,input().split())
if (A+B)%2 == 0:
  pint(int((A+B)//2))
else:
  print(('IMPOSSIBLE')

Fixed submission:
A,B = map(int,input().split())
if (A+B)%2 == 0:
  print(int((A+B)//2))
else:
  print('IMPOSSIBLE')
Buggy python submission (verdict: Time Limit Exceeded):
import sys
def main():
    N = int(sys.stdin.readline())
    A = [int(sys.stdin.readline()) for i in range(N)]
    maxa = max(A)
    if A.count(maxa) > 1:
        for i in range(N):
            print(maxa)
    else:
        for i in range(N):
            if i != A.index(maxa):
                print(maxa)
            else:
                print(sorted(A)[-2])
                
main()

Fixed submission:
import sys
def main():
    N = int(sys.stdin.readline())
    A = [int(sys.stdin.readline()) for i in range(N)]
    maxa = max(A)
    maxb = sorted(A)[-2]
    if A.count(maxa) > 1:
        for i in range(N):
            print(maxa)
    else:
        for i in range(N):
            if A[i] != maxa:
                print(maxa)
            else:
                print(maxb)
                
main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
N = int(sys.stdin.readline())
A = [int(sys.stdin.readline()) for i in range(N)]
for i in range(N):
    A2 = A.copy()
    A2[i] = 0
    print(max(A2))

Fixed submission:
import sys
def main():
    N = int(sys.stdin.readline())
    A = [int(sys.stdin.readline()) for i in range(N)]
    maxa = max(A)
    maxb = sorted(A)[-2]
    if A.count(maxa) > 1:
        for i in range(N):
            print(maxa)
    else:
        for i in range(N):
            if A[i] != maxa:
                print(maxa)
            else:
                print(maxb)
                
main()

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
for i in range(N):
    a = int(input())
    A.append(a)
for i in range(N):
    A2 = A.copy()
    A2[i] = 0
    print(max(A2))

Fixed submission:
import sys
def main():
    N = int(sys.stdin.readline())
    A = [int(sys.stdin.readline()) for i in range(N)]
    maxa = max(A)
    maxb = sorted(A)[-2]
    if A.count(maxa) > 1:
        for i in range(N):
            print(maxa)
    else:
        for i in range(N):
            if A[i] != maxa:
                print(maxa)
            else:
                print(maxb)
                
main()

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
for i in range(N):
    a = int(input())
    A.append(a)
for i in range(N):
    A2 = A.copy()
    A2.pop(i)
    print(max(A2))
    

Fixed submission:
import sys
def main():
    N = int(sys.stdin.readline())
    A = [int(sys.stdin.readline()) for i in range(N)]
    maxa = max(A)
    maxb = sorted(A)[-2]
    if A.count(maxa) > 1:
        for i in range(N):
            print(maxa)
    else:
        for i in range(N):
            if A[i] != maxa:
                print(maxa)
            else:
                print(maxb)
                
main()
Buggy python submission (verdict: Runtime Error):
import collections
S = input()
S2 = collections.counter(S)
c = True
for i,v in S2.items():
  if v == 2:
    continue
  else:
    c = False
if c:
  print('Yes')
else:
  print('No')

Fixed submission:
import collections
S = input()
S2 = collections.Counter(S)
c = True
for i,v in S2.items():
  if v == 2:
    continue
  else:
    c = False
if c:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
count = 0
s = s.replace('BC','X')
s = s.replace('B','Z').replace('C','Z')
s = s.split('Z')
for i in s:
    for j in range(len(i)):
        if i[j] == 'X':
            count += i[:j].count('A')
print(count)

Fixed submission:
s = input()
count = 0
s = s.replace('BC','X')
s = s.replace('B','Z').replace('C','Z')
s = s.split('Z')
for i in s:
    ac = 0
    for j in range(len(i)):
        if i[j] == 'A':
            ac += 1
        if i[j] == 'X':
            count += ac
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
count = 0
s = s.replace('BC','X')
for i in range(len(s)):
    if s[i] == 'X':
        for j in range(i,-1,-1):
            if s[j] == 'B' or s[j] == 'C':
                break
            if s[j] == 'A':
                count += 1
print(count)

Fixed submission:
s = input()
count = 0
s = s.replace('BC','X')
s = s.replace('B','Z').replace('C','Z')
s = s.split('Z')
for i in s:
    ac = 0
    for j in range(len(i)):
        if i[j] == 'A':
            ac += 1
        if i[j] == 'X':
            count += ac
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
count = 0
while 'ABC' in s:
    s = s.replace('ABC','BCA',1)
    count += 1
print(count)

Fixed submission:
s = input()
count = 0
s = s.replace('BC','X')
s = s.replace('B','Z').replace('C','Z')
s = s.split('Z')
for i in s:
    ac = 0
    for j in range(len(i)):
        if i[j] == 'A':
            ac += 1
        if i[j] == 'X':
            count += ac
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
count = 0
while 'ABC' in s:
    s = s.replace('ABC','BCA',1)
    count += 1
print(count)

Fixed submission:
s = input()
count = 0
s = s.replace('BC','X')
s = s.replace('B','Z').replace('C','Z')
s = s.split('Z')
for i in s:
    ac = 0
    for j in range(len(i)):
        if i[j] == 'A':
            ac += 1
        if i[j] == 'X':
            count += ac
print(count)
Buggy python submission (verdict: Runtime Error):
A,P = map(int,input())
print(int(((3*A)+P)//2))

Fixed submission:
A,P = map(int,input().split())
print(int(((3*A)+P)//2))
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
V = list(map(int,input().split()))
ans = []
for i in range(1,K+1):
    for j in range(2**i):
        gem = 0
        minus = []
        flag = True
        A = 0
        B = -1
        for k in range(i):
            if (j >> k) & 1 == 1:
                if A <= N-1:
                    if V[A] >= 0:
                        gem += V[A]
                    else:
                        minus.append(V[A])
                    A += 1
                else:
                    flag = False
                    break
            else:
                if B >= -N:
                    if V[B] >= 0:
                        gem += V[B]
                    else:
                        minus.append(V[B])
                    B -= 1
                else:
                    flag = False
                    break
        if flag:
            minus.sort(reverse = True)
            for l in range(K-i):
                if minus:
                    minus.pop()
            ans.append(gem + sum(minus))
print(max(ans))
        

Fixed submission:
N,K = map(int,input().split())
V = list(map(int,input().split()))
ans = []
for i in range(1,min(K,N)+1):
    for a in range(i+1):
        b = i-a
        AB = V[:a]
        if b > 0:
            AB += V[-b:]
        AB.sort(reverse = True)
        for j in range(K-i):
            if AB and AB[-1] < 0:
                AB.pop()
        ans.append(sum(AB))
print(max(ans))

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
V = list(map(int,input().split()))
ans = []
for i in range(1,K+1):
    for j in range(2**i):
        gem = []
        flag = True
        A = 0
        B = -1
        for k in range(i):
            if (j >> k) & 1 == 1:
                if A <= N-1:
                    gem.append(V[A])
                    A += 1
                else:
                    flag = False
                    break
            else:
                if B >= -N:
                    gem.append(V[B])
                    B -= 1
                else:
                    flag = False
                    break
        if flag:
            gem.sort(reverse = True)
            for l in range(K-i):
                if gem and gem[-1] < 0:
                    gem.pop()
            ans.append(sum(gem))
print(max(ans))
        

Fixed submission:
N,K = map(int,input().split())
V = list(map(int,input().split()))
ans = []
for i in range(1,min(K,N)+1):
    for a in range(i+1):
        b = i-a
        AB = V[:a]
        if b > 0:
            AB += V[-b:]
        AB.sort(reverse = True)
        for j in range(K-i):
            if AB and AB[-1] < 0:
                AB.pop()
        ans.append(sum(AB))
print(max(ans))
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
array = []
for i in range(M):
    a = list(map(int,input().split()))
    array.append(a)
maxa = max(array)
maxa = maxa[1]
array2 = [0 for i in range(maxa+2)]
for i in array:
    array2[i[0]] += 1
    array2[i[1]+1] -= 1
for i in range(len(array2)-1):
    array2[i+1] += array2[i]
print(array2.count(M))
    

Fixed submission:
N,M = map(int,input().split())
array = []
for i in range(M):
    a = list(map(int,input().split()))
    array.append(a)
maxa = max([i[1] for i in array])
array2 = [0 for i in range(maxa+2)]
for i in array:
    array2[i[0]] += 1
    array2[i[1]+1] -= 1
for i in range(len(array2)-1):
    array2[i+1] += array2[i]
print(array2.count(M))
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
A = sorted(list(map(int,input().split())))
BC = []
for i in range(M):
    a = list(map(int,input().split()))
    BC.append(a)
BC = sorted(BC, key = lambda x:x[1],reverse = True)
maxc = max([i[1] for i in BC])
Asub = [i for i in A if i <= maxc+1]
for b,c in BC:
    count = b
    Asub = sorted(Asub)
    for i in range(len(Asub)):
        if Asub[i] < c and count != 0:
            Asub[i] = c
            count -= 1
        else:
            break

print(sum(Asub) + sum(A[len(Asub):]))

Fixed submission:
def main():
    N,M = map(int,input().split())
    A = sorted(list(map(int,input().split())))
    BC = []
    for i in range(M):
        a = list(map(int,input().split()))
        BC.append(a)
    BC = sorted(BC, key = lambda x:x[1],reverse = True)
    sum = 0
    for b,c in BC:
        if sum + b <= N:
            sum += b
            for i in range(b):
                A.append(c)
        else:
            sub = N - sum
            for i in range(sub):
                A.append(c)
    A = sorted(A,reverse = True)
    suma = 0
    for i in range(N):
        suma += A[i]
    print(suma)    

main()

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
A = sorted(list(map(int,input().split())))
BC = []
for i in range(M):
    a = list(map(int,input().split()))
    BC.append(a)
BC = sorted(BC, key = lambda x:x[1],reverse = True)

for b,c in BC:
    count = b
    A = sorted(A)
    for i in range(len(A)):
        if A[i] < c and count != 0:
            A[i] = c
            count -= 1
        else:
            break

print(sum(A))

Fixed submission:
def main():
    N,M = map(int,input().split())
    A = sorted(list(map(int,input().split())))
    BC = []
    for i in range(M):
        a = list(map(int,input().split()))
        BC.append(a)
    BC = sorted(BC, key = lambda x:x[1],reverse = True)
    sum = 0
    for b,c in BC:
        if sum + b <= N:
            sum += b
            for i in range(b):
                A.append(c)
        else:
            sub = N - sum
            for i in range(sub):
                A.append(c)
    A = sorted(A,reverse = True)
    suma = 0
    for i in range(N):
        suma += A[i]
    print(suma)    

main()
Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
S = input()
S[K-1] = S[K-1].lower()
print(S)

Fixed submission:
N,K = map(int,input().split())
S = input()
S[K-1].lower()
print(S[:K-1]+ S[K-1].lower() + S[K:])

Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
S = input()
S[K-1] = S[K-1].upper()
print(S)

Fixed submission:
N,K = map(int,input().split())
S = input()
S[K-1].lower()
print(S[:K-1]+ S[K-1].lower() + S[K:])
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N = int(input())
uvw = [[]for i in range(N)]
for i in range(N-1):
    u,v,w = list(map(int,input().split()))
    uvw[u-1].append([v-1,w%2])
    uvw[v-1].append([u-1,w%2])    
color = [0 for i in range(N)]
que = deque()
que.append(0)
alr = [0]
while que:
    q = que.popleft()
    colorq = color[q]
    for i in uvw[q]:
        if i[0] not in alr:
            que.append(i[0])
            alr.append(i[0])
            if i[1] == 0:
                color[i[0]] = colorq
            else:
                color[i[0]] = abs(colorq-1)
for i in color:
    print(i)

Fixed submission:
from collections import deque
N = int(input())
uvw = [[]for i in range(N)]
for i in range(N-1):
    u,v,w = list(map(int,input().split()))
    uvw[u-1].append([v-1,w%2])
    uvw[v-1].append([u-1,w%2])    
color = [-1 for i in range(N)]
color[0] = 0
que = deque()
que.append(0)
while que:
    q = que.popleft()
    colorq = color[q]
    for i in uvw[q]:
        if color[i[0]] == -1:
            que.append(i[0])
            if i[1] == 0:
                color[i[0]] = colorq
            else:
                color[i[0]] = abs(colorq-1)
for i in color:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
R,G,B,N = list(map(int,input().split()))
count = 0
for r in range(N//R+1):
    for g in range((N-R*r)//G+1):
        if (N-(R*r+G*g))%B == 0 and N-(R*r+G*g) >= 0:
            count += 1
print(count)

Fixed submission:
R,G,B,N = list(map(int,input().split()))
count = 0
for r in range(N//R+1):
    for g in range((N-R*r)//G+1):
        if (N-(R*r+G*g))%B == 0 and N-(R*r+G*g) >= 0:
            count += 1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A=sorted(list(map(int,input().split())))
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
def gcdlist(lista):
    if len(lista) == 1:
        return lista[0]
    else:
        from functools import reduce
        return reduce(gcd,lista)
ans = []
ans.append(gcdlist(A[1:]))
ans.append(gcdlist(A[:-1]))
for i in range(1,N-1):
    ans.append(gcd(gcdlist(A[:i]),gcdlist(A[i+1:])))
print(max(ans))

Fixed submission:
N = int(input())
A=sorted(list(map(int,input().split())))
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
ans = []
gcdlist = [A[0]]
for i in range(1,N):
    gcdlist.append(gcd(gcdlist[i-1],A[i]))
gcdlistr = [A[-1]]
for i in range(N-2,-1,-1):
    gcdlistr.append(gcd(gcdlistr[N-i-2],A[i]))
gcdlistr.reverse()
gcdlist.insert(0,0)
gcdlist.append(0)
gcdlistr.insert(0,0)
gcdlistr.append(0)
for i in range(N):
    ans.append(gcd(gcdlist[i],gcdlistr[i+2]))
print(max(ans))

Buggy python submission (verdict: Runtime Error):
N = int(input())
A=sorted(list(map(int,input().split())))
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
def gcdlist(lista):
    if len(lista) == 1:
        return lista[0]
    else:
        from functools import reduce
        return reduce(gcd,lista)
first = A.pop(0)
ans = []
second = A[0]
gcda = gcdlist(A[1:])
for i in range(first,second+1):
    ans.append(gcd(i,gcda))
print(max(ans))

Fixed submission:
N = int(input())
A=sorted(list(map(int,input().split())))
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
ans = []
gcdlist = [A[0]]
for i in range(1,N):
    gcdlist.append(gcd(gcdlist[i-1],A[i]))
gcdlistr = [A[-1]]
for i in range(N-2,-1,-1):
    gcdlistr.append(gcd(gcdlistr[N-i-2],A[i]))
gcdlistr.reverse()
gcdlist.insert(0,0)
gcdlist.append(0)
gcdlistr.insert(0,0)
gcdlistr.append(0)
for i in range(N):
    ans.append(gcd(gcdlist[i],gcdlistr[i+2]))
print(max(ans))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = sorted(list(map(int,input().split())))
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
gcda = []
if N == 2:
    gcda.append(max(A))
else:
    
    for i in range(N):
        A2 = A.copy()
        A2.pop(i)
        element = gcd(A2[0],A2[1])
        for j in range(2,N-1):
            element = gcd(element,A2[j])
        gcda.append(element)
print(max(gcda))

Fixed submission:
N = int(input())
A=sorted(list(map(int,input().split())))
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
ans = []
gcdlist = [A[0]]
for i in range(1,N):
    gcdlist.append(gcd(gcdlist[i-1],A[i]))
gcdlistr = [A[-1]]
for i in range(N-2,-1,-1):
    gcdlistr.append(gcd(gcdlistr[N-i-2],A[i]))
gcdlistr.reverse()
gcdlist.insert(0,0)
gcdlist.append(0)
gcdlistr.insert(0,0)
gcdlistr.append(0)
for i in range(N):
    ans.append(gcd(gcdlist[i],gcdlistr[i+2]))
print(max(ans))
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
absA = [abs(i) for i in A]
minusA = [i for i in A if i<0]
mina = min(absA)
if (0 in A) or (len(minusA)%2 == 0):
    print(sum(absA))
else:
    print(absA -2*mina)
    

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
absA = [abs(i) for i in A]
minusA = [i for i in A if i<0]
mina = min(absA)
if (0 in A) or (len(minusA)%2 == 0):
    print(sum(absA))
else:
    print(sum(absA) -2*mina)
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()
K = int(input())
ans = ''
for i in S:
  if i = S[K-1]:
    ans += S[i]
  else:
    ans += '*'
print(ans)

Fixed submission:
N = int(input())
S = input()
K = int(input())
ans = ''
for i in S:
  if i == S[K-1]:
    ans += i
  else:
    ans += '*'
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
s=input()
if '0' not in s:
    print(len(s))
else:
    s2 = []
    count = 1
    for i in range(1,len(s)):
        if s[i-1] == s[i]:
            count += 1
        if s[i-1] != s[i]:
            s2.append(count)
            count = 1
    s2.append(count)
    if s[0] != '1':
        s2.insert(0,0)
    if s[-1] != '1':
        s2.append(0)
    ans2 = 0
    K2 = 2*K+1
    for i in range(0,max(1,(len(s2) - K2)//2 +2)):
        ans2 = max(ans2,sum(s2[2*i:2*i+K2]))
    print(ans2)

Fixed submission:
N,K = map(int,input().split())
s=input()
if '0' not in s:
    print(len(s))
else:
    s2 = [0]
    count = 0
    for i in range(len(s)-1):
        count += 1
        if s[i] != s[i+1]:
            s2.append(count)
    s2.append(count+1)
    if s[0] == '0':
        s2.insert(0,0)
    ans = 0
    for i in range(0,len(s2)-1,2):
        ans = max(ans,s2[min(len(s2)-1,i+2*K+1)] - s2[i])
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
s=input()
if '0' not in s:
    print(len(s))
else:
    s2 = []
    count = 1
    for i in range(1,len(s)):
        if s[i-1] == s[i]:
            count += 1
        if s[i-1] != s[i]:
            s2.append(count)
            count = 1
    s2.append(count)
    if s[0] != '1':
        s2.insert(0,0)
    if s[-1] != '1':
        s2.append(0)
    ans2 = 0
    K2 = 2*K+1
    for i in range(0,max(1,len(s2) - K2 +1),2):
        ans2 = max(ans2,sum(s2[i:i+K2]))
    print(ans2)

Fixed submission:
N,K = map(int,input().split())
s=input()
if '0' not in s:
    print(len(s))
else:
    s2 = [0]
    count = 0
    for i in range(len(s)-1):
        count += 1
        if s[i] != s[i+1]:
            s2.append(count)
    s2.append(count+1)
    if s[0] == '0':
        s2.insert(0,0)
    ans = 0
    for i in range(0,len(s2)-1,2):
        ans = max(ans,s2[min(len(s2)-1,i+2*K+1)] - s2[i])
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
s = input()
lista = []
if s[0] == '0':
    lista.append(0)
now = s[0]
count = 0
for i in s:
    if now == i:
        count += 1
    else:
        lista.append(count)
        count = 1
        now = i
lista.append(count)
ans = 0
for i in range(0,len(lista),2):
    ans= max(ans,sum(lista[i:i+2*K+1]))
for i in range(1,len(lista),2):
    ans= max(ans,sum(lista[i:i+2*K]))
print(ans)

Fixed submission:
N,K = map(int,input().split())
s=input()
if '0' not in s:
    print(len(s))
else:
    s2 = [0]
    count = 0
    for i in range(len(s)-1):
        count += 1
        if s[i] != s[i+1]:
            s2.append(count)
    s2.append(count+1)
    if s[0] == '0':
        s2.insert(0,0)
    ans = 0
    for i in range(0,len(s2)-1,2):
        ans = max(ans,s2[min(len(s2)-1,i+2*K+1)] - s2[i])
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import heapq
X,Y,Z,K = map(int,input().split())
A = sorted(list(map(int,input().split())),reverse=1)
B = sorted(list(map(int,input().split())),reverse=1)
C = sorted(list(map(int,input().split())),reverse=1)
Q = [(-A[0]-B[0]-C[0],0,0,0)]
heapq.heapify(Q)
abc = [[[1 for i in range(Z)] for j in range(Y)] for k in range(X)]
for i in range(K):
    n,a,b,c = heapq.heappop(Q)
    if a < X-1 and abc[a+1][b][c]:
        abc[a+1][b][c] = 0
        heapq.heappush(Q,(n+A[a]-A[a+1],a+1,b,c))
    if b < Y-1 and abc[a][b+1][c]:
        abc[a][b+1][c] = 0
        heapq.heappush(Q,(n+B[b]-B[b+1],a,b+1,c))
    if c < Z-1 and abc[a][b][c+1]:
        abc[a][b][c+1] = 0
        heapq.heappush(Q,(n+C[c]-C[c+1],a,b,c+1))
    print(-n)

Fixed submission:
from itertools import product
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 = sorted([a+b for a,b in product(A,B)],reverse=True)[:K]
ans = sorted([a+b for a,b in product(AB,C)],reverse=True)[:K]
for i in ans:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import product
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 = sorted([a+b for a,b in product(A,B)],reverse=True)[:K]
ans = sorted([a+b for a,b in product(AB,C)],reverse=True)[:K]
for i in ans:
    print(i)

Fixed submission:
from itertools import product
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 = sorted([a+b for a,b in product(A,B)],reverse=True)[:K]
ans = sorted([a+b for a,b in product(AB,C)],reverse=True)[:K]
for i in ans:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = input()
for i in range(Q):
    l,r = map(int,input().split())
    print(S[l-1:r].count('AC'))


Fixed submission:
import bisect
N,Q = map(int,input().split())
S = input()
lista = []
for j in range(N-1):
    if S[j:j+2] == 'AC':
        lista.append(j)
for i in range(Q):
    l,r = map(int,input().split())
    l,r = l-1,r-1
    lind = bisect.bisect_left(lista,l)
    rind = bisect.bisect_right(lista,r-1)
    print(rind-lind)