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

Fixed submission:
a,b,c = map(int,input().split(" "))
if a == b:
    if a == c:
        print("No")
    else:
        print("Yes")
else:
    if b == c:
        print("Yes")
    else:
        if a == c:
            print("Yes")
        else:
            print("No")

Buggy submission (verdict: Runtime Error):
a,b,c = map(int,input().split(" "))
if a == b:
    if a == c:
        print("No")
    else:
        print("Yes")
else
    if b == c:
        print("Yes")
    else:
        if a == c:
            print("Yes")
        else:
            print("No")
Problem p02777 (python)

Fixed submission:
s,t=input().split(" ")
a,b=map(int,input().split(" "))
u=input()
 
if s==u:
  print(a-1, b)
else:
  print(a, b-1)

Buggy submission (verdict: Runtime Error):
s,t=input().split(" ")
a,b.=map(int,input().split(" "))
u=input()
 
if s==u:
  print(a-1, b)
else:
  print(a, b-1)

Buggy submission (verdict: Runtime Error):
s,t=input().split(" ")
a,b.=map(int,input().split(" "))
u=input()
 
if s==u:
  print(int(a-1)" "int(b))
else:
  print(int(a)" "int(b-1))

Buggy submission (verdict: Runtime Error):
s,t=input().split(" ")
a,b.=map(int,input().split(" "))
u=input()
 
if s==u:
  print(a-1,b.split(" "))
else:
  print(a,b-1.split(" "))

Buggy submission (verdict: Runtime Error):
s,t=input().split(" ")
a,b.=map(int,input().split(" "))
u=input()

if s==u:
  print(a-1,b)
else:
  print(a,b-1)

Buggy submission (verdict: Runtime Error):
s,t=input().split()
a,b=map(int,input().split())
u=str(input())

if s==u:
  print(a-1 b)
else:
  print(a b-1)

Buggy submission (verdict: Runtime Error):
s,t=map(str,input().split(" "))
a,b=map(int,input().split(" "))
u=str(input())

if s==u:
  print(a-1" "b)
else:
  print(a" "b-1)
Problem p02790 (python)

Fixed submission:
a,b = map(int,input().split())
s = 0
if a <= b:
    for i in range(0,b):
        s += a*(10**i)

else:
    for i in range(0,a):
        s += b*(10**i)

print(s)

Buggy submission (verdict: Runtime Error):
,b = map(int,input().split())
s = 0
if a <= b:
    for i in range(0,b):
        s += a*(10**i)

else:
    for i in range(0,a):
        s += b*(10**i)

print(s)
Problem p02552 (python)

Fixed submission:
#!/usr/bin/env python3
import sys


def solve(x: int):

    if x == 1:
        return print('0')

    elif x == 0:
        return print('1')


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    x = int(next(tokens))  # type: int
    solve(x)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys


def solve(x: int):

    if x == 1:
        return print('0')

    elif x == 0:
        return print('1')1


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    x = int(next(tokens))  # type: int
    solve(x)

if __name__ == '__main__':
    main()
Problem p02570 (python)

Fixed submission:
D, T, S = map(int, input().split())

a = T * S - D
if a >= 0:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
from itertools import accumulate
MOD = 1000000007  # type: int


def solve(N: int, A: "List[int]"):
    aa = list(accumulate(A))
    print(aa)
    x = sum(A)
    print(x)

    ans = 0

    for i in range(N):
        ans += A[i]*(aa[N-1]-aa[i])%MOD
        ans %= MOD
    return print(ans)


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

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

number = 0
MOD = 1000000007

for i in range(N-1):
    for j in range(i+1, N):
        number += A[i]*A[j]


if number > MOD:
    print(number%MOD)
else:
    print(number)
Problem p02571 (python)

Fixed submission:
#!/usr/bin/env python3
import sys


def solve(S: str, T: str):
    length = len(T)
    s_list =[]
    counter = length
    ans = 0

    for i in range(len(S)-length+1):
        s = S[i:i+length]
        for i in range(length):
            #print(s[i], T[i])
            if s[i] != T[i]:
                ans+=1

        counter = min(ans, counter)

        ans = 0

    return print(counter)


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    T = next(tokens)  # type: str
    solve(S, T)

