Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
t=input()
ns,nt,nd=len(s),len(t),len(s)-len(t)
ans="z"*ns
flag=0
for i in range(2**nt):
  K=str(bin(i))[2:].zfill(nt)
  T=""
  for j in range(nt):
    if K[j]=="0":
      T+="?"
    else:
      T+=t[j]
  for k in range(nd+1):
    if s[k:].startswith(T):
      Key=s[:k]+t+s[k+nt:]
      ans=min(ans,Key.replace("?","a"))
      flag=1
print(ans if flag==1 else "UNRESTORABLE")

Fixed submission:
s=input()
t=input()
ns,nt,nd=len(s),len(t),len(s)-len(t)
ans="z"*ns
flag=0
for i in range(nd+1):
  judge=True
  for j in range(nt):
    ss=s[i+j]
    tt=t[j]
    if ss!="?" and ss!=tt:
      judge=False
  if judge:
    Key=s[:i]+t+s[i+nt:]
    ans=min(ans,Key.replace("?","a"))
    flag=1
print(ans if flag==1 else "UNRESTORABLE")

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
t=input()
ans="z"*len(s)
flag=0
for i in range(2**len(t)):
  K=str(bin(i))[2:].zfill(len(t))
  T=""
  for j in range(len(t)):
    if K[j]=="0":
      T+="?"
    else:
      T+=t[j]
  for k in range(len(s)-len(t)+1):
    if s[k:k+len(t)]==T:
      Key=s[:k]+t+s[k+len(t):]
      ans=min(ans,Key.replace("?","a"))
      flag=1
print(ans if flag==1 else "UNRESTORABLE")

Fixed submission:
s=input()
t=input()
ns,nt,nd=len(s),len(t),len(s)-len(t)
ans="z"*ns
flag=0
for i in range(nd+1):
  judge=True
  for j in range(nt):
    ss=s[i+j]
    tt=t[j]
    if ss!="?" and ss!=tt:
      judge=False
  if judge:
    Key=s[:i]+t+s[i+nt:]
    ans=min(ans,Key.replace("?","a"))
    flag=1
print(ans if flag==1 else "UNRESTORABLE")

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
t=input()
ans="z"*len(s)
flag=0
for i in range(2**len(t)):
  K=str(bin(i))[2:].zfill(len(t))
  T=""
  for j in range(len(t)):
    if K[j]=="0":
      T+="?"
    else:
      T+=t[j]
  for k in range(len(s)-len(t)+1):
    if s[k:k+len(t)]==T:
      Key=s[:k]+t+s[k+len(t):]
      ans=min(ans,Key.replace("?","a"))
      flag=1
print(ans if flag==1 else "UNRESTORABLE")

Fixed submission:
s=input()
t=input()
ns,nt,nd=len(s),len(t),len(s)-len(t)
ans="z"*ns
flag=0
for i in range(nd+1):
  judge=True
  for j in range(nt):
    ss=s[i+j]
    tt=t[j]
    if ss!="?" and ss!=tt:
      judge=False
  if judge:
    Key=s[:i]+t+s[i+nt:]
    ans=min(ans,Key.replace("?","a"))
    flag=1
print(ans if flag==1 else "UNRESTORABLE")

Buggy python submission (verdict: Runtime Error):
s=input()
t=input()
ans="z"*len(s)
flag=0
for i in range(2**len(t)):
  K=str(bin(i))[2:].zfill(5)
  T=""
  for j in range(len(t)):
    if K[j]=="0":
      T+="?"
    else:
      T+=t[j]
  for k in range(len(s)-len(t)+1):
    if s[k:k+len(t)]==T:
      Key=s[:k]+t+s[k+len(t):]
      ans=min(ans,Key.replace("?","a"))
      flag=1
print(ans if flag==1 else "UNRESTORABLE")

Fixed submission:
s=input()
t=input()
ns,nt,nd=len(s),len(t),len(s)-len(t)
ans="z"*ns
flag=0
for i in range(nd+1):
  judge=True
  for j in range(nt):
    ss=s[i+j]
    tt=t[j]
    if ss!="?" and ss!=tt:
      judge=False
  if judge:
    Key=s[:i]+t+s[i+nt:]
    ans=min(ans,Key.replace("?","a"))
    flag=1
print(ans if flag==1 else "UNRESTORABLE")
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
table=[]
for i in range(n):
  table.append([int(i) for i in input().split()])
