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

Fixed submission:
def c_to_infinity(S, K):
    for k, s in enumerate(S,1):
        if s != '1':
            if k > K:
                return '1'
            else:
                return s
    # Sは1のみで構成されていた
    return 1

S = input().strip()
K = int(input())
print(c_to_infinity(S, K))

Buggy submission (verdict: Runtime Error):
def c_to_infinity(S, K):
    for k, s in enumerate(S, 1):
        if k > K:
            ans = '1'  # K文字目まで1しかなかった
            break
        if s != '1':
            ans = s  # 現れた数字が5000兆回の操作によってK文字目に必ず現れる
            break
    return ans

S = input().strip()
K = int(input())
print(c_to_infinity(S, K))
Problem p03318 (python)

Fixed submission:
def d_snuke_numbers(K):
    import math

    def ns(n):  # n/S(n)の計算
        return n / sum(map(int, list(str(n))))

    def f(n):  # n<=xの中で ns(x) を最小にするような最小の値xを求める
        digit = len(str(n))
        # n自身も候補の1つである
        min_ns = ns(n)
        ret = n
        for d in range(digit + 1):
            x = (10**(d+1)) * math.floor(n / (10**(d+1)) + 1) - 1
            s = ns(x)
            if min_ns > s:
                min_ns = s
                ret = x
        return ret

    n = 0
    candidate = []
    for _ in range(K):
        n = f(n + 1)
        candidate.append(n)
    ans = '\n'.join(map(str, candidate))
    return ans

K = int(input())
print(d_snuke_numbers(K))

Buggy submission (verdict: Runtime Error):
def d_snuke_numbers(K):
    candidate = []
    for k in range(20):
        for l in range(1, 10):
            candidate.append(str(l)+str(9)*k)
    ans = []
    for k in range(K):
        ans.append(candidate[k])
    ans = '\n'.join(ans)
    return ans

K = int(input())
print(d_snuke_numbers(K))

Buggy submission (verdict: Runtime Error):
def d_snuke_numbers(K):
    candidate = []
    for k in range(16):
        for l in range(1, 10):
            candidate.append(str(l)+str(9)*k)
    ans = []
    for k in range(K):
        ans.append(candidate[k])
    ans = '\n'.join(ans)
    return ans

K = int(input())
print(d_snuke_numbers(K))

Buggy submission (verdict: Runtime Error):
def d_snuke_numbers(K):
    candidate = []
    for k in range(15):
        for l in range(1, 10):
            candidate.append(str(l)+str(9)*k)
    ans = []
    for k in range(K):
        ans.append(candidate[k])
    ans = '\n'.join(ans)
    return ans

K = int(input())
print(d_snuke_numbers(K))
Problem p03353 (python)

Fixed submission:
def c_kth_substring(S, K):
    tmp = []
    for i in range(len(S)):
        for j in range(i + 1, i + K + 1):
            if j <= len(S)+1:
                tmp.append(S[i:j])
    tmp = sorted(set(tmp))
    ans = tmp[K - 1]
    return ans

S = input().strip()
K = int(input())
print(c_kth_substring(S, K))

Buggy submission (verdict: Runtime Error):
def c_kth_substring(S, K):
    tmp = []
    for i in range(len(S)):
        for j in range(i + 1, len(S) + 1):
            tmp.append(S[i:j])
    tmp = sorted(set(tmp))
    ans = tmp[K - 1]
    return ans

S = input().strip()
K = int(input())
print(c_kth_substring(S, K))
Problem p03415 (python)

Fixed submission:
c = [input().strip() for j in range(3)]
print(c[0][0] + c[1][1] + c[2][2])

Buggy submission (verdict: Runtime Error):
c = [[i for i in input().strip().split()] for j in range(3)]
print(c[0][0] + c[1][1] + c[2][2])
Problem p03471 (python)

Fixed submission:
def c_Otoshidama(N, Y):
    ans = ''

    for yukichi in range(0, 2001):
        for higuchi in range(0, 2001):
            noguchi = N - yukichi - higuchi
            if noguchi >= 0:
                if Y == yukichi * 10000 + higuchi * 5000 + noguchi * 1000:
                    return '{} {} {}'.format(yukichi, higuchi, noguchi)
    return '-1 -1 -1'
  
N,Y=[int(i) for i in input().split()]
print(c_Otoshidama(N, Y))