if __name__ == '__main__':
    main()

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

suma=0
sumb=0
sumc=0

for i in range(len(T)):
    A = T[i:]
    B = T[:i+1]
    if A in S:
        pass
    else:
        suma+=1

    if B in S:
        pass
    else:
        sumb+=1

    if A in S:
        if B in S:
            pass
    else:
        sumc+=1


suma = min(suma, sumb)
suma = min(suma, sumc)
print(suma)
~
Problem p02699 (python)

Fixed submission:
arg = input()
s = (arg.split())[0]
w = (arg.split())[1]


if int(s) > int(w):
  print('safe')
else:
  print('unsafe')

Buggy submission (verdict: Runtime Error):
s = input()
w = input()

if int(s) > int(w):
  print('safe')
else:
  print('unsafe')
Problem p02682 (python)

Fixed submission:
A, B, C, K = map(int,input().split())
ans = 0
if(K<=A):
  ans = K
elif(K<=A+B):
  ans = A
else:
  ans = A-(K-A-B)
print(ans)

Buggy submission (verdict: Runtime Error):
A, B, C, K = map(int,input().split())
ans = 0
if(K<=A):
  ans = K
else if(K<=A+B):
  ans = A
else:
  ans = A-(K-A-B)
print(ans)
Problem p02699 (python)

Fixed submission:
S, W = map(int,input().split())
ans = "safe"
if(S<=W):
  ans = "unsafe"
print(ans)

Buggy submission (verdict: Runtime Error):
A, B, C, D = map(int,input().split())
ans = "Yes"
curA = A
curC = C
for i in range(max(A,C)):
  curC  = curC-B
  if(curC<=0):
    ans = "Yes"
    break
  curA = curA-D
  if(curA<=0):
    ans = "No"
    break
print(ans)
Problem p02793 (python)

Fixed submission:
def e_flatten(MOD=10**9 + 7):
    from fractions import gcd
    from functools import reduce
    N = int(input())
    A = [int(i) for i in input().split()]

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

    def inv(n, mod=MOD):
        return pow(n, mod - 2, mod)

    l = reduce(lcm, A) % MOD
    ans = [(l * inv(a)) % MOD for a in A]
    return sum(ans) % MOD

print(e_flatten())

Buggy submission (verdict: Runtime Error):
def e_flatten_prime_factorization(MOD=10**9 + 7):
    N = int(input())
    A = [int(i) for i in input().split()]

    def prime_factorization_dict(n):
        from collections import defaultdict
        """nを素因数分解したときの素数とその指数の辞書"""
        if n == 1:
            return {2: 0}  # 1は素数の0乗の積とみなす
        i, table = 2, defaultdict(int)
        while i**2 <= n:
            while n % i == 0:
                table[i] += 1
                n //= i
            i += 1
        if n > 1:
            table[n] = 1
        return table

    def prime_table(n):
        """n以下の素数のリスト(エラトステネスの篩)"""
        is_prime = [True] * (n + 1)
        is_prime[0] = is_prime[1] = False  # 0と1は素数でない
        for j in range(2, int(n**0.5) + 1):
            if not is_prime[j]:
                continue
            for k in range(j * 2, n + 1, j):
                is_prime[k] = False  # jの倍数は素数でない
        return {i: 0 for i in range(n + 1) if is_prime[i]}

    lcm_prime = prime_table(1000)
    for a in A:
        for base, exp in prime_factorization_dict(a).items():
            lcm_prime[base] = max(lcm_prime[base], exp)
    lcm = 1
    for base, exp in lcm_prime.items():
        lcm *= pow(base, exp, MOD)
        lcm %= MOD
    coefficient = sum(pow(a, MOD - 2, MOD) for a in A)
    return (lcm * coefficient) % MOD

print(e_flatten_prime_factorization())