Chk=True
for k in range(n):
  for i in range(n):
    for j in range(n):
      if table[i][k]+table[k][j]<table[i][j]:
        Chk=False
        table[i][j]=table[i][k]+table[k][j]

ans=0
for i in range(n):
  for j in range(i+1,n):
    C=True
    for k in range(n):
      if k==i or k==j:
        continue
      else:
        if table[i][k]+table[k][j]==table[i][j]:
          C=False
    if C:
      ans+=table[i][j]
print(ans if Chk else -1)

Fixed submission:
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
table=[]
for i in range(n):
  table.append([int(i) for i in input().split()])
Chk=True
for k in range(n):
  for i in range(n):
    for j in range(n):
      if table[i][k]+table[k][j]<table[i][j]:
        Chk=False
        table[i][j]=table[i][k]+table[k][j]

ans=0
for i in range(n):
  for j in range(i+1,n):
    C=True
    for k in range(n):
      if k==i or k==j:
        continue
      else:
        if table[i][k]+table[k][j]==table[i][j]:
          C=False
    if C:
      ans+=table[i][j]
print(ans if Chk else -1)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=lambda: sys.stdin.readline().rstrip()

from scipy.sparse.csgraph import floyd_warshall
n=int(input())
table=[]
for i in range(n):
  table.append([int(i) for i in input().split()])
d=floyd_warshall(csgraph=table, directed=False, return_predecessors=False)

Chk=True
for i in range(n):
  for j in range(n):
    if table[i][j]==int(d[i][j]):
      continue
    else:
      Chk=False
ans=0
for i in range(n):
  for j in range(i+1,n):
    C=True
    for k in range(n):
      if k==i or k==j:
        continue
      else:
        if table[i][k]+table[k][j]==table[i][j]:
          C=False
    if C:
      ans+=table[i][j]
print(ans if Chk else -1)

Fixed submission:
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
table=[]
for i in range(n):
  table.append([int(i) for i in input().split()])
Chk=True
for k in range(n):
  for i in range(n):
    for j in range(n):
      if table[i][k]+table[k][j]<table[i][j]:
        Chk=False
        table[i][j]=table[i][k]+table[k][j]

ans=0
for i in range(n):
  for j in range(i+1,n):
    C=True
    for k in range(n):
      if k==i or k==j:
        continue
      else:
        if table[i][k]+table[k][j]==table[i][j]:
          C=False
    if C:
      ans+=table[i][j]
print(ans if Chk else -1)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
table=[]
for i in range(n):
  table.append([int(_) for _ in input().split()])
T=[[1]*n for i in range(n)]
import itertools
chk,ans=True,0
for Com in itertools.combinations(range(n),3):
  a,b,c=Com[0],Com[1],Com[2]
  lab,lbc,lca=table[a][b],table[b][c],table[c][a]
  if lab>=lbc and lab>=lca:
    if lab>lbc+lca:
      chk=False
    elif lab==lbc+lca:
      T[a][b],T[b][a]=0,0
  elif lbc>=lab and lbc>=lca:
    if lbc>lab+lca:
      chk=False
    elif lbc==lab+lca:
      T[b][c],T[c][b]=0,0
  elif lca>=lab and lca>=lbc:
    if lca>lab+lbc:
      chk=False
    elif lca==lab+lbc:
      T[c][a],T[a][c]=0,0
for i in range(n):
  for j in range(i+1,n):
    if T[i][j]==1:
      ans+=table[i][j]
print(ans if chk==True else -1)

Fixed submission:
n=int(input())
table=[]
for i in range(n):
  table.append([int(_) for _ in input().split()])
T=[[1]*n for i in range(n)]
import itertools
chk,ans=True,0
for Com in itertools.combinations(range(n),3):
  a,b,c=Com[0],Com[1],Com[2]
  lab,lbc,lca=table[a][b],table[b][c],table[c][a]
  if lab>=lbc and lab>=lca:
    if lab>lbc+lca:
      chk=False
    elif lab==lbc+lca:
      T[a][b],T[b][a]=0,0
  elif lbc>=lab and lbc>=lca:
    if lbc>lab+lca:
      chk=False
    elif lbc==lab+lca:
      T[b][c],T[c][b]=0,0
  elif lca>=lab and lca>=lbc:
    if lca>lab+lbc:
      chk=False
    elif lca==lab+lbc:
      T[c][a],T[a][c]=0,0
