Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
def e_common_subsequence(N, M, S, T, MOD=10**9 + 7):
    # dp[i][j]: S[i], T[j] まで考慮したとき、この2つをペアにしたときの場合の数
    dp = [[0] * (M + 1) for _ in range(N + 1)]

    # S, T のどちらかを見ていない場合、空整数列のみが等しい整数列となる
    for i in range(N + 1):
        dp[i][0] = 1
    for j in range(M + 1):
        dp[0][j] = 1

    for i in range(N):
        for j in range(M):
            if S[i] == T[j]:
                # S[i], T[j] までで作れた等しい整数列に対して
                # 1つ新しい要素を付け加えられる。よって次式のように和を取る
                dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j]
            else:
                # S[i], T[j] は付け加えられないので、その分引く
                dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j] - dp[i][j] + MOD
            dp[i + 1][j + 1] %= MOD
    return dp[N][M]

N, M = [int(i) for i in input().split()]
S = [int(i) for i in input().split()]
T = [int(i) for i in input().split()]
print(e_common_subsequence(N, M, S, T))

Fixed submission:
def e_common_subsequence(N, M, S, T, MOD=10**9 + 7):
    # dp[i][j]: S[i], T[j] まで考慮したとき、この2つをペアにしたときの場合の数
    dp = [[0] * (M + 1) for _ in range(N + 1)]

    # S, T のどちらかを見ていない場合、空整数列のみが等しい整数列となる
    for i in range(N + 1):
        dp[i][0] = 1
    for j in range(M + 1):
        dp[0][j] = 1

    for i in range(N):
        for j in range(M):
            if S[i] == T[j]:
                # S[i], T[j] までで作れた等しい整数列に対して
                # 1つ新しい要素を付け加えられる。よって次式のように和を取る
                dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j]
            else:
                # S[i], T[j] は付け加えられないので、その分引く
                dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j] - dp[i][j] + MOD
            dp[i + 1][j + 1] %= MOD
    return dp[N][M]

N, M = [int(i) for i in input().split()]
S = [int(i) for i in input().split()]
T = [int(i) for i in input().split()]
print(e_common_subsequence(N, M, S, T))
Buggy python submission (verdict: Runtime Error):
def b_picking_up(N, Positions):
    from collections import defaultdict
    difference_count = defaultdict(int)  # xの差分とyの差分の組について、現れた回数
    before_x, before_y = Positions[0]
    for x, y in Positions[1:]:
        diff_x, diff_y = x - before_x, y - before_y
        difference_count[(diff_x, diff_y)] += 1
        before_x, before_y = x, y
    # print(difference_count)
    difference_count = sorted(difference_count.items(), key=lambda x: x[1], reverse=True)
    # print(difference_count)
    if difference_count[0][0] == (0, 0):
        if len(difference_count) == 1:
            return N
        else:
            p, q = difference_count[1][0]
    else:
        p, q = difference_count[0][0]

    ans = 1
    before_x, before_y = Positions[0]
    for x, y in Positions[1:]:
        diff_x, diff_y = x - before_x, y - before_y
        if (diff_x, diff_y) != (p, q):
            ans += 1
        before_x, before_y = x, y
    return ans

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

Fixed submission:
def b_picking_up(N, Positions):
    if N == 1:
        return 1  # 最初のボールに移動するのは必ずコスト1

    from collections import defaultdict
    difference_count = defaultdict(int)  # xの差分とyの差分の組について、現れた回数

    for i in range(N):
        for j in range(N):
            if i == j:
                continue
            # diff_x と diff_y がともに0となることは、入力の制約よりありえない
            diff_x = Positions[j][0] - Positions[i][0]
            diff_y = Positions[j][1] - Positions[i][1]
            difference_count[(diff_x, diff_y)] += 1
    return N - max(difference_count.values())  # 第2項はコスト0で移動できる座標の数

