Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02748 (python)

Fixed submission:
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = min(a) + min(b)
for i in range(M):
    x, y, c = map(int, input().split())
    price = a[x-1] + b[y-1] - c
    if ans > price:
        ans = price
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
A, B, M = map(int, input().split())
a = np.array(list(map(int, input().split())), dtype="int64")
b = np.array(list(map(int, input().split())), dtype="int64")
m = np.zeros((A, B), dtype="int64")

for i in range(M):
    x, y, c = map(int, input().split())
    if m[x-1][y-1] < c:
        m[x-1][y-1] = c

ans = 9999999999
for i in range(A):
    for j in range(B):
        price = a[i] + b[j] - m[i][j]
        if price < ans:
            ans = price
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
A, B, M = map(int, input().split())
a = np.array(list(map(int, input().split())))
b = np.array(list(map(int, input().split())))
m = np.zeros((A, B), dtype="int64")

for i in range(M):
    x, y, c = map(int, input().split())
    if m[x-1][y-1] < c:
        m[x-1][y-1] = c

ans = 9999999999
for i in range(A):
    for j in range(B):
        price = a[i] + b[j] - m[i][j]
        if price < ans:
            ans = price
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
A, B, M = map(int, input().split())
a = np.array(list(map(int, input().split())))
b = np.array(list(map(int, input().split())))
m = np.zeros((A, B), dtype="int64")

for i in range(M):
    x, y, c = map(int, input().split())
    if m[x-1][y-1] < c:
        m[x-1][y-1] = c

ans = 9999999999
for i in range(A):
    for j in range(B):
        price = a[i] + b[j] - m[i][j]
        if price < ans:
            ans = price
print(ans)
Problem p02767 (python)

Fixed submission:
import math

N = int(input())
Xi = list(map(int, input().split(" ")))

Xi_min = min(Xi)
Xi_max = max(Xi)

ans = 999999999
for i in range(Xi_min, Xi_max+1):
    tmp = 0
    for j in range(N):
        tmp += pow(Xi[j] - i, 2)
    if tmp < ans:
        ans = tmp

print(ans)

Buggy submission (verdict: Runtime Error):
import math

N = int(input())
Xi = list(map(int, input().split(" ")))

Xi_min = min(Xi)
Xi_max = max(Xi)

ans = math.inf
print("-----")
for i in range(Xi_min, Xi_max+1):
    tmp = 0
    for j in range(N):
        tmp += pow(Xi[j] - i, 2)
    if tmp < ans:
        ans = tmp

print(ans)
Problem p02775 (python)

Fixed submission:
def main():
    import sys
    input = sys.stdin.readline

    N = list(map(int, list(input()[:-1])))
    N = N[::-1] + [0]

    ans = 0
    for i in range(len(N)-1):
        if N[i] < 5:
            ans += N[i]
        elif N[i] > 5:
            ans += 10 - N[i]
            N[i+1] += 1
        else:
            ans += 5
            if N[i+1] >= 5:
                N[i+1] += 1

    print(ans + N[len(N)-1])

main()

Buggy submission (verdict: Runtime Error):
def main():
    import sys
    input = sys.stdin.readline

    N = list(map(int, list(input())))
    N = N[::-1] + [0]

    ans = 0
    for i in range(len(N)-1):
        if N[i] < 5:
            ans += N[i]
        elif N[i] > 5:
            ans += 10 - N[i]
            N[i+1] += 1
        else:
            ans += 5
            if N[i+1] >= 5:
                N[i+1] += 1

    print(ans + N[len(N)-1])

main()

Buggy submission (verdict: Runtime Error):
def main():
    import sys
    input = sys.stdin.readline

    N = list(map(int, list(input()[::-1]))) + [0]

    ans = 0
    for i in range(len(N)-1):
        if N[i] < 5:
            ans += N[i]
        elif N[i] > 5:
            ans += 10 - N[i]
            N[i+1] += 1
        else:
            ans += 5
            if N[i+1] >= 5:
                N[i+1] += 1

    print(ans + N[len(N)-1])

main()

Buggy submission (verdict: Runtime Error):
def main():
    import sys
    input = sys.stdin.readline

    N = list(map(int, list(input()[::-1]))) + [0]

    ans = 0
    for i in range(len(N)-1):
        if N[i] < 5:
            ans += N[i]
        elif N[i] > 5:
            ans += 10 - N[i]
            N[i+1] += 1
        else:
            ans += 5
            if N[i+1] >= 5:
                N[i+1] += 1

    print(ans + N[len(N)-1])