Buggy submission (verdict: Runtime Error):
def c_Otoshidama_N(N, Y):
    yen = Y // 1000
    # yukichi,higuchi,noguchiはそれぞれ、1万円札、5千円札、千円札の枚数(モデルの名字)
    for yukichi in range(0, 2001):
        # 10*yukichi + 5*higuchi + noguchi = yen と
        # yukichi + higuchi + noguchi = N について、yukichiを決めたときの連立方程式の解
        tmp1 = (yen - N - 9 * yukichi)
        tmp2 = (5 * N - yen + 5 * yukichi)
        if tmp1 % 4 == 0 and tmp2 % 4 == 0:
            higuchi = tmp1 // 4
            noguchi = tmp2 // 4
            if higuchi >= 0 and noguchi >= 0:
                return '{} {} {}'.format(yukichi, higuchi, noguchi)
    # どの組み合わせでも条件を満たさなかった
    return '-1 -1 -1'
  
N,Y=[int(i) for i in input().split()]
print(c_Otoshidama(N, Y))
Problem p03480 (python)

Fixed submission:
def d_WideFlip(S):
    n = len(S)
    T = []  # 解説pdfにおけるT(S)の定義と同じもの
    for k in range(n - 1):
        if S[k] != S[k + 1]:
            T.append(max(k + 1, n - (k + 1)))  # 設問の文字列は1-indexedのため
    if len(T) > 0:
        return min(T)
    else:
        return n  # Sは0のみまたは1のみで構成されていた

S = input()
print(d_WideFlip(S))

Buggy submission (verdict: Runtime Error):
def d_WideFlip(S):
    n = len(S)
    T = []  # 解説pdfにおけるT(S)の定義と同じもの
    for k in range(n - 1):
        if S[k] != S[k + 1]:
            T.append(max(k + 1, n - (k + 1)))  # 設問の文字列は1-indexedのため
    T = min(T)
    return T

S = input()
print(d_WideFlip(S))

Buggy submission (verdict: Runtime Error):
def d_WideFlip(S):
    import re
    from collections import Counter

    d = Counter(S)
    zero = d['0']
    one_continue = re.findall(r'1+', S)
    one_continue = len(max(one_continue))
    return max(zero, one_continue)

S = input()
print(d_WideFlip(S))
Problem p03543 (python)

Fixed submission:
def a_good_integer(N):
    if N[0] == N[1] and N[1] == N[2]:
        return('Yes')
    elif N[1] == N[2] and N[2] == N[3]:
        return('Yes')
    else:
        return('No')
      
N = input()
print(a_good_integer(N))

Buggy submission (verdict: Runtime Error):
N = input()
if N[0]==N[1] and N[1]==N[2] and N[2]==N[3]:
  print('Yes')
elif N[1]==N[2] and N[2]==N[3] and N[3]==N[4]:
  print('Yes')
else:
  print('No')
Problem p03550 (python)

Fixed submission:
def D_abs(N, Z, W, A):
    if N == 1:
        # Xは山札のたった1枚を引かねばならず、Yは山札から1枚も引けないから
        return abs(A[0] - W)
    else:
        # 山札は一番上しか見れないので、
        # Xがa_{N-1}を持ち、Yがa_{N}を持つか、
        # Xがa_{N}を持ち、YがWまたはa_{N-1}を持つかの
        # どちらかで終了する。
        return max(abs(A[N - 1] - W), abs(A[N - 1] - A[N - 2]))

N,Z,W = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
print(D_abs(N, Z, W, A))

Buggy submission (verdict: Runtime Error):
def d_abs(N, Z, W, A):
    # 山札の枚数が1枚なら、Xがそれを引いて終わる。山札が2枚以上なら、
    # Xは初手でN-1枚目かN枚目かのどちらかスコアが大きくなる方を取るのが最善。
    # そうしなかった場合、Xが最善手を取らなかったことになって前提に反するか、
    # Yが最善手を取ってスコアabs(A[N - 1] - A[N - 2])になるかのどちらかである
    ans = abs(A[0] - W) if N == 1 else max(abs(A[N - 1] - W), abs(A[N - 1] - A[N - 2]))
    return ans

N,Z,W = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
print(D_abs(N, Z, W, A))

