Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
S = input().strip()

MOD = 10**9 + 7
dp = np.zeros((100005, 13))
N = len(S)

dp[0][0] = 1
for i in range(N):
    c = -1
    if S[i] == '?':
        c = -1
    else:
        c = int(S[i])

    for j in range(10):
        if c != -1 and c != j:
            continue
        for ki in range(13):
            dp[i+1][(ki * 10 + j) % 13] += dp[i][ki]

    for j in range(13):
        dp[i+1][j] %= MOD

res = int(dp[N][5])

print(res)


Fixed submission:
S = input().strip()

MOD = 10**9 + 7
dp = [[0 for i in range(13)] for j in range(100005)]
N = len(S)

dp[0][0] = 1
for i in range(N):
    c = -1
    if S[i] == '?':
        c = -1
    else:
        c = int(S[i])

    for j in range(10):
        if c != -1 and c != j:
            continue
        for ki in range(13):
            dp[i+1][(ki * 10 + j) % 13] += dp[i][ki]

    for j in range(13):
        dp[i+1][j] %= MOD

res = int(dp[N][5])

print(res)

Buggy python submission (verdict: Runtime Error):
S = input().strip()

a = 130
for i in range(100000);
    b = a % 13

print(a)


Fixed submission:
S = input().strip()

MOD = 10**9 + 7
dp = [[0 for i in range(13)] for j in range(100005)]
N = len(S)

dp[0][0] = 1
for i in range(N):
    c = -1
    if S[i] == '?':
        c = -1
    else:
        c = int(S[i])

    for j in range(10):
        if c != -1 and c != j:
            continue
        for ki in range(13):
            dp[i+1][(ki * 10 + j) % 13] += dp[i][ki]

    for j in range(13):
        dp[i+1][j] %= MOD

res = int(dp[N][5])

print(res)

Buggy python submission (verdict: Runtime Error):
S = input().strip()

a = 130
for i in range(100000)
    b = a % 13

print(a)


Fixed submission:
S = input().strip()

MOD = 10**9 + 7
dp = [[0 for i in range(13)] for j in range(100005)]
N = len(S)

dp[0][0] = 1
for i in range(N):
    c = -1
    if S[i] == '?':
        c = -1
    else:
        c = int(S[i])

    for j in range(10):
        if c != -1 and c != j:
            continue
        for ki in range(13):
            dp[i+1][(ki * 10 + j) % 13] += dp[i][ki]

    for j in range(13):
        dp[i+1][j] %= MOD

res = int(dp[N][5])

print(res)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
dp = [1] * (M+1)
dpleft = [0] * (M)
MOD = 10 ** 9 + 7
ndp = [1] * (M+1)
for n in range(N):
    for m in range(M):
        if S[n] == T[m]:
            ndp[m+1] = ndp[m] + dp[m+1]
            dpleft[m] = dp[m+1]
        else:
            ndp[m+1] = ndp[m] + dpleft[m]
        dp[m] = ndp[m]
    dp[M] = ndp[M]
print(dp[-1] % MOD)

Fixed submission:
numX, numA = [int(i) for i in input().split()]

if numX < numA:
    print(0)
else:
    print(10)

Buggy python submission (verdict: Runtime Error):
# 累積和

N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))

dp = [1] * (M+1)
dpleft = [0] * (M)
MOD = 10 ** 9 + 7

for n in range(N):
    ndp = [1]
    for m in range(M):
        if S[n] == T[m]:
            ndp.append(ndp[-1] + dp[m+1])
            dpleft[m] = dp[m+1]
        else:
            ndp.append(ndp[-1] + dpleft[m])
    dp = ndp
print(dp[-1] % MOD)


Fixed submission:
numX, numA = [int(i) for i in input().split()]

if numX < numA:
    print(0)
else:
    print(10)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

# 1つ目の入力
num = int(input())

# スペース区切りの整数の入力
num_list = list(map(int,input().split()))

