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

Fixed submission:
def f(N): # N is string
    k = len(N)
    dp = [[[[0 for _ in range(10)] for _ in range(2)] for _ in range(2)] for _ in range(k+1)]
    for j in range(10):
        dp[1][0][0][j]=(j==int(N[0]))
        dp[1][0][1][j]=0
        dp[1][1][0][j]=(j<int(N[0]))
        dp[1][1][1][j]=0
    for i in range(2,k+1):
        for j in range(10):
            for m in range(10):
                dp[i][0][1][j] += (dp[i-1][0][0][m]+dp[i-1][0][1][m])*(abs(m-j)<=1)*(j==int(N[i-1]))
            dp[i][1][0][j]=1
            for m in range(10):
                dp[i][1][1][j] += (dp[i-1][0][0][m]+dp[i-1][0][1][m])*(abs(m-j)<=1)*(j<int(N[i-1]))\
                                    +dp[i-1][1][1][m]*(abs(m-j)<=1)
            for m in range(1,10):
                dp[i][1][1][j] += dp[i-1][1][0][m]*(abs(m-j)<=1)
    cnt = 0
    for j in range(10):
        cnt += dp[k][0][0][j]+dp[k][0][1][j]+dp[k][1][0][j]+dp[k][1][1][j]
    return cnt-1
K = int(input())
low = 0
high = 4*10**9
while high-low>1:
    mid = (high+low)//2
    n = f(str(mid))
    if n<K:
        low = mid
    elif n>=K:
        high = mid
print(high)

Buggy submission (verdict: Runtime Error):
def rn(x):
    z = list(map(int,list(str(x))))
    N = len(z)
    z.insert(0,0)
    dp = [[[0 for _ in range(10)] for _ in range(2)] for _ in range(N+1)]
    dp[1][0][z[1]]=1
    for j in range(z[1]):
        cp[1][1][j]=1
    for i in range(2,N+1):
        if abs(z[i]-z[i-1])<=1:
            dp[i][0][z[i]] = 1
        for j in range(10):
            dp[i][1][j] = dp[i-1][0][z[i-1]]*int(j<z[i])*int(abs(j-z[i-1])<=1)
            for k in range(10):
                dp[i][1][j] += dp[i-1][1][k]*int(abs(j-k)<=1)
    cnt = dp[N][0][z[N]]
    for j in range(10):
        cnt += dp[N][1][j]
    return cnt
K = int(input())
high = 3234566667
low = 0
while high-low>1:
    mid = (high+low)//2
    if rn(mid)>=K:
        high = mid
    else:
        low = mid
print(high)
Problem p02733 (python)

Fixed submission:
from itertools import product
INFTY = 10**4
H,W,K = map(int,input().split())
S = [list(map(int,list(input()))) for _ in range(H)]
cmin = INFTY
for x in product((0,1),repeat=H-1):
    cur = 0
    cnt = 0
    h = sum(x)+1
    A = [0 for _ in range(h)]
    for j in range(W):
        ind = 0
        A0 = [0 for _ in range(h)]
        for i in range(H):
            if i<H-1 and x[i]==1:
                A0[ind] += S[i][j]
                ind += 1
            else:
                A0[ind] += S[i][j]
        B = [A[i]+A0[i] for i in range(h)]
        if max(A0)>K:
            cnt = INFTY
            break
        if max(B)>K:
            cur = j
            cnt += 1
            A = A0[:]
        else:
            A = B[:]
    cmin = min(cmin,cnt+sum(x))
print(cmin)

Buggy submission (verdict: Runtime Error):
for x in product((0,1),repeat=H-1):
    cur = 0
    cnt = 0
    h = sum(x)+1
    A = [0 for _ in range(h)]
    flag = 0
    for j in range(W):
        ind = 0
        A0 = [0 for _ in range(h)]
        for i in range(H):
            if i<H-1 and x[i]==1:
                A0[ind] += S[i][j]
                ind += 1
            else:
                A0[ind] += S[i][j]
        B = [A[i]+A0[i] for i in range(h)]
        if j==0 and max(B)>K:
            flag = 1
            break
        if max(B)>K:
            cur = j
            cnt += 1
            A = A0[:]
        else:
            A = B[:]
    if flag ==0:
        cmin = min(cmin,cnt+sum(x))