for i in range(n):
  for j in range(i+1,n):
    if T[i][j]==1:
      ans+=table[i][j]
print(ans if chk==True else -1)
Buggy python submission (verdict: Runtime Error):
n=input()
if "9" in n:
    print("Yes")
elif:
    print("No")

Fixed submission:
n=input()
if "9" in n:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
n=input()
if 9 in n:
    print("Yes")
elif:
    print("No")

Fixed submission:
n=input()
if "9" in n:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
n=input()
if 9 in n:
    print("Yes")
elif
    print("No")

Fixed submission:
n=input()
if "9" in n:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
S=set()
for i in range(n):
  S=S^set([int(input())])
print(len(S))

Fixed submission:
n=int(input())
S=set()
for i in range(n):
  S^=set([input()])
print(len(S))

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
S=set()
for i in range(n):
  S=S^set([input()])
print(len(S))

Fixed submission:
n=int(input())
S=set()
for i in range(n):
  S^=set([input()])
print(len(S))

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
S=set()
for i in range(n):
  S=S^set([int(input())])
print(len(S))

Fixed submission:
n=int(input())
S=set()
for i in range(n):
  S^=set([input()])
print(len(S))

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
S=set()
for i in range(n):
  a=int(input())
  S=S^set([a])
print(len(S))

Fixed submission:
n=int(input())
S=set()
for i in range(n):
  S^=set([input()])
print(len(S))
Buggy python submission (verdict: Time Limit Exceeded):
import collections
n,m=map(int,input().split())
A=[]
for i in range(n):
  A.append([int(_) for _ in input().split()])
D=dict()
for i in range(m):
  D[i+1]=1
ans=n
for _ in range(m):
  p=[]
  append=p.append
  for i in range(n):
    for j in range(m):
      aij=A[i][j]
      if D[aij]==1:
        append(aij)
        break
  a,b=collections.Counter(p).most_common()[0]
  if b<ans:
    ans=b
  D[a]=0
print(ans)

Fixed submission:
import collections
n,m=map(int,input().split())
A=[]
for i in range(n):
  A.append([int(_) for _ in input().split()])
D=dict()
for i in range(m):
  D[i+1]=1
ans=n
for _ in range(m):
  p=[]
  for i in range(n):
    for j in range(m):
      if D[A[i][j]]==1:
        p.append(A[i][j])
        break
  pp=collections.Counter(p).most_common()
  a,b=pp[0]
  ans=min(ans,b)
  D[a]=0
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
n,m=map(int,input().split())
A=[]
for i in range(n):
  A.append([int(_) for _ in input().split()])
D=dict()
for i in range(m):
  D[i+1]=1
ans=n
for _ in range(m):
  p=[]
  for i in range(n):
    for j in range(m):
      if D[A[i][j]]==1:
        p.append(A[i][j])
        break
  a,b=collections.Counter(p).most_common()[0]
  if b<ans:
    ans=b
  D[a]=0
print(ans)

Fixed submission:
import collections
n,m=map(int,input().split())
A=[]
for i in range(n):
  A.append([int(_) for _ in input().split()])
D=dict()
for i in range(m):
  D[i+1]=1
ans=n
for _ in range(m):
  p=[]
  for i in range(n):
    for j in range(m):
      if D[A[i][j]]==1:
        p.append(A[i][j])
        break
  pp=collections.Counter(p).most_common()
  a,b=pp[0]
  ans=min(ans,b)
  D[a]=0
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
n,m=map(int,input().split())
A=[]
for i in range(n):
  A.append([int(_) for _ in input().split()])
D=dict()
for i in range(m):
  D[i+1]=1
ans=n
for _ in range(m):
  p=[]
  for i in range(n):
    for j in range(m):
      if D[A[i][j]]==1:
        p.append(A[i][j])
        break
  pp=collections.Counter(p).most_common()
  a,b=pp[0]
  ans=min(ans,b)
  D[a]=0
print(ans)

Fixed submission:
import collections
n,m=map(int,input().split())
A=[]
for i in range(n):
  A.append([int(_) for _ in input().split()])
D=dict()
for i in range(m):
  D[i+1]=1
