Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03078 (python)

Fixed submission:
from bisect import bisect_left

X,Y,Z,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

if X*Y*Z <= 50000:
  D = sorted([A[i]+B[j]+C[k] for i in range(X) for j in range(Y) for k in range(Z)],reverse=True)
  for i in range(K):
    print(D[i])
  
else:
  A = sorted(A)
  D = sorted([B[i]+C[j] for i in range(Y) for j in range(Z)])

  thr = K
  s = A[-1]+D[max(0,len(D)-thr)]
  prev_idx=0
  selected = [A[-1] + D[i] for i in range(max(0,len(D)-thr),len(D))]
  
  for i in range(1,X):
    r = s - A[-1-i]
    if r<=0:break
    idx = bisect_left(D,r,prev_idx,len(D)-1)
    if idx == len(D):break
    selected.extend([A[-1-i] + D[j] for j in range(idx,len(D))])
    prec_idx = idx

  selected = sorted(selected,reverse=True)

  for i in range(K):
    print(selected[i])

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left

X,Y,Z,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

if X*Y*Z <= 1:
  D = sorted([A[i]+B[j]+C[k] for i in range(X) for j in range(Y) for k in range(Z)],reverse=True)
  for i in range(K):
    print(D[i])
  
else:
  A = sorted(A)
  D = sorted([B[i]+C[j] for i in range(Y) for j in range(Z)])

  thr = K
  s = A[-1]+D[max(0,len(D)-thr)]
  prev_idx=0
  selected = [A[-1] + D[i] for i in range(max(0,len(D)-thr),len(D))]
  
  for i in range(1,X):
    r = s - A[-1-i]
    if r<=0:break
    idx = bisect_left(D,r,prev_idx,len(D)-1)
    if idx == len(D):break
    selected.extend([A[-1-i] + D[j] for j in range(idx,len(D))])
    prec_idx = idx

  selected = sorted(selected,reverse=True)

  for i in range(K):
    print(selected[i])
Problem p03128 (python)

Fixed submission:
N,M=map(int,input().split())
A=list(map(int,input().split()))