print(cmin)
Problem p02744 (python)

Fixed submission:
from itertools import combinations
def g(i):
    return chr(i+96)
def f(n,i):
    global Ind
    if n==0:
        B.append("".join(A))
        return
    if n==1:
        j = Ind.pop()
        A[j] = g(i)
        B.append("".join(A))
        A[j]=0
        Ind.append(j)
        Ind = sorted(Ind)
        return
    j0 = Ind.pop(0)
    Ind1 = Ind[:]
    A[j0] = g(i)
    for k in range(n):
        for x in combinations(Ind1,n-1-k):
            tmp = []
            for j in range(n-1-k):
                A[x[j]] = g(i)
                tmp.append(x[j])
            for j in tmp:
                Ind.remove(j)
            f(k,i+1)
            for j in tmp:
                A[j] = 0
                Ind.append(j)
            Ind = sorted(Ind)
    Ind.append(j0)
    Ind = sorted(Ind)
    
N = int(input())
A = [0 for _ in range(N)]
Ind = list(range(N))
B = []
f(N,1)
B = sorted(B)
for b in B:
    print(b)

Buggy submission (verdict: Runtime Error):
from collections import deque
D1 = {i:chr(i+96) for i in range(1,27)}
D2 = {val:key for key,val in D1.items()}

N = int(input())
heap = deque([(D[1],1)])
A = []
while heap:
    a,n = heap.popleft()
    if n<N:
        j = D2[a[-1]]
        for i in range(1,min(j+1,26)+1):
            heap.append((a+D1[i],n+1))
    if n==N:
        A.append(a)
A = sorted(A)
for i in range(len(A)):
    print(A[i])

Buggy submission (verdict: Runtime Error):
from itertools import combinations
def g(i):
    return chr(i+96)
def f(n,i):
    global Ind
    if n==0:
        B.append("".join(A))
        return
    if n==1:
        j = Ind.pop()
        A[j] = g(i)
        B.append("".join(A))
        A[j]=0
        Ind.append(j)
        Ind = sorted(Ind)
        return
    j = Ind.pop(0)
    A[j] = g(i)
    for k in range(n):
        for x in combinations(Ind,n-1-k):
            tmp = []
            for j in range(n-1-k):
                A[x[j]] = g(i)
                tmp.append(x[j])
            for j in tmp:
                Ind.remove(j)
            f(k,i+1)
            for j in tmp:
                A[j] = 0
                Ind.append(j)
            Ind = sorted(Ind)
    
N = int(input())
A = [0 for _ in range(N)]
Ind = list(range(N))
B = []
f(N,1)
B = sorted(B)
for b in B:
    print(b)
Problem p02756 (python)

Fixed submission:
from collections import deque
S = deque(list(input().strip()))
Q = int(input())
cnt = 0
for _ in range(Q):
    q = list(input().split())
    if int(q[0])==1:
        cnt += 1
    else:
        if cnt%2==0:
            if int(q[1])==1:
                S.appendleft(q[2])
            else:
                S.append(q[2])
        else:
            if int(q[1])==1:
                S.append(q[2])
            else:
                S.appendleft(q[2])
if cnt%2==0:
    print("".join(S))
else:
    S.reverse()
    print("".join(S))

Buggy submission (verdict: Runtime Error):
from collections import deque
S = deque(list(input().strip()))
Q = int(input())
P = 0
for _ in range(Q):
    q = list(input().split())
    if q[0]=="1":
        P += 1
        P = P%2
    else:
        c = q[2]
        if q[1]=="1":
            if P==0:
                S.appendleft(c)
            else:
                S.append(c)
        else:
            if P==0:
                S.append(c)
            else:
                S.appendleft(c)
if P==1:
    S = S[::-1]
print("".join(S))

Buggy submission (verdict: Runtime Error):
from collections import deque
S = deque(list(input().strip()))
Q = int(input())
cnt = 0
for i in range(Q):
    q = list(input().split())
    if len(q)==1:
        cnt += 1
    else:
        F = int(q[1])
        C = q[2]
        if cnt%2==0:
            if F==1:
                S.appendleft(C)
            else:
                S.append(C)
        else:
            if F==1:
                S.append(C)
            else:
                S.appendleft(C)