N = int(input())
Positions = [[int(i) for i in input().split()] for j in range(N)]
print(b_picking_up(N, Positions))
Buggy python submission (verdict: Time Limit Exceeded):
def d_lamp(H, W, Grid):
    num_left = [[0] * W for _ in range(H)]
    num_right = [[0] * W for _ in range(H)]
    num_down = [[0] * W for _ in range(H)]
    num_up = [[0] * W for _ in range(H)]

    for row in range(H):
        for col in range(W):
            if Grid[row][col] == '.':
                num_left[row][col] = 1 if col == 0 else (num_left[row][col - 1] + 1)

    for row in range(H):
        for col in range(W - 1, -1, -1):
            if Grid[row][col] == '.':
                num_right[row][col] = 1 if col == W - 1 else (num_right[row][col + 1] + 1)

    for col in range(W):
        for row in range(H):
            if Grid[row][col] == '.':
                num_up[row][col] = 1 if row == 0 else (num_up[row - 1][col] + 1)

    for col in range(W):
        for row in range(H - 1, -1, -1):
            if Grid[row][col] == '.':
                num_down[row][col] = 1 if row == H - 1 else (num_down[row + 1][col] + 1)

    ans = max(num_left[row][col] + num_right[row][col] + num_up[row][col]
              + num_down[row][col] - 3 for row in range(H) for col in range(W))
    return ans

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

Fixed submission:
def d_lamp(H, W, Grid):
    field_horizontal = [[0] * W for _ in range(H)]
    field_vertical = [[0] * W for _ in range(H)]
    field = [[0] * W for _ in range(H)]

    for row in range(H):
        tmp = 0
        for col in range(W):
            if Grid[row][col] == '.':
                tmp += 1
                field_horizontal[row][col] = tmp
            else:
                tmp = 0
        max_val = 0
        for col in range(W - 1, -1, -1):
            if Grid[row][col] == '.':
                max_val = max(max_val, field_horizontal[row][col])
                field_horizontal[row][col] = max_val
            else:
                max_val = 0

    for col in range(W):
        tmp = 0
        for row in range(H):
            if Grid[row][col] == '.':
                tmp += 1
                field_vertical[row][col] = tmp
            else:
                tmp = 0
        max_val = 0
        for row in range(H - 1, -1, -1):
            if Grid[row][col] == '.':
                max_val = max(max_val, field_vertical[row][col])
                field_vertical[row][col] = max_val
            else:
                max_val = 0

    for row in range(H):
        for col in range(W):
            field[row][col] = field_horizontal[row][col] + field_vertical[row][col]

    ans = 0
    for row in range(H):
        for col in range(W):
            ans = max(ans, field[row][col])

    return max(ans - 1, 0)

H, W = [int(i) for i in input().split()]
Grid = [input() for _ in range(H)]
print(d_lamp(H, W, Grid))
Buggy python 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))

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 python submission (verdict: Runtime Error):
def d_even_relation_bfs():
    from collections import deque
    N = int(input())
    Edges = [[int(i) - 1 for i in input().split()] for j in range(N - 1)]  # 0-indexed

    graph = [[] for _ in range(N)]
    for u, v, w in Edges:
        graph[u].append((v, w))
        graph[v].append((u, w))
    distance_from_root = [0] * N  # 根は頂点 0 とする

    queue = deque([(-1, 0, 0)])  # 親と現在の頂点番号，根から親までの距離
    while queue:
        parent, current, distance = queue.pop()
        distance_from_root[current] = distance
        for next_vertex, dist in graph[current]:
            if parent != next_vertex:  # 木を「逆戻り」しない頂点だけ調べる
                queue.appendleft((current, next_vertex, distance + dist))
    ans = (1 if d % 2 == 0 else 0 for d in distance_from_root)
    return ' '.join(map(str, ans))

print(d_even_relation_bfs())

