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

Fixed submission:
from functools import reduce
def pow_k(x, n):
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K = (K * x)
        x = (x * x)
        n //= 2
    return (K * x)
def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0
def modinv(a, m):
    g, x, y = xgcd(a, m)
    return x % m
def modmul(a,b):
    return a * b % 1000000007
def comb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(modmul, range(n, n - r, -1))
    under = reduce(modmul, range(1,r + 1))
    return over * modinv(under, 1000000007)

N,K = (int(x) for x in input().split())
for i in range(1,K+1):
    if i > N-K+1:
        print('0')
    else:
        a = comb(K-1,i-1)
        b = comb(N-K+1,i)
        print(a*b%1000000007)

Buggy submission (verdict: Runtime Error):
from functools import reduce
def pow_k(x, n):
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K = (K * x)
        x = (x * x)
        n //= 2
    return (K * x)
def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0
def modinv(a, m):
    g, x, y = xgcd(a, m)
    return x % m
def modmul(a,b):
    return a * b % 1000000007
def comb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(modmul, range(n, n - r, -1))
    under = reduce(modmul, range(1,r + 1))
    return over * modinv(under, 1000000007)

N,K = (int(x) for x in input().split())
for i in range(1,K+1):
    a = comb(K-1,i-1)
    b = comb(N-K+1,i)
    print(a*b%1000000007)
Problem p03013 (python)

Fixed submission:
N,M = (int(x) for x in input().split())
a = set(int(input()) for _ in range(M))
dp = [0] * N
broke = False
if N == 1:
    print('1')
    broke = True
elif 1 in a and 2 not in a:
    dp[1] = 1
elif 1 not in a and 2 in a:
    dp[0] = 1
else:
    dp[0] = 1
    dp[1] = 2
if 1 in a and 2 in a:
    print('0')
    broke = True
else:
    for i in range(3,N+1):
        if i-1 in a and i-2 in a:
            print('0')
            broke = True
            break
        elif i-1 in a:
            dp[i-1] = dp[i-3]
        elif i-2 in a:
            dp[i-1] = dp[i-2]
        else:
            dp[i-1] = (dp[i-2] + dp[i-3]) % 1000000007
if broke == False:
    print(dp[N-1])

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

N,M = (int(x) for x in input().split())
a = set(int(input()) for _ in range(M))
dp = [0] * N
broke = False
if 1 in a and 2 not in a:
    dp[1] = 1
elif 1 not in a and 2 in a:
    dp[0] = 1
else:
    dp[0] = 1
    dp[1] = 2
if 1 in a and 2 in a:
    print('0')
    broke = True
else:
    for i in range(3,N+1):
        if i-1 in a and i-2 in a:
            print('0')
            broke = True
            break
        elif i-1 in a:
            dp[i-1] = dp[i-3]
        elif i-2 in a:
            dp[i-1] = dp[i-2]
        else:
            dp[i-1] = (dp[i-2] + dp[i-3]) % 1000000007
if broke == False:
    print(dp[N-1])

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

N,M = (int(x) for x in input().split())
a = set(int(input()) for _ in range(M))
mem = [0] * N
def count_steps(n):
    if mem[n-1]:
        return mem[n-1]
    elif n - 1 in a and n - 2 in a:
        return 0
    elif n - 1 in a:
        if n > 2:
            mem[n-1] = count_steps(n-2)
            return mem[n-1]
        else:
            mem[1] = 1
            return 1
    elif n - 2 in a:
        mem[n-1] = count_steps(n-1)
        return mem[n-1]
    elif n == 1:
        mem[0] = 1
        return 1
    elif n == 2:
        mem[1] = 2
        return 2
    else:
        mem[n-1] = (count_steps(n-1) + count_steps(n-2)) % 1000000007
        return mem[n-1]
print(count_steps(N))
Problem p03634 (python)

Fixed submission:
import sys
input = sys.stdin.readline
from collections import deque

N = int(input())
connected = [[]for _ in range(N+1)]
for i in range(N-1):
    a, b, c = (int(x) for x in input().split())
    connected[a].append((b,c))
    connected[b].append((a,c))
Q, K = (int(x) for x in input().split())
distk = [-1] * (N+1)
d = deque([K])
distk[K] = 0
while d:
    temp = d.popleft()
    for vert, dist in connected[temp]:
        if distk[vert] == -1:
            d.append(vert)
            distk[vert] = distk[temp] + dist