ans=n
for _ in range(m):
  p=[]
  for i in range(n):
    for j in range(m):
      if D[A[i][j]]==1:
        p.append(A[i][j])
        break
  pp=collections.Counter(p).most_common()
  a,b=pp[0]
  ans=min(ans,b)
  D[a]=0
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
b=[]
k=0
for i in map(int, input().split()):
  if k%2==0:
    b.append(i)
    k+=1
  else:
    b.insert(0,i)
    k+=1
if n%2!=0:
  b=b[::-1]
print(*b,sep=" ")

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
print(*A[::-2],end=" ")
print(*A[N%2::2])

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
b=[]
for i in map(int, input().split()):
  b.append(i)
  b=b[::-1]
print(*b,sep=" ")
    

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
print(*A[::-2],end=" ")
print(*A[N%2::2])
Buggy python submission (verdict: Runtime Error):
def f(n):
  if n==1:
    return 1
  else:
    return f(n-1)*n

n,m=map(int,input().split())
ans=f(m)*f(n)
if n==m:
  ans*=2
elif abs(n-m)>1:
  ans=0
print(ans)

Fixed submission:
import math
n,m=map(int,input().split())
ans=math.factorial(m)*math.factorial(n)%(10**9+7)
if n==m:
  ans*=2
  ans%=(10**9+7)
elif abs(n-m)>1:
  ans=0
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
n,m=map(int,input().split())
ans=math.factorial(m)*math.factorial(n)
if n==m:
  ans*=2
elif abs(n-m)>1:
  ans=0
print(ans)


Fixed submission:
import math
n,m=map(int,input().split())
ans=math.factorial(m)*math.factorial(n)%(10**9+7)
if n==m:
  ans*=2
  ans%=(10**9+7)
elif abs(n-m)>1:
  ans=0
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
n,m=map(int,input().split())
ans=math.factorial(m)*math.factorial(n)
if n==m:
  ans*=2
elif abs(n-m)>1:
  ans=0
print(ans)

Fixed submission:
import math
n,m=map(int,input().split())
ans=math.factorial(m)*math.factorial(n)%(10**9+7)
if n==m:
  ans*=2
  ans%=(10**9+7)
elif abs(n-m)>1:
  ans=0
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n=int(input())
Edge=[[] for i in range(n)]
XY=[]
append=XY.append
for i in range(n):
  x,y=map(int,input().split())
  append([i,x,y])
XY.sort(key=lambda x:x[1])
for i in range(1,n):
  n1,x1,y1=XY[i-1][0],XY[i-1][1],XY[i-1][2]
  n2,x2,y2=XY[i][0],XY[i][1],XY[i][2]
  Edge[n1].append([min(abs(x2-x1),abs(y2-y1)),n2])
  Edge[n2].append([min(abs(x2-x1),abs(y2-y1)),n1])
XY.sort(key=lambda x:x[2])
for i in range(1,n):
  n1,x1,y1=XY[i-1][0],XY[i-1][1],XY[i-1][2]
  n2,x2,y2=XY[i][0],XY[i][1],XY[i][2]
  Edge[n1].append([min(abs(x2-x1),abs(y2-y1)),n2])
  Edge[n2].append([min(abs(x2-x1),abs(y2-y1)),n1])
import heapq
def prim_heap():
  used=[True]*n
  Edgelist=[]
  for e in Edge[0]:
    heapq.heappush(Edgelist,e)
  used[0]=False
  res=0
  while len(Edgelist)!=0:
    minedge=heapq.heappop(Edgelist)
    if not used[minedge[1]]:
      continue
    v=minedge[1]
    used[v]=False
    for e in Edge[v]:
      if used[e[1]]:
        heapq.heappush(Edgelist,e)
    res+=minedge[0]
  return res
print(prim_heap())

Fixed submission:
import sys
input = sys.stdin.readline
n=int(input())
Edge=[[] for i in range(n)]
XY=[]
append=XY.append
for i in range(n):
  x,y=map(int,input().split())
  append([i,x,y])
XY.sort(key=lambda x:x[1])
for i in range(1,n):
  n1,x1,y1=XY[i-1][0],XY[i-1][1],XY[i-1][2]
  n2,x2,y2=XY[i][0],XY[i][1],XY[i][2]
  Edge[n1].append([min(abs(x2-x1),abs(y2-y1)),n2])
  Edge[n2].append([min(abs(x2-x1),abs(y2-y1)),n1])
