Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
lst=[[] for _ in range(M)]
for i in range(M):
  lst[i]=list(map(int,input().split()))
ans=0
visited=[]
ini=lst.pop(0)
tmp=[i for i in range(ini[0],ini[1]+1)]

def f(tmp):
  if len(lst)==0:
    return len(tmp)
  else:
    l=lst.pop(0)
    v1,v2=l[0],l[1]
    if tmp==[]:
      return 0
    else:
      m1=v1
      M1=v2
      m2=min(tmp)
      M2=max(tmp)
      m,M=max(m1,m2),min(M1,M2)
      tmp=[i for i in range(m,M+1)]
      return f(tmp)
    
print(f(tmp))

Fixed submission:
N,M=map(int,input().split())
lst=[[] for _ in range(M)]
dif=10**19
v1,v2=map(int,input().split())
for i in range(M-1):
  v_1,v_2=map(int,input().split())
  v1,v2=max(v1,v_1),min(v2,v_2)
if v2-v1+1<=0:
  print(0)
else:
  print(v2-v1+1)
Buggy python submission (verdict: Runtime Error):
from collections import deque,defaultdict
N=int(input())
lst=defaultdict(list)
for i in range(N-1):
  u,v,w=map(int,input().split())
  lst[u].append([v,w])
  lst[v].append([u,w])

def dfs(d,col):
  if len(d)==0:
    return col
  s=d.pop()
  for i in lst[s]:
    v,w=i[0],i[1]
    lst[v].remove([s,w])
    d.append(v)
    if w%2==0:
      if col[u]!=-1:
        col[v]=col[u]
      elif col[v]!=-1:
        col[u]=col[v]
      else:
        col[u]=0
        col[v]=0
    else:
      if col[u]!=-1:
        col[v]=(col[u]+1)%2
      elif col[v]!=-1:
        col[u]=(col[v]+1)%2
      else:
        col[u]=0
        col[v]=1
  return dfs(d,col)

d=deque([1])
col=defaultdict(int)
for i in range(1,N+1):
  if i==1:
    col[i]=0
  else:
    col[i]=-1
ans=dfs(d,col)
for i in range(1,N+1):
  print(ans[i])

Fixed submission:
N=int(input())
E=[[] for _ in range(N)]
for i in range(N-1):
  u,v,w=map(int,input().split())
  u-=1
  v-=1
  E[u].append((v,w))
  E[v].append((u,w))
color=[-1]*N
color[0]=0
stack=[0]
while stack:
  u=stack.pop()
  for v,w in E[u]:
    if color[v]==-1:
      stack.append(v)
      if w%2==0:
        color[v]=color[u]
      else:
        color[v]=1 if color[u]==0 else 0
for i in range(N):
  print(color[i])

Buggy python submission (verdict: Runtime Error):
from collections import deque
N=int(input())
uvw=[[0,0,0] for _ in range(N-1)]
for i in range(N-1):
  u,v,w=list(map(int,input().split()))
  uvw[i]=[u,v,w]

d=deque()
d.append(1)
visited=[None]*N
visited[0]=0
def dfs(d,visited):
  l1=[]
  l2=[]
  s=d.pop()
  tmp=[]
  for i in range(len(uvw)):
    if uvw[i][0]==s:
      l1.append(i)
    if uvw[i][1]==s:
      l2.append(i)
  if l1!=[]:
    for i in l1:
      d.append(uvw[i][1])
      visited[uvw[i][1]-1]=(uvw[i][2]+visited[s-1])%2
      tmp.append([uvw[i][0],uvw[i][1],uvw[i][2]])
  if l2!=[]:
    for j in l2:
      d.append(uvw[j][0])
      visited[uvw[j][0]-1]=(uvw[j][2]+visited[s-1])%2
      tmp.append([uvw[j][0],uvw[j][1],uvw[j][2]])
  for lst in tmp:
    uvw.remove(lst)
  if len(d)==0 or (None not in visited):
    return visited
  return dfs(d,visited)

ans=dfs(d,visited)
for i in range(N):
  print(ans[i])

Fixed submission:
N=int(input())
E=[[] for _ in range(N)]
for i in range(N-1):
  u,v,w=map(int,input().split())
  u-=1
  v-=1
  E[u].append((v,w))
  E[v].append((u,w))
