Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n=int(input())
A=[int(input())]

for i in range(n-1):
  a=int(input())
  b=bisect.bisect_left(A,a,lo=0,hi=len(A))
  if b==0:
    A.insert(0,a)
  else:
    A[b-1]=a
print(len(A))


Fixed submission:
import bisect
from collections import deque
n=int(input())
A=deque([int(input())])

for i in range(n-1):
  a=int(input())
  b=bisect.bisect_left(A,a,lo=0,hi=len(A))
  if b==0:
    A.appendleft(a)
  else:
    A[b-1]=a
print(len(A))

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n=int(input())
A=[int(input())]
for i in range(n-1):
  a=int(input())
  b=bisect.bisect_right(A,a,lo=0,hi=len(A))
  if b!=0 and A[b-1]<a:
    A[b-1]=a
  elif A[b-1]==a:
    b=bisect.bisect_right(A,a-1,lo=0,hi=len(A))
    if b!=0:
      A[b-1]=a
    else:
      A.insert(0,a)
  else:
    A.insert(0,a)
print(len(A))


Fixed submission:
import bisect
from collections import deque
n=int(input())
A=deque([int(input())])

for i in range(n-1):
  a=int(input())
  b=bisect.bisect_left(A,a,lo=0,hi=len(A))
  if b==0:
    A.appendleft(a)
  else:
    A[b-1]=a
print(len(A))

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n=int(input())
A=[int(input())]
for i in range(n-1):
  a=int(input())
  b=bisect.bisect_right(A,a,lo=0,hi=len(A))
  if b!=0 and A[b-1]<a:
    A[b-1]=a
  elif A[b-1]==a:
    b=bisect.bisect_right(A,a-1,lo=0,hi=len(A))
    if b!=0:
      A[b-1]=a
    else:
      A.insert(0,a)
  else:
    A.insert(0,a)
print(len(A))


Fixed submission:
import bisect
from collections import deque
n=int(input())
A=deque([int(input())])

for i in range(n-1):
  a=int(input())
  b=bisect.bisect_left(A,a,lo=0,hi=len(A))
  if b==0:
    A.appendleft(a)
  else:
    A[b-1]=a
print(len(A))
Buggy python submission (verdict: Runtime Error):
N,D=map(int,input().split())
X = []
for i in range(N):
  X.append(input().split())