Fixed submission:
def c_dice_and_coin(N, K):
    ans = 0.0
    for i in range(1, N + 1):
        tmp = 1
        p = 0
        while i * tmp < K:
            tmp *= 2
            p += 1
        if p >= 50:
            continue
        ans += 1 / (2**p)
    ans /= N
    return ans

N, K = [int(i) for i in input().split()]
print(c_dice_and_coin(N, K))
Buggy python submission (verdict: Runtime Error):
def d_even_relation_dfs(N, Nodes):  # DFSによる
    graph = [[] for _ in range(N)]
    for u, v, w in Nodes:  # 0-basedとする
        graph[u - 1].append((v - 1, w))
        graph[v - 1].append((u - 1, w))

    def distance_from_root(parent, current, distance, ret=[0] * N):  # 根(頂点0)から各頂点への距離
        def dfs(p, c, d):
            ret[c] = d
            for next_edge, dist in graph[c]:
                if next_edge != p:  # 木を「逆戻り」しない頂点だけ調べる
                    dfs(c, next_edge, d + dist)
        dfs(parent, current, distance)
        return ret
    ans = (1 if d % 2 == 0 else 0 for d in distance_from_root(-1, 0, 0))  # 根の親は-1番とする
    return ' '.join(map(str, ans))

N = int(input())
Nodes = [[int(i) for i in input().split()] for j in range(N - 1)]
print(d_even_relation_dfs(N, Nodes))

Fixed submission:
def d_even_relation(N, Nodes):
    from collections import deque
    graph = [{} for _ in range(N)]
    for u, v, w in Nodes:
        graph[u - 1][v - 1] = w
        graph[v - 1][u - 1] = w

    ans = [0] * N
    queue = deque([(-1, -1, 0)])
    while queue:
        previous, parent, child = queue.pop()
        if parent == -1:
            ans[child] = 0
        elif previous != child:
            length = graph[parent][child]
            if length % 2 == 0:
                ans[child] = ans[parent]
            else:
                ans[child] = 1 if ans[parent] == 0 else 0
        for k in graph[child].keys():
            if parent != k:
                queue.appendleft((parent, child, k))
    return '\n'.join(map(str, ans))

N = int(input())
Nodes = [[int(i) for i in input().split()] for j in range(N - 1)]
print(d_even_relation(N, Nodes))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
V = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

ans = -float('inf')
d = len(V)
for b in range(2 ** d):
    tmp = 0
    for j in range(d):
        if ((b >> j) & 1):
            tmp += V[j] - C[j]
    ans = max(ans, tmp)
print(ans)

Fixed submission:
N = int(input())
V = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

ans = -float('inf')
d = len(V)
for b in range(2 ** d):
    tmp = 0
    for j in range(d):
        if ((b >> j) & 1):
            tmp += V[j] - C[j]
    ans = max(ans, tmp)
print(ans)
Buggy python submission (verdict: Runtime Error):
def c_gcd_on_blackboard(N, A):
    from functools import reduce
    from fractions import gcd
    odd, even = set(), set()
    for a in A:
        if a % 2 == 0:
            even.add(a)
        else:
            odd.add(a)
    if len(odd) >= 3:
        return 1
    if len(odd) == 0:
        even = sorted(even)
        even[0] = even[-1]
        return reduce(gcd, even)
    ans = 1
    for o in odd:
        ans = max(ans, reduce(gcd, even))
    return ans

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

Fixed submission:
def c_gcd_on_blackboard(N, A):
    # editorial通り
    from fractions import gcd

    left, right = [0] * (N + 1), [0] * (N + 1)
    for i in range(N):
        left[i + 1] = gcd(left[i], A[i])
    for i in range(N - 1, -1, -1):
        right[i] = gcd(right[i + 1], A[i])

    return max([gcd(left[i], right[i + 1]) for i in range(N)])

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