if cnt%2==0:
    print("".join(S))
else:
    S = S[::-1]
    print("".join(S))

Buggy submission (verdict: Runtime Error):
from collections import deque
S = deque(list(input().strip()))
Q = int(input())
cnt = 0
for _ in range(Q):
    q = list(input().split())
    if int(q[0])==1:
        cnt += 1
    else:
        if cnt%2==0:
            if int(q[1])==1:
                S.appendleft(q[2])
            else:
                S.append(q[2])
        else:
            if int(q[1])==1:
                S.append(q[2])
            else:
                S.appendleft(q[2])
if cnt%2==0:
    print("".join(S))
else:
    
    print("".join(S.reverse()))

Buggy submission (verdict: Runtime Error):
from collections import deque
S = deque(list(input().strip()))
Q = int(input())
cnt = 0
for _ in range(Q):
    q = list(input().split())
    if int(q[0])==1:
        cnt += 1
    else:
        if cnt%2==0:
            if int(q[1])==1:
                S.appendleft(q[2])
            else:
                S.append(q[2])
        else:
            if int(q[1])==1:
                S.append(q[2])
            else:
                S.appendleft(q[2])
if cnt%2==0:
    print("".join(S))
else:
    S = S[::-1]
    print("".join(S))
Problem p02775 (python)

Fixed submission:
S = input().strip()
INFTY=10**8
dp = [[INFTY for _ in range(2)] for _ in range(len(S))]
for k in range(10):
    n = int(S[-1])
    if k>= n:
        dp[0][0] = min(dp[0][0],2*k-n)
    else:
        dp[0][1] = min(dp[0][1],2*k-n+10)
for i in range(1,len(S)):
    n = int(S[-(1+i)])
    for k in range(10):
        if k>n:
            dp[i][0] = min(dp[i][0],2*k-n+dp[i-1][0],k+(k-1)-n+dp[i-1][1])
        elif k==n:
            dp[i][0] = min(dp[i][0],2*k-n+dp[i-1][0])
            if n==0:
                dp[i][1] = min(dp[i][1],k+(k-1)%10-n+dp[i-1][1])
            else:
                dp[i][1] = min(dp[i][1],k+10-n+k-1+dp[i-1][1])
        elif k<n:
            dp[i][1] = min(dp[i][1],k+10-n+k+dp[i-1][0],k+10-n+k-1+dp[i-1][1])
print(min(dp[len(S)-1][0],dp[len(S)-1][1]+1))

Buggy submission (verdict: Runtime Error):
S = input().strip()
dp = [[INFTY for _ in range(2)] for _ in range(len(S))]
for k in range(10):
    n = int(S[-1])
    if k>= n:
        dp[0][0] = min(dp[0][0],2*k-n)
    else:
        dp[0][1] = min(dp[0][1],2*k-n+10)
for i in range(1,len(S)):
    n = int(S[-(1+i)])
    for k in range(10):
        if k>n:
            dp[i][0] = min(dp[i][0],2*k-n+dp[i-1][0],k+(k-1)-n+dp[i-1][1])
        elif k==n:
            dp[i][0] = min(dp[i][0],2*k-n+dp[i-1][0])
            if n==0:
                dp[i][1] = min(dp[i][1],k+(k-1)%10-n+dp[i-1][1])
            else:
                dp[i][1] = min(dp[i][1],k+10-n+k-1+dp[i-1][1])
        elif k<n:
            dp[i][1] = min(dp[i][1],k+10-n+k+dp[i-1][0],k+10-n+k-1+dp[i-1][1])
print(min(dp[len(S)-1][0],dp[len(S)-1][1]+1))
Problem p02802 (python)

Fixed submission:
N,M = map(int,input().split())
C = {str(i):[0,0] for i in range(1,N+1)}
for _ in range(M):
    p,s = input().split()
    if s == "AC":
        if C[p][0]==0:
            C[p][0] = 1
    else:
        if C[p][0]==0:
            C[p][1] += 1