main()
Problem p02788 (python)

Fixed submission:
import math
from collections import deque

n, d, a = map(int, input().split())
xh = [list(map(int, input().split())) for _ in range(n)]
xh.sort(key=lambda x:x[0])
xh = deque(xh)

xh_field = deque()

cnt = 0
now_damage = 0
while xh:
    pos, hp = xh.popleft()
    if xh_field:
        while (xh_field and xh_field[0][0] < pos) :
            now_damage -= a * xh_field[0][1]
            xh_field.popleft() 
    if hp <= now_damage:
        pass
    elif hp > now_damage:
        atk_cnt = math.ceil((hp - now_damage) / a)
        cnt += atk_cnt
        now_damage += atk_cnt * a
        xh_field.append((2*d + pos, atk_cnt))        
print(cnt)

Buggy submission (verdict: Runtime Error):
n, d, a = map(int, input().split())
xh = [list(map(int, input().split())) for _ in range(n)]
xh.sort(key = lambda x:x[0])

cnt = 0
while len(xh) != 0:
    x, h = xh.pop(0)
    atk_end = x + d + d
    atk_cnt = (h + a - 1) // a
    cnt += atk_cnt
    for i in range(len(xh)):
        if xh[i][0] > atk_end:
            break
        xh[i][1] -= a * atk_cnt
    while xh[0][1] < 1:
        xh.pop(0)
        if len(xh) == 0:
            break

print(cnt)
Problem p02618 (python)

Fixed submission:
for i in range(365):
  print(i%26+1)

Buggy submission (verdict: Runtime Error):
import math
import fractions
#import sys
#input = sys.stdin.readline

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ZipArray(a):
    aa = [[a[i],i]for i in range(n)]

    aa.sort(key = lambda x : x[0])
    for i in range(n):
        aa[i][0]=i+1
    aa.sort(key = lambda x : x[1])
    b=[aa[i][0] for i in range(len(a))]
    return b

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans

def Zeros(a,b):
    if(b<=-1):
        return [0 for i in range(a)]
    else:
        return [[0 for i in range(b)] for i in range(a)]

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
            
'''
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 2
N = 10 ** 6 + 2
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

'''

#a = list(map(int, input().split()))

#################################################
#################################################
#################################################
#################################################


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

ans = [(i%26) for i in range(n)]

def cost(a,c,ans):
    val = 0
    last = [0 for i in range(26)]
    for i in range(n):
        for j in range(26):
            last += 1
        here = ans[i]
        val += a[i][here]
        last[here] = 0
        for j in range(26):
            val -= last[j]*c[j]
    return val
#

for i in range(n):
    maxim = -10**9
    idx = -1
    for j in range(26):
        if(maxim < a[i][j]):
            idx = j
            maxim = a[i][j]
    ans[i] = idx
#print(ans)

d = [[i,c[i]]]

for i in ans:
    print(i+1)
Problem p02691 (python)

Fixed submission:

n = int(input())
a = list(map(int, input().split()))
info = [0 for i in range(10**6)]
mid = 5*10**5

for i in range(n):
    if(a[i]<=2*10**5):
        num = a[i] - i
        info[mid + num] += 1
#print(info[mid-8:mid+8])
ans = 0
for i in range(n):
    if(a[i]<=2*10**5):
        num = a[i] - i
        ans += info[mid + num - a[i]*2]

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
info = [0 for i in range(10**6)]
mid = 5*10**5

for i in range(n):
    num = a[i] - i
    info[mid + num] += 1
#print(info[mid-8:mid+8])
ans = 0
for i in range(n):
    num = a[i] - i
    ans += info[mid + num - a[i]*2]

print(ans)
Problem p02743 (python)

Fixed submission:


import decimal
#decimal.getcontext().prec = 30
a,b,c = list(map(int, input().split()))
a = decimal.Decimal(a)
b = decimal.Decimal(b)
c = decimal.Decimal(c)
d = decimal.Decimal(0.5)
e = decimal.Decimal(1/10000000)

#print(a**decimal.Decimal(0.5))

if(a**d + b**d < (c)**d ):
    print("Yes")
else:
    print("No")
#print(a**d + b**d , (c)**d)

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

if(math.sqrt(a) + math.sqrt(b) < math.sqrt(c)-0.000001):
    print("Yes")
else:
    print("No")
print(math.sqrt(a) + math.sqrt(b),math.sqrt(c)-0.000001)
Problem p02842 (python)

Fixed submission:
import math

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

#a = list(map(int, input().split()))