XY.sort(key=lambda x:x[2])
for i in range(1,n):
  n1,x1,y1=XY[i-1][0],XY[i-1][1],XY[i-1][2]
  n2,x2,y2=XY[i][0],XY[i][1],XY[i][2]
  Edge[n1].append([min(abs(x2-x1),abs(y2-y1)),n2])
  Edge[n2].append([min(abs(x2-x1),abs(y2-y1)),n1])
import heapq
def prim_heap():
  used=[True]*n
  Edgelist=[]
  for e in Edge[0]:
    heapq.heappush(Edgelist,e)
  used[0]=False
  res=0
  while len(Edgelist)!=0:
    minedge=heapq.heappop(Edgelist)
    if not used[minedge[1]]:
      continue
    v=minedge[1]
    used[v]=False
    for e in Edge[v]:
      if used[e[1]]:
        heapq.heappush(Edgelist,e)
    res+=minedge[0]
  return res
print(prim_heap())
Buggy python submission (verdict: Runtime Error):
s=input()
S=[]
for i in range(len(s)):
  S.append(s[i])
print("yes" if len(setS))==len(s) else "No")

Fixed submission:
s=input()
S=[]
for i in range(len(s)):
  S.append(s[i])
print("yes" if len(set(S))==len(s) else "no")
Buggy python submission (verdict: Time Limit Exceeded):
import heapq
n=int(input())
A=[int(i) for i in input().split()]
AL=A[:n]
AR=[]
for i in range(2*n,3*n):
  AR.append(-A[i])
ALS,ARS=[0]*(n+1),[0]*(n+1)
ALS[0],ARS[0]=sum(AL),-sum(AR)
heapq.heapify(AL)
heapq.heapify(AR)
for i in range(n):
  heapq.heappushpop(AL,A[n+i])
  ALS[i+1]+=sum(AL)
  heapq.heappushpop(AR,-A[2*n-i-1])
  ARS[i+1]+=-sum(AR)
ARS=ARS[::-1]
ans=-float("inf")
for i in range(n+1):
  ans=max(ans,ALS[i]-ARS[i])
print(ans)

Fixed submission:
import heapq
n=int(input())
A=[int(i) for i in input().split()]
AL=A[:n]
AR=[0]*n
for i in range(2*n,3*n):
  AR[i-2*n]-=A[i]
ALS,ARS=[0]*(n+1),[0]*(n+1)
ALS[0],ARS[0]=sum(AL),sum(AR)
heapq.heapify(AL)
heapq.heapify(AR)
for i in range(n):
  l,r=A[n+i],-A[2*n-i-1]
  heapq.heappush(AL,l)
  ALS[i+1]=ALS[i]+l-heapq.heappop(AL)
  heapq.heappush(AR,r)
  ARS[i+1]=ARS[i]+r-heapq.heappop(AR)
ans=-float("inf")
for i in range(n+1):
  ans=max(ans,ALS[i]+ARS[n-i])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
n=int(input())
A=[int(i) for i in input().split()]
AL=A[:n]
AR=[]
for i in range(2*n,3*n):
  AR.append(-A[i])
ALS,ARS=[0]*(n+1),[0]*(n+1)
ALS[0],ARS[0]=sum(AL),-sum(AR)
heapq.heapify(AL)
heapq.heapify(AR)
for i in range(n):
  heapq.heappushpop(AL,A[n+i])
  ALS[i+1]+=sum(AL)
  heapq.heappushpop(AR,-A[2*n-i-1])
  ARS[i+1]+=-sum(AR)
ARS=ARS[::-1]
ans=-float("inf")
for i in range(n+1):
  ans=max(ans,ALS[i]-ARS[i])
print(ans)

Fixed submission:
import heapq
n=int(input())
A=[int(i) for i in input().split()]
AL=A[:n]
AR=[0]*n
for i in range(2*n,3*n):
  AR[i-2*n]-=A[i]
ALS,ARS=[0]*(n+1),[0]*(n+1)
ALS[0],ARS[0]=sum(AL),sum(AR)
heapq.heapify(AL)
heapq.heapify(AR)
for i in range(n):
  l,r=A[n+i],-A[2*n-i-1]
  heapq.heappush(AL,l)
  ALS[i+1]=ALS[i]+l-heapq.heappop(AL)
  heapq.heappush(AR,r)
  ARS[i+1]=ARS[i]+r-heapq.heappop(AR)
ans=-float("inf")
for i in range(n+1):
  ans=max(ans,ALS[i]+ARS[n-i])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
