Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    S=readline().strip()
    li=[0]*2019
    n=int(S)
    for i in range(len(S)):
        if i==0:
            pass
        else:
            n-=int(S[i-1])*pow(10,(len(S)-i))
        li[n%2019]+=1

    res=li[0]
    for i in range(2019):
        res+=li[i]*(li[i]-1)//2
    print(res)
    
if __name__=="__main__":
    main()

Fixed submission:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    S=readline().strip()
    li=[0]*2019
    n=int(S[-1])%2019
    m=1
    for i in range(len(S)):
        if i==0:
            pass
        else:
            m*=10
            m%=2019
            l=int(S[len(S)-i-1])
            n+=m*l
            n%=2019
        li[n]+=1

    res=li[0]
    for i in range(2019):
        res+=li[i]*(li[i]-1)//2
    print(res)
    
if __name__=="__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    S=readline().strip()
    li=[0]*2019
    n=int(S)
    for i in range(len(S)):
        if i==0:
            pass
        else:
            n-=int(S[i-1])*10**(len(S)-i)
        li[n%2019]+=1

    res=li[0]
    for i in range(2019):
        res+=li[i]*(li[i]-1)//2
    print(res)
    
if __name__=="__main__":
    main()

Fixed submission:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    S=readline().strip()
    li=[0]*2019
    n=int(S[-1])%2019
    m=1
    for i in range(len(S)):
        if i==0:
            pass
        else:
            m*=10
            m%=2019
            l=int(S[len(S)-i-1])
            n+=m*l
            n%=2019
        li[n]+=1

    res=li[0]
    for i in range(2019):
        res+=li[i]*(li[i]-1)//2
    print(res)
    
if __name__=="__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    S=readline().strip()
    li=[0]*2019
    for i in range(len(S)):
        n=int(S[i:])
        li[n%2019]+=1

    res=li[0]
    for i in range(2019):
        res+=li[i]*(li[i]-1)//2
    print(res)
    
if __name__=="__main__":
    main()

Fixed submission:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    S=readline().strip()
    li=[0]*2019
    n=int(S[-1])%2019
    m=1
    for i in range(len(S)):
        if i==0:
            pass
        else:
            m*=10
            m%=2019
            l=int(S[len(S)-i-1])
            n+=m*l
            n%=2019
        li[n]+=1

    res=li[0]
    for i in range(2019):
        res+=li[i]*(li[i]-1)//2
    print(res)
    
if __name__=="__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import sys
def main():
    input=sys.stdin.readline
    S=input()
    dp=[[0,0] for i in range(len(S)+1)]
    dp[0][1]=1
    for i in range(1,len(S)+1):
        for j in (0,1):
            if j==0:
                dp[i][0]=min(dp[i-1][0]+int(S[i-1]),dp[i-1][1]+10-int(S[i-1]))
            elif j==1:
                dp[i][1]=min(dp[i-1][0]+int(S[i-1])+1,dp[i-1][1]+10-int(S[i-1])-1)

    print(dp[len(S)][0])

if __name__=="__main__":
    main()

Fixed submission:
import sys
def main():
    input=sys.stdin.readline
    S=input().strip()
    dp=[[0,0] for i in range(len(S)+1)]
    dp[0][1]=1
    for i in range(1,len(S)+1):
        for j in (0,1):
            if j==0:
                dp[i][0]=min(dp[i-1][0]+int(S[i-1]),dp[i-1][1]+10-int(S[i-1]))
            elif j==1:
                dp[i][1]=min(dp[i-1][0]+int(S[i-1])+1,dp[i-1][1]+10-int(S[i-1])-1)

    print(dp[len(S)][0])

if __name__=="__main__":
    main()