Buggy python submission (verdict: Runtime Error):
def c_gcd_on_blackboard(N, A):
    from functools import reduce
    from fractions import gcd
    odd, even = set(), set()
    for a in A:
        if a % 2 == 0:
            even.add(a)
        else:
            odd.add(a)
    if len(odd) >= 3:
        return 1
    if len(odd) == 0:
        even = sorted(even)
        even[0] = even[-1]
        return reduce(gcd, even)
    ans = 1
    for o in odd:
        ans = max(ans, reduce(gcd, even))
    return ans

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

Fixed submission:
def c_gcd_on_blackboard(N, A):
    # editorial通り
    from fractions import gcd

    left, right = [0] * (N + 1), [0] * (N + 1)
    for i in range(N):
        left[i + 1] = gcd(left[i], A[i])
    for i in range(N - 1, -1, -1):
        right[i] = gcd(right[i + 1], A[i])

    return max([gcd(left[i], right[i + 1]) for i in range(N)])

N = int(input())
A = [int(i) for i in input().split()]
print(c_gcd_on_blackboard(N, A))
Buggy python submission (verdict: Runtime Error):
def d_flipping_signs_dp(N, A):
    dp = [[0] * 2 for _ in range(N + 1)]
    dp[0][0] = 0
    dp[0][1] = -float('inf')
    for i in range(N):
        dp[i + 1][0] = max(dp[i][0] + A[i], dp[i][1] - A[i])
        dp[i + 1][1] = max(dp[i][0] - A[i], dp[i][1] + A[i])
    return dp[N][0]

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

Fixed submission:
def d_flipping_signs(N, A):
    minus_count = 0
    _a = []
    for a in A:
        if a >= 0:
            _a.append(a)
        else:
            minus_count += 1
            _a.append(abs(a))
    ans = sum(_a)
    if minus_count % 2 == 1:
        ans -= 2 * min(_a)
    return ans

N = int(input())
A = [int(i) for i in input().split()]
print(d_flipping_signs(N, A))
Buggy python submission (verdict: Time Limit Exceeded):
def c_stones(N, S):
    import itertools
    if S.count('#') == 0 or S.count('.') == 0:
        return 0
    s = [(k, len(list(v))) for k, v in itertools.groupby(S)]
    ans = float('inf')
    for i in range(len(s)):
        ans1, ans2 = 0, 0
        if s[i][0] == '#':
            # ここから黒にする
            for j in range(len(s)):
                if j < i and s[j][0] == '#':
                    ans1 += s[j][1]
                elif j > i and s[j][0] == '.':
                    ans1 += s[j][1]
        elif s[i][0] == '.':
            # ここまで白にする
            for j in range(len(s)):
                if j < i and s[j][0] == '#':
                    ans1 += s[j][1]
                elif j > i and s[j][0] == '.':
                    ans1 += s[j][1]
        ans = min(ans1, ans)
    return ans

N = int(input())
S = input()
print(c_stones(N, S))


Fixed submission:
def c_stones(N, S):
    black_left_of_the_boundary, white_right_of_the_boundary = 0, S.count('.')
    ans = black_left_of_the_boundary + white_right_of_the_boundary
    for c in S:
        if c == '#':
            black_left_of_the_boundary += 1
        else:
            white_right_of_the_boundary -= 1
        ans = min(ans, black_left_of_the_boundary + white_right_of_the_boundary)
    return ans