n=int(input())
A=[int(i) for i in input().split()]
AL=A[:n]
ALS=[0]*(n+1)
ALS[0]=sum(AL)
heapq.heapify(AL)
for i in range(n):
  heapq.heappushpop(AL,A[n+i])
  ALS[i+1]+=sum(AL)
AR=[]
for i in range(2*n,3*n):
  AR.append(-A[i])
ARS=[0]*(n+1)
ARS[0]=-sum(AR)
heapq.heapify(AR)
for i in range(n):
  heapq.heappushpop(AR,-A[2*n-i-1])
  ARS[i+1]+=-sum(AR)
ARS=ARS[::-1]
ans=-float("inf")
for i in range(n+1):
  ans=max(ans,ALS[i]-ARS[i])
print(ans)

Fixed submission:
import heapq
n=int(input())
A=[int(i) for i in input().split()]
AL=A[:n]
AR=[0]*n
for i in range(2*n,3*n):
  AR[i-2*n]-=A[i]
ALS,ARS=[0]*(n+1),[0]*(n+1)
ALS[0],ARS[0]=sum(AL),sum(AR)
heapq.heapify(AL)
heapq.heapify(AR)
for i in range(n):
  l,r=A[n+i],-A[2*n-i-1]
  heapq.heappush(AL,l)
  ALS[i+1]=ALS[i]+l-heapq.heappop(AL)
  heapq.heappush(AR,r)
  ARS[i+1]=ARS[i]+r-heapq.heappop(AR)
ans=-float("inf")
for i in range(n+1):
  ans=max(ans,ALS[i]+ARS[n-i])
print(ans)
Buggy python submission (verdict: Runtime Error):
h,w=map(int,input().split())
if h*w%3==0:
  print(0)
else:
  ans=min(h,w)
  hh=h//2
  for ww in range(1,w):
    A=[hh*ww,(h-hh)*ww,h*(w-ww)]
    ans=min(ans,max(A)-min(A))
  ww=w//2
  for hh in range(1,h):
    B=[ww*hh,(w-ww)*hh,(h-hh)*w]
    ans=min(ans,max(B)-min(B))
print(ans)

Fixed submission:
h,w=map(int,input().split())
if h*w%3==0:
  print(0)
else:
  ans=min(h,w)
  hh=h//2
  for ww in range(1,w):
    A=[hh*ww,(h-hh)*ww,h*(w-ww)]
    ans=min(ans,max(A)-min(A))
  ww=w//2
  for hh in range(1,h):
    B=[ww*hh,(w-ww)*hh,(h-hh)*w]
    ans=min(ans,max(B)-min(B))
  print(ans)
Buggy python submission (verdict: Runtime Error):
List=list(input().upper().split())
for s in List:
  print(n[0],end="")

Fixed submission:
List=list(input().upper().split())
for s in List:
  print(s[0],end="")

Buggy python submission (verdict: Runtime Error):
List=list(input().split())
for n in List:
  print(n[0].Upper(),end="")

Fixed submission:
List=list(input().upper().split())
for s in List:
  print(s[0],end="")
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
count=0
A=[int(i) for i in input().split()]
if A[0]==0:
  A[0]+=1
  count+=1
elif A[0]<0:
  for i in range(len(A)):
    A[i]*=(-1)
for i in range(1,len(A)):
  s=sum(A[:i+1])
  if i%2==0:
    if s<=0:
      A[i]+=1-s
      count+=1-s
  else:
    if s>=0:
      A[i]-=1+s
      count+=1+s
print(count)

Fixed submission:
n=input()
a=[int(i) for i in input().split()]
def chk(a,t):
    ans=0
    x=0
    for i in a:
        x+=i
        if t==True and x<1:
            ans+=1-x
            x=1
        elif t==False and x>-1:
            ans+=x+1
            x=-1
        t=not t
    return ans
print(min(chk(a,True),chk(a,False)))

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
count=0
A=[int(i) for i in input().split()]
if A[0]==0:
  A[0]+=1
  count+=1
elif A[0]<0:
  for i in range(len(A)):
    A[i]*=(-1)
for i in range(1,len(A)):
  if i%2==0:
    while sum(A[:i+1])<=0:
      A[i]+=1
      count+=1
  else:
    while sum(A[:i+1])>=0:
      A[i]-=1
      count+=1
print(count)