Buggy python submission (verdict: Runtime Error):
import sys
def main():
    input=sys.stdin.readline
    S=input()
    dp=[[0,0] for i in range(len(S)+1)]
    dp[0][1]=1
    for i in range(1,len(S)+1):
        for j in (0,1):
            if j==0:
                dp[i][0]=min(dp[i-1][0]+int(S[i-1]),dp[i-1][1]+10-int(S[i-1]))
            elif j==1:
                dp[i][1]=min(dp[i-1][0]+int(S[i-1])+1,dp[i-1][1]+10-int(S[i-1])-1)

    print(dp[len(S)][0])

if __name__=="__main__":
    main()

Fixed submission:
import sys
def main():
    input=sys.stdin.readline
    S=input().strip()
    dp=[[0,0] for i in range(len(S)+1)]
    dp[0][1]=1
    for i in range(1,len(S)+1):
        for j in (0,1):
            if j==0:
                dp[i][0]=min(dp[i-1][0]+int(S[i-1]),dp[i-1][1]+10-int(S[i-1]))
            elif j==1:
                dp[i][1]=min(dp[i-1][0]+int(S[i-1])+1,dp[i-1][1]+10-int(S[i-1])-1)

    print(dp[len(S)][0])

if __name__=="__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import math
H,N=map(int,input().split())
A=[]
B=[]
for i in range(N):
   a,b=map(int,input().split())
   A.append(a)
   B.append(b)

DP=[[0]*(H+1) for i in range(N)]
DP.insert(0,[math.inf]*(H+max(A)))
DP[0][0]=0

for i in range(1,N+1):
   for j in range(1,H+1):
      if j-A[i-1]>0:
         DP[i][j]=min(DP[i-1][j],DP[i][j-A[i-1]]+B[i-1])
      else:
         DP[i][j]=min(DP[i-1][j],B[i-1])

print(DP[N][H])

Fixed submission:
H,N=map(int,input().split())
A=[]
B=[]
for i in range(N):
   a,b=map(int,input().split())
   A.append(a)
   B.append(b)

DP=[[0]*(H+max(A)) for i in range(N)]
DP.insert(0,[10**8+1]*(H+max(A)))
DP[0][0]=0

for i in range(1,N+1):
   for j in range(1,H+max(A)):
      if j-A[i-1]>0:
         DP[i][j]=min(DP[i-1][j],DP[i][j-A[i-1]]+B[i-1])
      else:
         DP[i][j]=min(DP[i-1][j],B[i-1])

print(DP[N][H])
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
from fractions import gcd
def main():
    #入力
    readline=stdin.readline
    N=int(readline())
    A=list(map(int,readline().split()))

    mod=10**9+7
    l=1
    for i in range(N):
        l=l*A[i]//gcd(l,A[i])

    res=0
    for i in range(N):
        res+=l//A[i]
        res%=mod
    
    print(res)

if __name__=="__main__":
    main()

Fixed submission:
from fractions import gcd 

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

def lcm(a,b):
   return a*b//gcd(a,b)

lcm_number=1

for i in range(N):
   lcm_number=lcm(lcm_number,A[i])

count=0
for i in range(N):
   count+=lcm_number//A[i]

print(count%(10**9+7))
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
numbers=list(map(int,input().strip().split()))

target_number=1
i=0

while len(numbers)>i+1:
  if(target_number in numbers):
    del numbers[i:numbers.index(target_number)]
    i+=1
    target_number+=1
  else:
    del numbers[i:]
  
if(len(numbers)>1):
  print(N-len(numbers))
  
elif(len(numbers)==1):
  if(numbers[0]==1):
    print(N-1)
  elif(numbers[0]!=1):
    print(-1)
    
elif(len(numbers)==0):
  print(-1)

Fixed submission:
N=int(input())
numbers=list(map(int,input().strip().split()))

target_number=1

for i in range(N):
  if(numbers[i]==target_number):
    target_number+=1
  
if(target_number>1):
  print(N-target_number+1)
  
elif(target_number==1):
  if(1 in numbers):
    print(N-1)
  else:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
numbers=list(map(int,input().strip().split()))

target_number=1
i=0