for i in range(Q):
    x, y = (int(x) for x in input().split())
    print(distk[x]+distk[y])

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

import scipy.sparse
N = int(input())
lil = scipy.sparse.lil_matrix((N, N), dtype = int)
for i in range(N-1):
    a, b, c = (int(x) for x in input().split())
    lil[a-1, b-1] = c
lil2 = scipy.sparse.csgraph.dijkstra(lil,directed=False).astype(int)
Q, K = (int(x) for x in input().split())
for i in range(Q):
    x, y = (int(x) for x in input().split())
    print(lil2[K-1][x-1]+lil2[K-1][y-1])

Buggy submission (verdict: Runtime Error):
import scipy.sparse
N = int(input())
lil = scipy.sparse.lil_matrix((N, N), dtype = int)
for i in range(N-1):
    a, b, c = (int(x) for x in input().split())
    lil[a-1, b-1] = c
lil2 = scipy.sparse.csgraph.dijkstra(lil, directed = False).astype(int)
Q, K = (int(x) for x in input().split())
for i in range(Q):
    x, y = (int(x) for x in input().split())
    print(lil2[K-1][x-1]+lil2[K-1][y-1])
Problem p03804 (python)

Fixed submission:
N,M,*f = open(0).read().split()
N = int(N)
M = int(M)
A = f[:N]
B = f[N:]
for i in range(N-M+1):
    for j in range(N-M+1):
        if A[i][j:j+M] == B[0]:
            for k in range(1,M):
                if A[i+k][j:j+M] != B[k]:
                    break
            else:
                print('Yes')
                break
    else:
        continue
    break
else:
    print('No')

Buggy submission (verdict: Runtime Error):
N,M,*f = open(0).read().split()
N = int(N)
M = int(M)
A = f[:N]
B = f[N:]
for i in range(N):
    for j in range(N-M+1):
        if A[i][j:j+M] == B[0]:
            for k in range(1,M):
                if A[i+k][j:j+M] != B[k]:
                    break
            else:
                print('Yes')
                break
    else:
        continue
    break
else:
    print('No')
Problem p02729 (python)

Fixed submission:
N,M = map(int,input().split())
print(int(N*(N-1)/2 + M*(M-1)/2))

Buggy submission (verdict: Runtime Error):
S = input()
flg = False
for i in range(len(S)/2-1):
    if S[i] == S[len(S)-i]:
        flg = True
    else:
        flg = False
for i in range(((len(S)-1) /2 -1)/2):
    if S[i] == S[(len(S)-1)/2-i]:
        pass
    else:
        flg = False
for i in range((len(S)-(len(S)+3)/2 -1)/2):
    if S[i] == S[(len(S)+3)/2 -i]:
        pass
    else:
        flg = False
 
if flg:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
print(math.factorial(N) + math.factorial(M))
Problem p02759 (python)

Fixed submission:
N = int(input())