N = int(input())
S = input()
print(c_stones(N, S))
Buggy python 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))

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 python submission (verdict: Runtime Error):
*Pos, K = [int(input()) for _ in range(6)]
print('Yay!' if Pos[4] - pos[0] <= K else ':(')

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 python submission (verdict: Runtime Error):
def d_cake_123_priority_queue(X, Y, Z, K, A, B, C):
    # editionalの解法3
    import heapq
    # 数列A, B, Cを降順ソート
    a, b, c = sorted(A, reverse=True), sorted(B, reverse=True), sorted(C, reverse=True)

    def evaluation(x, y, z):
        # heapqは最小値を取り出す方式なので、符号を反転させないといけない
        return (-(a[x] + b[y] + c[z]), x, y, z)

    # priority queue を定義し、(A_1 + B_1 + C_1, 1, 1, 1) を追加
    q = []
    heapq.heappush(q, evaluation(0, 0, 0))
    ans = []

    # priority queueに対するK回の操作の部分
    for _ in range(K):
        (e, x, y, z) = heapq.heappop(q)
        ans.append(-e)
        if x + 1 < X and evaluation(x + 1, y, z) not in q:
            heapq.heappush(q, evaluation(x + 1, y, z))
        if y + 1 < Y and evaluation(x, y + 1, z) not in q:
            heapq.heappush(q, evaluation(x, y + 1, z))
        if z + 1 < Z and evaluation(x, y, z + 1) not in q:
            heapq.heappush(q, evaluation(x, y, z + 1))
    return '\n'.join(map(str, ans[:K]))

X, Y, Z, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
print(d_cake_123_sort_modified(X, Y, Z, K, A, B, C))

Fixed submission:
def d_cake_123_sort_all(X, Y, Z, K, A, B, C):
    # editionalの解法2
    a, b, c = sorted(A, reverse=True), sorted(B, reverse=True), sorted(C, reverse=True)
    ans = []
    for i, a_i in enumerate(a, 1):
        for j, b_j in enumerate(b, 1):
            for k, c_k in enumerate(c, 1):
                if i * j * k <= K:
                    ans.append(a_i + b_j + c_k)
                else:
                    break
    ans.sort(reverse=True)
    return '\n'.join(map(str, ans[:K]))

X, Y, Z, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
print(d_cake_123_sort_all(X, Y, Z, K, A, B, C))

Buggy python submission (verdict: Runtime Error):
def d_cake_123_sort_modified(X, Y, Z, K, A, B, C):
    # editionalの解法1
    ab = sorted([a + b for b in B for a in A], reverse=True)[:K]
    ans = sorted([e + c for e in ab for c in C], reverse=True)[:K]
    return ' '.join(map(str, ans))

X, Y, Z, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
print(d_cake_123_sort_all(X, Y, Z, K, A, B, C))

Fixed submission:
def d_cake_123_sort_all(X, Y, Z, K, A, B, C):
    # editionalの解法2
    a, b, c = sorted(A, reverse=True), sorted(B, reverse=True), sorted(C, reverse=True)
    ans = []
    for i, a_i in enumerate(a, 1):
        for j, b_j in enumerate(b, 1):
            for k, c_k in enumerate(c, 1):
                if i * j * k <= K:
                    ans.append(a_i + b_j + c_k)
                else:
                    break
    ans.sort(reverse=True)
    return '\n'.join(map(str, ans[:K]))

X, Y, Z, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
print(d_cake_123_sort_all(X, Y, Z, K, A, B, C))
Buggy python submission (verdict: Time Limit Exceeded):
def c_synthetic_kadomatsu(N, A, B, C, L):
    from itertools import permutations

    ans = float('inf')
    # 竹の並び方を決める
    for perm in permutations(range(N)):
        # 左から竹をj, k, l本取り、それらを別々に合成し、
        # それらの長さと A, B, C とがどれだけ違うかを計算する
        for j in range(1, N):
            for k in range(1, N - j):
                for l in range(1, N - j - k + 1):
                    cost = 0
                    s, t, u = perm[:j], perm[j:j + k], perm[j + k:j + k + l]
                    a, b, c = [], [], []
                    for _s in s:
                        a.append(L[_s])
                    for _t in t:
                        b.append(L[_t])
                    for _u in u:
                        c.append(L[_u])
                    cost += (len(a) + len(b) + len(c) - 3) * 10
                    cost += abs(sum(a) - A) + abs(sum(b) - B) + abs(sum(c) - C)
                    ans = min(ans, cost)
    return ans