if N % 2 == 0:
  if 1 in A:
    print(int('1'*(N//2)))
    exit()

need =(2,5,5,4,5,6,3,7,6)

if 2 in A and 3 in A:
  del A[A.index(2)]
if 3 in A and 5 in A:
  del A[A.index(3)]
if 6 in A and 9 in A:
  del A[A.index(6)]
if 1 in A and 4 in A:
  del A[A.index(4)]
if 6 in A and 7 in A:
  del A[A.index(6)] 
if 7 in A and 9 in A:
  del A[A.index(9)] 
if 1 in A and 6 in A:
  del A[A.index(6)] 
if 1 in A and 9 in A:
  del A[A.index(9)] 
  
A = tuple(A)
M = len(A)

dp = [[0]*(N+1) for _ in range(M)]
dpmax = [0]*(N+1)

def take_max():
  return max(A[i]*(10**len(str(tmp2)) + tmp2,tmp2*10+A[i]))

for j in range(2,N+1):
  tmpmax = 0
  for i in range(M):
    tmp = need[A[i]-1]
    if j == tmp:
      dp[i][j] = A[i]
    elif j > tmp:
      if dpmax[j-tmp] != 0:
        tmp2 = dpmax[j-tmp]
        dp[i][j] = take_max()
    if tmpmax < dp[i][j]:
      tmpmax = dp[i][j]
  dpmax[j] = tmpmax
  
print(dpmax[-1])

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

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

need =[2,5,5,4,5,6,3,7,6]

if 2 in A and 3 in A:
  del A[A.index(2)]
if 3 in A and 5 in A:
  del A[A.index(3)]
if 6 in A and 9 in A:
  del A[A.index(6)]
if 1 in A and 4 in A:
  del A[A.index(4)]
if 6 in A and 7 in A:
  del A[A.index(6)] 
if 7 in A and 9 in A:
  del A[A.index(9)] 
if 1 in A and 6 in A:
  del A[A.index(6)] 
if 1 in A and 9 in A:
  del A[A.index(9)] 
  
M = len(A)

dp = [[0]*(N+1) for _ in range(M)]
dpmax = [0]*(N+1)

for j in range(2,N+1):
  tmpmax = 0
  for i in range(M):
    tmp = need[A[i]-1]
    if j == tmp:
      res = A[i]
    elif j > tmp:
      if dpmax[j-tmp] != 0:
        tmp2 = dpmax[j-tmp]
        res = max(A[i]*(10**len(str(tmp2)) + tmp2,tmp2*10+A[i]))
    if tmpmax < res:
      tmpmax = res
    dp[i][j] = res
  dpmax[j] = tmpmax
  
print(dpmax[-1])
Problem p03166 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**8)

N,M=map(int,input().split())
G = [[] for _ in range(N)]
for i in range(M):
  x,y=map(int,input().split())
  G[x-1].append(y-1)
  
dp = [-1]*N

def rec(v):
  if dp[v] != -1:
    return dp[v]
  res = 0
  for next_v in G[v]:
    res = max(res, rec(next_v)+1)
  dp[v] = res
  return dp[v]
  
for i in range(N):
  dp[i] = rec(i)
  
print(max(dp))

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
G = [[] for _ in range(N)]
for i in range(M):
  x,y=map(int,input().split())
  G[x-1].append(y-1)
  
dp = [-1]*N

def rec(v):
  if dp[v] != -1:
    return dp[v]
  res = 0
  for next_v in G[v]:
    res = max(res, rec(next_v)+1)
  dp[v] = res
  return dp[v]
  
for i in range(N):
  dp[i] = rec(i)
  
print(max(dp))
Problem p03177 (python)

Fixed submission:
import numpy as np

def matmul(A,B):
    N = len(A)
    C = np.eye(N, dtype=int)
    for n in range(N):
        C[n] = (A[n,:][:,None] * B % mod).sum(axis=0) % mod
    return C

def mat_power(A,k):
    N = len(A)
    if k == 0:
        return np.eye(N,dtype=int)
    X = mat_power(A,k//2)
    X = matmul(X,X)
    return matmul(A,X) if k&1 else X

N,K=map(int,input().split())
A = np.array([list(map(int,input().split())) for _ in range(N)],dtype=int)
mod = 10**9+7

print(mat_power(A,K).sum()%mod)

Buggy submission (verdict: Runtime Error):
import numpy as np

N,K=map(int,input().split())
A = np.array([list(map(int,input().split())) for _ in range(N)],dtype=int)
mod = 10**9+7

res = matrix_power(A,N,mod)
print(res.sum()%mod)

power_list=[A]
for i in range(1,K.bit_length()+1):
  power_list.append((power_list[-1]@power_list[-1])%mod)
  
B = np.identity(N).astype(int)
for i in range(K.bit_length()+1):
  if K>>i&1:
    B = (B @ power_list[i])%mod

print(B.sum()%mod)
Problem p03361 (python)

Fixed submission:
H,W=map(int,input().split())
s=[list(map(int, list(input().replace('#','1').replace('.','0')))) for _ in range(H)]

padded = [[0 for i in range(W+2)] for j in range(H+2)]

for i in range(H):
  for j in range(W):
    padded[i+1][j+1] = s[i][j] 

for i in range(1,H+1):
  for j in range(1,W+1):
    if padded[i][j]==1:
      if padded[i+1][j]==0 and padded[i-1][j]==0 and padded[i][j+1]==0 and padded[i][j-1]==0:
        print('No')
        exit()
print('Yes')

Buggy submission (verdict: Runtime Error):
H,W=map(int,input().split())
s=[list(map(int, list(input().replace('#','1').replace('.','0')))) for _ in range(W)]

padded = [[0 for i in range(W+2)] for j in range(H+2)]

for i in range(H):
  for j in range(W):
    padded[i+1][j+1] = s[i][j] 

for i in range(1,H+1):
  for j in range(1,W+1):
    if padded[i][j]==1:
      if padded[i+1][j]==0 and padded[i-1][j]==0 and padded[i][j+1]==0 and padded[i][j-1]==0:
        print('No')
        exit()
print('Yes')
Problem p03633 (python)

Fixed submission:
def gcd(a,b):
  if b == 0:return a
  return gcd(b,a%b)

N=int(input())
T=[]
if N==1:
  print(input())
  exit()
for i in range(N):
  t = int(input())
  T.append(t)
  if i == 0:continue
  elif i == 1:
    lcm = T[-2]*T[-1]//gcd(T[-2],T[-1])
  else:
    lcm = lcm * T[-1]//gcd(lcm,T[-1])

print(lcm)

Buggy submission (verdict: Runtime Error):
def gcd(a,b):
  if b == 0:return a
  return gcd(b,a%b)

N=int(input())
T=[]
for i in range(N):
  t = int(input())
  T.append(t)
  if i == 0:continue
  elif i == 1:
    lcm = T[-2]*T[-1]//gcd(T[-2],T[-1])
  else:
    lcm = lcm * T[-1]//gcd(lcm,T[-1])

print(lcm)

Buggy submission (verdict: Runtime Error):
def gcd(a,b):
  if b == 0:return 1
  return gcd(b,a%b)

N=int(input())
T=[]
for i in range(N):
  t = int(input())
  T.append(t)
  if i == 0:continue
  elif i == 1:
    lcm = T[-2]*T[-1]//gcd(T[-2],T[-1])
  else:
    lcm = lcm * T[-1]//gcd(lcm,T[-1])

print(lcm)
Problem p02582 (python)

Fixed submission:
S=input()
S=list(S)
c=0
max=0
for i in S:
    if i=="R":
        c+=1
    else:
        if max<c:
            max=c
            c=0

if max<c:
    max=c
    c=0

print(max)

Buggy submission (verdict: Runtime Error):
x,k,d=map(int,input().split())

x=abs(x)

if x>k*d:
    print(x-k*d)
else:
    r=k-x//d
    if r%2==0:
        print(x%d)
    else:
        print(d-x%d)
Problem p02639 (python)

Fixed submission:
a = list(map(int,input().split()))
count = 1

for i in a:
    if i == 0:
        print(count)
        break
    count+=1

Buggy submission (verdict: Runtime Error):
X, N = map(int,input().split())
p_list = list(map(int, input().split()))

p_list.sort()
r = 200
answer = 101

for i in range(0, 102):
    if i in p_list:
        continue
    else:
        if r > abs(i - X):
            r = abs(i - X)
            answer = i
        else:
            print(answer)
            break
Problem p02640 (python)

Fixed submission:
x, y = map(int,input().split())

if y % 2 == 0 and y >= x*2 and y <= x*4:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
x, y = map(int,input(),split())

if y % 2 == 0 and y >= x*2 and y <= x*4:
    print('Yes')
else:
    print('No')
Problem p03166 (python)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)


n,m=map(int,input().split())

p=[[] for _ in range(n)]

for _ in range(m):
    x,y=map(int,input().split())
    p[x-1].append(y-1)

f=[-1 for _ in range(n)]

def calc(x):
    if f[x]!=-1:
        return f[x]
    if len(p[x])==0:
        f[x]=0
        return 0
    f[x]=max([calc(i) for i in p[x]])+1
    return f[x]

m=0
for i in range(n):
    if f[i]!=-1:
        continue
    m=max(m,calc(i))
print(m)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())

p=[[] for _ in range(n)]

for _ in range(m):
    x,y=map(int,input().split())
    p[x-1].append(y-1)



def calc(x):
    if len(p[x])==0:
        return 0
    return max([calc(i) for i in p[x]])+1

m=0
for i in range(n):
    j=calc(i)
    if m<j:
        m=j
print(m)
Problem p03169 (python)

Fixed submission:
import numpy as np
from numba import njit

N=int(input())
a=[int(i) for i in input().split()]
x,y,z=0,0,0
for i in a:
    if i==1:
        x+=1
    elif i==2:
        y+=1
    elif i==3:
        z+=1


dp=np.full((N+1,N+1,N+1),-1,dtype=np.float64)

dp[0][0][0]=0

@njit('f8(i8,i8,i8,i8,f8[:,:,:])', cache=True)
def calc(h,i,j,N,dp):
    if h+i+j==0:
        return 0
    if dp[h][i][j]>=0:
        return dp[h][i][j]
    A=1
    if h>=1:
        A+=calc(h-1,i,j,N,dp)*h/N
    if i>=1:
        A+=calc(h+1,i-1,j,N,dp)*i/N
    if j>=1:
        A+=calc(h,i+1,j-1,N,dp)*j/N
    A=A*N/(h+i+j)
    dp[h][i][j]=A
    return A

a=calc(x,y,z,N,dp)

print(dp[x][y][z])

Buggy submission (verdict: Runtime Error):
N=int(input())
a=[int(i) for i in input().split()]
x,y,z=0
for i in a:
    if i==1:
        x+=1
    elif i==2:
        y+=1
    elif i==3:
        z+=1
n=x+y*2+z*3


dp=[[[-1 for _ in range(n+1)] for _ in range(n+1)] for _ in range(n+1)]
dp[0][0][0]=0
def calc(h,i,j):
    global n,N
    if h+i+j==0 or h<0 or h>n or i<0 or i>n or j<0:
        return 0
    if dp[h][i][j]!=-1:
        return dp[h][i][j]
    dp[h][i][j]=(calc(h-1,i,j)*h/N+calc(h+1,i-1,j)*i/N+calc(h,i+1,j-1)*j/N+1)*N/(h+i+j)
    return dp[h][i][j]

a=calc(x,y,z)
print(dp[x][y][z])
Problem p03171 (python)

Fixed submission:
import numpy as np
from numba import njit
N=int(input())
a=np.array([int(i) for i in input().split()],dtype=np.int64)
dp=np.full((N,N),-1,dtype=np.int64)
for i in range(N):
    dp[i][i]=a[i]

@njit('i8(i8,i8,i8[:,:],i8[:])', cache=True)
def calc(i,j,dp,a):
    if dp[i][j]!=-1:
        return dp[i][j]
    dp[i][j]=max(a[i]-calc(i+1,j,dp,a),a[j]-calc(i,j-1,dp,a))
    return dp[i][j]

calc(0,N-1,dp,a)
print(dp[0][N-1])

Buggy submission (verdict: Runtime Error):
import numpy as np
from numba import njit
N=int(input())
a=np.array([int(i) for i in input().split()],dtype=np.int64)
a.dtype
dp=np.full((N,N),-1,dtype=np.int64)
dp.dtype
for i in range(N):
    dp[i][i]=a[i]

@njit('i8(i8,i8,i8[:,:],i8[:])', cache=True)
def calc(i,j,dp,a):
    if dp[i][j]!=-1:
        return dp[i][j]
    dp[i][j]=max(a[i]-calc(i+1,j,dp,a),a[j]-calc(i,j-1,dp,a))
    return dp[i][j]

calc(0,N-1,dp,a)
print(dp[0][N-1])
Problem p03172 (python)

Fixed submission:
import numpy as np
from numba import njit

N,K=map(int,input().split())
a=np.array([int(i) for i in input().split()],dtype=np.int64)

dp=np.full((N+1,K+1),0,dtype=np.int64)
c=np.full(K+2,0,dtype=np.int64)
MOD=10**9+7

@njit('i8(i8,i8,i8,i8[:,:],i8[:])', cache=True)
def main(N,K,MOD,dp,c):

    dp[0][0]=1
    for i in range(1,N+1):
        c[0]=0
        for j in range(1,K+2):
            c[j]=(c[j-1]+dp[i-1][j-1])%MOD
        for j in range(K+1):
            dp[i][j]=(c[j+1]-c[max(0,j-a[i-1])])%MOD

    return dp[N][K]

print(main(N,K,MOD,dp,c))

Buggy submission (verdict: Runtime Error):
import numpy as np
from numba import njit

N,K=map(int,input().split())
a=np.array([int(i) for i in input().split()],dtype=np.int64)

dp=np.full((N+1,K+1),0,dtype=np.int64)
c=np.full(K+2,0,dtype=np.int64)
MOD=10**9+7

@njit('i8(i8,i8,i8,i8[:,:],i8[:])', cache=True)
def main(N,K,MOD,dp,c):

    dp[0][0]=1
    for i in range(1,N+1):
        c[0]=0
        for j in range(1,K+2):
            c[j]=(c[j-1]+dp[i-1][j-1])%MOD
        for j in range(K+1):
            dp[i][j]=(c[j+1]-c[max(0,j-a[i-1])])%MOD

    return dp[N][K]

print(main(N,K,dp,c))

Buggy submission (verdict: Runtime Error):
import numpy as np
from numba import njit

@njit( cache=True)
def main():
    N,K=map(int,input().split())
    a=np.array([int(i) for i in input().split()],dtype=np.int64)
    MOD=10**9+7

    dp=np.full((N+1,K+1),0,dtype=np.int64)
    c=np.full(K+2,0,dtype=np.int64)

    dp[0][0]=1


    for i in range(1,N+1):
        c[0]=0
        for j in range(1,K+2):
            c[j]=(c[j-1]+dp[i-1][j-1])%MOD
        for j in range(K+1):
            dp[i][j]=(c[j+1]-c[max(0,j-a[i-1])])%MOD

    print(dp[N][K])

def main()

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
a=np.array([int(i) for i in input().split()],dtype=np.int64)
MOD=10**9+7

dp=np.full((N+1,K+1),0,dtype=np.int64)
c=np.full(K+2,0,dtype=np.int64)

dp[0][0]=1


for i in range(1,N+1):
    c[0]=0
    for j in range(1,K+2):
        c[j]=(c[j-1]+dp[i-1][j-1])%MOD
    for j in range(K+1):
        dp[i][j]=(c[j+1]-c[max(0,j-a[i-1])])%MOD

print(dp[N][K])
Problem p03173 (python)

Fixed submission:
import numpy as np
from numba import njit
N=int(input())
a=np.array([int(i) for i in input().split()],dtype=np.int64)

s=[0]

dp=np.array([[-1 for i in range(N)] for _ in range(N)],dtype=np.int64)

for i in range(1,N+1):
    s.append(s[i-1]+a[i-1])

s=np.array(s,dtype=np.int64)
for i in range(N):
    dp[i][i]=0

@njit('i8(i8,i8,i8[:,:],i8[:])', cache=True)
def calc(i,j,dp,s):
    if dp[i][j]!=-1:
        return dp[i][j]
    m=10**14
    for k in range(i,j):
        m=min(m,calc(i,k,dp,s)+calc(k+1,j,dp,s)+s[j+1]-s[i])
    dp[i][j]=m
    return dp[i][j]

print(calc(0,N-1,dp,s))

Buggy submission (verdict: Runtime Error):
import numpy as np
from numba import njit
N=int(input())
a=np.array([int(i) for i in input().split()],dtype=np.int64)

s=[0]

dp=np.array([[-1 for i in range(N)] for _ in range(N)],dtype=np.int64)

for i in range(1,N+1):
    s.append(s[i-1]+a[i-1])

s=np.array(s,dtype=np.int64)
for i in range(N):
    dp[i][i]=0

@njit('i8(i8,i8,i8[:,:],i8[:])', cache=True)
def calc(i,j,dp,s):
    if dp[i][j]!=-1:
        return dp[i][j]
    m=float('inf')
    for k in range(i,j):
        m=min(m,calc(i,k,dp,s)+calc(k+1,j,dp,s)+s[j+1]-s[i])
    dp[i][j]=m
    return dp[i][j]

print(calc(0,N-1,dp,s))
Problem p03177 (python)

Fixed submission:
import numpy as np
N,K=map(int,input().split())
a=[[int(i) for i in input().split()] for _ in range(N)]
a=np.array(a,dtype=np.int64)
MOD=10**9+7

def matmul(A,B,MOD):
    N=len(A)
    C=np.zeros((N,N),dtype=np.int64)

    for n in range(N):
        C[n] = (A[n,:][:,None] * B % MOD).sum(axis=0) % MOD
    return C

def mat_power(A,k,MOD):
    N=len(A)
    D=np.identity(N,dtype=np.int64)
    while k:
        if k & 1:
            D=matmul(D,A,MOD)
        A = matmul(A,A,MOD)
        k >>= 1

    return D

A=mat_power(a,K,MOD)
ans=0
for i in range(N):
    for j in range(N):
        ans=(ans+A[i][j])%MOD

print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
N,K=map(int,input().split())
a=[[int(i) for i in input().split()] for _ in range(N)]
a=np.array(a,dtype=np.int64)
MOD=10**9+7

def matmul(A,B,MOD):
    N=len(A)
    C=np.zeros((N,N),dtype=np.int64)

    for n in range(N):
        C[n] = (A[n,:][:,None] * B % mod).sum(axis=0) % mod
    return C

def mat_power(A,k,MOD):
    N=len(A)
    D=np.identity(N,dtype=np.int64)
    while k:
        if k & 1:
            D=matmul(D,A,MOD)
        A = matmul(A,A,MOD)
        k >>= 1

    return D

A=mat_power(a,K,MOD)
ans=0
for i in range(N):
    for j in range(N):
        ans=(ans+A[i][j])%MOD

print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
N,K=map(int,input().split())
a=[[int(i) for i in input().split()] for _ in range(N)]
a=np.array(a,dtype=np.int64)
MOD=10**9+7

def matmul(A,B,MOD):
    N=len(A)
    C=np.zeros(N,dtype=np.int64)
    for i in range(N):
        for j in range(N):
            for k in range(N):
                C[i][j] += A[i][k]*B[k][j]%MOD
    return C

def mat_power(A,k,MOD):
    N=len(A)
    D=np.identity(N,dtype=np.int64)
    while k:
        if k & 1:
            D=matmul(D,A,MOD)
        A = matmul(A,A,MOD)
        k >>= 1

    return D

A=mat_power(a,K,MOD)
ans=0
for i in range(N):
    for j in range(N):
        ans=(ans+A[i][j])%MOD

print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
N,K=map(int,input().split())
a=[[int(i) for i in input().split()] for _ in range(N)]
a=np.array(a,dtype=np.int64)
MOD=10**9+7

def matmul(A,B,MOD):
    N=len(A)
    C=np.zeros(N,dtype=np.int64)
    for i in range(N):
        for j in range(N):
            for k in range(N):
            C[i][j] += A[i][k]B[k][j]%MOD
    return C

def mat_power(A,k,MOD):
    N=len(A)
    D=np.identity(N,dtype=np.int64)
    while k:
        if k & 1:
            D=matmul(D,A,MOD)
        A = matmul(A,A,MOD)
        k >>= 1

    return D

A=mat_power(a,K,MOD)
ans=0
for i in range(N):
    for j in range(N):
        ans=(ans+A[i][j])%MOD

print(ans)
Problem p03282 (python)

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

for j in range(len(S)):
    if S[j]=='1':
        if j==K-1:
            ans=1
            break
    else:
        x=[i for i in S if i!='1']
        ans=x[0]
        break

print(ans)

Buggy submission (verdict: Runtime Error):
S=input()
K=int(input())
S=list(S)

for j in range(len(S)):
    if S[j]=='1':
        if j==K:
            ans=1
    else:
        x=[i for i in S if i!="1"]
        ans=x[0]

print(ans)

Buggy submission (verdict: Runtime Error):
S=input()
K=int(input())
S=list(S)

for j in range(len(S)):
    if S[j]=='1':
        if j==K:
            ans=1
    else:
        x=[i for i in S if i!="1"]
        ans=x[0]

print(ans)
Problem p03074 (python)

Fixed submission:
N,K=map(int,input().split())
S=input()
X,Y=[],[]
M=0
for i in range(len(S)):
  if(S[i]=='1' and M==0):
    X.append(i)
    M+=1
  elif(S[i]=='1'):
    M+=1
  else:
    if(M):
      Y.append(i-1)
    M=0
if(M):
  Y.append(len(S)-1)
ans=0
if(len(X)>=K):
  for i in range(len(X)-K):
    ans=max(ans,Y[i+K]-X[i]+1)
else:
  ans=len(S)
if(len(X)):
  ans=max(ans,Y[min(K-1,len(X)-1)]+1)
  ans=max(ans,len(S)-X[max(len(X)-K,0)])
print(ans)

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
S=input()
X,Y=[],[]
M=0
for i in range(len(S)):
  if(S[i]=='1' and M==0):
    X.append(i)
    M+=1
  elif(S[i]=='1'):
    M+=1
  else:
    if(M):
      Y.append(i-1)
    M=0
if(M):
  Y.append(len(S)-1)
ans=0
if(len(X)>=K):
  for i in range(len(X)-K):
    ans=max(ans,Y[i+K]-X[i]+1)
else:
  ans=len(S)
ans=max(ans,Y[min(K-1,len(X)-1)]+1)
ans=max(ans,len(S)-X[max(len(X)-K,0)])
print(ans)

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
S=input()
X,Y=[],[]
M=0
for i in range(len(S)):
  if(S[i]=='1' and M==0):
    X.append(i)
    M+=1
  elif(S[i]=='1'):
    M+=1
  else:
    if(M):
      Y.append(i-1)
    M=0
if(M):
  Y.append(len(S)-1)
ans=0
if(len(X)>=K):
  for i in range(len(X)-K):
    ans=max(ans,Y[i+K]-X[i]+1)
else:
  ans=len(S)
ans=max(ans,Y[min(K-1,len(X))]+1)
ans=max(ans,len(S)-X[max(len(X)-K,0)])
print(ans)

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
S=input()
X,Y=[],[]
M=0
for i in range(len(S)):
  if(S[i]=='1' and M==0):
    X.append(i)
    M+=1
  elif(S[i]=='1'):
    M+=1
  else:
    if(M):
      Y.append(i-1)
    M=0
if(M):
  Y.append(len(S)-1)
ans=0
for i in range(max(len(X)-K,0)):
  ans=max(ans,Y[i+K]-X[i]+1)
ans=max(ans,Y[min(K-1,len(X))]+1)
ans=max(ans,len(S)-X[max(len(X)-K,0)])
print(ans)
Problem p03129 (python)

Fixed submission:
N,K=map(int,input().split())
if(K*2-1<=N):
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
X=[0]*4
for i in range(3):
  A,B=map(int,input().split())
  X[A-1]+=1
  X[B-1]+=1
X.sort()
if(X[0]==1 and X[1]==1 and X[2]==2):
  print("YES")
else:
  print("NO")
Problem p02574 (python)

Fixed submission:
nn=int(input())
aa=list(map(int,input().split()))
a=[x for x in aa if x!=1]
n=len(a)
if n<=1:
  print('pairwise coprime')
  exit()

# 素因数分解
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0:
        cnt+=1
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr
tmp=[i for i,j in factorization(min(a))]
not_flg=False
for t in tmp:
  flg=True
  for x in a:
    if x%t==0:
      pass
    else:
      flg=False
      break
  if flg:
    not_flg=flg
    break
if not_flg:
  if n==nn:
    print('not coprime')
  else:
    print('setwise coprime')
  exit()
#if n>78499:
if n>99999:
  print('setwise coprime')
  exit()
ary=set(())
for x in a:
  tmp={i for i,j in factorization(x)}
  for t in tmp:
    if t in ary:
      print('setwise coprime')
      exit()
    else:
      ary.add(t)
print('pairwise coprime')

Buggy submission (verdict: Runtime Error):
n=int(input())
aa=list(map(int,input().split()))
a=[x for x in aa if x!=1]
n=len(a)
# 素因数分解
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0:
        cnt+=1
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr
tmp=[i for i,j in factorization(min(a))]
not_flg=False
for t in tmp:
  flg=True
  for x in a:
    if x%t==0:
      pass
    else:
      flg=False
      break
  if flg:
    not_flg=flg
    break
if not_flg:
  print('not coprime')
  exit()
#if n>78499:
if n>99999:
  print('setwise coprime')
  exit()
ary=set(())
for x in a:
  tmp={i for i,j in factorization(x)}
  for t in tmp:
    if t in ary:
      print('setwise coprime')
      exit()
    else:
      ary.add(t)
print('pairwise coprime')

Buggy submission (verdict: Runtime Error):
n=int(input())
aa=list(map(int,input().split()))
a=[x for x in aa if x!=1]
n=len(a)
# 素因数分解
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0:
        cnt+=1
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr
tmp=[i for i,j in factorization(min(a))]
not_flg=False
for t in tmp:
  flg=True
  for x in a:
    if x%t==0:
      pass
    else:
      flg=False
      break
  if flg:
    not_flg=flg
    break
if not_flg:
  print('not coprime')
  exit()
if n>78498:
  print('setwise coprime')
  exit()
ary=set(())
for x in a:
  tmp={i for i,j in factorization(x)}
  for t in tmp:
    if t in ary:
      print('setwise coprime')
      exit()
    else:
      ary.add(t)
print('pairwise coprime')