A = [0,0]
for i in range(1,N+1):
    if C[str(i)][0]==1:
        A[0] += 1
        A[1] += C[str(i)][1]
print(*A)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
A = [0 for _ in range(N+1)]
B = [0 for _ in range(N+1)]
for _ in range(M):
    p,S = input().split()
    p = int(p)
    if S=="AC":
        if A[p]==0:
            A[p]=1
    else:
        if A[p]==0:
            B[p] += 1
for i in range(N+1):
    if A[p]==0:
        B[p]=0
print(sum(A),sum(B))
Problem p02813 (python)

Fixed submission:
from itertools import permutations
N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
A = []
for x in permutations(range(1,N+1),N):
    A.append(list(x))
A = sorted(A)
indP = A.index(P)
indQ = A.index(Q)
print(abs(indP-indQ))

Buggy submission (verdict: Runtime Error):
from itertools import permutations
N = int(input())
P = tuple(list(map(int,input().split())))
Q = tuple(list(map(int,input().split())))
cnt = 0
for x in permutations(range(1,N+1),N):
    if P==x:
        indP = cnt
    elif Q==x:
        indQ = cnt
    cnt += 1
print(abs(indP-indQ))
Problem p02814 (python)

Fixed submission:
def eveCheck(a):
    k = 0
    while a%2==0:
        a = a//2
        k += 1
    return k
def gcd(x,y):
    while y>0:
        x,y = y,x%y
    return x
N,M = map(int,input().split())
A = list(map(int,input().split()))
k = eveCheck(A[0])
flag = 0
for i in range(1,N):
    if k!=eveCheck(A[i]):
        flag = 1
        break
if flag==1:
    print(0)