N, A, B, C = [int(i) for i in input().split()]
L = [int(input()) for _ in range(N)]
print(c_synthetic_kadomatsu(N, A, B, C, L))


Fixed submission:
def c_synthetic_kadomatsu(N, A, B, C, L):
    from itertools import permutations
    # for j in range(1, N):
    #     for k in range(1, N - j):
    #         for l in range(1, N - j - k + 1):
    #             print(j, k, l, L[:j], L[j:j + k], L[j + k:j + k + l])
    ans = float('inf')
    for perm in permutations(range(N)):
        for j in range(1, N):
            for k in range(1, N - j):
                for l in range(1, N - j - k + 1):
                    cost = 0
                    s, t, u = perm[:j], perm[j:j + k], perm[j + k:j + k + l]
                    a, b, c = [], [], []
                    for _s in s:
                        a.append(L[_s])
                    for _t in t:
                        b.append(L[_t])
                    for _u in u:
                        c.append(L[_u])
                    cost += (len(a) + len(b) + len(c) - 3) * 10
                    cost += abs(sum(a) - A) + abs(sum(b) - B) + abs(sum(c) - C)
                    ans = min(ans, cost)
    return ans

N, A, B, C = [int(i) for i in input().split()]
L = [int(input()) for _ in range(N)]
print(c_synthetic_kadomatsu(N, A, B, C, L))
Buggy python submission (verdict: Runtime Error):
print('YES' if sum(divmod(int(input()), 2)) >= int(inpu()) else 'NO')

Fixed submission:
def a_anti_adjacency(N, K):
    if N % 2 == 0:
        ans = 'YES' if N // 2 >= K else 'NO'
    else:
        ans = 'YES' if (1 + N // 2) >= K else 'NO'
    return ans

N, K = [int(i) for i in input().split()]
print(a_anti_adjacency(N, K))
Buggy python submission (verdict: Time Limit Exceeded):
def d_xxor(N, K, A):
    # 参考: http://drken1215.hatenablog.com/entry/2019/02/03/224200
    ans = 0
    # N, K <= 10**12 < 2**40 なので、dの上限を40とする
    for d in range(40, -2, -1):
        # d=-1のケースはX=Kのケースを意味する
        if d != -1 and (K & (1 << d)) == 0:
            continue

        tmp = 0
        for e in range(40, -1, -1):
            bit_mask = 1 << e

            # Aの各要素を2進表記したとき、e番目のビットが立っているものは何個か？
            num = 0
            for a in A:
                if a & bit_mask != 0:
                    num += 1

            # このビットがfに貢献する値を決める。
            if e > d:
                if K & bit_mask != 0:
                    tmp += bit_mask * (N - num)  # X_e=1とする
                else:
                    tmp += bit_mask * num  # X_e=0とする
            elif e == d:
                tmp += bit_mask * num  # このビットは0とする(解説pdf参照)
            else:
                # これを満たすビットについては、独立に決めていい。
                # よって、貢献する値が大きな方を選べばいい
                tmp += bit_mask * max(num, N - num)
        ans = max(ans, tmp)
    return ans

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

Fixed submission:
def d_xxor(N, K, A):
    bit_max = 40  # N,K <= 10**12 < 2**40 なので、入力は40bit以下で表せる
    ans = 0

    for b in range(bit_max, -1, -1):
        power = 1 << b
        # Aの各要素を2進表記したとき、b番目のビットに1は何個立つか？
        bit_count_1 = len([1 for a in A if a & power != 0])

        # 解説における、「X_k=0とするか1とするか判定する」部分
        tmp = bit_count_1
        if power <= K and bit_count_1 <= N - bit_count_1:
            # X_k=1とした。XとKとの差を補正する。
            tmp = N - bit_count_1
            K -= power
        contribution = power * tmp

        ans += contribution  # 「b番目のビットがfに貢献する値」
    return ans

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