color=[-1]*N
color[0]=0
stack=[0]
while stack:
  u=stack.pop()
  for v,w in E[u]:
    if color[v]==-1:
      stack.append(v)
      if w%2==0:
        color[v]=color[u]
      else:
        color[v]=1 if color[u]==0 else 0
for i in range(N):
  print(color[i])
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
def gcd(a,b):
    if a==b:
      return a
    else:
      a,b=max(a,b),min(a,b)
      if a%b==0:
        return b
      else:
        return gcd(b,a%b)
def gcd_for_list(L):
    if len(L)==1:
      return L[0]
    for i in range(len(L)):
      if i==0:
        tmp=gcd(L[i],L[i+1])
      elif i==1:
        pass
      else:
        tmp=gcd(tmp,L[i])
    return tmp
ans=0
for i in range(0,n):
  if i==0:
    ans=max(ans,gcd_for_list(a[i+1:]))
  elif i==n-1:
    ans=max(ans,gcd_for_list(a[0:i]))
  else:
    l_r=a[0:i]
    l_l=a[i+1:]
    ans=max(ans,gcd(gcd_for_list(l_r),gcd_for_list(l_l)))
print(ans)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
def gcd(a,b):
    if a==b:
      return a
    else:
      a,b=max(a,b),min(a,b)
      if a%b==0:
        return b
      else:
        return gcd(b,a%b)
R=[]
L=[]
for i in range(n):
  if i==0:
    L.append(a[i])
    R.append(a[-i-1])
  else:
    vl,vr=gcd(a[i],L[-1]),gcd(a[-i-1],R[-1])
    L.append(vl)
    R.append(vr)
ans=0
for i in range(n):
  if i==0:
    ans=max(ans,R[-i-2])
  elif i==n-1:
    ans=max(ans,L[i-1])
  else:
    ans=max(ans,gcd(L[i-1],R[-i-2]))
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
lst=[]
ans=0
for i in range(5):
  a=int(input())
  if a%10==0:
    ans+=a
  else:
    lst.append(a)
C=[[] for _ in range(len(lst))]   
for i in range(len(lst)):
  v=lst[i]
  c=v%10
  C[i]=[-c,v]
C=sorted(C)
for i in range(len(lst)-1):
  v=C[i][1]
  c=-C[i][0]
  ans+=(v+(10-c))
print(ans+C[-1][1])

Fixed submission:
import sys
lst=[]
ans=0
for i in range(5):
  a=int(input())
  if a%10==0:
    ans+=a
  else:
    lst.append(a)
if len(lst)!=0:
  C=[[] for _ in range(len(lst))]   
  for i in range(len(lst)):
    v=lst[i]
    c=v%10
    C[i]=[-c,v]
  C=sorted(C)
  for i in range(len(lst)-1):
    v=C[i][1]
    c=-C[i][0]
    ans+=(v+(10-c))
  print(ans+C[-1][1])
else:
  print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
h=list(map(int,input().split()))
zeros=[]
prev=0
for i in  range(n):
  if h[i]==0:
    zeros.append((prev,i-1))
    prev=i+1
zeros.append((prev,n-1))
cnt=0
while zeros:
  l,r=zeros.pop()
  m=min(h[l:r+1])
  cnt+=m
  prev=l
  for i in range(l,r+1):
    h[i]-=m
    if h[i]==0:
      if i==l:
        prev=i+1
      else:
        if prev<=i-1:
          zeros.append((prev,i-1))
        prev=i+1
  if prev<=r:
    zeros.append((prev,r))
print(cnt)

Fixed submission:
n=int(input())
h=list(map(int,input().split()))
zeros=[]
prev=0
for i in  range(n):
  if h[i]==0:
    if i==0:
      prev=i+1
    else:
      if prev<=i-1:
        zeros.append((prev,i-1))
      prev=i+1
if prev<=n-1:
  zeros.append((prev,n-1))
cnt=0
while zeros:
  l,r=zeros.pop()
  m=min(h[l:r+1])
  cnt+=m
  prev=l
  for i in range(l,r+1):
    h[i]-=m
    if h[i]==0:
      if i==l:
        prev=i+1
      else:
        if prev<=i-1:
          zeros.append((prev,i-1))
        prev=i+1
  if prev<=r:
    zeros.append((prev,r))
