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

Fixed submission:
N,Q=map(int,input().split())
l=[[1,0,0]]
for i in range(1,N):
    a,b=map(int,input().split())
    l.append([b,a,0])
l.sort()
for i in range(Q):
    p,x=map(int,input().split())
    l[p-1][2]+=x
t=[l[0][2]]
for i in range(1,N):
    t.append(t[l[i][1]-1]+l[i][2])
print(*t)

Buggy submission (verdict: Runtime Error):
N,Q=map(int,input().split())
l=[[1,0,0]]
for i in range(1,N):
    a,b=map(int,input().split())
    l.append([b,a,0])
l.sort()
for i in range(Q):
    p,x=map(int,input().split())
    l[p-1][2]+=x
t=[l[0][2]]
for i in range(1,N):
    t.append(t[l[i][1]-1]+l[i][2])
print(*t)

Buggy submission (verdict: Runtime Error):
N,Q=map(int,input().split())
l=[[1,0,0]]
for i in range(1,N):
    a,b=map(int,input().split())
    l.append([b,a,0])
l.sort()
for i in range(Q):
    p,x=map(int,input().split())
    l[p-1][2]+=x
t=[l[0][2]]
for i in range(1,N):
    t.append(t[l[i][1]-1]+l[i][2])
print(*t)
Problem p03008 (python)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
l1=[i for i in range(3) if B[i]>A[i]]
l2=[i for i in range(3) if B[i]<A[i]]
r=[B[i]-A[i] for i in range(3)]
def b(l):
    global N
    if len(l)==3:
        M=0
        for i in range(N//A[0]+1):
            for j in range((N-i*A[0])//A[1]+1):
                k=(N-i*A[0]-j*A[1])//A[2]
                M=max(M,i*B[0]+j*B[1]+k*B[2]+(N-i*A[0]-j*A[1]-k*A[2]))
        N=M
    elif len(l)==2:
        M=0
        for i in range(N//A[l[0]]+1):
            j=(N-i*A[l[0]])//A[l[1]]
            M=max(M,i*B[l[0]]+j*B[l[1]]+(N-i*A[l[0]]-j*A[l[1]]))
        N=M
    elif len(l)==1:
        i=N//A[l[0]]
        N=i*B[l[0]]+N-i*A[l[0]]
def b2(l):
    global N
    if len(l)==3:
        M=0
        for i in range(N//B[0]+1):
            for j in range((N-i*B[0])//B[1]+1):
                k=(N-i*B[0]-j*B[1])//B[2]
                M=max(M,i*A[0]+j*A[1]+k*A[2]+(N-i*B[0]-j*B[1]-k*B[2]))
        N=M
    elif len(l)==2:
        M=0
        for i in range(N//B[l[0]]+1):
            j=(N-i*B[l[0]])//B[l[1]]
            M=max(M,i*A[l[0]]+j*A[l[1]]+(N-i*B[l[0]]-j*B[l[1]]))
        N=M
    elif len(l)==1:
        i=N//B[l[0]]
        N=i*A[l[0]]+N-i*B[l[0]]
b(l1)
r=list(map(lambda x: -x,r))
b2(l2)
print(N)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
l1=[i for i in range(3) if B[i]>A[i]]
l2=[i for i in range(3) if B[i]<A[i]]
r=[B[i]-A[i] for i in range(3)]
def b(l):
    global N
    if len(l)==3:
        for i in range(N//A[0]+1):
            for j in range((N-i*A[0])//A[1]+1):
                k=(N-i*A[0]-j*A[1])//A[2]
                N=max(M,i*B[0]+j*B[1]+k*B[2]+(N-i-j-k))
    elif len(l)==2:
        for i in range(N//A[l[0]]+1):
            j=(N-i*A[l[0]])//A[l[1]]
            N=max(M,i*B[l[0]]+j*B[l[1]]+(N-i-j))
    elif len(l)==1:
        i=N//A[l[0]]
        N=i*B[l[0]]+N-i
def b2(l):
    global N
    if len(l)==3:
        for i in range(N//B[0]+1):
            for j in range((N-i*B[0])//B[1]+1):
                k=(N-i*B[0]-j*B[1])//B[2]
                N=max(M,i*A[0]+j*A[1]+k*A[2]+(N-i-j-k))
    elif len(l)==2:
        for i in range(N//B[l[0]]+1):
            j=(N-i*B[l[0]])//B[l[1]]
            N=max(M,i*A[l[0]]+j*A[l[1]]+(N-i-j))
    elif len(l)==1:
        i=N//B[l[0]]
        N=i*A[l[0]]+N-i
b(l1)
r=list(map(lambda x: -x,r))
b2(l2)
print(N)
Problem p03096 (python)

Fixed submission:
import sys
def input():
    return sys.stdin.readline()[:-1]
N=int(input())
pr=10**9+7
a=0
l=[0]*(2*10**5)
C=[int(input())-1 for i in range(N)]
for i in range(N-1):
    if C[i]==C[i+1]:
        continue
    a,l[C[i]]=(l[C[i]]+a)%pr,(l[C[i]]+a+1)%pr
a+=l[C[-1]]
print((a+1)%pr)

Buggy submission (verdict: Runtime Error):
N=int(input())
pr=10**9+7
a=0
l=[0]*N
C=[int(input())-1 for i in range(N)]
for i in range(N-1):
    if C[i]==C[i+1]:
        continue
    a,l[C[i]]=(l[C[i]]+a)%pr,(l[C[i]]+a+1)%pr
a+=l[C[-1]]
print((a+1)%pr)

Buggy submission (verdict: Runtime Error):
import sys
def input():
    return sys.stdin.readline()[:-1]
N=int(input())
pr=10**9+7
a=0
l=[0]*(N+1)
C=[int(input())-1 for i in range(N)]
for i in range(N-1):
    if C[i]==C[i+1]:
        continue
    a,l[C[i]]=(l[C[i]]+a)%pr,(l[C[i]]+a+1)%pr
a+=l[C[-1]]
print((a+1)%pr)

Buggy submission (verdict: Runtime Error):
import sys
def input():
    return sys.stdin.readline()[:-1]
N=int(input())
pr=10**9+7
a=0
l=[0]*N
C=[int(input())-1 for i in range(N)]
for i in range(N-1):
    if C[i]==C[i+1]:
        continue
    a,l[C[i]]=(l[C[i]]+a)%pr,(l[C[i]]+a+1)%pr
a+=l[C[-1]]
print((a+1)%pr)
Problem p03145 (python)

Fixed submission:
a,b,c=map(int,input().split())
print(a*b//2)

Buggy submission (verdict: Runtime Error):
N=int(input())
h=list(map(int,input().split()))
t=[0]*N
a=0
for i in range(N):
        while t[i]<h[i]:
                for j in range(i,N):
                        if t[j]<h[j]:
                                t[j]+=1
                        else:
                                break
                a+=1
print(a)
Problem p03157 (python)

Fixed submission:
import sys
def input():
    return sys.stdin.readline()[:-1]
sys.setrecursionlimit(200000)
H,W=map(int,input().split())
S=[input() for i in range(H)]
l=[[0]*(W+2) for i in range(H+2)]
for i in range(1,H+1):
    for j in range(1,W+1):
        l[i][j]=1
a,c=0,1
def nu(h,w):
    global c,b
    if S[h-1][w-1]=="#":
        b+=1
    if l[h-1][w] and S[h-1][w-1]!=S[h-2][w-1]:
        l[h-1][w]=0
        c+=1
        nu(h-1,w)
    if l[h+1][w] and S[h-1][w-1]!=S[h][w-1]:
        l[h+1][w]=0
        c+=1
        nu(h+1,w)
    if l[h][w-1] and S[h-1][w-1]!=S[h-1][w-2]:
        l[h][w-1]=0
        c+=1
        nu(h,w-1)
    if l[h][w+1] and S[h-1][w-1]!=S[h-1][w]:
        l[h][w+1]=0
        c+=1
        nu(h,w+1)
for i in range(1,H+1):
    for j in range(1,W+2):
        if not l[i][j]:
            continue
        b,c=0,1
        l[i][j]=0
        nu(i,j)
        a+=b*(c-b)
print(a)

Buggy submission (verdict: Runtime Error):
H,W=map(int,input().split())
S=[input() for i in range(H)]
l=[[0]*(W+2) for i in range(H+2)]
for i in range(1,H+1):
    for j in range(1,W+1):
        l[i][j]=1
a,c=0,1
def nu(h,w):
    global c,b
    if S[h-1][w-1]=="#":
        b+=1
    if l[h-1][w] and S[h-1][w-1]!=S[h-2][w-1]:
        l[h-1][w]=0
        c+=1
        nu(h-1,w)
    if l[h+1][w] and S[h-1][w-1]!=S[h][w-1]:
        l[h+1][w]=0
        c+=1
        nu(h+1,w)
    if l[h][w-1] and S[h-1][w-1]!=S[h-1][w-2]:
        l[h][w-1]=0
        c+=1
        nu(h,w-1)
    if l[h][w+1] and S[h-1][w-1]!=S[h-1][w]:
        l[h][w+1]=0
        c+=1
        nu(h,w+1)
for i in range(1,H+1):
    for j in range(1,W+2):
        if not l[i][j]:
            continue
        b,c=0,1
        l[i][j]=0
        nu(i,j)
        a+=b*(c-b)
print(a)
Problem p03196 (python)

Fixed submission:
N,P=map(int,input().split())
if N==1:
    print(P)
else:
    a=1
    for i in range(2,10**6+1):
        s=0
        while True:
            if P%i==0:
                P//=i
                s+=1
            else:
                if s>=N:
                    a*=i**(s//N)
                break
    print(a)

Buggy submission (verdict: Runtime Error):
N,P=map(int,input().split())
if N==1:
    print(P)
else:
    a=1
    for i in range(2,10**6+1):
        s=0
        while True:
            if P%i==0:
                P//=i
                s+=1
            else:
                if s>=N:
                    a*=i**(s//N)
                break
    print(a)
Problem p03231 (python)

Fixed submission:
N,M=map(int,input().split())
S=input()
T=input()
from fractions import gcd
g=gcd(N,M)
L=N*M//g
for i in range(g):
    if S[i*N//g]!=T[i*M//g]:
        print(-1)
        break
else:
    print(L)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
S=input()
T=input()
from math import gcd
g=gcd(N,M)
L=N*M//g
for i in range(g):
    if S[i*N//g]!=T[i*M//g]:
        print(-1)
        break
else:
    print(L)
Problem p03244 (python)

Fixed submission:
n=int(input())
a,b=[None]*100000,[None]*100000
for i in range(100000):
    a[i]=[None]*2
    a[i][0]=0
    a[i][1]=i
    b[i]=[None]*2
    b[i][0]=0
    b[i][1]=i
l=list(map(int,input().split()))
for i in range(n//2):
    a[l[2*i]-1][0]+=1
    b[l[2*i+1]-1][0]+=1
a.sort(reverse=True)
b.sort(reverse=True)
if a[0][1]==b[0][1]:
    print(n-max(a[0][0]+b[1][0],a[1][0]+b[0][0]))
else:
    print(n-a[0][0]-b[0][0])

Buggy submission (verdict: Runtime Error):
6
105 119 105 119 105 119
Problem p03633 (python)

Fixed submission:
import fractions
def lcm(a, b):
    y = a*b // fractions.gcd(a, b)
    return (y)
N=int(input())
T = [int(input()) for i in range(N)]
if N==1:
    t=T[0]
else:
    t=lcm(T[0],T[1])
    if N>2:
        for i in range(1,N):
            t=lcm(t,T[i])
print(t)

Buggy submission (verdict: Runtime Error):
import fractions
def lcm(a, b):
    y = a*b / fractions.gcd(a, b)
    return int(y)
N=int(input())
T = [int(input()) for i in range(N)]
if N==1:
    t=T[0]
else:
    t=lcm(T[0],T[1])
    if N>2:
        for i in range(1,N):
            t=lcm(t,T[i])
print(t)

Buggy submission (verdict: Runtime Error):
import fractions
def lcm(a, b):
    y = a*b / fractions.gcd(a, b)
    return int(y)
N=int(input())
T = [int(input()) for i in range(N)]
t=lcm(T[0],T[1])
for i in range(1,N):
    t=lcm(t,T[i])
print(t)
Problem p04013 (python)

Fixed submission:
N,A=map(int, input().split())
x=tuple(map(lambda i:int(i)-A,input().split()))
l=[0]*5001
l[0]=1
for i in x:
    f=l.copy()
    for j in range(-2500,2501):
        if l[j]:
            f[i+j]+=l[j]
    l=f.copy()
print(l[0]-1)

Buggy submission (verdict: Runtime Error):
N,A=map(int, input().split())
x=tuple(map(lambda i:int(i)-A,input().split()))
l=[0]*5001
l[0]=1
for i in x:
    f=l.copy()
    for j in range(-2500,2501):
        if l[j]:
            f[i+j]+=l[j]
    l=f.copy()
print(l[0]-1)
Problem p02681 (python)

Fixed submission:
s=input()
t=input()

ls=len(s)
lt=len(t)

if lt==ls+1 and t.startswith(s):
    print ('Yes')
else:
    print("No")

Buggy submission (verdict: Runtime Error):
s=raw_input()
t=raw_input()

ls=len(s)
lt=len(t)

if lt==ls+1 and t.startswith(s):
    print ('Yes')
else:
    print("No")
Problem p02573 (python)

Fixed submission:
import numpy as np
i4 = np.int32
i8 = np.int64


def find(x, parents):
    if parents[x] == x:
        return x
    else:
        return find(parents[x], parents)


def union (x, y, parents, depth):
    x = find(x, parents)
    y = find(y, parents)
    if x == y:
        return

    if depth[x] == depth[y]:
        depth[x] += 1
        parents[y] = x
    elif depth[x] > depth[y]:
        parents[y] = x
    else:
        parents[x] = y


def main(in_file):
    stdin = open(in_file)
    N, M = [int(x) for x in stdin.readline().split()]
    a = np.empty(M, i8)
    b = np.empty(M, i8)
    for i in range(M):
        a[i], b[i] = [int(x) - 1 for x in stdin.readline().split()]
    parents = np.arange(N)
    depth = np.zeros(N, i8)
    for i in range(M):
        union(a[i], b[i], parents, depth)
    num = np.zeros(N, i8)
    for i in range(N):
        p = find(i, parents)
        num[p] += 1
    ans = num.max()
    print(ans)


main('/dev/stdin')

Buggy submission (verdict: Runtime Error):
import numpy as np
i4 = np.int32
i8 = np.int64


def find(x, parents):
    if parents[x] == x:
        return x
    else:
        return find(parents[x], parents)


def union (x, y, parents, depth):
    x = find(x, parents)
    y = find(y, parents)
    if x == y:
        return

    if depth[x] == depth[y]:
        depth[x] += 1
        parents[y] = x
    elif depth[x] > depth[y]:
        parents[y] = x
    else:
        parents[x] = y


def main(in_file):
    stdin = open(in_file)
    N, M = [int(x) for x in stdin.readline().split()]
    a = np.empty(M, i8)
    b = np.empty(M, i8)
    for i in range(M):
        a[i], b[i] = [int(x) - 1 for x in stdin.readline().split()]
    parents = np.arange(N)
    depth = np.zeros(N, i8)
    for i in range(M):
        union(a[i], b[i], parents, depth)
    num = np.zeros(M, i8)
    for i in range(N):
        p = find(i, parents)
        num[p] += 1
    ans = num.max()
    print(ans)


main('/dev/stdin')
Problem p02796 (python)

Fixed submission:
import numpy as np

stdin = np.fromstring(open(0).read(), np.int64, sep=' ')
N = stdin[0]
XL = stdin[1:].reshape(-1, 2).T
x = XL[0]
l = XL[1]
arg = np.argsort(x)
x = x[arg]
l = l[arg]
xleft = x - l
xright = x + l

count = 0
i = 0
while i < N - 1:
    for j in range(i + 1, N):
        if xright[i] > xright[j]:
            count += 1
            i = j
            break
        if xright[i] > xleft[j]:
            count += 1
            j = j + 1
        else:
            i = j
            break
    else:
        i = N - 1

print(N - count)

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

stdin = np.fromstring(open(0).read(), np.int64, sep=' ')
N = stdin[0]
XL = stdin[1:N].reshape(-1, 2).T
x = XL[0]
l = XL[1]
arg = np.argsort(x)
x = x[arg]
l = l[arg]

count = 0
i = 0
while i < N - 1:
    for j in range(i + 1, N):
        if x[i] + l[i] > x[j] - l[j]:
            count += 1
        else:
            i = j
            break
    else:
        break
print(N - count)
Problem p02797 (python)

Fixed submission:
N, K, S = map(int, input().split())
a = [S] * K
if S < 1000000000:
    b = [S + 1] * (N - K)
else:
    b = [S - 1] * (N - K)
print(' '.join(map(str, a + b)))

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

stdin = np.fromstring(open(0).read(), np.int64, sep=' ')
N = stdin[0]
XL = stdin[1:].reshape(-1, 2).T
x = XL[0]
l = XL[1]
arg = np.argsort(x)
x = x[arg]
l = l[arg]
xleft = x - l
xright = x + l

count = 0
i = 0
while i < N - 1:
    if xright[i] > xright[i + 1]:
        count += 1
        i += 1
    else:
        for j in range(i + 1, N):
            if xright[i] > xleft[j]:
                count += 1
                j = j + 1
            else:
                i = j
                break
        else:
            i = N - 1

print(N - count)

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

stdin = np.fromstring(open(0).read(), np.int64, sep=' ')
N = stdin[0]
XL = stdin[1:].reshape(-1, 2).T
x = XL[0]
l = XL[1]
arg = np.argsort(x)
x = x[arg]
l = l[arg]
xleft = x - l
xright = x + l

count = 0
i = 0
while i < N - 1:
    for j in range(i + 1, N):
        if xright[i] > xright[j]:
            count += 1
            i += 1
            break
        elif xright[i] > xleft[j]:
            count += 1
            j = j + 1
        else:
            i = j
            break
    else:
        i = N - 1

print(N - count)

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

stdin = np.fromstring(open(0).read(), np.int64, sep=' ')
N = stdin[0]
XL = stdin[1:].reshape(-1, 2).T
x = XL[0]
l = XL[1]
arg = np.argsort(x)
x = x[arg]
l = l[arg]
xleft = x - l
xright = x + l

count = 0
i = 0
while i < N - 1:
    for j in range(i + 1, N):
        if xright[i] > xright[j]:
            count += 1
            i += 1
            break    
        elif xright[i] > xleft[j]:
            count += 1
            j = j + 1
        else:
            i = j
            break
    else:
        i = N - 1

print(N - count)
Problem p02845 (python)

Fixed submission:
N = int(input())
A = map(int, input().split())
MOD = 1000000007
ans = 1
cnt = [3 if i == 0 else 0 for i in range(N + 1)]

for a in A:
    ans = ans * cnt[a] % MOD
    if ans == 0:
        break
    cnt[a] -= 1
    if cnt[a] < 0:
        cnt[N + 10] = 0
    cnt[a + 1] += 1

print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
i8 = np.int64
i4 = np.int32

def solve(A, N):
    MOD = 1000000007
    x = 0
    y = 0
    z = 0
    count = 1
    for i in range(N):
        if A[i] == x:
            if x == y and x == z:
                count = (count * 3) % MOD
            elif x == y:
                count = (count * 2) % MOD
            x += 1
        elif A[i] == y:
            if y == z:
                count = (count * 2) % MOD
            y += 1
        elif A[i] == z:
            z += 1
        else:
            A[N] = 1
    return count

def main2():
    stdin = open('/dev/stdin')
    N = int(stdin.readline())
    A = np.empty(N, i8)
    for i, c in enumerate(map(int, stdin.readline().split())):
        A[i] = c
    print(solve(A, N))

main2()
Problem p02960 (python)

Fixed submission:
import numpy as np

MOD = 1000000007
S = input()[::-1]

a = 10 ** np.arange(6) % 13
b = np.tile(np.arange(10),(6, 1))
c = a * b.T % 13
c = c.T
f = np.zeros((6, 13, 13), dtype=np.int64)
for i in range(6):
    f[i, 0, c[i]] = 1
    for j in range(12):
        f[i, j + 1] = np.roll(f[i, j], 1)

prev = np.zeros(13, dtype=np.int64)
prev[0] = 1
digit = 0

for i, c in enumerate(S):
    k = i % 6
    if c == '?':
        cur = np.dot(prev, f[k]) % MOD
        prev, cur = cur, prev
    else:
        digit += a[k] * (ord(c) - ord('0'))

m = (5 - digit) % 13
print(prev[m])

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

MOD = 1000000007
S = input()[::-1]

a = 10 ** np.arange(6) % 13
b = np.tile(np.arange(10),(6, 1))
c = a * b.T % 13
c = c.T
f = np.zeros((6, 13, 13), dtype=np.int64)
for i in range(6):
    f[i, 0, c[i]] = 1
    for j in range(12):
        f[i, j + 1] = np.roll(f[i, j], 1)

prev = np.zeros(13, dtype=np.int64)
prev[0] = 1
digit = 0

for i, c in enumerate(S):
    k = i % 6
    if c == '?':
        cur = prev @ f[k] % MOD
        prev, cur = cur, prev
    else:
        digit += a[k] * (ord(c) - ord('0'))

m = (5 - digit) % 13
print(prev[m])
Problem p02975 (python)

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
a.sort()

if a[N -1] == 0:
    print("Yes")
    exit(0)

if N % 3 == 0:
    i = N // 3
    if a[0] ^ a[i] == a[2 * i]:
        if a[0] == a[i -1] and a[i] == a[2 * i - 1] and a[2 * i] == a[N -1]:
            print("Yes")
            exit(0)

print("No")

Buggy submission (verdict: Runtime Error):
from collections import defaultdict

N = int(input())
a = list(map(int, input().split()))
d = defaultdict()
for c in a[1:]:
    d[c] += 1
for i in range(1, N):
    x = a[0]
    y = a[i]
    d[y] -= 1
    for _ in range(N - 2):
        z = x ^ y
        if z in d and d[z] > 0:
            d[z] -= 1
            x = y
            y = z
        else:
            break
    else:
        if a[0] == x ^ y:
            print("Yes")
            exit(0)

print("No")
Problem p03007 (python)

Fixed submission:
import sys
import numpy as np

N = sys.stdin.readline()
a = np.fromstring(sys.stdin.readline(), dtype='i4', sep=' ')
a.sort()
p = a[a <= 0]
q = a[a > 0]

if len(p) == 0:
    print(np.sum(q[1:]) - q[0])
    t = q[0]
    for c in q[1:-1]:
        print(str(t) + ' ' + str(c))
        t -= c
    print(str(q[-1]) + ' ' + str(t))
elif len(q) == 0:
    print(p[-1] - np.sum(p[:-1]))
    t = p[-1]
    for c in p[:-1]:
        print(str(t) + ' ' + str(c))
        t -= c
else:
    print(sum(q) - sum(p))
    t = p[0]
    for c in q[:-1]:
        print(str(t) + ' ' + str(c))
        t -= c
    print(str(q[-1]) + ' ' + str(t))
    t = q[-1] - t
    for c in p[1:]:
        print(str(t) + ' ' + str(c))
        t -= c

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

N = sys.stdin.readline()
a = np.fromstring(sys.stdin.readline(), dtype='i4', sep=' ')
a.sort()
p = a[a <= 0]
q = a[a > 0]

if len(p) == 0:
    print(np.sum(q[1:]) - q[0])
    t = q[0]
    for c in q[1:-1]:
        print(str(t) + ' ' + str(c))
        t -= c
    print(str(q[-1]) + ' ' + str(t))
elif len(q) == 0:
    print(p[-1] - np.sum(p[:-1]))
    t = p[-1]
    for c in p[:-1]:
        print(str(t) + ' ' + str(c))
        t -= c
else:
    print(sum(q) - sum(p))
    t = p[0]
    for c in q[:-1]:
        print(str(t) + ' ' + str(c))
        t -= c
    print(str(q[-1]) + ' ' + str(t))
    t = q[-1] - t
    for c in p[1:]:
        print(str(t) + ' ' + str(c))
        t -= c
Problem p03088 (python)

Fixed submission:
import re

N = int(input())
memo = [{} for i in range(N+1)]
MOD = 10 ** 9 + 7


def dfs(cur, last3):
    if last3 in memo[cur]:
        return memo[cur][last3]
    if cur == N:
        return 1
    ret = 0
    for c in 'ACGT':
        if not re.match('.AGC|.ACG|.GAC|A.GC|AG.C', last3 + c):
            ret += dfs(cur + 1, last3[1:] + c)
    ret = ret % MOD
    memo[cur][last3] = ret
    return ret


print(dfs(0, 'TTT'))

Buggy submission (verdict: Runtime Error):
iimport re
import functools

N = int(input())
MOD = 10 ** 9 + 7


@functools.lru_cache(maxsize=2**13)
def dfs(cur, last3):
    if cur == N:
        return 1
    ret = 0
    for c in 'ACGT':
        if not re.match('.AGC|.ACG|.GAC|A.GC|AG.C', last3 + c):
            ret += dfs(cur + 1, last3[1:] + c)
    return ret % MOD


print(dfs(0, 'TTT'))
Problem p03096 (python)

Fixed submission:
import sys

N = int(input())
C = []
pre = 0
for _ in range(N):
    c = int(sys.stdin.readline())
    if pre == c:
        continue
    else:
        C.append(c)
        pre = c

ans = 1
dic = {}
for c in C:
    if c in dic.keys():
        a = dic[c]
        dic[c] += ans
        ans += a
    else:
        dic[c] = ans

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

Buggy submission (verdict: Runtime Error):
import sys

N = int(input())
C = [0]
for line in sys.stdin:
    c = int(line)
    if c[-1] == c:
        continue
    else:
        C.append(c)

ans = 1
dic = {}
for c in C:
    if c in dic.keys():
        a = dic[c]
        dic[c] += ans
        ans += a
    else:
        dic[c] = ans

print(ans % (10 ** 9 + 7))
Problem p03128 (python)

Fixed submission:
def f(x):
    k = int(x)
    return c[k], k


c = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
N, M = list(map(int, input().split()))
A = list(map(f, input().split()))
A = sorted(A, key=lambda x: x[0] * 10 - x[1])

# 数字を作成するのに必要なマッチ数のリストを作成
b = []
dic = {}
n = 0
for d in A:
    if n != d[0]:
        b.append(d[0])
        n = d[0]
        dic[n] = d[1]

ans = [0] * b[0]
n = b[0]
while True:
    max_ = 0
    for d in b:
        if n - d == 0:
            if dic[d] > max_:
                max_ = dic[d]
        elif n - d > 0 and ans[n - d] > 0:
            t = ans[n - d] * 10 + dic[d]
            max_ = max(max_, t)

    if n == N:
        print(max_)
        break
    ans.append(max_)
    n += 1

Buggy submission (verdict: Runtime Error):
c = [0,2,5,5,4,5,6,3,7,6]
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))

B = [0] * M
for i in range(M):
    B[i] = c[A[i]]

x = min(B)
value = 0
for i in range(M):
    if B[i] == x:
        value = max(A[i], value)
y = N % x
if y == 0:
    print(str(value) * (N / x))
else:
    k = 10
    for i in range(M):
        if B[i] % x == y:
            if k > B[i]:
                k = B[i]
                l = A[i]
            elif k == B[i]:
                l = max(l, A[i])
    if value > l:
        print(str(value) * ((N - k) // x) + str(l))
    else:
        print(str(l) + str(value) * ((N - k) // x))

Buggy submission (verdict: Runtime Error):
c = [0,2,5,5,4,5,6,3,7,6]
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))

B = [0] * M
for i in range(M):
    B[i] = c[A[i]]

x = min(B)
value = 0
for i in range(M):
    if B[i] == x:
        value = max(A[i], value)
y = N % x
if y == 0:
    print(str(value) * (N / x))
else:
    k = 10
    for i in range(M):
        if B[i] % x == y:
            if k > B[i]:
                k = B[i]
                l = A[i]
            elif k == B[i]:
                l = max(l, A[i])
    if value > l:
        print(str(value) * ((N - k) // x) + str(l))
    else:
        print(str(l) + str(value) * ((N - k) / x))