def judge(num_list, num):
    if num == 1:
        return('Yes')
    for i in range(0,len(num_list)-1):
        for j in range(i+1,len(num_list)):
          if num_list[i] -1 <= num_list[j]:
            if i+1 == num-1:
                return('Yes')
          else:
            return('No')


print(judge(num_list, num))

Fixed submission:
# -*- coding: utf-8 -*-

# 1つ目の入力
num = int(input())

# スペース区切りの整数の入力
num_list = list(map(int,input().split()))

def judge(num_list, num):
    if num == 1:
        return('Yes')

    decrease = False
    for i in range(0,len(num_list)):
        if i + 1 == num:  # 終わりなので、何もしない
            return('Yes')  # 最後までOKだったので、Yesをリターン

        if num_list[i] == num_list[i+1]:
            pass
        elif num_list[i] < num_list[i+1]:
            decrease = False
        elif num_list[i] - 1 <= num_list[i+1]:
            if decrease:
                return('No')
            else:
                decrease = True
        else:
            return('No')
        '''
        for j in range(i+1,len(num_list)):
          if num_list[i] -1 <= num_list[j]:
            if i+1 == num-1:
                return('Yes')
          else:
            return('No')
        '''


print(judge(num_list, num))
Buggy python submission (verdict: Runtime Error):
p, q, r = map(int, input().split())
print(min([p+q, q+r, r+p])

Fixed submission:
p, q, r = map(int, input().split())
print(min([p+q, q+r, r+p]))
Buggy python submission (verdict: Runtime Error):
n = int(input())
lst = []
STATUS = "Good"
while n > 0:
    lst.append(n%10)
    n //= 10 # 必須
lst.reverse()
for i in range(3):
  if lst[i] == lst[i + 1]:
    STATUS = "Bad"
  else:
    pass
print(STATUS)

Fixed submission:
n = str(input())
lst = []
STATUS = "Good"
lst = list(map(int, n))
for i in range(3):
  if lst[i] == lst[i + 1]:
    STATUS = "Bad"
  else:
    pass
print(STATUS)
Buggy python submission (verdict: Time Limit Exceeded):
num = int(input())
power = 1

for i in range(1,num+1):
  power *= i
print(power % (pow(10,9) + 7))

Fixed submission:
import math
num = int(input())
power = math.factorial(num)

print(power % (pow(10,9) + 7))
Buggy python submission (verdict: Time Limit Exceeded):
start,end,devide = map(int,input().split())
num = 0
for i in range(start,end + 1):
  if i % devide == 0:
    num +=1
    num += (end - i) // devide
    break
print(num)

Fixed submission:
a, b, x  = map(int, input().split())
 
if a != 0:
	print(b//x - (a-1)//x)
else:
	print(b//x + 1)

Buggy python submission (verdict: Time Limit Exceeded):
start,end,devide = map(int,input().split())
num = 0
for i in range(start,end + 1):
  if i % devide == 0:
    num +=1
    num += (end - i) // devide
    break
print(num)

Fixed submission:
a, b, x  = map(int, input().split())
 
if a != 0:
	print(b//x - (a-1)//x)
else:
	print(b//x + 1)
Buggy python submission (verdict: Runtime Error):
result = True
for i in range(n):
    # except the last case, 前よりも自分が高ければ下がる
    if (i != (n-1)):
        if(h[i] > h[i+1]): 
            h[i] -= 1
    # except the 1st case, 後ろよりも自分が高ければ下がる
    elif (i != 0):
        if(h[i] > h[i-1]): 
            h[i] -= 1
    # 後ろよりも自分が低ければアウト
    if (i != 0):
        if(h[i] < h[i-1]):
            result = False
            break

if result:
    print("Yes")
else:
    print("No")

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

result = True
for i in range(n):
    if n == 1:
        break
    
    pos = ""
    if (i == 0):
        if (h[i] > h[i+1]):
            h[i] -= 1
    elif (i == (n-1)):
        if (h[i] > h[i-1]):
            h[i] -= 1
    else:
        if (h[i] > h[i+1]) | (h[i] > h[i-1]):
            h[i] -= 1
    
    if (i != 0):
        if(h[i] < h[i-1]):
            result = False
            break

            
if result:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s = []
for i in range(N):
    p = list(input())
    p.sort()
    q = "".join(p)
    s.append(q)


cnt = 0
for i in range(N-1):
    cnt += s[i+1:].count(s[i])


print(cnt)
        


Fixed submission:
N = int(input())
s = []
for i in range(N):
    p = list(input())
    p.sort()
    q = "".join(p)
    s.append(q)

cnt = 0
s = sorted(s)
seq = 1
prek = s[0] 
for k in range(1, N):
    if prek == s[k]:
        seq += 1
    else:
        cnt += seq*(seq-1)/2
        seq = 1

    prek = s[k]

cnt += seq*(seq-1)/2


print(int(cnt))
Buggy python submission (verdict: Time Limit Exceeded):
import sys  
input = sys.stdin.readline

N, M = list(map(int, input().split()))


k = [0]*N
for i in range(M):
    l, r = list(map(int, input().split()))
    for q in range(l-1, r):
        k[q] += 1

ans = 0
for k_ in k:
    if k_ == M:
        ans +=1

print(ans)

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

N, M = list(map(int, input().split()))



ans = -1
l_min , r_max = list(map(int, input().split()))
for i in range(M-1):
    l, r = list(map(int, input().split()))
    if r_max < l or r < l_min:
        ans = 0
        break

    if l_min <= l and l <= r_max:
        l_min = l

    if l_min <= r and r <= r_max:
        r_max = r


if ans == 0:
    print(ans)
else:
    print(r_max - l_min + 1)
Buggy python submission (verdict: Runtime Error):

N = int(input())
x = [int(input()) for i in range(5)]


for i in range(5):
    if x[i] == min(x):
        break
    
del x[i+1:]

lenx = len(x)
for k in range(4):
    for w in range(lenx-1):
        cnt=0
        if x[w] =< x[w+1] :
            del x[w+1]
            lenx -=1
        else:
            cnt+=1
            
ans=0
if lenx==0:
    print(5)
else:
    if N%x[0]==0:
        ans+=N/x[0]
    else:
        ans+=N//x[0]+1

    for p in range(1,lenx):
        d = N-(ans-p)*x[p]
        if d%x[p] == 0:
            ans+=d/x[p]
        else:
            ans+=d//x[p]+1

    print(ans+5-lenx)
        

Fixed submission:
import math
N = int(input())
x = [int(input()) for i in range(5)]


y = min(x)
print(math.ceil(N/y)+4)

Buggy python submission (verdict: Runtime Error):

N = int(input())
x = [int(input()) for i in range(5)]
ans = [0]*5
if N%x[0]==0:
    ans[0] =  N//x[0]
else:
    ans[0] =  N//x[0] + 1

j = False
if x[0] == min(x):
    print(ans[0]+4)
else:

    for i in range(1,5):
        if j:
           break
        elif x[i] == min(x[i:]):
            j = True
            if (N-(x[i]*(ans[i-1]-1)))%x[i] == 0:
                ans[i] = (N-(x[i]*(ans[i-1]-1)))//x[i]
            else:
                ans[i] = (N-(x[i]*(ans[i-1]-1)))//x[i] + 1
        elif x[i] < x[i-1]:
            if (N-(x[i]*(ans[i-1]-1)))%x[i] == 0:
                ans[i] = (N-(x[i]*(ans[i-1]-1)))//x[i]
            else:
                ans[i] = (N-(x[i]*(ans[i-1]-1)))//x[i] + 1
        else
            if (N-(x[i]*(ans[i-1]-1)))%x[i] == 0:
                ans[i] = (N-(x[i-1]*(ans[i-1]-1)))//x[i]
            else:
                ans[i] = (N-(x[i-1]*(ans[i-1]-1)))//x[i] + 1


    for i in range(1, 5):
        if ans[i] == 0:
            ans[i] = 1
    
    print(sum(ans))


Fixed submission:
import math
N = int(input())
x = [int(input()) for i in range(5)]


y = min(x)
print(math.ceil(N/y)+4)
Buggy python submission (verdict: Runtime Error):
A, B, C = map(int, input().split())
if B//A>C:
    print(C)
else:
    print(b//A)


Fixed submission:
A, B, C = map(int, input().split())
if B//A>C:
    print(C)
else:
    print(B//A)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Slength = len(S)

def remove(preS):
    return "".join(("".join(preS.split('01'))).split('10'))




while True:
    T = remove(S)

    if T == S:
        break
    else:
        S = T
    

print(Slength-len(T))

Fixed submission:
S = input()

print(min(S.count("0"), S.count("1"))*2)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Slength = len(S)

def remove(preS):
    return "".join(("".join(preS.split('01'))).split('10'))




while True:
    T = remove(S)

    if T == S:
        break
    else:
        S = T
    

print(Slength-len(T))

Fixed submission:
S = input()

print(min(S.count("0"), S.count("1"))*2)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Slength = len(S)

def remove01(preS):
    return "".join(preS.split('01'))

def remove10(preS):
    return "".join(preS.split('10'))



while True:
    T = remove10(remove01(S))

    if T == S:
        break
    else:
        S = T
    

print(Slength-len(T))

Fixed submission:
S = input()

print(min(S.count("0"), S.count("1"))*2)
Buggy python submission (verdict: Runtime Error):
import sys  
import numpy as np

input = sys.stdin.readline
A = int(input())
a = list(map(int, input().split()))
sum1 = 0
for i in range(1,A):
    if a[i-1] == a[i]:
        sum+=1
        a[i] = 0

print(sum1)

Fixed submission:
import sys  
import numpy as np

input = sys.stdin.readline
A = int(input())
a = list(map(int, input().split()))
sum1 = 0
for i in range(1,A):
    if a[i-1] == a[i]:
        sum1+=1
        a[i] = 0

print(sum1)
Buggy python submission (verdict: Runtime Error):
import sys  
import numpy as np

input = sys.stdin.readline
N = int(input())
S = list(input())

S = S[:-1]

temp = []
for i in range(1,N-1):
    a = S[:i]
    b = S[i:]
    a = list(set(a))
    b = list(set(b))

    j = list(set(a+b))
    
    temp.append(len(a) + len(b) - len(j))
    

print(max(temp))

Fixed submission:
import sys  
import numpy as np

input = sys.stdin.readline
N = int(input())
S = list(input())

S = S[:-1]

temp = []
for i in range(1,N):
    a = S[:i]
    b = S[i:]
    a = list(set(a))
    b = list(set(b))

    j = list(set(a+b))
    
    temp.append(len(a) + len(b) - len(j))
    

print(max(temp))
Buggy python submission (verdict: Runtime Error):

import sys  
import numpy as np
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
k = [0] * max(3,(max(a)+1))

for p in a:
    k[p] += 1
ans = 0
for q,r,s in zip(k, k[1:] , k[2:]):
    ans = max(ans, q+r+s)

print(ans)

Fixed submission:
import sys  
import numpy as np
N1 = list(map(int, input().split()))
N2 = list(map(int, input().split()))
N3 = list(map(int, input().split()))

temp = []
for i in range(3):
    a  = N1[i] + N2[i] - 2*N3[i]
    temp.append(a)
temp2 = []

temp2.append(N1[0] + N1[1] - 2*N1[2])

temp2.append(N2[0] + N2[1] - 2*N2[2])

temp2.append(N3[0] + N3[1] - 2*N3[2])


if len(list(set(temp))) == 1 & len(list(set(temp2))) == 1:
    print("Yes")
else :
    print("No")
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))

print(abs(max(a)-min(a))

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
 
print(abs(max(a)-min(a)))
Buggy python submission (verdict: Runtime Error):
A, B= map(int, input().split())

if A==1 & B==!:
    print("Draw")
elif A==1 :
    print("Alice")
elif B==1 :
    print("Bob")
elif A > B:
    print("Alice")
elif B>A:
    print("Bob")
else :
    print("Draw")

Fixed submission:
A, B= map(int, input().split())

if A==1:
    A = 14

if B==1:
    B = 14

if A > B:
    print("Alice")
elif B > A:
    print("Bob")
else :
    print("Draw")
Buggy python submission (verdict: Runtime Error):
A = map(int, input().split())
if A.sort() == [5,5,7]:
  print("YES")
else:
  print("NO")

Fixed submission:
A = list(map(int, input().split()))
A.sort()
if A == [5,5,7]:
  print("YES")
else:
  print("NO")

Buggy python submission (verdict: Runtime Error):
A = map(int, input().split())
if A.sort() == [5,5,7]:
  print("YES")
eles:
  print("NO")

Fixed submission:
A = list(map(int, input().split()))
A.sort()
if A == [5,5,7]:
  print("YES")
else:
  print("NO")

Buggy python submission (verdict: Runtime Error):
A = map(int, input().split())
if A.sort() == [5,7,7]:
  print("YES")
eles:
  print("NO")

Fixed submission:
A = list(map(int, input().split()))
A.sort()
if A == [5,5,7]:
  print("YES")
else:
  print("NO")

Buggy python submission (verdict: Runtime Error):
A = map(int, input().split())
if A.sort() = [5,7,7]:
  print("YES")
eles:
  print("NO")


Fixed submission:
A = list(map(int, input().split()))
A.sort()
if A == [5,5,7]:
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
a = int(input()) 
b = [int(input()) for i in range(a)] 
 
m=max(b)
sorted(b)
for i in range(a):
  if m>b[i]:
    print(m)
  else:
    print(sorted(b)[-2])

Fixed submission:
a = int(input()) 
b = [int(input()) for i in range(a)] 
 
m=max(b)
sorted(b)
s=sorted(b)[-2]
for i in range(a):
  if m>b[i]:
    print(m)
  else:
    print(s)

Buggy python submission (verdict: Time Limit Exceeded):
a = int(input()) 
b = [int(input()) for i in range(a)] 
 
m=max(b)
for i in range(a):
  if m>b[i]:
    print(m)
  else:
    d=b[i]
    b.pop(i)
    print(max(b))
    b.insert(i,d)

Fixed submission:
a = int(input()) 
b = [int(input()) for i in range(a)] 
 
m=max(b)
sorted(b)
s=sorted(b)[-2]
for i in range(a):
  if m>b[i]:
    print(m)
  else:
    print(s)

Buggy python submission (verdict: Runtime Error):
a = int(input()) 
b = [int(input()) for i in range(a)] 
 
m=max(b)
for i in range(a):
  if m>b[i]:
    print(m)
  else:
    d=b[i]
  	b.pop(i)
  	print(max(b))
  	b.insert(i,d)

Fixed submission:
a = int(input()) 
b = [int(input()) for i in range(a)] 
 
m=max(b)
sorted(b)
s=sorted(b)[-2]
for i in range(a):
  if m>b[i]:
    print(m)
  else:
    print(s)

Buggy python submission (verdict: Time Limit Exceeded):
a = int(input()) 
b = [int(input()) for i in range(a)] 
for i in range(a):
  d=b[i]
  b.pop(i)
  print(max(b))
  b.insert(i,d)

Fixed submission:
a = int(input()) 
b = [int(input()) for i in range(a)] 
 
m=max(b)
sorted(b)
s=sorted(b)[-2]
for i in range(a):
  if m>b[i]:
    print(m)
  else:
    print(s)

Buggy python submission (verdict: Runtime Error):
a = int(input()) 
b = [int(input()) for i in range(n)] 
for i in range(a):
  d=b[i]
  b.pop(i)
  print(max(b))
  b.insert(i,d)

Fixed submission:
a = int(input()) 
b = [int(input()) for i in range(a)] 
 
m=max(b)
sorted(b)
s=sorted(b)[-2]
for i in range(a):
  if m>b[i]:
    print(m)
  else:
    print(s)

Buggy python submission (verdict: Runtime Error):
a = int(input()) 
b = [int(input()) for i in range(n)] 
for i in range(a):
  d=b[i-1]
  c=pop(b.i-1)
  print(max(c))
  b.insert(i-1.d)

Fixed submission:
a = int(input()) 
b = [int(input()) for i in range(a)] 
 
m=max(b)
sorted(b)
s=sorted(b)[-2]
for i in range(a):
  if m>b[i]:
    print(m)
  else:
    print(s)

Buggy python submission (verdict: Runtime Error):
a = int(input()) 
b = [int(input()) for i in range(n)] 
for i in range(a):
  c=pop(b.i-1)
  print(max(c))

Fixed submission:
a = int(input()) 
b = [int(input()) for i in range(a)] 
 
m=max(b)
sorted(b)
s=sorted(b)[-2]
for i in range(a):
  if m>b[i]:
    print(m)
  else:
    print(s)
Buggy python submission (verdict: Time Limit Exceeded):
import collections

n = int(input())
s = input()
cnt = 0
for i in range(n)[::-1]:
  ch = s[i:]
  c = collections.Counter(ch)
  tmp_cnt = 1
  for k,v in c.items():
    if k != s[i]:
      tmp_cnt *= (v+1)
  cnt += tmp_cnt % (10**9+7)
print(cnt% (10**9+7))

Fixed submission:
import collections

n = int(input())
s = input()
cnt = 0
dictionary = {}

for i in range(n)[::-1]:
  if s[i] in dictionary.keys():
    dictionary[s[i]] += 1
  else:
    dictionary[s[i]] = 1
  ch = s[i:]
  tmp_cnt = 1
  for k,v in dictionary.items():
    if k != s[i]:
      tmp_cnt *= (v+1)
  cnt += tmp_cnt % (10**9+7)
print(cnt % (10**9+7))

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

n = int(input())
s = raw_input()
cnt = 0
dictionary = {}

for i in range(n)[::-1]:
  if s[i] in dictionary.keys():
    dictionary[s[i]] += 1
  else:
    dictionary[s[i]] = 1
  ch = s[i:]
  tmp_cnt = 1
  for k,v in dictionary.items():
    if k != s[i]:
      tmp_cnt *= (v+1)
  cnt += tmp_cnt %(10**9+7)
print(cnt%(10**9+7))

Fixed submission:
import collections

n = int(input())
s = input()
cnt = 0
dictionary = {}

for i in range(n)[::-1]:
  if s[i] in dictionary.keys():
    dictionary[s[i]] += 1
  else:
    dictionary[s[i]] = 1
  ch = s[i:]
  tmp_cnt = 1
  for k,v in dictionary.items():
    if k != s[i]:
      tmp_cnt *= (v+1)
  cnt += tmp_cnt % (10**9+7)
print(cnt % (10**9+7))

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

n = int(input())
s = input()
cnt = 0
for i in range(n)[::-1]:
  ch = s[i:]
  c = collections.Counter(ch)
  tmp_cnt = 1
  for k,v in c.items():
    if k != s[i]:
      tmp_cnt *= (v+1)
  cnt += tmp_cnt
print(cnt)

Fixed submission:
import collections

n = int(input())
s = input()
cnt = 0
dictionary = {}

for i in range(n)[::-1]:
  if s[i] in dictionary.keys():
    dictionary[s[i]] += 1
  else:
    dictionary[s[i]] = 1
  ch = s[i:]
  tmp_cnt = 1
  for k,v in dictionary.items():
    if k != s[i]:
      tmp_cnt *= (v+1)
  cnt += tmp_cnt % (10**9+7)
print(cnt % (10**9+7))
Buggy python submission (verdict: Runtime Error):
n = int(input())
array = [int(i) for i in input().split()]
ans=-1e14

for i in range(n, 2*n+1):
    l_array = sorted(array[:i])
    r_array = sorted(array[i:])
    ans = max(ans, sum(l_array[i-n:])-sum(r_array[:n]))

print(ans)

Fixed submission:
h,w = [int(i) for i in input().split()]

def solve(h,w):
    ans = min(h,w)
    for i in range(1,h):
        p1 = w*i
        p2 = (h-i)*(w//2)
        p3 = h*w-p1-p2
        ans = min(ans, max(p1,p2,p3)-min(p1,p2,p3))
    return ans 

ans = min(solve(h,w), solve(w,h))
if h*w % 3 == 0:
    ans = 0

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import heapq

n = int(input())
array = [int(i) for i in input().split()]
ans=-1e14
l_array = []
r_array = []
l_sum = [0]*(n+1)
r_sum = [0]*(n+1)

# left-n and right-n numbers
for i in range(n):
    heapq.heappush(l_array, array[i])
    heapq.heappush(r_array, (-array[3*n-1-i], array[3*n-1-i]))

l_sum[0] = sum(l_array)
r_sum[n] = sum([i[1] for i in r_array])

for i in range(n, 2*n):
    heapq.heappush(l_array, array[i])
    heapq.heappush(r_array, (-array[3*n-1-i], array[3*n-1-i]))
    heapq.heappop(l_array)
    heapq.heappop(r_array)

    l_sum[i-n+1] = sum(l_array)
    r_sum[2*n-1-i] = sum([j[1] for j in r_array])

for i in range(n+1):
    ans = max(ans, l_sum[i]-r_sum[i])

print(ans)

Fixed submission:
import heapq

n = int(input())
array = [int(i) for i in input().split()]
ans=-1e14
l_array = []
r_array = []
l_sum = [0]*(n+1)
r_sum = [0]*(n+1)

# left-n and right-n numbers
for i in range(n):
    heapq.heappush(l_array, array[i])
    heapq.heappush(r_array, (-array[3*n-1-i], array[3*n-1-i]))

l_sum[0] = sum(l_array)
r_sum[n] = sum([i[1] for i in r_array])

for i in range(n, 2*n):
    heapq.heappush(l_array, array[i])
    heapq.heappush(r_array, (-array[3*n-1-i], array[3*n-1-i]))
    l_min = heapq.heappop(l_array)
    r_max = heapq.heappop(r_array)[1]

    # l_sum[i-n+1] = sum(l_array)
    # r_sum[2*n-1-i] = sum([j[1] for j in r_array])
    l_sum[i-n+1] = l_sum[i-n] - l_min + array[i]
    r_sum[2*n-1-i] = r_sum[2*n-i] - r_max + array[3*n-1-i]

for i in range(n+1):
    ans = max(ans, l_sum[i]-r_sum[i])

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
array = [int(i) for i in input().split()]
ans=-1e14

for i in range(n, 2*n+1):
    l_array = sorted(array[:i]) 
    r_array = sorted(array[i:])
    ans = max(ans, sum(l_array[i-n:])-sum(r_array[:n]))

print(ans)

Fixed submission:
import heapq

n = int(input())
array = [int(i) for i in input().split()]
ans=-1e14
l_array = []
r_array = []
l_sum = [0]*(n+1)
r_sum = [0]*(n+1)

# left-n and right-n numbers
for i in range(n):
    heapq.heappush(l_array, array[i])
    heapq.heappush(r_array, (-array[3*n-1-i], array[3*n-1-i]))

l_sum[0] = sum(l_array)
r_sum[n] = sum([i[1] for i in r_array])

for i in range(n, 2*n):
    heapq.heappush(l_array, array[i])
    heapq.heappush(r_array, (-array[3*n-1-i], array[3*n-1-i]))
    l_min = heapq.heappop(l_array)
    r_max = heapq.heappop(r_array)[1]

    # l_sum[i-n+1] = sum(l_array)
    # r_sum[2*n-1-i] = sum([j[1] for j in r_array])
    l_sum[i-n+1] = l_sum[i-n] - l_min + array[i]
    r_sum[2*n-1-i] = r_sum[2*n-i] - r_max + array[3*n-1-i]

for i in range(n+1):
    ans = max(ans, l_sum[i]-r_sum[i])

print(ans)