if N % 2 == 0:
    print(N//2)
else:
    print(N//2 + 1)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
s = [0] * m
c = [0] * m
ans = [0] * n
flg = [0] * n
for i in range(m):
    s[i],c[i] = map(int,input().split())
for j in range(m):
    if flg[s[j]-1] == 1 and ans[s[j]-1] != c[j]:
        print(-1)
        exit()
    else:
        ans[s[j]-1] = c[j]
        flg[s[j]-1] = 1
    
if n > 1 and flg[0] == 1 and ans[0] == 0 :
    print(-1)
elif n > 1 and flg[0] == 0:
    ans[0] = 1
    print(''.join(map(str,ans)))
    exit()
else:
    print(''.join(map(str,ans)))
Problem p02831 (python)

Fixed submission:
from fractions import gcd
a,b= map(int,input().split())
print(a*b//gcd(a,b))

Buggy submission (verdict: Runtime Error):
import math
a,b= map(int,input().split())
print(a*b//math.gcd(a,b))

Buggy submission (verdict: Runtime Error):
import math
a,b= map(int,input().split())
print(a*b//math.gcd(a,b))
Problem p02729 (python)

Fixed submission:
N, M = map(int, input().split())
 
print(int(N * (N - 1) / 2 + M * (M - 1) /2))

Buggy submission (verdict: Runtime Error):

N, M = map(int, readline().split())

print(N * (N - 1) / 2 + M * (M - 1) /2)
Problem p02836 (python)

Fixed submission:
S = input()

cnt = 0
for i in range(len(S) // 2):
  if S[i] != S[len(S) - 1 - i]:
    cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
S = input()

cnt = 0
for i in range(S // 2):
  if S[i] != S[len(S) - 1 - i]:
    cnt += 1
print(cnt)
Problem p02860 (python)

Fixed submission:
_ = input()
s = input()
if len(s) % 2 == 1:
  print("No")
  exit(0)
if s[:len(s) // 2] == s[len(s) // 2:]:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
s = input()
if s % 2 == 1:
  print("No")
  exit(0)
if s[:len(s) // 2 - 1] == s[len(s) // 2:]:
  print("Yes")
else:
  print("No")
Problem p02754 (python)

Fixed submission:
n,a,b = map(int,input().split())
print((n//(a+b))*a+min(n%(a+b),a))

Buggy submission (verdict: Runtime Error):
n,a,b = map(int,input().split())
cnt = 0
ball = ''
while cnt<n:
    ball += 'b'*a
    ball += 'r'*b
    cnt += a+b
print(ball.count('b',0,n))
Problem p03053 (python)

Fixed submission:
h,w = map(int,input().split())
a = [input() for i in range(h)]

from collections import deque
q = deque()
reach = [[False]*w for i in range(h)]
for i in range(h):
    for j in range(w):
        if a[i][j]=='#':
            q.append([i,j,0])
            reach[i][j] = True

ans = 0
while q:
    i,j,cnt = q.popleft()
    ans = max(ans,cnt)
    for k,l in [[1,0],[-1,0],[0,1],[0,-1]]:
        if 0<=i+k<h and 0<=j+l<w:
            if not reach[i+k][j+l]:
                q.append([i+k,j+l,cnt+1])
                reach[i+k][j+l] = True

print(ans)

Buggy submission (verdict: Runtime Error):
h,w = map(int,input().split())
a = [input() for i in range(h)]

from collections import deque
q = deque()
reach = [[False]*w for i in range(h)]
for i in range(h):
    for j in range(w):
        if a[i][j]=='#':
            q.append([i,j,0])
            reach[i][j] = True

ans = 0
while q:
    i,j,cnt = q.popleft()
    for k,l in [[1,0],[-1,0],[0,1],[0,-1]]:
        if 0<=i+k<w and 0<=j+l<h:
            if not reach[i+k][j+l]:
                q.append([i+k,j+l,cnt+1])
                reach[i+k][j+l] = True
    ans = max(ans,cnt)

print(ans)
Problem p03745 (python)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
c = 1
x = 0
for i in range(n-1):
    y = a[i+1]-a[i]
    if x*y<0:
        if i<n-2:x = a[i+2]-a[i+1]
        c+=1
    elif y!=0:x=y
print(c)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
c = 1
x = a[1]-a[0]
for i in range(1,n-1):
    y = a[i+1]-a[i]
    if x*y<0:
        if i<n-2:x = a[i+2]-a[i+1]
        c+=1
print(c)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
c = 1
x = a[1]-a[0]
for i in range(1,n-1):
    y = a[i+1]-a[i]
    if x*y<0:
        if i!=n-2:x = a[i+2]-a[i+1]
        c+=1
print(c)
Problem p02624 (python)

Fixed submission:
def calc(n, a, d):
    return (n * (2 * a + (n - 1) * d)) // 2


n = int(input())
ans = 0
for i in range(1, n + 1):
    n_ = (n // i)
    d, a = i, i
    sm = calc(n_, a, d)
    ans += sm
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
ans = 0
for i in range(1, n + 1):
    ans += ((n // i) * (2 * i + (n // i)  - 1) * i)) // 2
print(ans)
Problem p02598 (python)

Fixed submission:
def ceil(n, m):
    return -(-n // m)

# K回のカットで長さlにできるかどうか
def possible(l, K):
    cut = 0
    if l <= 0:
        return False
    for i in range(N):
        cut += ceil(A[i], l) - 1
        if cut > K:
            return False
    return True

N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
L = sum(A)

ng = (L // (N + K)) - 1  # min -1
ok = max(A)

while ok - ng > 1:
    mid = (ok + ng) // 2
    if possible(mid, K):
        ok = mid
    else:
        ng = mid

print(ok)

Buggy submission (verdict: Runtime Error):
def ceil(n, m):
    return -(-n // m)

# K回のカットで長さlにできるかどうか
def possible(l, K):
    cut = 0
    for i in range(N):
        cut += ceil(A[i], l) - 1
        if cut > K:
            return False
    return True

N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
L = sum(A)

ng = (L // (N + K)) - 1  # min -1
ok = max(A)

while ok - ng > 1:
    mid = (ok + ng) // 2
    if possible(mid, K):
        ok = mid
    else:
        ng = mid

print(ok)
Problem p02892 (python)

Fixed submission:
N = int(input())
S = [None] * N

for i in range(0, N):
    S[i] = [int(s) for s in list(input())]


def local_max_level(S, N, n): # n is the starting vertex
    levels = [None] * N
    levels[n] = 0

    for l in range(0, N): # for each level l
        for i in range(0, N): # look at every vertex i
            if levels[i] == l: # which is at level l
                # scan column S[i]
                for j in range(0, N): # scan all vertices and look for adjacent vertex to i
                    if S[i][j] == 1: # vertex j is adjacent to i
                        if levels[j] == None:
                            levels[j] = l + 1

                        elif levels[j] == l - 1: continue
                        elif levels[j] == l + 1: continue
                        else:
                            return -1
    return max(levels)

def n_partite(S, N):

    M = 0
    for n in range(0, N):  # try starting with every vertex
        m = local_max_level(S, N, n)
        if m == -1: # not n-partite
            return -1
        else:
            M = max(M, m)
    return M + 1

print(n_partite(S, N))

Buggy submission (verdict: Runtime Error):
N = int(input())
S = [None] * N

for i in range(0, N):
    S[i] = [int(s) for s in list(input())]

m = 0
n_partite = True

for n in range(0, N):  # try starting with every vertex
    levels = [None] * N
    levels[n] = 0

    for l in range(0, N): # max possible levels
        for i in range(0, N): # look at every vertex
            if levels[i] == l: # vertex i is at level l
                # scan column S[i]
                for j in range(0, N): # scan all vertices and look for adjacent vertex to i
                    if S[i][j] == 1: # vertex j is adjacent to i
                        if levels[j] == None:
                            levels[j] = l + 1
                        elif levels[j] == l - 1: continue
                        elif levels[j] == l + 1: continue
                        else:
                            n_partite = False
                            break
    m = max( max(levels), m)

if n_partite:
    print(m + 1)
else:
    print(-1)
Problem p03013 (python)

Fixed submission:
N, M = [int(x) for x in input().split()]
a = [int(input()) for _ in range(M)]
p = 10 ** 9 + 7

if M == 0:
    a = [-1]

fib = [1, 1] + [None] * (N - 1)
for i in range(2, N + 1):
    fib[i] = (fib[i - 1] + fib[i - 2]) % p

ans = 1
for j in range(M):
    if a[j] == N or (j + 1 < M and a[j] + 1 == a[j + 1]):
        ans = 0
        break

    if j == 0:
        ans = fib[a[j] - 1]
    else:
        ans *= fib[a[j] - 1 - (a[j - 1] + 1)]
        ans %= p
else:
    ans *= fib[N - a[M - 1] - 1]
    ans %= p

print(ans)

Buggy submission (verdict: Runtime Error):
N, M = [int(x) for x in input().split()]
a = [int(input()) for _ in range(M)]
p = 10 ** 9 + 7

fib = [1, 1] + [None] * (N - 1)
for i in range(2, N + 1):
    fib[i] = (fib[i - 1] + fib[i - 2]) % p

for j in range(M):
    if a[j] == N or (j + 1 < M and a[j] + 1 == a[j + 1]):
        ans = 0
        break
        
    if j == 0:
        ans = fib[a[j] - 1]
    else:
        ans *= fib[a[j] - 1 - (a[j - 1] + 1)]
        ans %= p
else:
    ans *= fib[N - a[M - 1] - 1]
    ans %= p

print(ans)
Problem p03209 (python)

Fixed submission:
# レベルiバーガーの層数は 2^(i+2) - 3
def layers(i):
    return 2 ** (i + 2) - 3

# レベルiバーガーのパティ数は 2^(i+1) - 1
def patties(i):
    return 2 ** (i + 1) - 1

def solve(n, x):
    layers = 2 ** (n + 1) - 3  # レベルn-1バーガーの層の数
    patties = 2 ** n - 1    # レベルn-1バーガーのパティの数
    if x == 0:
        ans = 0
    elif x < layers + 1:
        ans = solve(n - 1, x - 1)
    elif x == layers + 1:
        ans = patties
    elif x == layers + 2:
        ans = patties + 1
    elif x < 2 * layers + 2:
        ans = patties + 1 + solve(n - 1, x - layers - 2)
    else:
        ans = 2 * patties + 1
    return ans

N, X = [int(x) for x in input().split()]
print(solve(N, X))

Buggy submission (verdict: Runtime Error):
def solve(n, x):
    layers = 2 ** (n + 1) - 3  # レベルn-1バーガーの層の数
    patties = 2 ** n - 1    # レベルn-1バーガーのパティの数
    if x == 0:
        ans = 0
    elif x <= layers + 1:
        ans = solve(n - 1, x - 1)
    else:
        ans = patties + 1 + solve(n - 1, x - layers - 2)
        
    return ans

N, X = [int(x) for x in input().split()]
print(solve(N, X))
Problem p03291 (python)

Fixed submission:
s = input()
n = len(s)
p = 10 ** 9 + 7

q = s.count('?')
l_a = [0] * n  # l_a[i] := s[i]より左にあるAの数
l_x = [0] * n  # l_x[i] := s[i]より左にある?の数
r_c = [0] * n  # r_c[i] := s[i]より右にあるCの数
r_x = [0] * n  # r_x[i] := s[i]より右にある?の数

for i in range(1, n):  # 1〜n-1
    l_a[i] = l_a[i - 1] + int(s[i - 1] == 'A')
    l_x[i] = l_x[i - 1] + int(s[i - 1] == '?')
    r_c[n - i - 1] = r_c[n - i] + int(s[n - i] == 'C')
    r_x[n - i - 1] = r_x[n - i] + int(s[n - i] == '?')

ans = 0
pow_q = []
for i in range(0, 4):
    pow_q.append(max(1, 3 ** (q - i) % p))

for i in range(n):
    if s[i] == 'B':
        ans += (l_a[i] * r_c[i] % p) * pow_q[0] % p  # ABC
        ans += (l_x[i] * r_c[i] % p) * pow_q[1] % p # ?BC
        ans += (l_a[i] * r_x[i] % p) * pow_q[1] % p # AB?
        ans += (l_x[i] * r_x[i] % p) * pow_q[2] % p # ?B?
        ans %= p
    elif s[i] == '?':
        ans += (l_a[i] * r_c[i] % p) * pow_q[1] % p # A?C
        ans += (l_x[i] * r_c[i] % p) * pow_q[2] % p # ??C
        ans += (l_a[i] * r_x[i] % p) * pow_q[2] % p # A??
        ans += (l_x[i] * r_x[i] % p) * pow_q[3] % p # ???
        ans %= p

print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
n = len(s)
p = 10 ** 9 + 7

# i = 0, ..., nについて
# dp[i][0] = i文字目まででありうる文字列の数（ABCなら1、AB?なら3）
# dp[i][1] = i文字目までに含まれるAの数
# dp[i][2] = i文字目までに含まれるABのパターン数
# dp[i][3] = i文字目までに含まれるABCのパターン数
dp = [[0 for j in range(4)] for i in range(n + 1)]
dp[0][0] = 1 # ''空の文字列は1パターン
for j in range(1, 4):
    dp[0][j] = 0  # 空の文字列にはAもABもABCも入っていない

for i in range(1, n + 1):
    m = 3 if s[i - 1] == '?' else 1

    for j in range(4):
        dp[i][j] = dp[i - 1][j] * m

    if s[i - 1] == 'A' or s[i - 1] == '?':
        dp[i][A] =  (dp[i][A] + dp[i - 1][0]) % p
    if s[i - 1] == 'B' or s[i - 1] == '?':
        dp[i][AB] = (dp[i][AB] + dp[i - 1][A]) % p
    if s[i - 1] == 'C' or s[i - 1] == '?':
        dp[i][ABC] = (dp[i][ABC] + dp[i - 1][AB]) % p

print(dp[n][ABC])

Buggy submission (verdict: Runtime Error):
s = input()
n = len(s)
p = 10 ** 9 + 7

# i = 0, ..., nについて
# dp[i][0] = i文字目まででありうる文字列の数（ABCなら1、AB?なら3）
# dp[i][1] = i文字目までに含まれるAの数
# dp[i][2] = i文字目までに含まれるABのパターン数
# dp[i][3] = i文字目までに含まれるABCのパターン数
dp = [[0 for j in range(4)] for i in range(n + 1)]
dp[0][0] = 1 # ''空の文字列は1パターン
for j in range(1, 4):
    dp[0][j] = 0  # 空の文字列にはAもABもABCも入っていない

print("dp[0] = {}".format(dp[0]))
for i in range(1, n + 1):
    m = 3 if s[i - 1] == '?' else 1

    for j in range(4):
        dp[i][j] = dp[i - 1][j] * m

    if s[i - 1] == 'A' or s[i - 1] == '?':
        dp[i][A] =  (dp[i][A] + dp[i - 1][0]) % p
    if s[i - 1] == 'B' or s[i - 1] == '?':
        dp[i][AB] = (dp[i][AB] + dp[i - 1][A]) % p
    if s[i - 1] == 'C' or s[i - 1] == '?':
        dp[i][ABC] = (dp[i][ABC] + dp[i - 1][AB]) % p

print(dp[n][ABC])
Problem p02557 (python)

Fixed submission:
from collections import defaultdict
dic = defaultdict(int)
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
for x,y in zip(A,B):
  dic[x] += 1
  dic[y] += 1
L = list(dic.values())
MAX = max(L)
if MAX > N:
  print("No"); exit()
INF = float("inf")
dicA_min = defaultdict(lambda: INF); dicA_max = defaultdict(lambda: 0)
dicB_min = defaultdict(lambda: INF); dicB_max = defaultdict(lambda: 0)
for i in range(N):
  dicA_min[A[i]] = min(dicA_min[A[i]],i)
  dicA_max[A[i]] = max(dicA_max[A[i]],i)
  dicB_min[B[i]] = min(dicB_min[B[i]],i)
  dicB_max[B[i]] = max(dicB_max[B[i]],i)
#print(dicA_min,dicA_max)
L = list(dicB_min.keys())
mink = -INF
maxk = INF
Flag = False
for t in L:
  if dicA_min[t] == INF:
    continue
  mink = max(dicA_max[t]-dicB_min[t]+1,mink)
  maxk = min(dicA_min[t]+N-dicB_max[t]-1,maxk)
  Flag = True
if not Flag:
  print("Yes")
  print(*B)
  exit()
#print(mink,maxk)
if mink >= 0:
  ans = B[-mink:] + B[:-mink]
else:
  ans = B[-mink:] + B[:-mink]
print("Yes")
print(*ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
dic = defaultdict(int)
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
for x,y in zip(A,B):
  dic[x] += 1
  dic[y] += 1
L = list(dic.values())
MAX = max(L)
if MAX > N:
  print("No"); exit()
INF = float("inf")
dicA_min = defaultdict(lambda: INF); dicA_max = defaultdict(lambda: 0)
dicB_min = defaultdict(lambda: INF); dicB_max = defaultdict(lambda: 0)
for i in range(N):
  dicA_min[A[i]] = min(dicA_min[A[i]],i)
  dicA_max[A[i]] = max(dicA_max[A[i]],i)
  dicB_min[B[i]] = min(dicB_min[B[i]],i)
  dicB_max[B[i]] = max(dicB_max[B[i]],i)
#print(dicA_min,dicA_max)
L = list(dicB_min.keys())
mink = -INF
maxk = INF
for t in L:
  if dicA_min[t] == INF:
    continue
  mink = max(dicA_max[t]-dicB_min[t]+1,mink)
  maxk = min(dicA_min[t]+N-dicB_max[t]-1,maxk)
#print(mink,maxk)
if mink >= 0:
  ans = B[-mink:] + B[:-mink]
else:
  ans = B[-mink:] + B[:-mink]
print("Yes")
print(*ans)
Problem p02711 (python)

Fixed submission:
a = int(input())

b = [int(x) for x in list(str(a))]

ans =0
for i in range(len(b)):
  if b[i] == 7:
    ans = 1
if ans == 0:
  print("No")
else:
  print("Yes")

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

def zenbu(m, B):
    if m == 1:
        return B[0]
    elif m == 2:
        return max(B[0],B[1])
    elif m == 3:
        return max(B[0],B[1],B[2])
    elif m%2 == 0: #偶数の場合
        temp = 0
        for i in range(m//2-1):
            temp += B[i*2]
        return max(temp+ max(B[m-2],B[m-1]), zenbu(m-2, B)+ B[m-1])
    else:#奇数の場合
        temp = 0
        for i in range((m-1)//2):
            temp += B[i*2]
        return max(temp, zenbu(m-2,B)+ B[m-1], zenbu(m-3,B)+ max(B[m-2],B[m-1]))

ans = zenbu(n,A)

print(ans)