Buggy submission (verdict: Runtime Error):
def e_flatten_prime_factorization(MOD=10**9 + 7):
    from collections import defaultdict
    N = int(input())
    A = [int(i) for i in input().split()]

    def prime_factorization_dict(n):
        """nを素因数分解したときの素数とその指数の辞書"""
        from collections import defaultdict
        if n == 1:
            return {2: 0}  # 1は素数の0乗の積とみなす
        i, table = 2, defaultdict(int)
        while i**2 <= n:
            while n % i == 0:
                table[i] += 1
                n //= i
            i += 1
        if n > 1:
            table[n] = 1
        return table

    lcm_prime = defaultdict(int)
    for a in A:
        for base, exp in prime_factorization_dict(a).items():
            lcm_prime[base] = max(lcm_prime[base], exp)
    lcm = 1
    for base, exp in lcm_prime.items():
        lcm *= pow(base, exp, MOD)
        lcm %= MOD
    coefficient = sum(pow(a, MOD - 2, MOD) for a in A)
    return (lcm * coefficient) % MOD

print(e_flatten())

Buggy submission (verdict: Runtime Error):
def e_flatten(MOD=10**9 + 7):
    from math import gcd
    from functools import reduce
    N = int(input())
    A = [int(i) for i in input().split()]

    lcm = reduce(lambda x, y: x * y // gcd(x, y), A) % MOD
    coefficient = sum(pow(a, MOD - 2, MOD) for a in A)
    return (lcm * coefficient) % MOD

print(e_flatten())
Problem p02834 (python)

Fixed submission:
def f_playing_tag_on_tree():
    from collections import deque

    def bfs(tree, distance, first_pos):
        q = deque([(first_pos, -1)])
        while q:
            current, parent = q.pop()
            for child in tree[current]:
                if child == parent:
                    continue
                distance[child] = distance[current] + 1
                q.appendleft((child, current))

    N, U, V = map(int, input().split())
    tree = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b = map(int, input().split())
        tree[a - 1].append(b - 1)
        tree[b - 1].append(a - 1)

    # 両者について、最初にいる場所から他の頂点への移動回数を求める
    dist_aoki = [0] * N
    bfs(tree, dist_aoki, V - 1)
    dist_takahashi = [0] * N
    bfs(tree, dist_takahashi, U - 1)

    ans = 0
    for aoki, takahashi in zip(dist_aoki, dist_takahashi):
        # 注目した頂点 v には高橋くんの方が先に到達できる
        if aoki > takahashi:
            # 青木くんは v の親で高橋くんを捕まえることになるので、
            # v までの距離 - 1 が解となりうる
            ans = max(ans, aoki - 1)
    return ans

print(f_playing_tag_on_tree())

Buggy submission (verdict: Runtime Error):
def f_playing_tag_on_tree():
    N, U, V = [int(i) for i in input().split()]
    Edges = [[int(i) for i in input().split()] for j in range(N - 1)]

    tree = [[] for _ in range(N)]
    for u, v in Edges:
        tree[u - 1].append(v - 1)
        tree[v - 1].append(u - 1)

    depth = [-1] * N

    def dfs(current, parent, dep):
        depth[current] = dep

        for child in tree[current]:
            if child == parent:
                continue
            dfs(child, current, dep + 1)
        return None
    dfs(V - 1, -1, 0)
    return max(depth) - 1

print(f_playing_tag_on_tree())
Problem p02990 (python)

Fixed submission:
def d_blue_and_red_balls(N, K, MOD=10**9 + 7):
    class Combination(object):
        """
        順列組み合わせ
        参考: https://harigami.net/contents?id=5f169f85-5707-4137-87a5-f0068749d9bb
        """
        __slots__ = ["mod", "factorial", "inverse"]

        def __init__(self, max_n: int = 10**6, mod: int = 10**9 + 7):
            fac, inv = [1], []
            fac_append, inv_append = fac.append, inv.append

            for i in range(1, max_n + 1):
                fac_append(fac[-1] * i % mod)

            inv_append(pow(fac[-1], mod - 2, mod))

            for i in range(max_n, 0, -1):
                inv_append(inv[-1] * i % mod)

            self.mod, self.factorial, self.inverse = mod, fac, inv[::-1]

        def combination(self, n, r):
            if r == n or r == 0:
                return 1
            if r > n:
                return 0
            return self.factorial[n] * self.inverse[r] * self.inverse[n - r] % self.mod

    comb = Combination(max(N - K + 1, K - 1))
    ans = [comb.combination(N - K + 1, i) * comb.combination(K - 1, i - 1) %
           MOD for i in range(1, K + 1)]
    return '\n'.join(map(str, ans))

N, K = [int(i) for i in input().split()]
print(d_blue_and_red_balls(N, K))

Buggy submission (verdict: Runtime Error):
def d_blue_and_red_balls(N, K, MOD=10**9 + 7):
    from math import factorial

    def comb(n, r):
        if r == n or r == 0:
            return 1
        if r > n:
            return 0
        return factorial(n) // (factorial(r) * factorial(n - r))

    ans = [comb(N - K + 1, i) * comb(K - 1, i - 1) % MOD for i in

N, K = [int(i) for i in input().split()]
print(d_blue_and_red_balls(N, K))

Buggy submission (verdict: Runtime Error):
def d_blue_and_red_balls(N, K, MOD=10**9 + 7):
    from math import factorial

    def comb(n, r):
        return factorial(n) // (factorial(r) * factorial(n - r))

    ans = [comb(N - K + 1, i) * comb(K - 1, i - 1) % MOD for i in range(1, K + 1)]
    return '\n'.join(map(str, ans))

N, K = [int(i) for i in input().split()]
print(d_blue_and_red_balls(N, K))
Problem p03017 (python)

Fixed submission:
def a_kenken_race(N, A, B, C, D, S):
    # cond1: 道のりの途中に岩が2つ連続する場所があると、ゴールに到達できない
    # cond2: ふぬけ君の道のりの途中に空きが3マス分ないと、すぬけ君が追い越せない
    cond1 = '##' in S[A - 1:C] or '##' in S[B - 1:D]
    cond2 = '...' not in S[B - 2:D + 1]

    if cond1:
        ans = 'No'
    elif C > D and cond2:
        ans = 'No'
    else:
        ans = 'Yes'  # ふぬけ君から順にゴールさせる/すぬけ君が追い越す ことができる
    return ans

N, A, B, C, D = [int(i) for i in input().split()]
S = input()
print(a_kenken_race(N, A, B, C, D, S))

Buggy submission (verdict: Runtime Error):
def a_kenken_race(N, A, B, C, D, S):
    # cond1: 道のりの途中に岩が2つ連続する場所があると、ゴールに到達できない
    # cond2: ふぬけ君の道のりの途中に空きが3マス分ないと、すぬけ君が追い越せない
    cond1 = S[A:C + 1].count('##') == 0 and S[B:D + 1].count('##') == 0
    cond2 = S[B:D + 1].count('...') >= 1
    if C < D:
        # ふぬけ君をゴールに行かせてからすぬけ君をゴールに行かせればよい
        ans = 'Yes' if cond1 else 'No'
    else:
        # すぬけ君は途中でふぬけ君を追い越せないといけない
        ans = 'Yes' if cond1 and cond2 else 'No'
    return ans

S = input()
print(a_kenken_race(N, A, B, C, D, S))
Problem p03053 (python)

Fixed submission:
def a_darker_and_darker(H, W, Grid):
    def is_in_field(row, col):
        return (0 <= row < H) and (0 <= col < W)

    grid, q = [[None] * W for _ in range(H)], []
    # 黒マスがどこにあるかを調べる。ついでにgridを初期化
    for row in range(H):
        for col in range(W):
            if Grid[row][col] == '#':
                grid[row][col] = True
                q.append((row, col))
            else:
                grid[row][col] = False

    # '#'があるマスから上下左右に移動することを繰り返して任意のマスに到達する。
    # 何回繰り返せばすべてのマスに到達できるか？
    directions = ((-1, 0), (0, 1), (1, 0), (0, -1))  # 上右下左の隣接マスを指定
    ans = 0
    while q:
        tmp = []
        for row, col in q:
            for dr, dc in directions:
                nr, nc = row + dr, col + dc
                if is_in_field(nr, nc) and (not grid[nr][nc]):
                    grid[nr][nc] = True
                    tmp.append((nr, nc))
        ans += (1 if tmp else 0)
        q = tmp
    return ans

H, W = [int(i) for i in input().split()]
Grid = [input() for _ in range(H)]
print(a_darker_and_darker(H, W, Grid))

Buggy submission (verdict: Runtime Error):
def a_darker_and_darker(H, W, Grid, INF=float('inf')):
    def is_in_field(row, col):
        return (0 <= row < W) and (0 <= col < H)

    grid, q = [[None] * W for _ in range(H)], []
    # 黒マスがどこにあるかを調べる。ついでにgridを初期化
    for row in range(H):
        for col in range(W):
            if Grid[row][col] == '#':
                grid[row][col] = True
                q.append((row, col))
            else:
                grid[row][col] = False

    # '#'があるマスから上下左右に移動することを繰り返して任意のマスに到達する。
    # 何回繰り返せばすべてのマスに到達できるか？
    directions = ((-1, 0), (0, 1), (1, 0), (0, -1))  # 上右下左の隣接マスを指定
    ans = 0
    while q:
        tmp = []
        for row, col in q:
            for dr, dc in directions:
                nr, nc = row + dr, col + dc
                if is_in_field(nr, nc) and (not grid[nr][nc]):
                    grid[nr][nc] = True
                    tmp.append((nr, nc))
        ans += (1 if tmp else 0)
        q = tmp
    return ans

H, W = [int(i) for i in input().split()]
Grid = [input() for _ in range(H)]
print(a_darker_and_darker(H, W, Grid))

Buggy submission (verdict: Runtime Error):
def a_darker_and_darker(H, W, Grid, INF=float('inf')):
    from collections import deque

    def is_in_field(row, col):
        return (0 <= row < W) and (0 <= col < H)

    q = deque()
    for row in range(H):
        for col in range(W):
            if Grid[row][col] == '#':
                q.append((row, col, 0))

    grid = [[float('inf')] * W for _ in range(H)]
    directions = ((-1, 0), (0, 1), (1, 0), (0, -1))  # 上右下左の隣接マスを指定
    while q:
        row, col, move = q.pop()
        grid[row][col] = min(grid[row][col], move)

        for dr, dc in directions:
            nr, nc = row + dr, col + dc
            if is_in_field(nr, nc) and grid[nr][nc] == INF:
                q.appendleft((nr, nc, move + 1))
    return max([max(row) for row in grid])

H, W = [int(i) for i in input().split()]
Grid = [input() for _ in range(H)]
print(a_darker_and_darker(H, W, Grid))
Problem p03073 (python)

Fixed submission:
def c_coloring_colorfully(S):
    s1 = '10' * (len(S) // 2) + ('1' if len(S) % 2 == 1 else '')
    s2 = '01' * (len(S) // 2) + ('0' if len(S) % 2 == 1 else '')
    ans1, ans2 = 0, 0
    for k, s in enumerate(S):
        if s != s1[k]:
            ans1 += 1
        if s != s2[k]:
            ans2 += 1
    return min(ans1, ans2)

S = input()
print(c_coloring_colorfully(S))

Buggy submission (verdict: Runtime Error):
def c_coloring_colorfully(S):
    s1 = '10' * (len(S) // 2) + ('1' if len(S) % 2 == 1 else '')
    s2 = '01' * (len(S) // 2) + ('0' if len(S) % 2 == 1 else '')
    ans1, ans2 = 0, 0
    for k, s in enumerate(S):
        if s != s1[k]:
            ans1 += 1
        if s != s2[k]:
            ans2 += 1
    return min(ans1, ans2)

S = input()
print(c_doloring_colorfully(S))
Problem p03075 (python)

Fixed submission:
*Pos, K = [int(input()) for _ in range(6)]
for s in range(5):
  for t in range(s + 1, 5):
    if Pos[t] - Pos[s] > K:
      print(':(')
      exit()
print('Yay!')

Buggy submission (verdict: Runtime Error):
*Pos, K = [int(input()) for _ in range(6)]
print('Yay!' if Pos[4] - pos[0] <= K else ':(')
Problem p03201 (python)

Fixed submission:
def b_powers_of_two(N, A):
    # 参考: https://beta.atcoder.jp/contests/agc029/submissions/3804857
    from bisect import bisect_left
    a = sorted(A)
    ans = 0
    for j in range(N - 1, -1, -1):
        # b > a[j]となるような最小のb(これは2の冪乗である)を探す
        b = 1
        while b <= a[j]:
            b <<= 1

        k = bisect_left(a, b - a[j])
        if k < j and (b - a[j] == a[k]):
            # a[k] <= a[j] であり、かつ、a[j] + a[k] = b(2の冪乗)
            # となるペア(j, k)が見つかれば、貪欲にペアにしてよい。
            # (a[j] を放置すると、ペアにできる可能性がある整数が少なくなり、得にならない)
            ans += 1
            # 整数でなくしておいて、ペアに使えないようにする。
            # ペアのうち、要素番号が大きい方は足し、小さい方は引いておくと、
            # 同じ値が複数あったときも二部探索で以前にペアにした整数を
            # ピックアップすることがなくなる。
            a[j] += 0.1
            a[k] -= 0.1

    return ans

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

Buggy submission (verdict: Runtime Error):
def b_powers_of_two(N, A):
    # 参考: https://beta.atcoder.jp/contests/agc029/submissions/3804857
    from bisect import bisect_left
    a = sorted(A)
    ans = 0
    for j in range(N - 1, -1, -1):
        # b > a[j]となるような最小のb(これは2の冪乗である)を探す
        b = 1
        while b <= a[j]:
            b <<= 1

        k = bisect_left(a, b - a[j])
        if k < j and (b - a[j] == a[k]):
            # a[k] <= a[j] であり、かつ、a[j] + a[k] = b(2の冪乗)
            # となるペア(j, k)が見つかれば、貪欲にペアにしてよい。
            # (a[j] を放置すると、ペアにできる可能性がある整数が少なくなり、得にならない)
            ans += 1
            # 整数でなくしておいて、ペアに使えないようにする。
            # ペアのうち、要素番号が大きい方は足し、小さい方は引いておくと、
            # 同じ値が複数あったときも二部探索で以前にペアにした整数を
            # ピックアップすることがなくなる。
            a[j] += 0.1
            a[k] -= 0.1

    return ans

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

Buggy submission (verdict: Runtime Error):
def b_powers_of_two(N, A):
    # 参考: https://beta.atcoder.jp/contests/agc029/submissions/3804857
    from bisect import bisect_left
    a = sorted(A)
    ans = 0
    for j in range(N - 1, -1, -1):
        # b > a[j]となるような最小のb(これは2の冪乗である)を探す
        b = 1
        while b <= a[j]:
            b <<= 1

        k = bisect_left(a, b - a[j])
        if k < j and (b - a[j] == a[k]):
            # a[k] <= a[j] であり、かつ、a[j] + a[k] = b(2の冪乗)
            # となるペア(j, k)が見つかれば、貪欲にペアにしてよい。
            # (a[j] を放置すると、ペアにできる可能性がある整数が少なくなり、得にならない)
            ans += 1
            # 整数でなくしておいて、ペアに使えないようにする。
            # ペアのうち、要素番号が大きい方は足し、小さい方は引いておくと、
            # 同じ値が複数あったときも二部探索で以前にペアにした整数を
            # ピックアップすることがなくなる。
            a[j] += 0.1
            a[k] -= 0.1

    return ans

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

Fixed submission:
def c_christmas_eve(N, K, H):
    H.sort()
    ans = float('inf')
    for j in range(N - K + 1):
        h_max = H[j + K - 1]
        h_min = H[j]
        ans = min(ans, h_max - h_min)
    return ans

N, K = [int(i) for i in input().split()]
H = [int(input()) for _ in range(N)]
print(c_christmas_eve(N, K, H))

Buggy submission (verdict: Runtime Error):
def c_christmas_eve(N, K, H):
    H.sort()
    ans = float('inf')
    for j in range(N - K + 1):
        h_max = H[j + 2]
        h_min = H[j]
        ans = min(ans, h_max - h_min)
    return ans

N, K = [int(i) for i in input().split()]
H = [int(input()) for _ in range(N)]
print(c_christmas_eve(N, K, H))