else:
    m = A[0]
    for i in range(1,N):
        m = m*(A[i]//gcd(m,A[i]))
    a = m//2
    print((M-a)//m+1)

Buggy submission (verdict: Runtime Error):
cd(x,y):
    while y>0:
        x,y = y,x%y
    return x
N,M = map(int,input().split())
A = list(set(list(map(int,input().split()))))
B = []
for i in range(len(A)):
    B.append((A[i]//2)%2)
B = list(set(B))
if len(B)==2:
    print(0)
else:
    a = A[0]
    for i in range(1,len(A)):
        a = gcd(a,A[i])
    b = a
    for x in A:
        b *= x//a
    if B[0]==1:
        k = (M-b//2)//b
        print(k+1)
    else:
        A = sorted(A)
        flag = 1
        for i in range(1,len(A)):
            if A[i]%A[i-1]!=0:
                flag = 0
                break
        if flag==1:
            k = (M-b//2)//b
            print(k+1)
        else:
            print(0)
Problem p02824 (python)

Fixed submission:
from bisect import bisect_left,bisect_right
N,M,V,P = map(int,input().split())
A = sorted(list(map(int,input().split())))
low = -1
high = A[-1]+M
while high-low>1:
    mid = (low+high)//2
    indL = bisect_left(A,mid-M)
    indR = bisect_right(A,mid)
    if indL>N-P:
        high = mid
        continue
    if indR<N-P+1:
        low = mid
        continue
    tot = M*V
    i = indL
    while i<N-P+1:
        if tot-(mid-A[i])<0:break
        tot -= mid-A[i]
        i += 1
    if i<N-P+1 or 0<=tot<=M*(P-1+indL):
        high = mid
    else:
        low = mid
ind = bisect_left(A,high-M)
print(N-ind)

Buggy submission (verdict: Runtime Error):
from bisect import bisect_right
N,M,V,P = map(int,input().split())
A = sorted(list(map(int,input().split())))
cnt = M*V
B = [[A[i],i] for i in range(N)]
for i in range(N):
    if cnt>=M:
        B[i][0] += M
        cnt -= M
    else:break
B = sorted(B,key=lambda x:x[1],reverse=True)
B = sorted(B,key=lambda x:x[0],reverse=True)
ind = B[P-1][1]
cur = P-1
while True:
    if B[cur+1][0]==B[cur][0]:
        ind = B[cur+1][1]
        cur += 1
    else:break
low = -1
high = ind
while high-low>1:
    mid = (high+low)//2
    cnt = M*V
    B = A[:]
    for i in range(mid+1):
        B[i] += M
        cnt -= M
    b = B[mid]
    for i in range(mid+1,N):
        if B[i]<b and cnt>=b-B[i]:
            B[i] += b-B[i]
            cnt -= b-B[i]
        else:break
    for i in range(N-1,-1,-1):
        if cnt>=M:
            B[i] += M
            cnt -= M
        elif 0<cnt<M:
            B[i] += cnt
            break
    ind = bisect_right(B,b)
    if N-ind<P:
        high = mid
    else:
        low = mid
print(N-high)
Problem p02838 (python)

Fixed submission:
p = 10**9+7
N = int(input())
C = {i:0 for i in range(60)}
A = input().split()
for i in range(N):
    a = bin(int(A[i]))[2:]
    n = len(a)
    for j in range(n):
        if a[j]=="1":
            C[n-1-j] += 1
cnt = 0
for i in range(60):
    if C[i]>0:
        cnt = (cnt+C[i]*(N-C[i])*2**i)%p
print(cnt)

Buggy submission (verdict: Runtime Error):
N = int(input())
C = {i:0 for i in range(20)}
A = input().split()
for i in range(N):
    a = bin(int(A[i]))[2:]
    n = len(a)
    for j in range(n):
        if a[j]=="1":
            C[n-1-j] += 1
cnt = 0
for i in range(20):
    if C[i]>0:
        cnt += C[i]*(N-C[i])*2**i
print(cnt)
Problem p02845 (python)

Fixed submission:
p = 10**9+7
N = int(input())
A = list(map(int,input().split()))
cnt = 1
cnt0 =0
C = {i:0 for i in range(N)}
B = []
for i in range(N):
    a = A[i]
    if a==0:
        cnt = (cnt*(3-cnt0))%p
        cnt0 += 1
    else:
        cnt = (cnt*C[a-1])%p
        C[a-1] -= 1
    C[a] += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
p = 10**9+7
N = int(input())
A = list(map(int,input().split()))
C={0:1}
ans = 3
for i in range(1,N):
    a = A[i]
    if a not in C:
        C[a]=0
    C[a] += 1
    if C[a]==1:
        ans = (ans*C[a-1])%p
    elif a==0 and C[a]==2:
        ans = ans*2
    elif a>0 and C[a]==2:
        ans = (ans*(C[a-1]-1))%p
print(ans)

Buggy submission (verdict: Runtime Error):
p = 10**9+7
N = int(input())
A = list(map(int,input().split()))
ans = 3
C = {0:1}
for i in range(1,N):
    a = A[i]
    if a not in C:
        C[a] = 0
    C[a] += 1
    if C[a]==1:
        ans = (ans*C[a-1])%p
    elif a>0 and C[a]==2:
        ans = (ans*(C[a-1]-1))%p
    elif a==0 and C[a]==2:
        ans = (ans*2)%p
print(ans)

Buggy submission (verdict: Runtime Error):
p = 10**9+7
N = int(input())
A = list(map(int,input().split()))
cnt = 1
cnt0 =0
C = {0:0}
B = []
for i in range(N):
    a = A[i]
    if a==0:
        cnt = (cnt*(3-cnt0))%p
        cnt0 += 1
    else:
        cnt = (cnt*C[a-1])%p
        C[a-1] -= 1
    if a not in C:
        C[a] = 0
    C[a] += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
p = 10**9+7
N = int(input())
A = list(map(int,input().split()))
C = {}
D = {}
cnt = 1
for i in range(N):
    a = A[i]
    if a not in C:
        C[a] = 0
        D[a] = 0
    C[a] += 1
    D[a] += 1
    if a>0:
        cnt = (cnt*C[a-1])%p
        C[a-1] -= 1
if D[0]==3:
    cnt = (cnt*6)%p
else:
    cnt = (cnt*3)%p
print(cnt)

Buggy submission (verdict: Runtime Error):
p = 10**9+7
N = int(input())
A = list(map(int,input().split()))
C = {}
D = {}
cnt = 1
for i in range(N):
    a = A[i]
    if a not in C:
        C[a] = 0
        D[a] = 0
    C[a] += 1
    D[a] += 1
    if a>0:
        cnt = (cnt*C[a-1])%p
        C[a-1] -= 1
if D[0]==3:
    cnt = (cnt*6)%p
else:
    cnt = (cnt*3)%p
print(cnt)
Problem p02846 (python)

Fixed submission:
T1,T2 = map(int,input().split())
A1,A2 = map(int,input().split())
B1,B2 = map(int,input().split())
dif = T1*A1+T2*A2-T1*B1-T2*B2
if dif==0:
    print("infinity")
elif dif>0:
    if B1>A1:
        k = int(((B1-A1)*T1)/dif)
        if abs(((B1-A1)*T1)/dif-round(((B1-A1)*T1)/dif))<1e-20:
            print(2*round(((B1-A1)*T1)/dif))
        else:
            print(2*k+1)
    else:
        print(0)
else:
    if A1>B1:
        k = int(((A1-B1)*T1)/abs(dif))
        if abs((A1-B1)*T1/abs(dif)-round(((A1-B1)*T1)/abs(dif)))<1e-20:
            print(2*round(((A1-B1)*T1)/abs(dif)))
        else:
            print(2*k+1)
    else:
        print(0)

Buggy submission (verdict: Runtime Error):
T1,T2 = map(int,input().split())
A1,A2 = map(int,input().split())
B1,B2 = map(int,input().split())
dif = T1*A1+T2*A2-T1*B1-T2*B2
if dif==0:
    print("infinity")
elif dif>0:
    if B1>A1:
        k = int(((B1-A1)*T1)/dif)
        if abs(((B1-A1)*T1)/dif-round(((B1-A1)*T1)/dif))<1e-20:
            print(2*round(((B1-A1)*T1)/dif))
        else:
            print(2*k+1)
    else:
        print(0)
else:
    if A1>B1:
        k = int(((A1-B1)*T1)/abs(dif))
        if abs((A1-B1)*T1/abs(dif)-round(((A1-B1)*T1)/abs(dif))<1e-20:
            print(2*round(((A1-B1)*T1)/abs(dif)))
        else:
            print(2*k+1)
    else:
        print(0)
Problem p02855 (python)

Fixed submission:
H,W,K = map(int,input().split())
S = [input().strip() for _ in range(H)]
A = [[0 for _ in range(W)] for _ in range(H)]
row = 0
cnt = 1
for i in range(H):
    B = []
    for j in range(W):
        if S[i][j]=="#":
            B.append(j)
    if len(B)==0:
        continue
    elif len(B)==1:
        for k in range(row,i+1):
            for j in range(W):
                A[k][j] = cnt
        cnt += 1
        row = i+1
    else:
        for l in range(len(B)):
            if l==0:
                for k in range(row,i+1):
                    for j in range(B[0]+1):
                        A[k][j] = cnt
                cnt += 1
            elif l<len(B)-1:
                for k in range(row,i+1):
                    for j in range(B[l-1]+1,B[l]+1):
                        A[k][j] = cnt
                cnt += 1
            else:
                for k in range(row,i+1):
                    for j in range(B[-2]+1,W):
                        A[k][j] = cnt
                cnt += 1
        row = i+1
if row != H:
    for i in range(row,H):
        for j in range(W):
            A[i][j] = A[i-1][j]
for i in range(H):
    print(*A[i])

Buggy submission (verdict: Runtime Error):
H,W,K = map(int,input().split())
S = [input().strip() for _ in range(H)]
A = [[0 for _ in range(W)] for _ in range(H)]
G = []
for i in range(H):
    for j in range(W):
        if S[i][j]=="#":
            G.append((i,j))
G = sorted(G,key=lambda x:x[0])
G = sorted(G,key=lambda x:x[1])
k = len(G)
cnt = 1
u = 0
l = 0
for i in range(k):
    if G[i][1]<W-1 and G[i][1]<G[i+1][1]:
        for i1 in range(u,H):
            for j1 in range(l,G[i+1][1]):
                A[i1][j1] = cnt
        u = 0
        l = G[i+1][1]
        cnt += 1
    elif G[i][1]<W-1 and G[i][1]==G[i+1][1]:
        j = i+2
        flag = 0
        while j<k:
            if G[i][1]<G[j][1]:
                flag = 1
                break
            j += 1
        if flag==1:
            for i1 in range(u,G[i+1][0]):
                for j1 in range(l,G[j][1]):
                    A[i1][j1] = cnt
            u = G[i+1][0]
            cnt += 1
        else:
            for i1 in range(u,G[i+1][0]):
                for j1 in range(l,W):
                    A[i1][j1] = cnt
            u = G[i+1][0]
            l = 0
            cnt += 1
    else:
        if i<k-1:
            for i1 in range(u,G[i+1][0]):
                A[i1][W-1] = cnt
            u = G[i+1][0]
            cnt += 1
        else:
            for i1 in range(u,H):
                A[i1][W-1] = cnt
for i in range(H):
    print(*A[i])
Problem p02901 (python)

Fixed submission:
from itertools import product
N,M = map(int,input().split())
G = {i:[] for i in range(M)}
for i in range(M):
    a,b = map(int,input().split())
    G[i] = [a,list(map(int,input().split()))]
INFTY = 10**11
dp = [[INFTY for S in range(2**N)] for _ in range(M+1)]
for j in range(M+1):
    dp[j][0] = 0
for j in range(M):
    for S in range(2**N):
        y = 0
        for x in G[j][1]:
            y += 2**(x-1)
        dp[j+1][S] = min(dp[j][S],dp[j][S&(~y)]+G[j][0])
a =dp[M][2**N-1]
if a>=INFTY:
    print(-1)
else:
    print(a)

Buggy submission (verdict: Runtime Error):
INFTY = 10**8+10
N,M = map(int,input().split())
A = {}
for i in range(1,M+1):
    a,b = map(int,input().split())
    C = list(map(int,input().split()))
    A[i] = (a,C)
C = {}
for i in range(1,M+1):
    for j in A[i][1]:
        if j not in C:
            C[j] = 0
        C[j] += 1
if len(C)==N:
    dp = [[INFTY for _ in range(2**N)] for _ in range(M+1)]
    dp[0][0] = 0
    for i in range(1,M+1):
        for S in range(2**N):
            dp[i][S] = dp[i-1][S]
            for a in A[i][1]:
                dp[i][S] = min(dp[i-1][S&~a]+A[i][0])
    print(dp[M,2**N-1])
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
INFTY = 10**8+10
N,M = map(int,input().split())
A = {}
for i in range(1,M+1):
    a,b = map(int,input().split())
    C = list(map(int,input().split()))
    A[i] = (a,C)
C = {}
for i in range(1,M+1):
    for j in A[i][1]:
        if j not in C:
            C[j] = 0
        C[j] += 1
if len(C)==N:
    dp = [[INFTY for _ in range(2**N)] for _ in range(M+1)]
    dp[0][0] = 0
    for i in range(1,M+1):
        for S in range(2**N):
            dp[i][S] = dp[i-1][S]
            for a in A[i][1]:
                dp[i][S] = min(dp[i-1][S&~a]+A[i][0])
    print(dp[M,2**N-1])
else:
    print(-1)
Problem p02913 (python)

Fixed submission:
N = int(input())
S = input().strip()
cmax = 0
for k in range(1,N):
    X = S[:N-k]
    Y = S[k:]
    cur = 0
    cnt = 0
    for i in range(N-k):
        if X[i]!=Y[i]:
            cmax = max(cmax,min(cnt,k))
            cur = i
            cnt = 0
        else:
            cnt += 1
    cmax = max(cmax,min(cnt,k))
print(cmax)

Buggy submission (verdict: Runtime Error):
= int(input())
S = input().strip()
cmax = 0
for k in range(1,N//2+1):
    C = {}
    x = S[:k]
    C[x]=[0]
    for i in range(1,N-k+1):
        x = x[1:]+S[i+k-1]
        if x not in C:
            C[x]=[]
        C[x].append(i)
    flag = 0
    for a in C:
        if len(C[a])>1:
            if C[a][0]-C[a][-1]>=k:
                cmax = max(cmax,k)
                flag = 1
                break
            if flag==1:break
print(cmax)