Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import itertools
def main():
    N,M,Q = map(int,input().split())
    q = []
    for i in range(Q):
        a,b,c,d = map(int,input().split())
        q.append([a-1,b-1,c,d])
    A = [i for i in range(1,M+1)]
    if N==10:

        ans = 0
        for i, qq in enumerate(q):
            if A[qq[1]] - A[qq[0]] == qq[2]:
                ans += qq[3]
        print(ans)

    else:
        aa = list(itertools.combinations(A,N))
        ans = 0

        for i, cc in enumerate(aa):
            ans1 = 0
            for j, qq in enumerate(q):
                if cc[qq[1]] - cc[qq[0]] == qq[2]:
                    ans1 += qq[3]
            # print(ans1,cc)
            ans = max(ans,ans1)
        print(ans)

if __name__=='__main__':
    main()


Fixed submission:
import itertools
def main():
    N,M,Q = map(int,input().split())
    q = []
    for i in range(Q):
        a,b,c,d = map(int,input().split())
        q.append([a-1,b-1,c,d])
    A = [i for i in range(1,M+1)]
    # if N==10:
    #
    #     ans = 0
    #     for i, qq in enumerate(q):
    #         if A[qq[1]] - A[qq[0]] == qq[2]:
    #             ans += qq[3]
    #     print(ans)
    #
    # else:
    aa = list(itertools.combinations_with_replacement(A,N))
    ans = 0

    for i, cc in enumerate(aa):
        ans1 = 0
        for j, qq in enumerate(q):
            if cc[qq[1]] - cc[qq[0]] == qq[2]:
                ans1 += qq[3]
            # print(ans1,cc)
        ans = max(ans,ans1)
    print(ans)

if __name__=='__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import itertools
def main():
    N,M,Q = map(int,input().split())
    q = []
    for i in range(Q):
        a,b,c,d = map(int,input().split())
        q.append([a-1,b-1,c,d])
    A = [i for i in range(1,M+1)]
    if N==10:

        ans = 0
        for i, qq in enumerate(q):
            if A[qq[1]] - A[qq[0]] == qq[2]:
                ans += qq[3]
        print(ans)

    else:
        aa = list(itertools.combinations(A,N))
        ans = 0
        
        for i, cc in enumerate(aa):
            ans1 = 0
            for j, qq in enumerate(q):
                if cc[qq[1]] - cc[qq[0]] == qq[2]:
                    ans1 += qq[3]
            print(ans1,cc)
            ans = max(ans,ans1)
        print(ans)

if __name__=='__main__':
    main()


Fixed submission:
import itertools
def main():
    N,M,Q = map(int,input().split())
    q = []
    for i in range(Q):
        a,b,c,d = map(int,input().split())
        q.append([a-1,b-1,c,d])
    A = [i for i in range(1,M+1)]
    # if N==10:
    #
    #     ans = 0
    #     for i, qq in enumerate(q):
    #         if A[qq[1]] - A[qq[0]] == qq[2]:
    #             ans += qq[3]
    #     print(ans)
    #
    # else:
    aa = list(itertools.combinations_with_replacement(A,N))
    ans = 0

    for i, cc in enumerate(aa):
        ans1 = 0
        for j, qq in enumerate(q):
            if cc[qq[1]] - cc[qq[0]] == qq[2]:
                ans1 += qq[3]
            # print(ans1,cc)
        ans = max(ans,ans1)
    print(ans)