while len(numbers)>i+1:
  if(target_number in numbers):
    del numbers[i:numbers.index(target_number)]
    i+=1
    target_number+=1
  else:
    del numbers[i:]
  
if(len(numbers)>1):
  print(N-len(numbers))
  
elif(len(numbers)==1):
  if(numbers[0]==1):
    print(N-1)
  elif(numbers[0]!=1):
    print(-1)
    
elif(len(numbers)==0):
  print(-1)

Fixed submission:
N=int(input())
numbers=list(map(int,input().strip().split()))

target_number=1

for i in range(N):
  if(numbers[i]==target_number):
    target_number+=1
  
if(target_number>1):
  print(N-target_number+1)
  
elif(target_number==1):
  if(1 in numbers):
    print(N-1)
  else:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
numbers=list(map(int,input().strip().split()))

L=len(numbers)
target_number=1
i=0
while L>i+1:
  if(numbers[i]!=target_number):
    numbers.pop(target_number-1)
    L-=1
  elif(numbers[i]==target_number):
    i+=1
    target_number+=1

if(L>1):
  print(N-target_number)
  
elif(L==1):
  if(numbers[0]==1):
    print(N-1)
  elif(numbers[0]!=1):
    print(-1)

Fixed submission:
N=int(input())
numbers=list(map(int,input().strip().split()))

target_number=1

for i in range(N):
  if(numbers[i]==target_number):
    target_number+=1
  
if(target_number>1):
  print(N-target_number+1)
  
elif(target_number==1):
  if(1 in numbers):
    print(N-1)
  else:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
numbers=list(map(int,input().strip().split()))

target_number=1
i=0
while len(numbers)>i+1:
  if(numbers[i]!=target_number):
    numbers.pop(target_number-1)
  elif(numbers[i]==target_number):
    i+=1
    target_number+=1

if(len(numbers)>1):
  print(N-target_number)
  
elif(len(numbers)==1):
  if(numbers[0]==1):
    print(N-1)
  elif(numbers[0]!=1):
    print(-1)

Fixed submission:
N=int(input())
numbers=list(map(int,input().strip().split()))

target_number=1

for i in range(N):
  if(numbers[i]==target_number):
    target_number+=1
  
if(target_number>1):
  print(N-target_number+1)
  
elif(target_number==1):
  if(1 in numbers):
    print(N-1)
  else:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
bin_A=[bin(c) for c in A]
flags=[True]*N

count=0
for keta in range(60):
   count_0=0
   count_1=0
   for i in range(N):
      if flags[i]:
         if bin_A[i][-1*(keta+1)]=="b":
            count_0+=1
            flags[i]=False
         elif bin_A[i][-1*(keta+1)]=="0":
            count_0+=1
         else:
            count_1+=1
      elif flags[i]==False:
         count_0+=1
   count+=count_0*count_1*2**keta

print(count%(10**9+7))

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
bin_A=[bin(c) for c in A]
flags=[True]*N

count=0
for keta in range(60):
   count_0=0
   count_1=0
   for i in range(N):
      if flags[i]:
         if bin_A[i][-1*(keta+1)]=="b":
            count_0+=1
            flags[i]=False
         elif bin_A[i][-1*(keta+1)]=="0":
            count_0+=1
         else:
            count_1+=1
      elif flags[i]==False:
         count_0+=1
   count+=count_0*count_1*2**keta

print(count%(10**9+7))
Buggy python submission (verdict: Runtime Error):
N,K=input().split()
N,K=[int(N),int(K)]
A=list(map(int,input().split()))
F=list(map(int,input().split()))

A=sorted(A)
F=sorted(F,reverse=True)
time=list()

for i in range(N):
   time.append(A[i]*F[i])

goal_max=max(time)
goal_min=0
goal_ave=int((goal_max+goal_min)/2)
goal=int((goal_max+goal_min)/2)

col={"-1":"NG"}
for i in range(goal_max+1):
   col[str(i)]=None