n = int(input())

ans = [-1 for i in range(80002)]
for i in range(50002):
    price = int((i*1.08)//1)
    ans[price] = i

if(ans[n]!=-1):
    print(ans[n])
else:
    print(':(')

Buggy submission (verdict: Runtime Error):
import math

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

#a = list(map(int, input().split()))

n = int(input())

ans = [-1 for i in range(30002)]
for i in range(10001):
    price = int((i*1.08)//1)
    ans[price] = i

if(ans[n]!=-1):
    print(ans[n])
else:
    print(':(')
Problem p02845 (python)

Fixed submission:
import math

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

#a = list(map(int, input().split()))

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

phase = 0
now = [0,0,0]
ans=1

for i in range(n):
    if(a[i]==-1):
        now[phase]=1
        ans*=3-phase
        ans%=1000000007
        phase+=1
    else:
        corr = []
        for j in range(3):
            if(now[j]==a[i]):
                corr.append(j)
        ans*=len(corr)
        ans%=1000000007
        if(len(corr)!=0):
            now[corr[0]]+=1
print(ans)

Buggy submission (verdict: Runtime Error):
import math

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

#a = list(map(int, input().split()))

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

phase = 0
now = [0,0,0]
ans=1

for i in range(n):
    if(a[i]==0):
        now[phase]=1
        ans*=3-phase
        ans%=1000000007
        phase+=1
    else:
        corr = []
        for j in range(3):
            if(now[j]==a[i]):
                corr.append(j)
        ans*=len(corr)
        ans%=1000000007
        now[corr[0]]+=1
print(ans)

Buggy submission (verdict: Runtime Error):
import math

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

#a = list(map(int, input().split()))

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

phase = 0
now = [0,0,0]
ans=1

for i in range(n):
    if(a[i]==0):
        now[phase]=1
        ans*=3-phase
        ans%=1000000007
        phase+=1
    else:
        corr = []
        for j in range(3):
            if(now[j]==a[i]):
                corr.append(j)
        ans*=len(corr)
        ans%=1000000007
        now[corr[0]]+=1
print(ans)
Problem p02866 (python)

Fixed submission:
import math

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

dist = [0 for i in range(n)]
for i in range(n):
    dist[a[i]] += 1
#print(dist)


if (a[0]!=0):
    print(0)
else:
    zero = 0
    for j in range(n):
        if(a[j]==0):
            zero+=1
    #print(zero)
    if(zero==1):
        ans = 1
        now = 1
        total = 1
        while(total<n and now<=n-1):
            for j in range(dist[now]):
                ans *= dist[now-1]
                #print(ans)
                ans %= 998244353
                total+=1
            now+=1
            
        print(ans)
    else:
        print(0)

Buggy submission (verdict: Runtime Error):
import math

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

dist = [0 for i in range(n)]
for i in range(n):
    dist[a[i]] += 1
#print(dist)
ans = 1

if (a[0]!=0):
    print(0)
else:
    
    now = 1
    total = 1
    while(total<n):
        for j in range(dist[now]):
            ans *= dist[now-1]
            ans %= 998244353
            total+=1
        now+=1
        
    print(ans)
Problem p02924 (python)

Fixed submission:
n = int(input())
print(n*(n-1)//2)

Buggy submission (verdict: Runtime Error):
print(n*(n-1)//2)
Problem p02972 (python)

Fixed submission:
import math

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

n = int(input())
a = list(map(int, input().split()))
ans = [0 for i in range(n)]
ball = []

for ii in range(n):
    #print(ans)
    i = n-ii
    if(a[i-1]!=ans[i-1]):
        d = make_divisors(i)
        ball.append(i)
        for k in d:
            ans[k-1] = 1-ans[k-1]
print(len(ball))
print(' '.join(map(str,ball)))

Buggy submission (verdict: Runtime Error):
import math
m = list(map(int, input().split()))[0]
a = list(map(int, input().split()))


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
  
b = [False for i in range(m)]
c = [False for i in range(m)]

for i in range(m):
    ii = m - i
    if(a[ii-1] != b[ii-1]):
        k = make_divisors(ii)
        for j in k:
            b[j-1] = not b[j-1]
        c[ii-1] = True
    print("b",b)
    print("c",c)
    print()

ans = ""
count = 0
for i in range(m):
    if(c[i] == True):
        ans+= str(i+1) + " "
        count +=1
        
print(count)
print(ans)
Problem p02995 (python)

Fixed submission:
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

a,b,x,y = list(map(int, input().split()))

z = x * y // gcd(x,y)

def num(u,v,k):
    ww=v//k - (u-1)//k
    return ww

print((b-a+1)-(num(a,b,x)+num(a,b,y)-num(a,b,z)))

Buggy submission (verdict: Runtime Error):
import math

a,b,x,y = list(map(int, input().split()))

z = x * y // math.gcd(x,y)

def num(u,v,k):
    ww=v//k - (u-1)//k
    return ww

print((b-a+1)-(num(a,b,x)+num(a,b,y)-num(a,b,z)))
Problem p03006 (python)

Fixed submission:
n = list(map(int, input().split()))
n = n[0]
xy=[]
for i in range(n):
    x,y = list(map(int, input().split()))
    xy.append([x,y])

distlist=[]
distnum=[]

for i in range(n):
    for j in range(n):
        vec=[xy[i][0]-xy[j][0], xy[i][1]-xy[j][1]]
        if(i==j):
             continue
        flag=0
        for k in range(len(distlist)):
            if(distlist[k][0]==vec[0] and distlist[k][1]==vec[1]):
                distnum[k] += 1
                flag=1
                break
        if(flag==0):
            distlist.append(vec)
            distnum.append(1)

if(n==1):
    print(1)
else:
    print(max(n-max(distnum),1))

Buggy submission (verdict: Runtime Error):
n = list(map(int, input().split()))
n = n[0]
xy=[]
for i in range(n):
    x,y = list(map(int, input().split()))
    xy.append([x,y])

distlist=[]
distnum=[]

for i in range(n):
    for j in range(n):
        vec=[xy[i][0]-xy[j][0], xy[i][1]-xy[j][1]]
        if(i==j):
             continue
        flag=0
        for k in range(len(distlist)):
            if(distlist[k][0]==vec[0] and distlist[k][1]==vec[1]):
                distnum[k] += 1
                flag=1
                break
        if(flag==0):
            distlist.append(vec)
            distnum.append(1)

print(n-max(distnum))
Problem p03061 (python)

Fixed submission:
import fractions

n = list(map(int, input().split()))
n = n[0]
a = list(map(int, input().split()))

left=[0 for i in range(n)]
right=[0 for i in range(n)]
left[0] = a[0]
right[-1] = a[-1]
for i in range(n-2):
    left[i+1] = fractions.gcd(left[i],a[i+1])
    right[-i-2] = fractions.gcd(right[-i-1],a[-i-2])

gcds=[left[n-2], right[1]]
for i in range(n-2):
    gcds.append(fractions.gcd(left[i], right[i+2]))

print(max(gcds))

Buggy submission (verdict: Runtime Error):
import math

n = list(map(int, input().split()))
n = n[0]
a = list(map(int, input().split()))

left=[0 for i in range(n)]
right=[0 for i in range(n)]
left[0] = a[0]
right[-1] = a[-1]
for i in range(n-2):
    left[i+1] = math.gcd(left[i],a[i+1])
    right[-i-2] = math.gcd(right[-i-1],a[-i-2])

gcds=[left[n-2], right[1]]
for i in range(n-2):
    gcds.append(math.gcd(left[i], right[i+2]))

print(max(gcds))

Buggy submission (verdict: Runtime Error):
import math

n = list(map(int, input().split()))
n = n[0]
a = list(map(int, input().split()))

left=[0 for i in range(n)]
right=[0 for i in range(n)]
left[0] = a[0]
right[-1] = a[-1]
for i in range(n-2):
    left[i+1] = math.gcd(left[i],a[i+1])
    right[-i-2] = math.gcd(right[-i-1],a[-i-1])

gcds=[left[n-2], right[1]]
for i in range(n-2):
    gcds.append(math.gcd(left[i], right[i+2]))
print(max(gcds))

Buggy submission (verdict: Runtime Error):
import math

n = list(map(int, input().split()))
n = n[0]
a = list(map(int, input().split()))

left=[0 for i in range(n)]
right=[0 for i in range(n)]
left[0] = a[0]
right[-1] = a[-1]
for i in range(n-2):
    left[i+1] = math.gcd(left[i],a[i+1])
    right[-i-2] = math.gcd(right[-i-1],a[-i-1])

gcds=[left[n-2], right[1]]
for i in range(n-2):
    gcds.append(math.gcd(left[i], right[i+2]))
print(max(gcds))

Buggy submission (verdict: Runtime Error):
import math

n = list(map(int, input().split()))
n = n[0]
a = list(map(int, input().split()))

left=[0 for i in range(n-1)]
right=[0 for i in range(n)]
left[0] = a[0]
right[-1] = a[-1]
for i in range(n-2):
    left[i+1] = math.gcd(left[i],a[i+1])
    right[-i-1] = math.gcd(right[-i],a[-i-1])

gcds=[left[n-2], right[1]]
for i in range(n-2):
    gcds.append(math.gcd(left[i], right[i+2]))
print(max(gcds))
Problem p03421 (python)

Fixed submission:
import math

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

#a = list(map(int, input().split()))

#####################################


#2:26
n,a,b = list(map(int, input().split()))
ans=[]
if(n<a+b-1 or n>a*b):
    print(-1)
else:
    if(b>=2):
        x = (n-a)//(b-1)
        y = (n-a)%(b-1)
    else:
        x=1
        y=1
    times=[0 for i in range(b-1)]
    for i in range(a):
        ans.append(n-a+i+1)
    for i in range(b-1):
        if(i<y):
            times[i]=x+1
        else:
            times[i]=x
    now = n-a
    for i in range(b-1):
        now -= times[i]
        for j in range(times[i]):
            ans.append(now+j+1)
print(' '.join(map(str,ans)))

Buggy submission (verdict: Runtime Error):
import math

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

#a = list(map(int, input().split()))

#####################################


#2:26
n,a,b = list(map(int, input().split()))
ans=[]
if(n<a+b-1 or n>a*b):
    print(-1)
else:
    x = (n-a)//(b-1)
    y = (n-a)%(b-1)
    times=[0 for i in range(b-1)]
    for i in range(a):
        ans.append(n-a+i+1)
    for i in range(b-1):
        if(i<y):
            times[i]=x+1
        else:
            times[i]=x
    now = n-a
    for i in range(b-1):
        now -= times[i]
        for j in range(times[i]):
            ans.append(now+j+1)
print(' '.join(map(str,ans)))
Problem p03610 (python)

Fixed submission:
s = input()
a = ""
for i in range((len(s)+1)//2):
  a = a+ str(s[2*i])
print(a)

Buggy submission (verdict: Runtime Error):
s = input()
a = ""
for i in range(len(s+1)//2):
  a += s[2*i]
print(a)
Problem p03972 (python)

Fixed submission:

w,h = list(map(int, input().split()))
ws = []
hs = []
for i in range(w): ws.append(int(input()))
for i in range(h): hs.append(int(input()))

ws.sort(reverse = True)
hs.sort(reverse = True)

remainW = w
remainH = h
aliveW = [1 for i in range(w)]
aliveH = [1 for i in range(h)]

ans = 0
while(remainW>0 or remainH>0):
    #print(ans, remainW, remainH)
    costW = ws[remainW-1] * (remainH + 1)
    costH = hs[remainH-1] * (remainW + 1)
    if(remainH!=0 and (ws[remainW-1] > hs[remainH-1] or remainW==0)):
        ans += costH
        remainH = max(0,remainH-1)
    else:
        ans += costW
        remainW = max(0,remainW-1)
print(ans)

Buggy submission (verdict: Runtime Error):

w,h = list(map(int, input().split()))
ws = []
hs = []
for i in range(w): ws.append(int(input()))
for i in range(h): hs.append(int(input()))

ws.sort(reverse = True)
hs.sort(reverse = True)

remainW = w
remainH = h
aliveW = [1 for i in range(w)]
aliveH = [1 for i in range(h)]

ans = 0
while(remainW>0 or remainH>0):
    #print(ans, remainW, remainH)
    costW = ws[remainW-1] * (remainH + 1)
    costH = hs[remainH-1] * (remainW + 1)
    if(ws[remainW-1] > hs[remainH-1] or remainW==0):
        ans += costH
        remainH-=1
    else:
        ans += costW
        remainW -= 1
print(ans)

Buggy submission (verdict: Runtime Error):

w,h = list(map(int, input().split()))
ws = []
hs = []
for i in range(w): ws.append(int(input()))
for i in range(h): hs.append(int(input()))

ws.sort(reverse = True)
hs.sort(reverse = True)

remainW = w
remainH = h
aliveW = [1 for i in range(w)]
aliveH = [1 for i in range(h)]

ans = 0
while(remainW>0 or remainH>0):
    #print(ans, remainW, remainH)
    costW = ws[remainW-1] * (remainH + 1)
    costH = hs[remainH-1] * (remainW + 1)
    if(costW > costH or remainW==0):
        ans += costH
        remainH-=1
    else:
        ans += costW
        remainW -= 1
print(ans)