Buggy submission (verdict: Runtime Error):
def D_abs(N, Z, W, A):
    if N == 1:
        # Xは山札のたった1枚を引かねばならず、Yは山札から1枚も引けないから
        return abs(A[0] - W)
    else:
        # 山札は一番上しか見れないので、
        # Xがa_{N-1}を持ち、Yがa_{N}を持つか、
        # Xがa_{N}を持ち、YがWまたはa_{N-1}を持つかの
        # どちらかで終了する。
        return max(abs(A[N - 1] - W), abs(A[N - 1] - A[N - 2]))

N,Z,W = [int(_) for _ in input().split()]
A = [int(input()) for _ in range(N)]
print(D_abs(N, Z, W, A))
Problem p03564 (python)

Fixed submission:
def B_Addition_and_Multiplication(N, K):
    if N==1:
        return 2
    multiply = 0  # 掛け算する回数
    add = 0  # 足し算する回数
    tmp = 1
    while tmp < K:
        tmp *= 2
        multiply += 1
    add = N - multiply

    ans = pow(2, multiply) + K * add
    return ans
  
N = int(input())
K = int(input())
print(B_Addition_and_Multiplication(N, K))

Buggy submission (verdict: Runtime Error):
def B_Addition_and_Multiplication(N, K):
  	if N==1:
      return 2
    multiply = 0  # 掛け算する回数
    add = 0  # 足し算する回数
    tmp = 1
    while tmp < K:
        tmp *= 2
        multiply += 1
    add = N - multiply

    ans = pow(2, multiply) + K * add
    return ans
  
N = int(input())
K = int(input())
print(B_Addition_and_Multiplication(N, K))
Problem p03578 (python)

Fixed submission:
import collections
N = int(input())
D = [int(i) for i in input().split()]
M = int(input())
T = [int(i) for i in input().split()]

count_D = collections.Counter(D)
count_T = collections.Counter(T)

ans = 'YES'
for k,v in count_T.items():
  if count_D[k] < v:
    ans = 'NO'
    break
print(ans)

Buggy submission (verdict: Runtime Error):
import collections
N = int(input())
D = [int(i) for i in input().split()]
M = int(input())
T = [int(i) for i in input().split()]

count_D = collections.Counter(D)
count_T = collections.Counter(T)

ans = 'YES'
for k,v in count_T.items():
  if D[k] < v:
    ans = 'NO'
    break
print(ans)
Problem p03612 (python)

Fixed submission:
def D_Derangement(N, p):
    count = 0
    i = 0
    while i < N:
        if p[i] == i + 1: #p_i=iなら
            count += 1
            i += 2
        else:
            i += 1
            continue
    return count
 
N = int(input())
p = [int(i) for i in input().split()]
print(D_Derangement(N, p))

Buggy submission (verdict: Runtime Error):
def d_derangement(N, P):
    ans = 0
    is_target = True  # 要素番号iはチェックする必要があるか否か
    for i in range(N):
        if P[i] == i + 1 and is_target:
            # p_i=iならp_{i+1}とスワップすれば条件を満たす
            ans += 1
            is_target = False  # i+1番目はチェックする必要がない
        else:
            is_target = True
    return ans

N = int(input())
p = [int(i) for i in input().split()]
print(d_derangement(N, P))

Buggy submission (verdict: Runtime Error):
def D_Derangement(N, p):
    count = 0
    i = 0
    while i < N:
        if p[i] == i + 1:
            if p[i + 1] == i + 2:
                count += 1
                i += 2
                continue
            else:
                count += 1
                i += 1
                continue
        else:
            i += 1
            continue
    return count
 
N = int(input())
p = [int(i) for i in input().split()]
print(D_Derangement(N, p))
Problem p03633 (python)

Fixed submission:
def Q3(x):
    def gcd(a, b):
        if b > a:
            a, b = b, a
        while b > 0:
            a, b = b, a % b
        return a

    def lcm(a, b):
        return (a * b) // gcd(a, b)

    N = x[0]
    lst = x[1:]
    if N == 1:
        return lst[0]
    else:
        l = lcm(lst[0], lst[1])
        for x in lst:
            l = lcm(l, x)
        return l

n = int(input())
t = [int(input()) for i in range(n)]
t.insert(0,n)
print(Q3(t))