flag=True

while(flag):
   counter=0
   print(goal)
   for i in range(N):
      counter+=(A[i]-int(goal/F[i]))

   if(counter<=K):
      if col[str(goal-1)]=="NG":
         print(goal)
         flag=False
      else:
         col[str(goal)]="OK"
         if goal==int((goal+goal_ave)/2):
            goal=int((goal+goal_ave)/2)-1
            print("b")         
         #elif goal!=goal_ave:
         #   goal=int((goal+goal_ave)/2)
         #   print("a")
         else:
            goal=int((goal+goal_min)/2)
            print("c")

   elif(counter>K):
      if col[str(goal+1)]=="OK":
         print(goal+1)
         flag=False
      else:
         col[str(goal)]="NG"
         if goal==int((goal+goal_ave)/2):
            goal=int((goal+goal_ave)/2)+2
         #elif goal!=goal_ave:
         #   goal=int((goal+goal_ave)/2)    
         else:
            goal=int((goal+goal_max)/2)

Fixed submission:
a,b=input().split()
a,b=[int(a),int(b)]

if(1<=a and a<=9 and 1<=b and b<=9):
   print(a*b)
else:
   print(-1)
Buggy python submission (verdict: Runtime Error):
N=int(input())
K=list()

for i in range(1,int(N**0.5)+1):
  if(N/i in list(range(1,N+1))):
    M=int(N/i)  #N<=M
    L=i
    K.append(M+L-2)
    
print(min(K))

Fixed submission:
N=int(input())
K=list()

for i in range(1,int(N**0.5)+1):
  if(int(N/i)==N/i):
    M=int(N/i)  #N<=M
    L=i
    K.append(M+L-2)
    
print(min(K))
Buggy python submission (verdict: Time Limit Exceeded):
def binary_search(a,b,j):
   left=j
   right=N
   while left<right-1:
      mid=(left+right)//2
      if L[mid]<a+b:
         left=mid
      else:
         right=mid

   return left

N=int(input())
L=list(map(int,input().split()))
L.sort()

count=0

for i in range(N):
   for j in range(N):
      if j<=i:
         continue
      if j==N-1:
         continue
      a=L[i]
      b=L[j]

      c_index=binary_search(a,b,j)
      count+=c_index-j

print(count)

Fixed submission:
def binary_search(a,b,j):
   left=j
   right=N
   while left<right-1:
      mid=(left+right)//2
      if L[mid]<a+b:
         left=mid
      else:
         right=mid

   return left

N=int(input())
L=list(map(int,input().split()))
L.sort()

count=0

for i in range(N):
   for j in range(N):
      if j<=i:
         continue
      if j==N-1:
         continue
      a=L[i]
      b=L[j]

      c_index=binary_search(a,b,j)
      count+=c_index-j

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n,m=map(int,readline().split())
    a=[0]*m
    b=[0]*m
    c=[0]*m
    for i in range(m):
        a[i],b[i]=map(int,readline().split())
        li=list(map(int,readline().split()))
        for j in range(len(li)):
            c[i]|=1<<(li[j]-1)

    inf=10**9
    dp=[[inf]*(1<<n) for _ in range(m+1)]
    dp[0][0]=0
    for i in range(1,m+1):
        for j in range(1<<n):
            #i番目の鍵を使わない
            dp[i][j]=min(dp[i-1][j],dp[i][j])

            #i番目の鍵を使う
            dp[i][j|c[i-1]]=min(dp[i][j|c[i-1]],dp[i-1][j]+a[i-1])

    ans=dp[m][(1<<n)-1]
    print(ans if ans<inf else -1)

if __name__=="__main__":
    main()