c=0
for n in range(0,N-1):
  for m in range(n+1,N):
    a=0
    for j in range(0,D):
      a=a+int((int(X[n][j])-(int(X[m][j])**2)
    if (int(a**(1/2)))**2==a:
      c=c+1
print(c)

Fixed submission:
n,d=map(int,input().split())
X=[[]*d for i in range(n)]
for i in range(n):
  X[i]=list(map(int,input().split()))
b=0
for i in range(n-1):
  for j in range(i+1,n):
    a=0
    for k in range(d):
      a=a+(X[i][k]-X[j][k])**2
      a=float(a)
    if a**(1/2)==int(a**(1/2)):
      b=b+1
print(b)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input()) 
d = list(map(int, input().split()))
a=int(N/2)
for i in range(len(d)-1):
	for j in range(i+1, len(d)):
		if d[i] > d[j]:
			temp = d[i]
			d[i] = d[j]
			d[j] = temp
print(d[a]-d[a-1])

Fixed submission:
N = int(input()) 
d = list(map(int, input().split()))
a=int(N/2)
def quick_sort(arr):
    left = []
    right = []
    if len(arr) <= 1:
        return arr

    # データの状態に左右されないためにrandom.choice()を用いることもある。
    # ref = random.choice(arr)
    ref = arr[0]
    ref_count = 0

    for ele in arr:
        if ele < ref:
            left.append(ele)
        elif ele > ref:
            right.append(ele)
        else:
            ref_count += 1
    left = quick_sort(left)
    right = quick_sort(right)
    return left + [ref] * ref_count + right
d=quick_sort(d)
print(d[a]-d[a-1])
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
def nCr(n, r):
    """
    Calculate the number of combination (nCr = nPr/r!).
    The parameters need to meet the condition of n >= r >= 0.
    It returns 1 if r == 0, which means there is one pattern
    to choice 0 items out of the number of n.
    """

    # 10C7 = 10C3
    r = min(r, n-r)

    # Calculate the numerator.
    numerator = 1
    for i in range(n, n-r, -1):
        numerator *= i

    # Calculate the denominator. Should use math.factorial?
    denominator = 1
    for i in range(r, 1, -1):
        denominator *= i

    return numerator // denominator
for i in range(K-1):
  print(nCr(N-K+1,i+1):nCr(K-1,i+1))

Fixed submission:
N, K = map(int, input().split())
def nCr(n, r):
    if n<r :
      return 0
    else:
      """
      Calculate the number of combination (nCr = nPr/r!).
      The parameters need to meet the condition of n >= r >= 0.
      It returns 1 if r == 0, which means there is one pattern
      to choice 0 items out of the number of n.
      """
  
      # 10C7 = 10C3
      r = min(r, n-r)
  
      # Calculate the numerator.
      numerator = 1
      for i in range(n, n-r, -1):
          numerator *= i
  
      # Calculate the denominator. Should use math.factorial?
      denominator = 1
      for i in range(r, 1, -1):
          denominator *= i
  
      return numerator // denominator
for i in range(K):
  a=nCr(N-K+1,i+1)*nCr(K-1,i)
  print(a%1000000007)
Buggy python submission (verdict: Runtime Error):
N,L=map(int, input().split())
if N+L-1<=0:
  print(int(L*(N-1)+N*(N-1)/2-N+1))
elif L>=0:
  print(int(L*(N-1)+N*(N+1)/2-1-N+1))
else :
  print(int(L*N+N*(N+1)/2-N))

Fixed submission:
s=int(input())
a=s//1000
b=(s-a*1000)//100
c=(s-a*1000-b*100)//10
d=s-a*1000-b*100-c*10
if a==b :
    print("Bad")
elif b==c:
    print("Bad")
elif c==d:
    print("Bad")
else:
    print("Good")

Buggy python submission (verdict: Runtime Error):
s=input()
a=s//1000
b=(s-a*1000)//100
c=(s-a*1000-b*100)//10
d=s-a*1000-b*100-c*10
if a==b :
    print"Bad"
    elif b==c:
        print"Bad"
    elif c==d:
        print"Bad"
else:
    print"Good"

Fixed submission:
s=int(input())
a=s//1000
b=(s-a*1000)//100
c=(s-a*1000-b*100)//10
d=s-a*1000-b*100-c*10
if a==b :
    print("Bad")
elif b==c:
    print("Bad")
elif c==d:
    print("Bad")
else:
    print("Good")
Buggy python submission (verdict: Runtime Error):
N, X = map(int, input().split())
L = list(map(int, input().split()))
B=sum(L)
count=1
if X>=B:
  print(len(L)+1)
else:
  i=0
  H=0
  while H<=X:
    H=H+L[i]
    i=i+1
  print(i)

Fixed submission:
N,L=map(int, input().split())
if N+L-1<=0:
  print(int(L*(N-1)+N*(N-1)/2-N+1))
elif L>=0:
  print(int(L*(N-1)+N*(N+1)/2-1-N+1))
else :
  print(int(L*N+N*(N+1)/2-N))
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
L=[0]*M
R=[0]*M
for i in range(M):
    L[i],R[i]=map(int,input().split())
def quick_sort(arr):
    left = []
    right = []
    if len(arr) <= 1:
        return arr

    # データの状態に左右されないためにrandom.choice()を用いることもある。
    # ref = random.choice(arr)
    ref = arr[0]
    ref_count = 0

    for ele in arr:
        if ele < ref:
            left.append(ele)
        elif ele > ref:
            right.append(ele)
        else:
            ref_count += 1
    left = quick_sort(left)
    right = quick_sort(right)
    return left + [ref] * ref_count + right
L=quick_sort(L)
R=quick_sort(R)
a=L[M-1]
b=R[0]
if a>b:
  print("0")
else:
  print(b-a+1)

Fixed submission:
N, M = map(int, input().split())
S = []
for _ in range(M):
    S.append(int(input()))
def fib(n):
  if n==-1:
    return 0
  elif n==0:
    return 1
  else:
    a, b = 0, 1
    for i in range(n):
        a, b = b, a + b
    return b
if len(S)==0:
  c=fib(N)
  print(c%1000000007)
else:
  if S[0]==1:
    c=1
  else:
    c=fib(S[0]-1)
  for i in range(M-1):
    c=c*fib(S[i+1]-S[i]-2)
  c=c*fib(N-S[M-1]-1)
  c=c%1000000007
  print(c)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
S = []
for _ in range(M):
    S.append(int(input()))
def fib(n):
  if n==-1:
    return 0
  elif n==0:
    return 1
  else:
    a, b = 0, 1
    for i in range(n):
        a, b = b, a + b
    return b
if S[0]==1:
  c=1
else:
  c=fib(S[0]-1)
for i in range(M-1):
  c=c*fib(S[i+1]-S[i]-2)
c=c*fib(N-S[M-1]-1)
c=c%1000000007
print(c)

Fixed submission:
N, M = map(int, input().split())
S = []
for _ in range(M):
    S.append(int(input()))
def fib(n):
  if n==-1:
    return 0
  elif n==0:
    return 1
  else:
    a, b = 0, 1
    for i in range(n):
        a, b = b, a + b
    return b
if len(S)==0:
  c=fib(N)
  print(c%1000000007)
else:
  if S[0]==1:
    c=1
  else:
    c=fib(S[0]-1)
  for i in range(M-1):
    c=c*fib(S[i+1]-S[i]-2)
  c=c*fib(N-S[M-1]-1)
  c=c%1000000007
  print(c)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
S = []
for _ in range(M):
    S.append(int(input()))
def fib(n):
  if n==0:
    return 0
  else:
    a, b = 0, 1
    for i in range(n):
        a, b = b, a + b
    return b
if S[0]==1:
  c=1
else:
  c=fib(S[0]-1)
for i in range(M-1):
  c=c*fib(S[i+1]-S[i]-2)
c=c*fib(N-S[M-1]-1)
c=c%1000000007
print(c)

Fixed submission:
N, M = map(int, input().split())
S = []
for _ in range(M):
    S.append(int(input()))
def fib(n):
  if n==-1:
    return 0
  elif n==0:
    return 1
  else:
    a, b = 0, 1
    for i in range(n):
        a, b = b, a + b
    return b
if len(S)==0:
  c=fib(N)
  print(c%1000000007)
else:
  if S[0]==1:
    c=1
  else:
    c=fib(S[0]-1)
  for i in range(M-1):
    c=c*fib(S[i+1]-S[i]-2)
  c=c*fib(N-S[M-1]-1)
  c=c%1000000007
  print(c)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
h,w=map(int,input().split())
g = [['#']*(w+2) for i in range(h+2)]
for i in range(h):
  g[i+1][1:-1] = list(input())
L=[[0]*(w+2) for i in range(h+2)]
R=[[0]*(w+2) for i in range(h+2)]
D=[[0]*(w+2) for i in range(h+2)]
U=[[0]*(w+2) for i in range(h+2)]
for i in range(h+2):
  for j in range(w+2):
    if g[i][j]=="#":
      L[i][j]=0
    else:
      L[i][j]=L[i][j-1]+1
for i in range(h+2):
  for j in range(w+1,-1,-1):
    if g[i][j]=="#":
      R[i][j]=0
    else:
      R[i][j]=R[i][j+1]+1
for i in range(h+2):
  for j in range(w+2):
    if g[i][j]=="#":
      D[i][j]=0
    else:
      D[i][j]=D[i-1][j]+1
for i in range(h+1,-1,-1):
  for j in range(w+2):
    if g[i][j]=="#":
      U[i][j]=0
    else:
      U[i][j]=U[i+1][j]+1
Max=0
for i in range(h+2):
  for j in range(w+2):
    a=0
    a=L[i][j]+R[i][j]+D[i][j]+U[i][j]
    if a>Max:
      Max=a
print(Max-3)

Fixed submission:
import bisect
h,w=map(int,input().split())
g = [['#']*(w+2) for i in range(h+2)]
for i in range(h):
  g[i+1][1:-1] = list(input())
L=[[0]*(w+2) for i in range(h+2)]
R=[[0]*(w+2) for i in range(h+2)]
D=[[0]*(w+2) for i in range(h+2)]
U=[[0]*(w+2) for i in range(h+2)]
for i in range(h+2):
  for j in range(w+2):
    if g[i][j]=="#":
      L[i][j]=0
    else:
      L[i][j]=L[i][j-1]+1
for i in range(h+2):
  for j in range(w+1,-1,-1):
    if g[i][j]=="#":
      R[i][j]=0
    else:
      R[i][j]=R[i][j+1]+1
for i in range(h+2):
  for j in range(w+2):
    if g[i][j]=="#":
      D[i][j]=0
    else:
      D[i][j]=D[i-1][j]+1
for i in range(h+1,-1,-1):
  for j in range(w+2):
    if g[i][j]=="#":
      U[i][j]=0
    else:
      U[i][j]=U[i+1][j]+1
Max=0
for i in range(h+2):
  for j in range(w+2):
    a=0
    a=L[i][j]+R[i][j]+D[i][j]+U[i][j]
    if a>Max:
      Max=a
print(Max-3)
Buggy python submission (verdict: Runtime Error):
from collections import deque
n=int(input())
S=list(input())
G=[[] for i in range(n)]
for i in range(n-1):
  a,b=map(int,input().split())
  G[a-1].append(b-1)
  G[b-1].append(a-1)
ans=10**10
for i in range(n):#根
  D=deque([i])
  A=[i]
  V=[0]*n
  V[i]=1
  C=[[] for i in range(n)]
  while len(D)>0:
    x=D[0]
    D.popleft()
    for j in range(len(G[x])):
      if V[G[x][j]]==0:
        V[G[x][j]]=1
        D.append(G[x][j])
        A.append(G[x][j])
        C[x].append(G[x][j])
  A=A[::-1]
  Ans=[[0]*3 for i in range(n)]
  for v in A:
    if len(C[v])==1:
      vc=C[v][0]
      Ans[v]=[Ans[vc][0],Ans[vc][1]+Ans[vc][2],Ans[vc][2]]
    elif len(C[v])!=0:
      L=[]
      LL=[]
      cc=0
      s=0
      M=0
      for vc in C[v]:
        m=Ans[vc][1]+Ans[vc][2]
        if m>M:
          M=m
          MM=Ans[vc][0]
        L.append(Ans[vc][1]+Ans[vc][2])
        LL.append(2*Ans[vc][0]+Ans[vc][1]+Ans[vc][2])
        cc=cc+Ans[vc][2]
        s=s+Ans[vc][0]
      if sum(LL)-M-2*MM>=M:
        ss=sum(L)//2
      else:
        ss=sum(LL)-M-2*MM-s
      Ans[v]=[s+ss,sum(L)-2*ss,cc]
    if S[v]=="1":
      Ans[v][2]+=1
  if Ans[i][1]==0:
    if Ans[i][0]<ans:
      ans=Ans[i][0]
if ans==10**10:
  print(-1)
else:
  print(ans)

Fixed submission:
from collections import deque
n=int(input())
S=list(input())
G=[[] for i in range(n)]
for i in range(n-1):
  a,b=map(int,input().split())
  G[a-1].append(b-1)
  G[b-1].append(a-1)
ans=10**10
AAA=10**10
for i in range(n):#根
  D=deque([i])
  A=[i]
  V=[0]*n
  V[i]=1
  C=[[] for i in range(n)]
  while len(D)>0:
    x=D[0]
    D.popleft()
    for j in range(len(G[x])):
      if V[G[x][j]]==0:
        V[G[x][j]]=1
        D.append(G[x][j])
        A.append(G[x][j])
        C[x].append(G[x][j])
  A=A[::-1]
  Ans=[[0]*3 for i in range(n)]
  for v in A:
    if len(C[v])==1:
      vc=C[v][0]
      Ans[v]=[Ans[vc][0],Ans[vc][1]+Ans[vc][2],Ans[vc][2]]
    elif len(C[v])!=0:
      L=[]
      LL=[]
      cc=0
      s=0
      M=0
      MM=0
      for vc in C[v]:
        m=Ans[vc][1]+Ans[vc][2]
        if m>M:
          M=m
          MM=Ans[vc][0]
        L.append(Ans[vc][1]+Ans[vc][2])
        LL.append(2*Ans[vc][0]+Ans[vc][1]+Ans[vc][2])
        cc=cc+Ans[vc][2]
        s=s+Ans[vc][0]
      if sum(LL)-M-2*MM>=M:
        ss=sum(L)//2
      else:
        ss=sum(LL)-M-2*MM-s+MM
      Ans[v]=[s+ss,sum(L)-2*ss,cc]
    if S[v]=="1":
      Ans[v][2]+=1
  if Ans[i][1]==0:
    if Ans[i][0]<ans:
      ans=Ans[i][0]
if ans==10**10:
  print(-1)
else:
  print(ans)
Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
V=list(map(int,input().split()))
A=0
s=0
S=0
while A<=K:
  B=0
  while B<=K-A:
    C=0
    while (C<=K-A-B and C<=A+B):
      if A==0:
        s=0
      else:
        for i in range(A):
          s=s+V[i]
      if B==0:
        s=s
      else:
        for j in range(B):
          s=s+V[N-j-1]
      left=[]
      for k in range(A):
        left.append(V[k])
      right=[]
      for l in range(B):
        right.append(V[N-l-1])
      v=left+right
      v=sorted(v)
      for m in range(C):
        s=s-v[m]
      print(v)
      print(s)
      C=C+1
    B=B+1
  A=A+1
        


Fixed submission:
from collections import deque
import itertools
n,k=map(int,input().split())
v=deque(list(map(int,input().split())))
a=0
ans=0
while a<=n and a<=k:
  w=deque(itertools.islice(v,0,None))
  b=0
  A=deque([0])
  for i in range(a):
    p=w.popleft()
    A.append(p)
  while a+b<=n and a+b<=k:
    x=deque(itertools.islice(w,0,None))
    B=deque(itertools.islice(A,0,None))
    for j in range(b):
      B.append(x.pop())
    B=deque(sorted(B))
    c=0
    while c<k-a-b and B[0]<0 and c<a+b:
      B.popleft()
      c=c+1
    V=sum(B)
    if V>ans:
      ans=V
    b=b+1
  a=a+1
print(ans)
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
L=[0]*M
R=[0]*M
for i in range(M):
    L[i],R[i]=map(int,input().split())
def quick_sort(arr):
    left = []
    right = []
    if len(arr) <= 1:
        return arr

    # データの状態に左右されないためにrandom.choice()を用いることもある。
    # ref = random.choice(arr)
    ref = arr[0]
    ref_count = 0

    for ele in arr:
        if ele < ref:
            left.append(ele)
        elif ele > ref:
            right.append(ele)
        else:
            ref_count += 1
    left = quick_sort(left)
    right = quick_sort(right)
    return left + [ref] * ref_count + right
L=quick_sort(L)
R=quick_sort(R)
a=L[M-1]
b=R[0]
if a>b:
  print("0")
else:
  print(b-a+1)

Fixed submission:
N,M=map(int,input().split())
L=[0]*M
R=[0]*M
for i in range(M):
    L[i],R[i]=map(int,input().split())
a=L[0]
for i in range(M):
  if L[i]>a:
    a=L[i]
  else:
    a=a
b=R[0]
for i in range(M):
  if R[i]<b:
    b=R[i]
  else:
    b=b
if b-a<0:
  print("0")
else:
  print(b-a+1)
Buggy python submission (verdict: Time Limit Exceeded):
def dijkstra(s,n,w,cost):
    #始点sから各頂点への最短距離
    #n:頂点数,　w:辺の数, cost[u][v] : 辺uvのコスト(存在しないときはinf)
    d = [float("inf")] * n
    used = [False] * n
    d[s] = 0
    
    while True:
        v = -1
        #まだ使われてない頂点の中から最小の距離のものを探す
        for i in range(n):
            if (not used[i]) and (v == -1):
               v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i
        if v == -1:
               break
        used[v] = True
               
        for j in range(n):
               d[j] = min(d[j],d[v]+cost[v][j])
    return d

################################
n = int(input()) #n:頂点数　w:辺の数
w=n-1
cost = [[float("inf") for i in range(n)] for i in range(n)] 
#cost[u][v] : 辺uvのコスト(存在しないときはinf この場合は10**10)
for i in range(w):
    x,y,z = map(int,input().split())
    x=x-1
    y=y-1
    cost[x][y] = z
    cost[y][x] = z
A=dijkstra(0,n,w,cost)
for i in range(n):
  print(A[i]%2)

Fixed submission:
from collections import deque
n=int(input())
A=[[[] for j in range(2)] for i in range(n)]
for i in range(n-1):
  u,v,w=map(int,input().split())
  w=w%2
  A[u-1][0].append(v-1)
  A[u-1][1].append(w)
  A[v-1][0].append(u-1)
  A[v-1][1].append(w)
B=deque([0])
C=[0]*n
C[0]=1
ans=[0]*n
while len(B)>0:
  s=B[0]
  B.popleft()
  for i in range(len(A[s][0])):
    if C[A[s][0][i]]==0:
      B.append(A[s][0][i])
      C[A[s][0][i]]=1
      ans[A[s][0][i]]=(ans[s]+A[s][1][i])%2
for i in range(n):
  print(ans[i])

Buggy python submission (verdict: Time Limit Exceeded):
def dijkstra(s,n,w,cost):
    #始点sから各頂点への最短距離
    #n:頂点数,　w:辺の数, cost[u][v] : 辺uvのコスト(存在しないときはinf)
    d = [float("inf")] * n
    used = [False] * n
    d[s] = 0
    
    while True:
        v = -1
        #まだ使われてない頂点の中から最小の距離のものを探す
        for i in range(n):
            if (not used[i]) and (v == -1):
               v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i
        if v == -1:
               break
        used[v] = True
               
        for j in range(n):
               d[j] = min(d[j],d[v]+cost[v][j])
    return d

################################
n = int(input()) #n:頂点数　w:辺の数
w=n-1
cost = [[float("inf") for i in range(n)] for i in range(n)] 
#cost[u][v] : 辺uvのコスト(存在しないときはinf この場合は10**10)
for i in range(w):
    x,y,z = map(int,input().split())
    x=x-1
    y=y-1
    cost[x][y] = z
    cost[y][x] = z
A=dijkstra(0,n,w,cost)
for i in range(n):
  print(A[i]%2)

Fixed submission:
from collections import deque
n=int(input())
A=[[[] for j in range(2)] for i in range(n)]
for i in range(n-1):
  u,v,w=map(int,input().split())
  w=w%2
  A[u-1][0].append(v-1)
  A[u-1][1].append(w)
  A[v-1][0].append(u-1)
  A[v-1][1].append(w)
B=deque([0])
C=[0]*n
C[0]=1
ans=[0]*n
while len(B)>0:
  s=B[0]
  B.popleft()
  for i in range(len(A[s][0])):
    if C[A[s][0][i]]==0:
      B.append(A[s][0][i])
      C[A[s][0][i]]=1
      ans[A[s][0][i]]=(ans[s]+A[s][1][i])%2
for i in range(n):
  print(ans[i])
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
h,w=map(int,input().split())
G=[["#"]*(w+2) for i in range(h+2)]
for i in range(1,h+1):
  G[i]=["#"]+list(input())+["#"]
X=deque()
Y=deque()
V=[[0]*(w+2) for i in range(h+2)]
V[0]=[0]*(w+2)
for i in range(1,h+1):
  V[i]=[0]+[10**7]*w+[0]
V[h+1]=[0]*(w+2)
for i in range(1,h+1):
  for j in range(1,w+1):
    if G[i][j]=="#":
      X.append(i)
      Y.append(j)
      V[i][j]=0
XX=[-1,0,0,1]
YY=[0,-1,1,0]
while len(X)!=0:
  x=X[0]
  y=Y[0]
  X.popleft()
  Y.popleft()
  for i in range(4):
    if V[x+XX[i]][y+YY[i]]==10**7:
      V[x+XX[i]][y+YY[i]]=V[x][y]+1
      X.append(x+XX[i])
      Y.append(y+YY[i])
ans=0
for i in range(h+2):
  for j in range(w+2):
    if V[i][j]>ans:
      ans=V[i][j]
print(ans)

Fixed submission:
from collections import deque
h,w=map(int,input().split())
G=[["#"]*(w+2) for i in range(h+2)]
for i in range(1,h+1):
  G[i]=["#"]+list(input())+["#"]
X=deque()
Y=deque()
V=[[0]*(w+2) for i in range(h+2)]
V[0]=[0]*(w+2)
for i in range(1,h+1):
  V[i]=[0]+[10**7]*w+[0]
V[h+1]=[0]*(w+2)
for i in range(1,h+1):
  for j in range(1,w+1):
    if G[i][j]=="#":
      X.append(i)
      Y.append(j)
      V[i][j]=0
XX=[-1,0,0,1]
YY=[0,-1,1,0]
while len(X)!=0:
  x=X[0]
  y=Y[0]
  X.popleft()
  Y.popleft()
  for i in range(4):
    if V[x+XX[i]][y+YY[i]]==10**7:
      V[x+XX[i]][y+YY[i]]=V[x][y]+1
      X.append(x+XX[i])
      Y.append(y+YY[i])
ans=0
for i in range(h+2):
  for j in range(w+2):
    if V[i][j]>ans:
      ans=V[i][j]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 2*10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

b,w=map(int,input().split())
x=0
y=0
for i in range(1,b+w+1):
  x=(x*2+cmb(i-2,b-1))%mod
  y=(y*2+cmb(i-2,w-1))%mod
  print((mod+pow(2,i-1,mod)-x+y)*pow(pow(2,i,mod),mod-2,mod)%mod)

Fixed submission:
def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 2*10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

b,w=map(int,input().split())
x=0
y=0
for i in range(1,b+w+1):
  x=(x*2+cmb(i-2,b-1))%mod
  y=(y*2+cmb(i-2,w-1))%mod
  print((mod+pow(2,i-1,mod)-x+y)*pow(pow(2,i,mod),mod-2,mod)%mod)
Buggy python submission (verdict: Runtime Error):
import bisect
a,b,q=map(int,input().split())
A=[-10**11]
for i in range(a):
  A.append(int(input()))
A.append(10**11)
B=[-10**11]
for i in range(b):
  B.append(int(input()))
B.append(10**11)
for i in range(q):
  x=int(input())
  c=bisect.bisect_left(A,x,hi=len(A))
  d=bisect.bisect_left(B,x,hi=len(A))
  ans=min(abs(A[c-1]-x)+abs(B[d-1]-A[c-1]),abs(A[c-1]-x)+abs(B[d]-A[c-1]),abs(A[c]-x)+abs(B[d-1]-A[c]),abs(A[c]-x)+abs(B[d]-A[c]),abs(B[d-1]-x)+abs(B[d-1]-A[c-1]),abs(B[d-1]-x)+abs(B[d-1]-A[c]),abs(B[d]-x)+abs(B[d]-A[c-1]),abs(B[d]-x)+abs(B[d]-A[c]))
  print(ans)

Fixed submission:
import bisect
a,b,q=map(int,input().split())
A=[-10**11]
for i in range(a):
  A.append(int(input()))
A.append(10**11)
B=[-10**11]
for i in range(b):
  B.append(int(input()))
B.append(10**11)
for i in range(q):
  x=int(input())
  c=bisect.bisect_left(A,x,hi=len(A))
  d=bisect.bisect_left(B,x,hi=len(B))
  ans=min(abs(A[c-1]-x)+abs(B[d-1]-A[c-1]),abs(A[c-1]-x)+abs(B[d]-A[c-1]),abs(A[c]-x)+abs(B[d-1]-A[c]),abs(A[c]-x)+abs(B[d]-A[c]),abs(B[d-1]-x)+abs(B[d-1]-A[c-1]),abs(B[d-1]-x)+abs(B[d-1]-A[c]),abs(B[d]-x)+abs(B[d]-A[c-1]),abs(B[d]-x)+abs(B[d]-A[c]))
  print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,W=map(int,input().split())
w=[0]*n
v=[0]*n
for i in range(n):
  w[i],v[i]=map(int,input().split())
V=[[0]*(W+3) for i in range(n+1)]
for i in range(1,n+1):
  for j in range(1,W+3):
    if j-w[i-1]<0:
      V[i][j]=V[i-1][j]
    else:
      V[i][j]=max(V[i-1][j],V[i-1][j-w[i-1]]+v[i-1])
print(V[n][W])

Fixed submission:
n,W=map(int,input().split())
w=[0]*n
v=[0]*n
for i in range(n):
  w[i],v[i]=map(int,input().split())
V=[[0]*(W+3) for i in range(n+1)]
for i in range(1,n+1):
  for j in range(1,W+3):
    if j-w[i-1]<0:
      V[i][j]=V[i-1][j]
    else:
      V[i][j]=max(V[i-1][j],V[i-1][j-w[i-1]]+v[i-1])
print(V[n][W])