Fixed submission:
n=input()
a=[int(i) for i in input().split()]
def chk(a,t):
    ans=0
    x=0
    for i in a:
        x+=i
        if t==True and x<1:
            ans+=1-x
            x=1
        elif t==False and x>-1:
            ans+=x+1
            x=-1
        t=not t
    return ans
print(min(chk(a,True),chk(a,False)))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=lambda: sys.stdin.readline().rstrip()
n,m=map(int,input().split())
E=[]
for _ in range(m):
  E.append(tuple(int(i) for i in input().split()))
q=int(input())
Q=[]
for _ in range(q):
  Q.append(tuple(int(i) for i in input().split()))

DP=[[[0]*2 for i in range(n)] for j in range(11)]
for i in range(q):
  v,d,c=Q[i]
  DP[d][v-1][0]=i+1
  DP[d][v-1][1]=c

for d in range(10)[::-1]:
  for v in range(n):
    if DP[d+1][v][0]>DP[d][v][0]:
      DP[d][v]=DP[d+1][v]
  for e in range(m):
    a,b=E[e]
    a-=1
    b-=1
    if DP[d+1][a][0]>DP[d][b][0]:
      DP[d][b]=DP[d+1][a]
    if DP[d+1][b][0]>DP[d][a][0]:
      DP[d][a]=DP[d+1][b]
for i in range(n):
  print(DP[0][i][1])




Fixed submission:
import sys
input=lambda: sys.stdin.readline().rstrip()
n,m=map(int,input().split())
E=[]
for _ in range(m):
  E.append(tuple(int(i) for i in input().split()))
q=int(input())
Q=[]
for _ in range(q):
  Q.append(tuple(int(i) for i in input().split()))

DP=[[[0]*2 for i in range(n)] for j in range(11)]
for i in range(q):
  v,d,c=Q[i]
  DP[d][v-1][0]=i+1
  DP[d][v-1][1]=c

for d in range(10)[::-1]:
  for v in range(n):
    if DP[d+1][v][0]>DP[d][v][0]:
      DP[d][v]=DP[d+1][v]
  for e in range(m):
    a,b=E[e]
    a-=1
    b-=1
    if DP[d+1][a][0]>DP[d][b][0]:
      DP[d][b]=DP[d+1][a]
    if DP[d+1][b][0]>DP[d][a][0]:
      DP[d][a]=DP[d+1][b]
for i in range(n):
  print(DP[0][i][1])
Buggy python submission (verdict: Runtime Error):
import collections
import heapq
n=int(input())
A=[int(i) for i in input().split()]
Ans=[0]*n
M=[0]#自分より前の最大値をメモ。これ以下だと現れない
for i in range(n):
  M.append(max(M[-1],A[i]))
D=collections.defaultdict(int)
H=[]
for i in range(n):
  j=n-1-i
  if A[j]<=M[j]:
    heapq.heappush(H,-A[j])#出現しないインデックスの数を管理。大きいほうから取り出す。
  else:
    Ans[j]=(A[j]-M[j])*(D[A[j]]+1)#自分より前の最大値と自分の差かける自分自身と同じ数のこれまでの出現回数
    D[M[j]]+=D[A[j]]+1#自分自身より後ろの自分と同じ数全てを自分より前の最大値まで減らすことで増える分
    ct=0
    while H:#自分より後ろで自分より小さいが、自分の前の最大値より大きいものを全て見る
      a=heapq.heappop(H)
      a=-a
      if a<=M[j]:
        heapq.heappush(H,-a)
        break
      else:
        Ans[j]+=a-M[j]
        D[M[j]]+=1

for a in Ans:
  print(Ans)


Fixed submission:
import collections
import heapq
n=int(input())
A=[int(i) for i in input().split()]
Ans=[0]*n
M=[0]
for i in range(n):
  M.append(max(M[-1],A[i]))
D=collections.defaultdict(int)
H=[]
for i in range(n):
  j=n-1-i
  if A[j]<=M[j]:
    heapq.heappush(H,-A[j])
  else:
    Ans[j]=(A[j]-M[j])*(D[A[j]]+1)
    D[M[j]]+=D[A[j]]+1
    ct=0
    while H:
      a=heapq.heappop(H)
      a=-a
      if a<=M[j]:
        heapq.heappush(H,-a)
        break
      else:
        Ans[j]+=a-M[j]
        D[M[j]]+=1

for a in Ans:
  print(a)