Fixed submission:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n,m=map(int,readline().split())
    a=[0]*m
    b=[0]*m
    c=[0]*m
    for i in range(m):
        a[i],b[i]=map(int,readline().split())
        li=list(map(int,readline().split()))
        for j in range(len(li)):
            c[i]|=1<<(li[j]-1)

    inf=10**9
    dp=[[inf]*(1<<n) for _ in range(m+1)]
    dp[0][0]=0
    for i in range(1,m+1):
        for j in range(1<<n):
            #i番目の鍵を使わない
            dp[i][j]=min(dp[i-1][j],dp[i][j])

            #i番目の鍵を使う
            dp[i][j|c[i-1]]=min(dp[i][j|c[i-1]],dp[i-1][j]+a[i-1])

    ans=dp[m][(1<<n)-1]
    print(ans if ans<inf else -1)

if __name__=="__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n=int(readline())
    m=n//2
    a=list(map(int,readline().split()))

    s=sum(a)//2
    ans=[0]*n
    k=n-1
    for i in range(n):
        t=0
        for j in range(m):
            t+=a[i]
            i+=2
            i%=n
        ans[k]=(s-t)*2
        k+=1
        k%=n

    print(*ans)

if __name__=="__main__":
    main()

Fixed submission:
def main():
    N=int(input())
    A=list(map(int,input().split()))
    w=sum(A)
    if N==3:
        li=[]
        for i in range(1,N):
            li.append(w-2*A[i])
        li.append(w-2*A[0])
        result=" ".join(map(str,li))
        print(result)
    else:
        li=[0]*N
        n=N//2
        count=0
        for j in range(1,2*n+1,2):  #w_1を先に求める
            count+=2*A[j]
        li[0]=w-count
        
        for i in range(N-1):  #漸化式を用いて残りを求める
            li[i+1]=2*A[i]-li[i]

        result=" ".join(map(str,li))
        print(result)
if __name__=="__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    H,W=map(int,readline().split())
    grid=[]
    for i in range(H):
        S=readline().strip()
        grid.append(S)
    up=[[0]*W for _ in range(H)]
    down=[[0]*W for _ in range(H)]
    left=[[0]*W for _ in range(H)]
    right=[[0]*W for _ in range(H)]

    #up,left
    for i in range(H):
        for j in range(W):
            if grid[i][j]==".":
                if i==0:
                    up[i][j]=1
                else:
                    up[i][j]=up[i-1][j]+1
            
                if j==0:
                    left[i][j]=1
                else:
                    left[i][j]=left[i][j-1]+1

    #down,right
    for i in range(H-1,-1,-1):
        for j in range(W-1,-1,-1):
            if grid[i][j]==".":
                if i==H-1:
                    down[i][j]=1
                else:
                    down[i][j]=down[i+1][j]+1

                if j==W-1:
                    right[i][j]=1
                else:
                    right[i][j]=right[i][j+1]+1

    res=0
    for i in range(H):
        for j in range(W):
            if grid[i][j]==".":
                res=max(res,up[i][j]+down[i][j]+left[i][j]+right[i][j]-3)
    
    print(res)
if __name__=="__main__":
    main()

Fixed submission:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    H,W=map(int,readline().split())
    grid=[]
    for i in range(H):
        S=readline().strip()
        grid.append(S)
    up=[[0]*W for _ in range(H)]
    down=[[0]*W for _ in range(H)]
    left=[[0]*W for _ in range(H)]
    right=[[0]*W for _ in range(H)]

    #up,left
    for i in range(H):
        for j in range(W):
            if grid[i][j]==".":
                if i==0:
                    up[i][j]=1
                else:
                    up[i][j]=up[i-1][j]+1
            
                if j==0:
                    left[i][j]=1
                else:
                    left[i][j]=left[i][j-1]+1

    #down,right
    for i in range(H-1,-1,-1):
        for j in range(W-1,-1,-1):
            if grid[i][j]==".":
                if i==H-1:
                    down[i][j]=1
                else:
                    down[i][j]=down[i+1][j]+1

                if j==W-1:
                    right[i][j]=1
                else:
                    right[i][j]=right[i][j+1]+1

    res=0
    for i in range(H):
        for j in range(W):
            if grid[i][j]==".":
                res=max(res,up[i][j]+down[i][j]+left[i][j]+right[i][j]-3)
    
    print(res)