if __name__=='__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    a,b,n = map(int,input().split())
    aa = min(b,n)
    for i in range(aa,n):

        ans = max(ans,a*aa//b  - a * (aa//b))
    print(ans)
if __name__=='__main__':
    main()


Fixed submission:
def main():
    a,b,n = map(int,input().split())
    aa = min(b-1,n)
    ans = a*aa//b  - a * (aa//b)
    print(ans)
if __name__=='__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, x, y = map(int,input().split())
    ans = [0] * n
    dp = [[0] * (n - 1) for i in range(n)]
    for i in range(1,n+1):
        for j in range(1,n+1):
            dirct = abs(i-j)
            mid_x = abs(x-i) + 1 + abs(y - j)
            mid_y = abs(y-i) + 1 + abs(x - j)
            ans[min(dirct, mid_x, mid_y)] += 1
    for i in range(1, n ):
        print(ans[i] // 2)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n, x, y = map(int,input().split())
    ans = [0] * n
    dp = [[0] * (n - 1) for i in range(n)]
    for i in range(1,n+1):
        for j in range(i,n+1):
            dirct = abs(i-j)
            mid_x = abs(x-i) + 1 + abs(y - j)
            mid_y = abs(y-i) + 1 + abs(x - j)
            ans[min(dirct, mid_x, mid_y)] += 1
    for i in range(1, n ):
        print(ans[i])


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import collections
def main():
    n = int(input())
    a = list(map(int,input().split()))
    cnt = collections.Counter(a)
    cnt_m = cnt.most_common()
    if cnt.most_common()[0][1] == 1:
        for i in range(n):
            print(0)

        return

    for i, aa in enumerate(a):
        ans = 0
        for j in range(len(cnt)):
            cnt_a = cnt_m[j][0]
            cnt_num = cnt_m[j][1]
            if cnt_num == 1:
                break
            else:
                if cnt_a == aa:
                    cnt_num -= 1
                ans += cnt_num * (cnt_num - 1)
        print(ans//2)


if __name__=='__main__':
    main()


Fixed submission:
import collections
def main():
    n = int(input())
    a = list(map(int,input().split()))
    cnt_ary = [0] * n

    for i,aa in enumerate(a):
        cnt_ary[aa-1] += 1


    tmp = 0
    ans_ary = [0] * n
    for i, cc in enumerate(cnt_ary):
        ans_ary[i] = cc * (cc-1)

    t = sum(ans_ary)
    ans = 0
    for i, aa in enumerate(a):
        ans = 0
        ans = t - ans_ary[aa-1]
        ans += (cnt_ary[aa-1] - 1) * (cnt_ary[aa-1] - 2)
        print(ans//2)



if __name__=='__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import collections
def main():
    n = int(input())
    a = list(map(int,input().split()))
    cnt = collections.Counter(a)
    cnt_m = cnt.most_common()
    if cnt.most_common()[0][1] == 1:
        for i in range(n):
            print(0)

        return

    for i, aa in enumerate(a):
        ans = 0
        for j in range(len(cnt)):
            cnt_a = cnt_m[j][0]
            cnt_num = cnt_m[j][1]
            if cnt_num == 1:
                break
            else:
                if cnt_a == aa:
                    cnt_num -= 1
                ans += cnt_num * (cnt_num - 1)
        print(ans//2)


if __name__=='__main__':
    main()


Fixed submission:
import collections
def main():
    n = int(input())
    a = list(map(int,input().split()))
    cnt_ary = [0] * n

    for i,aa in enumerate(a):
        cnt_ary[aa-1] += 1


    tmp = 0
    ans_ary = [0] * n
    for i, cc in enumerate(cnt_ary):
        ans_ary[i] = cc * (cc-1)

    t = sum(ans_ary)
    ans = 0
    for i, aa in enumerate(a):
        ans = 0
        ans = t - ans_ary[aa-1]
        ans += (cnt_ary[aa-1] - 1) * (cnt_ary[aa-1] - 2)
        print(ans//2)



if __name__=='__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    h,w = map(int, input().split())
    s = []
    for i in range(h):
        ss = list(input())
        s.append(ss)

    now = [0,0]
    cnt = 0
    if s[0][0] == '#':
        cnt += 1
        # s[0][0] = '.'
    if s[h-1][w-1] == '#':
        # cnt += 1
        # s[h-1][w-1] = '.'

    dp = [[-1] * w for i in range(h)]
    dp[0][0] = cnt

    for i in range(h):
        for j in range(w):
            tmp_up = 100000
            tmp_left = 100000
            change  = 0
            if s[i][j] == '#':
                change = 1
            if i == 0 and j == 0:
                continue
            if i != 0:
                if s[i-1][j] == '#' and s[i][j] == '#':
                    tmp_up = dp[i-1][j]
                else:
                    tmp_up = dp[i-1][j] + change
            if j != 0:
                if s[i][j-1] == '#' and s[i][j] == '#':
                    tmp_left = dp[i][j-1]
                else:

                    tmp_left = dp[i][j-1] + change

            dp[i][j] = min(tmp_up,tmp_left)


    print(dp[h-1][w-1])
    print(dp)

if __name__ == '__main__':
    main()


Fixed submission:
def main():
    h,w = map(int, input().split())
    s = []
    for i in range(h):
        ss = list(input())
        s.append(ss)

    now = [0,0]
    cnt = 0
    if s[0][0] == '#':
        cnt += 1
        # s[0][0] = '.'
    

    dp = [[-1] * w for i in range(h)]
    dp[0][0] = cnt

    for i in range(h):
        for j in range(w):
            tmp_up = 100000
            tmp_left = 100000
            change  = 0
            if s[i][j] == '#':
                change = 1
            if i == 0 and j == 0:
                continue
            if i != 0:
                if s[i-1][j] == '#' and s[i][j] == '#':
                    tmp_up = dp[i-1][j]
                else:
                    tmp_up = dp[i-1][j] + change
            if j != 0:
                if s[i][j-1] == '#' and s[i][j] == '#':
                    tmp_left = dp[i][j-1]
                else:

                    tmp_left = dp[i][j-1] + change

            dp[i][j] = min(tmp_up,tmp_left)


    print(dp[h-1][w-1])

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import math
def main():
    h = int(input())
    cnt = 0
    ans = 0
    tmp = 1
    a = int(math.log2(h))
    cnt = 2 **a
    ans = (1-2**(a+1))//(1-2)
    print(ans)

if __name__=='__main__':
    main()


Fixed submission:
import math
def main():
    h = int(input())
    cnt = 0
    ans = 0
    tmp = 1
    a = int(math.log2(h))
    cnt = 2 **a
    ans = (1-2**a)//(1-2)
    print(ans+cnt)
    
if __name__=='__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import math
def main():
    h = int(input())
    cnt = 0
    ans = 0
    tmp = 1
    a = int(math.log2(h))
    cnt = 2 **a
    ans = (1-2**a)//(1-2)
    print(ans+cnt)
    # while True:
    #     h //=2
    #
    #     cnt += tmp
    #     tmp *= 2
    #     if h==1:
    #         break
    #
    # print(cnt+tmp)
if __name__=='__main__':
    main()


Fixed submission:
import math
def main():
    h = int(input())
    cnt = 0
    ans = 0
    tmp = 1
    a = int(math.log2(h))
    cnt = 2 **a
    ans = (1-2**a)//(1-2)
    print(ans+cnt)
    
if __name__=='__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    h = int(input())
    cnt = 0
    ans = 0
    tmp = 1
    while True:
        h //=2

        cnt += tmp
        tmp *= 2
        if h==1:
            break

    print(cnt+tmp)
if __name__=='__main__':
    main()


Fixed submission:
import math
def main():
    h = int(input())
    cnt = 0
    ans = 0
    tmp = 1
    a = int(math.log2(h))
    cnt = 2 **a
    ans = (1-2**a)//(1-2)
    print(ans+cnt)
    
if __name__=='__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import math
def main():
    a,b = map(int ,input().split())
    ans=a*b//math.gcd(a,b)
    print(ans)
if __name__=='__main__':
    main()


Fixed submission:
import fractions
def main():
    a,b = map(int ,input().split())
    ans=a*b//fractions.gcd(a,b)
    print(ans)
if __name__=='__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    flg=0
    f=1
    temp=n
    while temp > 0:
        f*=temp
        temp-=2
    a=str(f)
    cnt=0
    for i in range(1,n+1):
        if a[-i] == '0':
            cnt+=1
        else:
            break
    print(cnt)
if __name__=='__main__':
    main()


Fixed submission:
def main():

    n = int(input())

    if n%2 == 1:
        print(0)
        return
    ans = 0
    n = n // 2

    while n>4:
        ans += n // 5
        n = n // 5

    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import math
def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True


a=int(input())
i=2
j=1
flag=0
x=0
y=0
min=a**0.5
intmin=int(min)
if not is_prime(a):

    for i in range(intmin,a):
        if a%i == 0:
            if i!=a:
                print(int(i-2+(a/i)))
            else:
                print(a-1)
            break
else:
    print(a-1)



# try:
#     for i in range(2,a//2):
#         mod=a%i
#         if mod==0:
#             if min > (a/i) + i -2:
#                 min = (a/i) + i -2
#     print(min)
# except ZeroDivisionError:
#     print("ZeroDivisionError!!")


Fixed submission:
import math
import copy

n=int(input())

i=int(n**0.5)
j=0
# print(i)

for i in range(i+1,0,-1):
    # print(i)
    if n==i:
        print(n-1)
        break
    if n%i==0:
        j=n/i
        print(int(i+j-2))
        break

Buggy python submission (verdict: Time Limit Exceeded):
a=int(input())
i=2
j=1
flag=0
x=0
y=0
min=a**0.5
intmin=int(min)

for i in range(intmin,a):
    if a%i == 0:
        if i!=a:
            print(int(i-2+(a/i)))
        else:
            print(a-1)
        break


# try:
#     for i in range(2,a//2):
#         mod=a%i
#         if mod==0:
#             if min > (a/i) + i -2:
#                 min = (a/i) + i -2
#     print(min)
# except ZeroDivisionError:
#     print("ZeroDivisionError!!")


Fixed submission:
import math
import copy

n=int(input())

i=int(n**0.5)
j=0
# print(i)

for i in range(i+1,0,-1):
    # print(i)
    if n==i:
        print(n-1)
        break
    if n%i==0:
        j=n/i
        print(int(i+j-2))
        break
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=list(map(int, input().split()))

i=1
j=0
k=0
ta=0
rb=0
tc=0
cnt=0
m=0

aa=[]
bb=[]
c=[]
for i in range(len(l)*(len(l)-1)):
    # if i%(n)!=0:
    j = int(i/n)
    k = n*(j)+i%n-n*j
    # aa.append(j)
    # bb.append(k)
    # c.append(i)
    if j < k:
        for m in range(k+1,len(l)):
            if l[m] < l[j]+l[k] and l[j]<l[m]+l[k] and l[k]<l[m]+l[j]:
                cnt+=1
print(cnt)
# print(aa)
# print(bb)
# print(c)
#
#

# for i in range(0,len(l)-2):
#
#     for j in range(i+1,len(l)-1):
#
#         for k in range(j+1,len(l)):
#             if l[i] < l[j]+l[k] and l[j]<l[i]+l[k] and l[k]<l[i]+l[j]:
#                 cnt+=1
# print(cnt)


Fixed submission:
import bisect
n=int(input())
l=list(map(int, input().split()))

i=1
j=0
k=0
ta=0
rb=0
tc=0
cnt=0
m=0
ls=sorted(l)



for i in range(0,len(ls)-2):

    for j in range(i+1,len(ls)-1):
        l1 = ls[i]
        l2 = ls[j]
        ll= l1+l2
        # mid = 0
        k = bisect.bisect_left(ls,ll) - 1

        cnt+=k-j
print(cnt)

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

i=0
j=0
k=0
ta=0
rb=0
tc=0
cnt=0
for i in range(0,len(l)-2):

    for j in range(i+1,len(l)-1):

        for k in range(j+1,len(l)):
            if l[i] < l[j]+l[k] and l[j]<l[i]+l[k] and l[k]<l[i]+l[j]:
                cnt+=1
print(cnt)



Fixed submission:
import bisect
n=int(input())
l=list(map(int, input().split()))

i=1
j=0
k=0
ta=0
rb=0
tc=0
cnt=0
m=0
ls=sorted(l)



for i in range(0,len(ls)-2):

    for j in range(i+1,len(ls)-1):
        l1 = ls[i]
        l2 = ls[j]
        ll= l1+l2
        # mid = 0
        k = bisect.bisect_left(ls,ll) - 1

        cnt+=k-j
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
i=1
b = []
j=0



while i<=n:
    print(a.index(i)+1, end=" ")
    i+=1

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
i=1
b = []
j=0

map = {a[i]:str(i+1) for i in range(n)}
print(" ".join([map[i] for i in range(1, n+1)]))

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

while i<=n:
    print(a.index(i)+1, end=" ")
    i+=1

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
i=1
b = []
j=0

map = {a[i]:str(i+1) for i in range(n)}
print(" ".join([map[i] for i in range(1, n+1)]))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
n=int(input())
a=list(map(int,input().split()))
i=0
b = []
j=0

while i < n:
    j =a.index(min(a))+1
    a[j-1]+=n
    i+=1
    print(j, end=" ")


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
i=1
b = []
j=0

map = {a[i]:str(i+1) for i in range(n)}
print(" ".join([map[i] for i in range(1, n+1)]))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
n=int(input())
a=list(map(int,input().split()))
i=0
b = []
j=0

while i < n:
    j =a.index(min(a))+1
    b.append(j)
    a[j-1]+=n
    i+=1
    print(j, end=" ")


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
i=1
b = []
j=0

map = {a[i]:str(i+1) for i in range(n)}
print(" ".join([map[i] for i in range(1, n+1)]))
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n,m=map(int,input().split())
    a=list(map(int,input().split()))

    for i in range(m):
        a.sort(reverse=True)
        a[0] = a[0] // 2
    print(sum(a))
if __name__=='__main__':
    main()


Fixed submission:
import heapq
def main():
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    for i,aa in enumerate(a):
        a[i] = -1 * aa
    heapq.heapify(a)
    for i in range(m):
        tmp = heapq.heappop(a) * (-1) // 2
        heapq.heappush(a,tmp * (-1))
    print(sum(a) * (-1))
if __name__=='__main__':
    main()
Buggy python submission (verdict: Runtime Error):
a,b = map(int,input())
ans = 0
if b % a != 0:
  ans += 1
ans += b // a
print(ans)

Fixed submission:
a,b = map(int,input().split())
ans = 0
while True:
  n = ans * a -(ans - 1)
  if n >= b:
    break
  ans += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
parent = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    parent[a].append(b)
    parent[b].append(a)
import queue
check = [0] * n

ans = [0] * n

for i in range(q):
    p,x = map(int,input().split())
    p -= 1
    ans[p] += x

a = ''
qq = queue.Queue()
qq.put(0)
check[0] = 1
while not qq.empty():
    now = qq.get()
    for j, son in enumerate(parent[now]):
        if check[son] == 1:
            continue
        ans[son] += ans[now]
        check[son] = 1
        qq.put(son)
for i in range(n):
    a += str(ans[i]) + ' '
print(a)


Fixed submission:
n,q = map(int,input().split())
parent = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    parent[a].append(b)
    parent[b].append(a)
import collections
check = [0] * n

ans = [0] * n

for i in range(q):
    p,x = map(int,input().split())
    p -= 1
    ans[p] += x

a = ''
qq = collections.deque([0])
check[0] = 1
while len(qq) > 0:
    now = qq.popleft()
    for j, son in enumerate(parent[now]):
        if check[son] == 1:
            continue
        ans[son] += ans[now]
        check[son] = 1
        qq.append(son)
for i in range(n):
    a += str(ans[i]) + ' '
print(a)
Buggy python submission (verdict: Runtime Error):
a,b,c = map(int,input())

print(max(0,a-b-c))


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

print(max(0,c-a+b))

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

print(max(0,a-b-c)

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

print(max(0,c-a+b))
Buggy python submission (verdict: Time Limit Exceeded):
import heapq
n,m = map(int,input().split())
a = list(map(int,input().split()))
bc = []
for _ in range(m):
    b,c = map(int,input().split())
    bc.append((b,c))
heapq.heapify(a)
now = heapq.heappop(a)
for i, s in enumerate(bc):
    b, c = s
    for j in range(b):
        if now > c:
            break
        heapq.heappush(a,c)
        now = heapq.heappop(a)
heapq.heappush(a,now)
print(sum(a))


Fixed submission:
import collections
import heapq

n,m = map(int,input().split())
a = list(map(int,input().split()))
bc = []
for _ in range(m):
    b,c = map(int,input().split())
    bc.append((b,c))
cnt = collections.Counter(a).most_common()
heapq.heapify(cnt)


for i, set_bc in enumerate(bc):
    now0,now1 = heapq.heappop(cnt)
    b,c = set_bc
    if now0 >= c:
        heapq.heappush(cnt,(now0,now1))
        now1 = 0
        continue
    tmpb = 0
    for j in range(b):
        if now0 < c:
            if now1 >= b:
                now1 -= b
                tmpb += b
                heapq.heappush(cnt,(c,tmpb))
                break
            tmpb += now1
            b -= now1
            now0,now1 = heapq.heappop(cnt)
        else:
            heapq.heappush(cnt,(c,tmpb))
            break
    if now1 != 0:
        heapq.heappush(cnt,(now0,now1))
        now1 = 0
if now1 != 0:
    heapq.heappush(cnt,(now0,now1))
ans = 0

for i in range(len(cnt)):
    val, num = heapq.heappop(cnt)
    ans += val * num
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
n,m = map(int,input().split())
a = list(map(int,input().split()))
bc = []
for _ in range(m):
    b,c = map(int,input().split())
    bc.append((b,c))
heapq.heapify(a)
now = heapq.heappop(a)
for i, s in enumerate(bc):
    b, c = s
    for j in range(b):
        if now > c:
            break
        heapq.heappush(a,c)
        now = heapq.heappop(a)
heapq.heappush(a,now)
print(sum(a))


Fixed submission:
import collections
import heapq

n,m = map(int,input().split())
a = list(map(int,input().split()))
bc = []
for _ in range(m):
    b,c = map(int,input().split())
    bc.append((b,c))
cnt = collections.Counter(a).most_common()
heapq.heapify(cnt)


for i, set_bc in enumerate(bc):
    now0,now1 = heapq.heappop(cnt)
    b,c = set_bc
    if now0 >= c:
        heapq.heappush(cnt,(now0,now1))
        now1 = 0
        continue
    tmpb = 0
    for j in range(b):
        if now0 < c:
            if now1 >= b:
                now1 -= b
                tmpb += b
                heapq.heappush(cnt,(c,tmpb))
                break
            tmpb += now1
            b -= now1
            now0,now1 = heapq.heappop(cnt)
        else:
            heapq.heappush(cnt,(c,tmpb))
            break
    if now1 != 0:
        heapq.heappush(cnt,(now0,now1))
        now1 = 0
if now1 != 0:
    heapq.heappush(cnt,(now0,now1))
ans = 0

for i in range(len(cnt)):
    val, num = heapq.heappop(cnt)
    ans += val * num
print(ans)
Buggy python submission (verdict: Runtime Error):
s=list(input())

# s1 = (int)(s[0] + s[1])
s1=int(s[0])*10+int(s[1])
s2=int(s[2])*10+int(s[3])

if s1<=12 and s2<=12 and s1>0 and s2>0:
    ans='AMBIGUOUS'
elif s1<=12 and  (s2>12 or s2 == 0)and s1>0:
    ans ='MMYY'
elif (s1>12 s1==0) and s2<=12 and s2>0:
    ans ='YYMM'
else:
    ans='NA'
print(ans)


Fixed submission:
s=list(input())

# s1 = (int)(s[0] + s[1])
s1=int(s[0])*10+int(s[1])
s2=int(s[2])*10+int(s[3])

if s1<=12 and s2<=12 and s1>0 and s2>0:
    ans='AMBIGUOUS'
elif s1<=12 and  (s2>12 or s2 == 0)and s1>0:
    ans ='MMYY'
elif (s1>12 or s1==0) and s2<=12 and s2>0:
    ans ='YYMM'
else:
    ans='NA'
print(ans)

Buggy python submission (verdict: Runtime Error):
s=list(int(input()))

s1=s[0]*10+s[1]
s2=s[3]*10+s[4]

if s1<=12 and s2<=12:
    ans='AMBIGUOUS'
elif s1<=12 and s2>12:
    ans ='MMYY'
elif s1>12 and s2<=12:
    ans ='YYMM'
else:
    ans='NA'




Fixed submission:
s=list(input())

# s1 = (int)(s[0] + s[1])
s1=int(s[0])*10+int(s[1])
s2=int(s[2])*10+int(s[3])

if s1<=12 and s2<=12 and s1>0 and s2>0:
    ans='AMBIGUOUS'
elif s1<=12 and  (s2>12 or s2 == 0)and s1>0:
    ans ='MMYY'
elif (s1>12 or s1==0) and s2<=12 and s2>0:
    ans ='YYMM'
else:
    ans='NA'
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
R,G,B,N = map(int,input().split())
r_max = N // R + 1
g_max = N // G + 1
ans = 0
for r in range(r_max):
    r_num = R * r
    for g in range(g_max):
        g_num = G * g
        b_num = N - r_num - g_num
        if b_num >= 0:
            if b_num % B == 0:
                ans += 1
                # print(r_num,g_num,b_num)
print(ans)


Fixed submission:
R,G,B,N = map(int,input().split())
r_max = N // R + 1
g_max = N // G + 1
ans = 0
for r in range(r_max):
    r_num = R * r
    for g in range(g_max):
        g_num = G * g
        b_num = N - r_num - g_num
        if b_num >= 0:
            if b_num % B == 0:
                ans += 1
                # print(r_num,g_num,b_num)
print(ans)