print(cnt)
Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
h=[]
for i in range(N):
  h.append(int(input()))
h=sorted(h,reverse=True)
tmp=10**10
for i in range(K):
  tmp=min(tmp,h[i]-h[i+K-1])
print(tmp)

Fixed submission:
N,K=map(int,input().split())
h=[]
for i in range(N):
  h.append(int(input()))
h=sorted(h,reverse=True)
tmp=10**10
for i in range(N-K+1):
  tmp=min(tmp,h[i]-h[i+K-1])
print(tmp)
Buggy python submission (verdict: Time Limit Exceeded):
class BIT_2D():
    def __init__(self,h,w):
        self.h=h
        self.w=w 
        self.table=[[0]*(w+1) for _ in range(h+1)]

    def add(self,i,j,x):
        init_j=j
        while i<=self.h:
            while j<=self.w:
                self.table[i][j]+=x
                j+=(j&-j)
            j=init_j
            i+=(i&-i)
        return None

    def sum(self,i,j):
        s=0
        init_j=j
        while i>0:
            while j>0:
                s+=self.table[i][j]
                j-=(j&-j)
            j=init_j
            i-=(i&-i)
        return s
      
n,m,q=map(int,input().split())
bit2d=BIT_2D(n,n)
for i in range(m):
  i,j=map(int,input().split())
  bit2d.add(i,j,1)
for i in range(q):
  i,j=map(int,input().split())
  ans=bit2d.sum(j,j)-bit2d.sum(j,i-1)-bit2d.sum(i-1,j)+bit2d.sum(i-1,i-1)
  print(ans)

Fixed submission:
class BIT_2D():
    def __init__(self,h,w):
        self.h=h
        self.w=w 
        self.table=[[0]*(w+1) for _ in range(h+1)]

    def add(self,i,j,x):
        init_j=j
        while i<=self.h:
            while j<=self.w:
                self.table[i][j]+=x
                j+=(j&-j)
            j=init_j
            i+=(i&-i)
        return None

    def sum(self,i,j):
        s=0
        init_j=j
        while i>0:
            while j>0:
                s+=self.table[i][j]
                j-=(j&-j)
            j=init_j
            i-=(i&-i)
        return s
      
n,m,q=map(int,input().split())
bit2d=BIT_2D(n,n)
for i in range(m):
  i,j=map(int,input().split())
  bit2d.add(i,j,1)
for i in range(q):
  i,j=map(int,input().split())
  ans=bit2d.sum(j,j)-bit2d.sum(j,i-1)-bit2d.sum(i-1,j)+bit2d.sum(i-1,i-1)
  print(ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())
lst=list(map(int,input().split()))
lst_=sorted(lst)
def f(b):
  ans=0
  for i in range(1,N+1):
    ans+=abs(lst[i-1]-(b+i))
  return ans