if __name__=="__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def bfs():
   while len(que)>0:
      now=que.popleft()
      now_step=steps[now[0]][now[1]]
      for dy,dx in (-1,0),(1,0),(0,-1),(0,1):
         ny=now[0]+dy
         nx=now[1]+dx
         if 0<=ny<=H-1 and 0<=nx<=W-1:
            if maze[ny][nx]==".":
               maze[ny][nx]="#"
               que.append([ny,nx])
               steps[ny][nx]=now_step+1

from collections import deque

H,W=map(int,input().split())
maze=[]
for i in range(H):
   A=input()
   A=[c for c in A]
   maze.append(A)

steps=[[-1]*W for i in range(H)]
que=deque([])
for i in range(H):
   for j in range(W):
      if maze[i][j]=="#":
         que.append([i,j])
         steps[i][j]=0

bfs()

max_step=0
for i in range(H):
   for j in range(W):
      max_step=max(max_step,steps[i][j])

print(max_step)

Fixed submission:
def bfs():
   while len(que)>0:
      now=que.popleft()
      now_step=steps[now[0]][now[1]]
      for dy,dx in (-1,0),(1,0),(0,-1),(0,1):
         ny=now[0]+dy
         nx=now[1]+dx
         if 0<=ny<=H-1 and 0<=nx<=W-1:
            if maze[ny][nx]==".":
               maze[ny][nx]="#"
               que.append([ny,nx])
               steps[ny][nx]=now_step+1

from collections import deque

H,W=map(int,input().split())
maze=[]
for i in range(H):
   A=input()
   A=[c for c in A]
   maze.append(A)

steps=[[-1]*W for i in range(H)]
que=deque([])
for i in range(H):
   for j in range(W):
      if maze[i][j]=="#":
         que.append([i,j])
         steps[i][j]=0

bfs()

max_step=0
for i in range(H):
   for j in range(W):
      max_step=max(max_step,steps[i][j])

print(max_step)
Buggy python submission (verdict: Runtime Error):
from sys import stdin
from math import gcd
def main():
    #入力
    readline=stdin.readline
    N=int(readline())
    A=list(map(int,readline().split()))
    A.insert(0,0)
    A.append(0)

    L=[0]*N
    R=[0]*N
    for i in range(1,N):
        L[i]=gcd(L[i-1],A[i])
    for i in range(N-2,-1,-1):
        R[i]=gcd(R[i+1],A[i+2])

    res=0
    for i in range(N):
        res=max(res,gcd(L[i],R[i]))
    print(res)

if __name__=="__main__":
    main()

Fixed submission:
from sys import stdin
from fractions import gcd
def main():
    #入力
    readline=stdin.readline
    N=int(readline())
    A=list(map(int,readline().split()))
    A.insert(0,0)
    A.append(0)

    L=[0]*N
    R=[0]*N
    for i in range(1,N):
        L[i]=gcd(L[i-1],A[i])
    for i in range(N-2,-1,-1):
        R[i]=gcd(R[i+1],A[i+2])

    res=0
    for i in range(N):
        res=max(res,gcd(L[i],R[i]))
    print(res)

if __name__=="__main__":
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    N=int(input())
    A=int(input())
    B=int(input())
    C=int(input())
    D=int(input())
    E=int(input())
    for i in (A,B,C,D,E):
        min_num=min(i,min_num)
    print((N//min_num+1)+4)
    
if __name__=="__main__":
    main()

Fixed submission:
import math
def main():
    N=int(input())
    A=int(input())
    B=int(input())
    C=int(input())
    D=int(input())
    E=int(input())
    min_num=N+1
    for i in (A,B,C,D,E):
        min_num=min(i,min_num)
    print(math.ceil(N/min_num)+4)
    
if __name__=="__main__":
    main()