Buggy submission (verdict: Runtime Error):
def c_multiple_clocks(N, T):
    from fractions import gcd
    from functools import reduce
    return reduce(lambda a, b: (a * b) // gcd(a, b), T)

N = int(input())
T = [int(input()) for _ in range(N)]
print(c_multiple_Clocks(N, T))
Problem p03636 (python)

Fixed submission:
string=input('')
first=string[0]
last=string[len(string)-1]
mid=str(len(string[1:len(string)-1]))
print(first+mid+last)

Buggy submission (verdict: Runtime Error):
string=input()
first=string[0]
last=string[len(string)-1]
mid=str(len(string[1:len(string-1)]))
print(first+mid+last)
Problem p03643 (python)

Fixed submission:
x=input("")
print("ABC{}".format(x))

Buggy submission (verdict: Runtime Error):
in=input("")
print("ABC{}".format(in))

Buggy submission (verdict: Runtime Error):
in=input()
print("ABC{}".format(in))
Problem p03644 (python)

Fixed submission:
x=int(input(""))
k=0
while True:
  if pow(2,k)>x:
    break
  k+=1
print(pow(2,k-1))

Buggy submission (verdict: Runtime Error):
x=input("")
k=0
while(pow(2,k)<=x):
  k+=1
print(k)
Problem p03659 (python)

Fixed submission:
def Q3(x):
    N = x[0][0]
    lst = x[1][:]
    s = lst[0]
    allsum = sum(lst)
    minimum = abs(allsum - s * 2)
    
    for k in range(1, N - 1):
        s += lst[k]
        a = abs(allsum - s * 2)
        minimum = min(minimum, a)
    return minimum

l = [int(i) for i in input().split()]
m = [int(i) for i in input().split()]
n = [l,m]
print(Q3(n))

Buggy submission (verdict: Runtime Error):
def c_splitting_pile(N, A):
    # Aの要素の総和をX、カードの山の先頭i枚の総和をxとすると、
    # |y-x|=|X-2x|である。各iについてこの値を計算すればよい
    total = sum(A)
    ans = float('inf')
    s = 0
    for i in range(N-1):
        s += A[i]
        ans = min(ans, abs(total - s * 2))
    return ans

N = int(input())
A = [int(i) for i in input().split()]
print(c_splitting_pile(N, A)
Problem p03714 (python)

Fixed submission:
def d_3N_Numbers(N, A):
    import heapq
    left = A[:N]
    heapq.heapify(left)
    # heappopがキューの最小値を取り出す一方、rightからは最大値を取り出してほしいので、
    # -1を掛ける
    right = [-i for i in A[2 * N:]]
    heapq.heapify(right)
    left_sum = [sum(left)]
    right_sum = [-sum(right)]  # 定義で-1を付けた都合上

    # 同じ要素をleftとrightで取り合っても、相殺されるので問題ない
    for k in range(N, 2 * N):
        heapq.heappush(left, A[k])
        v = heapq.heappop(left)
        left_sum.append(left_sum[-1] + A[k] - v)
    for k in range(2 * N - 1, N - 1, -1):
        # -1をかけるのは、rightの定義の都合上
        heapq.heappush(right, -A[k])
        v = heapq.heappop(right)
        right_sum.append(right_sum[-1] + A[k] - (-v))
    right_sum = right_sum[::-1]
    ans = []
    for a, b in zip(left_sum, right_sum):
        ans.append(a - b)
    return max(ans)

N = int(input())
A = [int(i) for i in input().split()]
print(d_3N_Numbers(N, A))

Buggy submission (verdict: Runtime Error):
def d_3n_numbers(N, A):
    import heapq
    left = A[:N]
    heapq.heapify(left)
    # heappopはキューの最小値を取り出すが、rightからは最大値を取り出したいので-1を掛ける
    # 後にマイナスが付いているところは、それの帳尻を合わせている
    right = [-i for i in A[2 * N:]]
    heapq.heapify(right)

    # 最初、leftには数列の先頭N個が、rightには末尾N個が格納されている
    # 数列のN番目から2N番目まで順に、leftに格納して最小値を捨てることを繰り返す
    # 数列の2N番目からN番目まで順に、rightに格納して最大値を捨てることを繰り返す
    left_sum = [sum(left)]
    right_sum = [-sum(right)]
    for k in range(N, 2 * N):
        heapq.heappush(left, A[k])
        v = heapq.heappop(left)
        left_sum.append(left_sum[-1] + A[k] - v)
    for k in range(2 * N - 1, N - 1, -1):
        heapq.heappush(right, -A[k])
        v = heapq.heappop(right)
        right_sum.append(right_sum[-1] + A[k] - (-v))

    score = [a - b for a, b in zip(left_sum, right_sum[::-1])]
    return max(score)

N = int(input())
A = [int(i) for i in input().split()]
print(d_3N_Numbers(N, A))

Buggy submission (verdict: Runtime Error):
def d_3n_numbers(N, A):
    import heapq

    def _heappush_max(heap, item):
        heap.append(item)
        heapq._siftdown_max(heap, 0, len(heap) - 1)
    setattr(heapq, '_heappush_max', _heappush_max)

    left = A[:N]
    heapq.heapify(left)
    right = A[2 * N:]
    heapq._heapify_max(right)
    left_sum, right_sum = [sum(left)], [sum(right)]

    # 同じ要素をleftとrightで取り合っても、相殺されるので問題ない
    for k in range(N, 2 * N):
        heapq.heappush(left, A[k])
        v = heapq.heappop(left)
        left_sum.append(left_sum[-1] + A[k] - v)
    for k in range(2 * N - 1, N - 1, -1):
        heapq._heappush_max(right, A[k])
        v = heapq._heappop_max(right)
        right_sum.append(right_sum[-1] + A[k] - v)
    right_sum = right_sum[::-1]

    ans_candidate = [a - b for a, b in zip(left_sum, right_sum)]
    return max(ans_candidate)

N = int(input())
A = [int(i) for i in input().split()]
print(d_3n_numbers(N, A))
Problem p03738 (python)

Fixed submission:
A = int(input())
B = int(input())
if A>B:
  print('GREATER')
elif A<B:
  print('LESS')
else:
  print('EQUAL')

Buggy submission (verdict: Runtime Error):
A,B = [int(i) for i in input().split()]
if A>B:
  print('GREATER')
elif A<B:
  print('LESS')
else:
  print('EQUAL')
Problem p03760 (python)

Fixed submission:
O = input().strip()
E = input().strip()

end = 0
if len(O)-len(E)==1:
  end = 1
ans = ''
for i in range(len(O)-end):
  ans += O[i] + E[i]
if end==1:
  ans += O[-1]
print(ans)

Buggy submission (verdict: Runtime Error):
O = input().strip()
E = input().strip()

end = 0
if len(O)-len(E)=1:
  end = 1
ans = ''
for i in range(len(O)-end):
  ans += O[i] + E[i]
if end==1:
  ans += O[-1]
print(ans)
Problem p03777 (python)

Fixed submission:
a,b = [i for i in input().strip().split()]
if a=='H':
  if b=='H':
    print('H')
  else:
    print('D')
else:
  if b=='H':
    print('D')
  else:
    print('H')

Buggy submission (verdict: Runtime Error):
a,b = [int(i) for i in input().split()]
if a=='H':
  if b=='H':
    print('H')
  else:
    print('D')
else:
  if b=='H':
    print('D')
  else:
    print('H')
Problem p03798 (python)

Fixed submission:
def d_Menagerie(N, S):
    s = S + S[0:2]  # 円環状に並んでいることを考慮
    for ans in ['SS', 'SW', 'WS', 'WW']:  # Sは羊、Wは狼。1番と2番の種類を仮定する
        cond = False
        for i in range(1, N + 1):
            if (ans[-1] == 'S' and s[i] == 'o') or (ans[-1] == 'W' and s[i] == 'x'):
                # この場合、今注目している動物の両隣は同じ種類。
                # よって、今注目している動物の右隣を左隣と同じにする。
                ans += ans[-2]
            else:
                # 両隣は違う種類。右隣を左隣と逆にする。
                ans += ('S' if ans[-2] == 'W' else 'W')
        if ans[:2] == ans[N:]:
            # sの最初の2文字(仮定)と最後の2文字が一致した文字列のみ受理する。
            # 1つ見つければ良いので、すぐにbreakする
            cond = True
            ans = ans[:N]
            break
    # 目的の文字列が存在すればその文字列を返し、存在しなければ-1を返す
    if cond:
        return ans
    else:
        return '-1'
    return None

N = int(input())
S = input().strip()
print(d_Menagerie(N, S))

Buggy submission (verdict: Runtime Error):
def d_menagerie(N, S):
    s = S + S[0:2]  # 円環状に並んでいることを考慮
    for ans in ['SS', 'SW', 'WS', 'WW']:  # Sは羊、Wは狼。1番と2番の種類を仮定する
        for i in range(1, N + 1):
            if (ans[-1] == 'S' and s[i] == 'o') or (ans[-1] == 'W' and s[i] == 'x'):
                # この場合、今注目している動物の両隣は同じ種類。
                # よって、今注目している動物の右隣を左隣と同じにする。
                ans += ans[-2]
            else:
                # 両隣は違う種類。右隣を左隣と逆にする。
                ans += ('S' if ans[-2] == 'W' else 'W')
        if ans[:2] == ans[N:]:
            # sの最初の2文字(仮定)と最後の2文字が一致した文字列のみ受理する。
            # 1つ見つければ良いので、すぐにbreakする
            ans = ans[:N]
            break
    else:  # どの割り当て方も矛盾した
        ans = '-1'
    return ans

N = int(input())
S = input().strip()
print(d_Menagerie(N, S))
Problem p03854 (python)

Fixed submission:
def c_Daydream(S):
    # Sを逆にしたものから一覧にある文字列を逆にしたものを除いていき、空文字にできるか？
    s = S[::-1]
    while True:
        if len(s) >= 5 and s[0:5] == 'maerd':
            s = s[5:]
        elif len(s) >= 7 and s[0:7] == 'remaerd':
            s = s[7:]
        elif len(s) >= 5 and s[0:5] == 'esare':
            s = s[5:]
        elif len(s) >= 6 and s[0:6] == 'resare':
            s = s[6:]
        elif len(s) == 0:
            return 'YES'
        else:
            return 'NO'
S = input().strip()
print(c_Daydream(S))

Buggy submission (verdict: Runtime Error):
def c_daydream(S):
    import re
    # Sを逆にしたものから該当する文字を除いていき、空文字列にできるか？
    s = S[::-1]
    dict = ['dream'[::-1], 'dreamer'[::-1], 'erase'[::-1], 'eraser'[::-1]]
    n = len(s)
    while n > 0:
        for d in dict:
            if s.startswith(d):
                s = re.sub('^' + d, '', s)
                break
        else:
            return 'NO'
        n = len(s)
    return 'YES'

S = input().strip()
print(c_Daydream(S))
Problem p03957 (python)

Fixed submission:
import sys
S = input().strip()

for j in range(len(S)):
  for k in range(j+1,len(S)):
    if S[j] == 'C' and S[k] == 'F':
      print('Yes')
      sys.exit()
print('No')

Buggy submission (verdict: Runtime Error):
import sys
S = input().strip()

for j in range(len(S)):
  for k in range(j+1,len(S)):
    if S[i] == 'C' and S[j] == 'F':
      print('Yes')
      sys.exit()
print('No')
Problem p03964 (python)

Fixed submission:
def c_AtCoDeer_and_ElectionReport(N, R):
    from math import ceil
    from decimal import Decimal
    t = 1  # 高橋の票数
    a = 1  # 青木の票数
    for x, y in R:
        n = Decimal(max(ceil(t / x), ceil(a / y)))
        t = n * x
        a = n * y
    return t + a

N = int(input())
R = [[int(i) for i in input().split()] for j in range(N)]
print(c_AtCoDeer_and_ElectionReport(N, R))

Buggy submission (verdict: Runtime Error):
def c_atcodeer_and_election_report(N, R):
    t, a = 1, 1  # 高橋, 青木の票数
    for x, y in R:
        # t<=nx ∧ a<=ny を満たす最小のnを求める
        n = max(t // x, a // y)
        if t > n * x or a > n * y:
            n += 1
        t = n * x
        a = n * y
    return t + a

N = int(input())
R = [[int(i) for i in input().split()] for j in range(N)]
print(c_AtCoDeer_and_ElectionReport(N, R))
Problem p04013 (python)

Fixed submission:
def c_Tak_and_Cards(N, A, S):
    X = max(S + [A])
    y = [0] + [x - A for x in S]
    dp = [[0 for _ in range(2 * N * X + 1)] for _ in range(N + 1)]
    dp[0][N * X] = 1
    for j in range(N + 1):
        for t in range(2 * N * X + 1):
            if j == 0 and t == N * X:
                dp[j][t] = 1
            elif j >= 1 and (t - y[j] < 0 or t - y[j] > 2 * N * X):
                dp[j][t] = dp[j - 1][t]
            elif j >= 1 and 0 <= t - y[j] <= 2 * N * X:
                dp[j][t] = dp[j - 1][t] + dp[j - 1][t - y[j]]
            else:
                dp[j][t] = 0
    return dp[N][N * X] - 1
N,A = [int(i) for i in input().split()]
S = [int(i) for i in input().split()]
print(c_Tak_and_Cards(N, A, S))

Buggy submission (verdict: Runtime Error):
def c_atcodeer_and_election_report(N, R):
    from math import ceil
    t = 1  # 高橋の票数
    a = 1  # 青木の票数
    for x, y in R:
        # t<=nx ∧ a<=ny を満たす最小のnを求める
        n = max(ceil(t / x), ceil(a / y))
        t = n * x
        a = n * y
    return t + a
N = int(input())
R = [[int(i) for i in input().split()] for j in range(N)]
print(c_atcodeer_and_election_report(N, R))

Buggy submission (verdict: Runtime Error):
def c_Tak_and_Cards(N, A, S):
    X = max(S)
    y = [x - A for x in S]
    dp = [[0 for _ in range(2 * N * X + 1)] for _ in range(N + 1)]
    dp[0][N * X] = 1
    for j in range(N):
        for t in range(X, (2 * N - 1) * X):
            dp[j + 1][t] = dp[j][t] + dp[j][t - y[j]]
    return dp[N][N * X] - 1
N,A = [int(i) for i in input().split()]
S = [int(i) for i in input().split()]
print(c_Tak_and_Cards(N, A, S))
Problem p04014 (python)

Fixed submission:
def d_DigitSum(N, S):
    if S == N:
        # f(b,N)=Nを満たすbはN+1が最小
        return N + 1
    if S > N:
        return -1

    from math import sqrt, floor, ceil

    def f(b, n):
        if n < b:
            return n
        else:
            return f(b, n // b) + (n % b)

    sn = ceil(sqrt(N))
    # 2<=b<=√Nまで探索
    for b in range(2, sn + 1):
        if f(b, N) == S:
            return b
    # √N<=b<=Nまで探索
    for p in range(sn, 0, -1):
        if (N - S) % p == 0:
            b = (N - S) // p + 1
            if f(b, N) == S:
                return b
    return -1
N = int(input())
S = int(input())
print(d_DigitSum(N, S))

Buggy submission (verdict: Runtime Error):
def d_DigitSum(N, S):
    if S == N:
        # f(b,N)=Nを満たすbはN+1が最小
        return N + 1

    from math import sqrt, floor

    def f(b, n):
        if n < b:
            return n
        else:
            return f(b, floor(n / b)) + n % b
    sq = floor(sqrt(N))
    # 2<=b<=√Nまで探索
    for b in range(2, sq + 1):
        if f(b, N) == S:
            return b
    # √N<=b<=Nまで探索
    for p in range(1, sq):
        b = (N - S) // p + 1
        if f(b, N) == S:
            return b
    return -1
N = int(input())
S = int(input())
print(d_DigitSum(N, S))
Problem p04033 (python)

Fixed submission:
a,b = [int(i) for i in input().split()]
if a > 0:
  print('Positive')
elif a == 0:
  print('Zero')
else:
  if b >= 0:
    print('Zero')
  elif abs(b-a) % 2 == 0:
    print('Negative')
  else:
    print('Positive')

Buggy submission (verdict: Runtime Error):
a,b = [int(i) for i in input().split()]
if a > 0:
  print('Positive')
elif a = 0:
  print('Zero')
else:
  if b >= 0:
    print('Zero')
  elif b-a % 2 == 0:
    print('Negative')
  else:
    print('Positive')
Problem p04043 (python)

Fixed submission:
X = [int(i) for i in input().split()]
if sorted(X)==[5,5,7]:
  print('YES')
else:
  print('NO')

Buggy submission (verdict: Runtime Error):
A, B, C = [int(i) for i in input().split()]
if sorted([A,B,C]==[5,5,7]):
  print('YES')
else:
  print('NO')
Problem p04044 (python)

Fixed submission:
N,L = [int(i) for i in input().split()]
S=[input().strip() for j in range(N)]
print(''.join(sorted(S)))

Buggy submission (verdict: Runtime Error):
N,L = [int(i) for i in input().split()]
S=[[i for i in input().strip()] for j in range(N)]
print(''.join(sorted(S)))