if N%2==1:
  b=lst_[(N-1)//2]-((N-1)//2+1)
  print(f(b))
else:
  b1=lst_[N//2]-(N//2+1)
  b2=lst_[b1-1]-(b1+1)
  print(min(f(b1),f(b2)))

Fixed submission:
import copy
N=int(input())
lst=list(map(int,input().split()))
lst2=copy.copy(lst)
for i in range(1,N+1):
  lst2[i-1]-=i
lst2=sorted(lst2)
b=lst2[N//2]
ans=0
for i in range(N):
  ans+=abs(lst[i]-(b+i+1))
print(ans)
Buggy python submission (verdict: Runtime Error):
 N,K=map(int,input().split())
a=list(map(int,input().split()))
index=a.index(1)
l=index
r=index
cnt=0
if index<=(N//2-1 if N%2==0 else N//2):
  while l!=0:
    if cnt==0:
      if l-K+1<0:
        r=K-1
    l=max(0,l-K+1)
    cnt+=1
  while r!=N-1:
    r=min(N-1,r+K-1)
    cnt+=1
  print(cnt)
else:
  while r!=N-1:
    if cnt==0:
      if r+K-1>N-1:
        l=N-K
    r=min(N-1,r+K-1)
    cnt+=1
  while l!=0:
    l=max(0,l-K+1)
    cnt+=1
  print(cnt)

Fixed submission:
N,K=map(int,input().split())
if (N-1)%(K-1)==0:
  print((N-1)//(K-1))
else:
  print((N-1)//(K-1)+1)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
a=list(map(int,input().split()))
acc_s=[]
acc_s.append(0)
for i in range(N):
  if i==0:
    acc_s.append(a[i])
  else:
    acc_s.append(a[i]+acc_s[-1])
cnt=0
for i in range(N):
  for j in range(i+1,N+1):
    if acc_s[j]-acc_s[i]==0:
      cnt+=1
print(cnt)

Fixed submission:
from collections import defaultdict
N=int(input())
a=list(map(int,input().split()))
acc_s=[]
acc_s.append(0)
dic=defaultdict(int)
dic[0]=1
for i in range(N):
  if i==0:
    acc_s.append(a[i])
    dic[a[i]]+=1
  else:
    v=a[i]+acc_s[-1]
    dic[v]+=1
    acc_s.append(v)
cnt=0
for key in dic.keys():
  v=dic[key]
  cnt+=(v*(v-1)//2)
print(cnt)
Buggy python submission (verdict: Runtime Error):
import sys
N,H=map(int,input().split())
B=[]
index=-1
tmp=-1
for i in range(N):
  a,b=map(int,input().split())
  B.append(b)
  if a>tmp:
    index=i
    tmp=a
a_,b_=tmp,B[index]
cnt=0
if sum(B)>=H:
  B=sorted(B,reverse=True)
  while H>0:
    cnt+=1
    b=B.pop(0)
    H-=b
  print(cnt)
else:
  B.remove(b_)
  B=sorted(B,reverse=True)
  while len(B)!=0 :
    b=B.pop(0)
    if b<=a_:
      break
    H-=b
    cnt+=1
  if H-b_<=0:
    print(cnt+1)
    sys.exit()
  v=(H-b_)//a_
  cnt+=v
  H-=a_*v
  if 0=<H<=b_:
    cnt+=1
  else:
    cnt+=2
  print(cnt)

Fixed submission:
N,H=map(int,input().split())
B=[]
index=-1
tmp=-1
for i in range(N):
  a,b=map(int,input().split())
  B.append(b)
  if a>tmp:
    index=i
    tmp=a
a_,b_=tmp,B[index]
cnt=0
B=sorted(B,reverse=True)
while H>0 and len(B)!=0:
  b=B.pop(0)
  if b<a_:
    break
  H-=b
  cnt+=1
if H<=0:
  print(cnt)
else:
  v=H//a_
  if H%a_==0:
    cnt+=v
  else:
    cnt+=(v+1)
  print(cnt)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=sorted(list(map(int,input().split())))
B=list(map(int,input().split()))
C=sorted(list(map(int,input().split())))
ans=0
for i in range(N):
  val=B[i]
  mid_a=A[N//2-1]
  mid_c=C[N//2-1]
  if mid_a<val:
    count1=0
    for i in range(N//2,N):
      if A[i]<val:
        count1+=1
      else:
        break
    val1=N//2+count1
  else:
    count2=0
    for i in range(N//2):
      if A[i]<val:
        count2+=1
      else:
        break
    val1=count2
  if mid_c>val:
    count3=0
    for i in range(N//2):
      if C[i]<val:
        count3+=1
      else:
        break
    val2=N-count3
  else:
    for i in range(N//2,N):
      if C[i]>val:
        val2=N-i
        break
      else:
        if i==N:
          val2=0
        else:
          pass
  ans+=val1*val2
print(ans)

Fixed submission:
import bisect
N=int(input())
A=sorted(list(map(int,input().split())))
B=list(map(int,input().split()))
C=sorted(list(map(int,input().split())))
ans=0
for val in B:
  val1=bisect.bisect_left(A,val)
  val2=N-bisect.bisect_right(C,val)
  ans+=val1*val2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
G=[[] for _ in range(N)]
for i in range(N-1):
  x,y,d=map(int,input().split())
  x-=1
  y-=1
  G[x].append((y,d))
  G[y].append((x,d))
Q,K=map(int,input().split())
stack=[K-1]
seen=[]
dist=[float('inf')]*N
dist[K-1]=0
while stack:
  u=stack.pop()
  seen.append(u)
  for v,d in G[u]:
    if v not in seen:
      dist[v]=min(dist[v],dist[u]+d)
      stack.append(v)
for q in range(Q):
  x,y=map(int,input().split())
  print(dist[x-1]+dist[y-1])

Fixed submission:
N=int(input())
G=[[] for _ in range(N)]
for i in range(N-1):
  x,y,d=map(int,input().split())
  x-=1
  y-=1
  G[x].append((y,d))
  G[y].append((x,d))
Q,K=map(int,input().split())
stack=[K-1]
unseen=[1]*N
dist=[float('inf')]*N
dist[K-1]=0
while stack:
  u=stack.pop()
  unseen[u]=0
  for v,d in G[u]:
    if unseen[v]:
      dist[v]=min(dist[v],dist[u]+d)
      stack.append(v)
for q in range(Q):
  x,y=map(int,input().split())
  print(dist[x-1]+dist[y-1])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict,deque
import sys
N=int(input())
G=defaultdict(list)
for i in range(N-1):
  x,y,d=map(int,input().split())
  G[x].append((y,d))
  G[y].append((x,d))
Q,K=map(int,input().split())
stack=deque()
stack.append(K)
seen=[]
dist=[float('inf')]*N
dist[K-1]=0
while stack:
  u=stack.pop()
  seen.append(u)
  for v,d in G[u]:
    if v not in seen:
      dist[v-1]=min(dist[v-1],dist[u-1]+d)
      stack.append(v)
for q in range(Q):
  x,y=map(int,input().split())
  print(dist[x-1]+dist[y-1])

Fixed submission:
N=int(input())
G=[[] for _ in range(N)]
for i in range(N-1):
  x,y,d=map(int,input().split())
  x-=1
  y-=1
  G[x].append((y,d))
  G[y].append((x,d))
Q,K=map(int,input().split())
stack=[K-1]
unseen=[1]*N
dist=[float('inf')]*N
dist[K-1]=0
while stack:
  u=stack.pop()
  unseen[u]=0
  for v,d in G[u]:
    if unseen[v]:
      dist[v]=min(dist[v],dist[u]+d)
      stack.append(v)
for q in range(Q):
  x,y=map(int,input().split())
  print(dist[x-1]+dist[y-1])
Buggy python submission (verdict: Runtime Error):
N=int(input())
h=[]
a=list(map(int,input().split()))
cnt_dic=defaultdict(int)
for i in range(N):
  cnt_dic[a[i]]+=1
cnt_l=sorted(cnt_dic.values(),reverse=True)
ans=len(cnt_l)
tmp=0
for i in range(ans):
  if cnt_l[i]%2==0:
    tmp+=1
if tmp%2==0:
  pass
else:
  ans-=1
print(ans)

Fixed submission:
from collections import defaultdict
N=int(input())
h=[]
a=list(map(int,input().split()))
cnt_dic=defaultdict(int)
for i in range(N):
  cnt_dic[a[i]]+=1
cnt_l=sorted(cnt_dic.values(),reverse=True)
ans=len(cnt_l)
tmp=0
for i in range(ans):
  if cnt_l[i]%2==0:
    tmp+=1
if tmp%2==0:
  pass
else:
  ans-=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,K,L=map(int,input().split())

class UnionFind():
  def __init__(self,N):
    self.parents=list(range(N))
    self.size=[1]*N
  def find(self,x):
    if self.parents[x]==x:
      return x
    else:
      self.parents[x]=self.find(self.parents[x])
      return self.parents[x]
  def union(self,x,y):
    x,y=self.find(x),self.find(y)
    if x==y:
      return 
    if self.size[x]<self.size[y]:
      self.size[y]+=self.size[x]
      self.parents[x]=y
    else:
      self.size[x]+=self.size[y]
      self.parents[y]=x
      
ans=['1']*N
UF=UnionFind(N)
for i in range(K):
  x,y=map(int,input().split())
  UF.union(x-1,y-1)
tmp=[]
for j in range(L):
  x,y=map(int,input().split())
  if UF.find(x-1)==UF.find(y-1):
    v=UF.find(x-1)
    ans[x-1]=str(int(ans[x-1])+1)
    ans[y-1]=str(int(ans[y-1])+1)
    tmp.append([v,x,y])
searched=[]
for k in range(len(tmp)-1):
  for l in range(k+1,len(tmp)):
    if tmp[k][0]==tmp[l][0]:
      x,y=tmp[k][1],tmp[k][2]
      z,w=tmp[l][1],tmp[l][2]
      tmp_l=[[x,z],[x,w],[y,z],[y,w]]
      if y==z:
        tmp_l.remove([y,z])
      for _ in tmp_l:
        if [tmp[k][0]]+_ not in tmp and _ not in searched :
          x,y=_[0],_[1]
          searched.append([x,y])
          ans[x-1]=str(int(ans[x-1])+1)
          ans[y-1]=str(int(ans[y-1])+1)      
print(' '.join(ans))

Fixed submission:
N,K,L=map(int,input().split())

class UnionFind():
  def __init__(self,N):
    self.parents=list(range(N))
    self.size=[1]*N
  def find(self,x):
    if self.parents[x]==x:
      return x
    else:
      self.parents[x]=self.find(self.parents[x])
      return self.parents[x]
  def union(self,x,y):
    x,y=self.find(x),self.find(y)
    if x==y:
      return 
    if self.size[x]<self.size[y]:
      self.size[y]+=self.size[x]
      self.parents[x]=y
    else:
      self.size[x]+=self.size[y]
      self.parents[y]=x

uf1=UnionFind(N)
uf2=UnionFind(N)
for i in range(K):
  x,y=map(int,input().split())
  uf1.union(x-1,y-1)
for j in range(L):
  x,y=map(int,input().split())
  uf2.union(x-1,y-1)

keys=[(uf1.find(x),uf2.find(x)) for x in range(N)]
count={}
for key in keys:
  if key in count:
    count[key]+=1
  else:
    count[key]=1
print(*[count[key] for key in keys])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int,input().split()))

ans = l[0]

for i in range(1,len(l)):
    ans = ans * l[i]
    if ans == 0:
        break

if ans >= 1000000000000000001:
    print(-1)
else:
    print(ans)
    

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

ans = l[0]

minn = min(l)

if (minn == 0):
    print(0)
else:
    for i in range(1,len(l)):
        ans = ans * l[i]

        if ans >= 1000000000000000001:
            break
    
    if ans >= 1000000000000000001:
        print(-1)
    else:
        print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
max,n = map(int,input().split())
l = list(map(int,input().split()))

double = [ i + max for i in l]
ll = l + double

sum = 0
home = 0
ans = 9999999
for i in range(n):
    for j in range(n-1):
        sum += ll[i+j+1] - ll[i+j]
        #print('ll[i+j+1]%d  -  ll[i+j]%d= sum%d    i=%d  j=%d'%(ll[i+j+1],ll[i+j],sum,i,j))

    ans = sum if sum < ans else ans
    #ans = min(ans,sum)
    sum = 0
    
print(ans)

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

ll = l[:]

ll.append(k)
ll.pop(0)
s = []
x = (l[0] + k) - l[-1]


for i,j in zip(l,ll):
    s.append(j - i)

print(k - max(s+[x]))
Buggy python submission (verdict: Runtime Error):
x,k,d=map(int,input().split())
ans=0
if x>k*d:
    ans=(x-k*d)
else:
    temp=k-(n//d)
    if temp %2==0:
        ans=n%d
    else:
        ans=d-n%d
print(ans)


Fixed submission:
x,k,d=map(int,input().split())
ans=0
if abs(x)>k*d:
    ans=(abs(x)-k*d)
else:
    temp=k-(x//d)
    if temp %2==0:
        ans=x%d
    else:
        ans=d-x%d
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
k=int(input())
if k%2==0:
    ans=-1
else:
    cnt=1
    cur=7
    while True:
        if cur%k==0:
            ans=cnt
            break
        if cnt>k:
            ans=-1
            break
        cnt+=1
        cur=(7*(10**cnt))//9
print(ans)


Fixed submission:
k = int(input())
if k % 2 == 0 or k % 5 == 0:
    print(-1)
    exit()
cnt, yep = 0, 0
while True:
    yep = (yep * 10 + 7) % k
    cnt += 1
    if yep == 0:
        break
print(cnt)
Buggy python submission (verdict: Runtime Error):
x,y=map(int,input().strip().split())

if x*4<b:
  print("No")
elif y%2!=0:
  print("No")
else:
  print("Yes")


Fixed submission:
x,y=map(int,input().strip().split())
if x*4<y or x*2>y:
  print("No")
elif y%2!=0:
  print("No")
else:
  print("Yes")
Buggy python submission (verdict: Runtime Error):
n = int(input())
a=int((str(n))[-1])
hon=[2,4,5,7,9]
pon=[0,1,6,8]
if a in hon:
  return "hon"
elif a in pon :
  return "pon"
else:
  return "bon"


Fixed submission:
n = int(input())
a=int((str(n))[-1])
hon=[2,4,5,7,9]
pon=[0,1,6,8]
if a in hon:
  print("hon")
elif a in pon :
  print("pon")
else:
  print("bon")

Buggy python submission (verdict: Runtime Error):

a=int(str(n)[-1])

if a == 2, 4, 5, 7, 9:
  return "hon"
elif a == 0, 1, 6 or 8:
  return "pon"
else:
  return "bon"

Fixed submission:
n = int(input())
a=int((str(n))[-1])
hon=[2,4,5,7,9]
pon=[0,1,6,8]
if a in hon:
  print("hon")
elif a in pon :
  print("pon")
else:
  print("bon")

Buggy python submission (verdict: Runtime Error):
n= int(input())
a=int(str(n)[-1])

if a == 2, 4, 5, 7, 9:
  return "hon"
elif a == 0, 1, 6 or 8:
  return "pon"
else:
  return "bon"

Fixed submission:
n = int(input())
a=int((str(n))[-1])
hon=[2,4,5,7,9]
pon=[0,1,6,8]
if a in hon:
  print("hon")
elif a in pon :
  print("pon")
else:
  print("bon")
Buggy python submission (verdict: Runtime Error):
k=int(input())
s=str(input())

if len(s)<=k:
  print(s)
  else:
    print(s[0:k]+"...")

Fixed submission:
k=int(input())
s=str(input())

if len(s)<=k:
  print(s)
else:
    print(s[0:k]+"...")

Buggy python submission (verdict: Runtime Error):
k=int(input())
s=str(input())
if len(s)<=k:
  print(k)
  else:
    print(s.replace(s[K:len(s)],"..."))

Fixed submission:
k=int(input())
s=str(input())

if len(s)<=k:
  print(s)
else:
    print(s[0:k]+"...")

Buggy python submission (verdict: Runtime Error):
if len(S)<=K:
  print(K)
else:
  print(S.replace(S[K:len(S)],"..."))

Fixed submission:
k=int(input())
s=str(input())

if len(s)<=k:
  print(s)
else:
    print(s[0:k]+"...")
Buggy python submission (verdict: Runtime Error):
n,k = map(int, input().split())

count=[0]*(n+1)

for i in range(n):
  d=int(input())
  a=list(map(int, input().split()))
  ans=0
  for i in range(len(a)):
         count[i]+=1
print(count.count(0))

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

count=[0]*(n)

for i in range(k):
  d=int(input())
  a=list(map(int, input().split()))
  for x in a:
    count[x-1]+=1
print(count.count(0))
Buggy python submission (verdict: Runtime Error):
import math
n=int(input())
x=list(map(int,input().split()))
l=min(x)
r=max(x)
cost=[]
for i in range(l,r):
    curcost=0
    for j in range(n):
        curcost+=(x[j]-i)**2
    cost.append(curcost)
print(min(cost))

Fixed submission:
n=int(input())
x=list(map(int,input().split()))
l=min(x)
r=max(x)
cost=[]
for i in range(l,r+1):
    curcost=0
    for j in range(n):
        curcost+=(x[j]-i)**2
    cost.append(curcost)
print(min(cost))
Buggy python submission (verdict: Runtime Error):
import math
a,b=map(int,input().strip().split())
ans=0
sockets=1
while sockets<b:
  outlets-=1
  sockets+=a
  ans+=1
print(ans)

Fixed submission:
import math
a,b=map(int,input().strip().split())
ans=0
sockets=1
while sockets<b:
  sockets-=1
  sockets+=a
  ans+=1
print(ans)

Buggy python submission (verdict: Runtime Error):
import math
a,b=input.split(" ")
print(math.ceil(a/b))

Fixed submission:
import math
a,b=map(int,input().strip().split())
ans=0
sockets=1
while sockets<b:
  sockets-=1
  sockets+=a
  ans+=1
print(ans)