Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
# E - Knapsack 2
from collections import defaultdict


def main():
    N, W, *WV = map(int, open(0).read().split())
    dp = defaultdict(int)
    dp[0] = 0
    for w, v in zip(*[iter(WV)] * 2):
        for cur_w, cur_v in tuple(dp.items()):
            if w + cur_w <= W:
                dp[w + cur_w] = max(dp[w + cur_w], v + cur_v)
    print(max(dp.values()))


if __name__ == "__main__":
    main()


Fixed submission:
# temp
n,w = map(int,input().split())
wv = [tuple(map(int,input().split())) for i in range(n)]

dp = [0] + [float("inf")]*(10**5)
for i in range(n):
    for j in range(10**5,wv[i][1]-1,-1):
        dp[j] = min(dp[j],dp[j-wv[i][1]]+wv[i][0])

res = 0
for v,e in enumerate(dp):
    if e <= w:
        res = v
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
# temp
n,w = map(int,input().split())
wv = [tuple(map(int,input().split())) for i in range(n)]

dp = [0] + [float("inf")]*(10**5)
for i in range(n):
    for j in range(10**5,wv[i][1]-1,-1):
        dp[j] = min(dp[j],dp[j-wv[i][1]]+wv[i][0])

res = 0
for v,e in enumerate(dp):
    if e <= w:
        res = v
print(res)

Fixed submission:
# temp
n,w = map(int,input().split())
wv = [tuple(map(int,input().split())) for i in range(n)]

dp = [0] + [float("inf")]*(10**5)
for i in range(n):
    for j in range(10**5,wv[i][1]-1,-1):
        dp[j] = min(dp[j],dp[j-wv[i][1]]+wv[i][0])

res = 0
for v,e in enumerate(dp):
    if e <= w:
        res = v
print(res)
Buggy python submission (verdict: Runtime Error):
def get_lcs(S: str, T: str):
    N, M = len(S), len(T)
    dp = [[0] * (M + 1) for _ in range(N + 1)]
    for i, s in enumerate(S):
        for j, t in enumerate(T):
            if s == t:
                dp[i + 1][j + 1] = dp[i][j] + 1
            else:
                dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1])

    reversed_lcs = ""
    while N and M:
        if S[N - 1] == T[M - 1]:
            N -= 1
            M -= 1
            reversed_lcs += S[N]
        if dp[N - 1][M] > dp[N][M - 1]:
            N -= 1
        else:
            M -= 1
    return reversed_lcs[::-1]


def main():
    S, T = open(0).read().split()
    print(get_lcs(S, T))


if __name__ == "__main__":
    main()


Fixed submission:
# dpF - LCS
def main():
    S, T = tuple(input().rstrip() for _ in range(2))
    n, m = len(S), len(T)
    dp = [[0] * (m + 1) for _ in range(n + 1)]
    for i in range(1, n + 1):
        for j in range(1, m + 1):
            if S[i - 1] == T[j - 1]:
                dp[i][j] = dp[i - 1][j - 1] + 1
            else:
                dp[i][j] = max(dp[i][j - 1], dp[i - 1][j])
    ans = []
    while n > 0 and m > 0:
        if dp[n][m] == dp[n - 1][m]:
            n -= 1
        elif dp[n][m] == dp[n][m - 1]:
            m -= 1
        else:
            n -= 1
            m -= 1
            ans += [S[n]]
    print(*ans[::-1], sep="")


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# dpF - LCS
def main():
    S, T = tuple(input().rstrip() for _ in range(2))
    n, m = len(S), len(T)
    dp = [[0] * (m + 1) for _ in range(n + 1)]
    for i in range(1, n + 1):
        for j in range(1, m + 1):
            if S[i - 1] == T[j - 1]:
                dp[i][j] = dp[i - 1][j - 1] + 1
            else:
                dp[i][j] = max(dp[i][j - 1], dp[i - 1][j])
    ans = []
    while n > 0 and m > 0:
        if dp[n][m] == dp[n - 1][m]:
            n -= 1
        elif dp[n][m] == dp[n][m - 1]:
            m -= 1
        else:
            n -= 1
            m -= 1
            ans += [S[n]]
    print(*ans[::-1], sep="")


if __name__ == "__main__":
    main()

Fixed submission:
# dpF - LCS
def main():
    S, T = tuple(input().rstrip() for _ in range(2))
    n, m = len(S), len(T)
    dp = [[0] * (m + 1) for _ in range(n + 1)]
    for i in range(1, n + 1):
        for j in range(1, m + 1):
            if S[i - 1] == T[j - 1]:
                dp[i][j] = dp[i - 1][j - 1] + 1
            else:
                dp[i][j] = max(dp[i][j - 1], dp[i - 1][j])
    ans = []
    while n > 0 and m > 0:
        if dp[n][m] == dp[n - 1][m]:
            n -= 1
        elif dp[n][m] == dp[n][m - 1]:
            m -= 1
        else:
            n -= 1
            m -= 1
            ans += [S[n]]
    print(*ans[::-1], sep="")


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
# K - Stones
def main():
    N, K, *A = map(int, open(0).read().split())
    dp = [0] * (K + 1)
    for i in range(K):
        for a in A:
            if i + a > K:
                break
            dp[i + a] |= dp[i] ^ 1
    print("First" if dp[-1] else "Second")


if __name__ == "__main__":
    main()


Fixed submission:
# K - Stones
def main():
    N, K, *A = map(int, open(0).read().split())
    dp = [0] * (K + 1)
    for i in range(1, K + 1):
        for a in A:
            if i - a >= 0:
                dp[i] |= dp[i - a] ^ 1
    print("First" if dp[-1] else "Second")


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# K - Stones
def main():
    N, K, *A = map(int, open(0).read().split())
    dp = [0] * (K + 1)
    for i in range(1, K + 1):
        for a in A:
            if i - a >= 0:
                dp[i] |= dp[i - a] ^ 1
    print("First" if dp[-1] else "Second")


if __name__ == "__main__":
    main()


Fixed submission:
# K - Stones
def main():
    N, K, *A = map(int, open(0).read().split())
    dp = [0] * (K + 1)
    for i in range(1, K + 1):
        for a in A:
            if i - a >= 0:
                dp[i] |= dp[i - a] ^ 1
    print("First" if dp[-1] else "Second")


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
# ABC115D - Christmas
def burger(n):
    x = "P"
    for i in range(n):
        x = "B" + x + "P" + x + "B"
    return x


def main():
    N, X = tuple(map(int, input().split()))
    n_burger = burger(N)[:X]
    ans = n_burger.count("P")
    print(ans)


if __name__ == "__main__":
    main()

Fixed submission:
# ABC115D - Christmas
def burger(n, x):
    if n == 0:
        return 0 if x <= 0 else 1
    if x <= 1 + B[n - 1]:
        return burger(n - 1, x - 1)
    return burger(n - 1, x - 2 - B[n - 1]) + P[n - 1] + 1


def main():
    global B, P
    N, X = tuple(map(int, input().split()))
    B, P = [1], [1]  # burger, patty
    for i in range(N):
        B += [B[i] * 2 + 3]
        P += [P[i] * 2 + 1]
    ans = burger(N, X)
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
# ABC114C - 755
n = input()
digit = len(n)
ans = 0
for i in range(1, digit):
    ans += len([i for i in itertools.product("357", repeat=i) if len(set(i)) == 3])
tup = tuple(i for i in n)
lst = [i for i in itertools.product("357", repeat=digit) if len(set(i)) == 3] + [tup]
lst.sort()
ans += lst.index(tup)
print(ans)

Fixed submission:
# ABC114C - 755
def shichi_go_san(s="0"):
    if int(s) > n:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in "753") else 0
    for c in "753":
        ret += shichi_go_san(s + c)
    return ret


n = int(input())
print(shichi_go_san())
Buggy python submission (verdict: Runtime Error):
# AGC028
from fractions import gcd


def main():
    n, m = tuple(map(int, input().rstrip().split()))
    S, T = tuple(input().rstrip() for _ in range(2))
    l = n // gcd(n, m) * m
    x = [""] * l
    for i in range(n):  # place S in x
        j = (l // n) * i
        x[j] = S[i]

    for i in range(m):  # check T adapts to x or not
        j = (l // m) * i
        if x[j] not in ("", T[i]):
            print(-1)
            break
    else:
        print(l)


if __name__ == "__main__":
    main()

Fixed submission:
# AGC028
from fractions import gcd


def main():
    n, m = tuple(map(int, input().rstrip().split()))
    S, T = tuple(input().rstrip() for _ in range(2))
    l = n // gcd(n, m) * m
    x = {}
    for i in range(n):  # place S in x
        j = (l // n) * i
        x[j] = S[i]
    for i in range(m):  # check T adapts to x or not
        j = (l // m) * i
        if j in x and x[j] != T[i]:
            print(-1)
            break
    else:
        print(l)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
# ABC112A - Programming Education
def main():
    N, A, B = map(int, open(0).read().split())
    flg = N == 1
    print("Hello World" if flg else A + B)


if __name__ == "__main__":
    main()

Fixed submission:
# ABC112A - Programming Education
n = int(input())
if n == 1:
    print("Hello World")
else:
    a, b = list(map(int, [input().rstrip() for _ in range(2)]))
    print(a + b)
Buggy python submission (verdict: Runtime Error):
# AGC027A - Candy Distribution Again
# greedy algorithm
from itertools import accumulate as acc


def main():
    # maximize the number of proper distribution -> begin with small values
    N, X, *A = map(int, open(0).read().split())
    A.sort()
    ac = list(acc(A))
    if ac[-1] < x:  # the last one receives more than expected -> ans - 1
        ans = n - 1
    else:
        ans = sum(i <= x for i in ac)
    print(ans)


if __name__ == "__main__":
    main()

Fixed submission:
# AGC027A - Candy Distribution Again
# greedy algorithm
from itertools import accumulate


def main():
    # maximize the number of proper distribution -> begin with small values
    n, x = tuple(map(int, input().rstrip().split()))
    A = sorted(map(int, input().rstrip().split()))
    ac = list(accumulate(A))
    if ac[-1] < x:
        ans = n - 1
    else:
        ans = sum(i <= x for i in ac)
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
# ABC109C - Skip
from math import gcd

n, x = list(map(int, input().rstrip().split()))
lst = list(map(int, input().rstrip().split()))
d = abs(x - lst[0])
for i in range(n):
    dif = abs(x - lst[i])
    if dif % d == 0:
        continue
    d = gcd(d, dif)
print(d)

Fixed submission:
# ABC109C - Skip
def gcd(a, b):
    while a:
        a, b = b % a, a
    return b
        

n, x = list(map(int, input().rstrip().split()))
lst = list(map(int, input().rstrip().split()))
d = abs(x - lst[0])
for i in range(n):
    dif = abs(x - lst[i])
    if dif % d == 0:
        continue
    d = gcd(d, dif)
print(d)

Buggy python submission (verdict: Runtime Error):
# ABC109C - Skip
from math import gcd

n, x = list(map(int, input().rstrip().split()))
lst = list(map(int, input().rstrip().split()))
d = abs(x - lst[0])
for i in range(n):
    dif = abs(x - lst[i])
    if dif % d == 0:
        continue
    else:
        d = gcd(d, dif)
print(d)

Fixed submission:
# ABC109C - Skip
def gcd(a, b):
    while a:
        a, b = b % a, a
    return b
        

n, x = list(map(int, input().rstrip().split()))
lst = list(map(int, input().rstrip().split()))
d = abs(x - lst[0])
for i in range(n):
    dif = abs(x - lst[i])
    if dif % d == 0:
        continue
    d = gcd(d, dif)
print(d)
Buggy python submission (verdict: Runtime Error):
# ABC107C - Candles (ARC101C)
def main():
    N, K, *X = map(int, open(0).read().split())
    ans = float("inf")
    for l, r in zip(X, X[k - 1 :]):
        ans = min(ans, r - l + min(abs(l), abs(r)))
    print(ans)


if __name__ == "__main__":
    main()

Fixed submission:
# ABC107C - Candles (ARC101C)
def main():
    n, k = tuple(map(int, input().rstrip().split()))
    x = tuple(map(int, input().rstrip().split()))
    ans = float("inf")
    for i in range(n - k + 1):
        a, b = x[i], x[i + k - 1]
        if a < b < 0 or 0 < a < b:
            ans = min(ans, max(abs(a), abs(b)))
        else:
            ans = min(ans, max(abs(a), abs(b)) + min(abs(a), abs(b)) * 2)
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
# ABC104A - Rated for Me
r = list(map(int, input().rstrip().split()))
if r < 1200:
    print("ABC")
elif 1200 <= r < 2800:
    print("ARC")
else:
    print("AGC")

Fixed submission:
# ABC104A - Rated for Me
r = int(input())
if r < 1200:
    print("ABC")
elif 1200 <= r < 2800:
    print("ARC")
else:
    print("AGC")
Buggy python submission (verdict: Runtime Error):
# ABC104B - AcCepted
s = input().rstrip()
if (
    s[0] == "A"
    and s[2:-1].count("C") == 1
    and s.translate(str.maketrans({"A": None, "C": None}).islower()
):
    print("AC")
else:
    print("WA")

Fixed submission:
# ABC104B - AcCepted
s = input().rstrip()
if (
    s[0] == "A"
    and s[2:-1].count("C") == 1
    and s.replace("A", "").replace("C", "").islower()
):
    print("AC")
else:
    print("WA")
Buggy python submission (verdict: Time Limit Exceeded):
### ABC104C - All Green
from itertools import permutations


def main():
    D, G = map(int, input().split())
    A = [(0, 0)] + [tuple(map(int, input().split())) for _ in range(D)]
    ans = float("inf")
    for perm in permutations(range(1, D + 1), D):
        cur, cnt = G, 0
        for i in perm:
            point, (num, bonus) = i * 100, A[i]
            if cur / point < num:
                cnt += cur // point
                cur -= point * (cur // point)
            else:
                cnt += num
                cur -= point * num + bonus
            if cur <= 0:
                ans = min(ans, cnt)
                break
    print(ans)


if __name__ == "__main__":
    main()

Fixed submission:
# ABC104C - All Green
def ans(g, i, L):
    # Assume the case using question no.i
    if i == 0:  # base case
        return float("inf")

    n = min(g // (i * 100), L[i][0])  # n:count
    s = n * i * 100  # s:score

    # add bonus if available
    if n == L[i][0]:
        s += L[i][1]

    # make up for the shortage
    if s < g:
        n += ans(g - s, i - 1, L)

    # compare to other cases without question no.i recursively
    return min(n, ans(g, i - 1, L))


def main():
    d, g = list(map(int, input().rstrip().split()))
    arr = [0] + [list(map(int, input().rstrip().split())) for _ in range(d)]
    print(ans(g, d, arr))


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
# ABC102C - Linear Approximation (ARC100C)
from statistics import median_high, median_low


def main():
    n = int(input())
    A = tuple(map(int, input().rstrip().split()))
    A = tuple(j - i for i, j in enumerate(A, start=1))
    ans = float("inf")
    for b in range(median_low(A), median_high(A) + 1):
        ans = min(ans, sum(abs(a - b) for a in A))
    print(ans)


if __name__ == "__main__":
    main()

Fixed submission:
# ABC102C - Linear Approximation (ARC100C)
from statistics import median


def main():
    n = int(input())
    A = tuple(map(int, input().rstrip().split()))
    A = tuple(j - i for i, j in enumerate(A, start=1))
    b = median(A)
    ans = sum(abs(a - b) for a in A)
    print(int(ans))


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
# ABCB - Digit Sums
n = int(input())
sn = 0
for i in range(len(str(n))):
    n_temp = n
    sn += n_temp % 10
    n_temp //= 10
print("Yes" if n % sn == 0 else "No")

Fixed submission:
# ABCB - Digit Sums
n = int(input())
sn = sum(list(map(int, list(str(n)))))
print("Yes" if n % sn == 0 else "No")

Buggy python submission (verdict: Runtime Error):
# ABCB - Digit Sums
n = int(input())
sn = 0
for i in range(len(str(n))):
    n_temp = 0
    sn += n_temp % 10
    n_temp //= 10
print("Yes" if n % sn == 0 else "No")

Fixed submission:
# ABCB - Digit Sums
n = int(input())
sn = sum(list(map(int, list(str(n)))))
print("Yes" if n % sn == 0 else "No")

Buggy python submission (verdict: Runtime Error):
# ABCB - Digit Sums
n = int(input())
sn = 0
for i in range(len(str(n))):
    sn += n % 10
    s //= 10
print("Yes" if n % sn == 0 else "No")

Fixed submission:
# ABCB - Digit Sums
n = int(input())
sn = sum(list(map(int, list(str(n)))))
print("Yes" if n % sn == 0 else "No")

Buggy python submission (verdict: Runtime Error):
# ABCB - Digit Sums
n = int(input())
sn = 0
for i in range(len(str(n))):
    sn += n % 10
print("Yes" if n % sn == 0 else "No")

Fixed submission:
# ABCB - Digit Sums
n = int(input())
sn = sum(list(map(int, list(str(n)))))
print("Yes" if n % sn == 0 else "No")
Buggy python submission (verdict: Runtime Error):
# ABC097B - Exponential
x = int(input())
lst = []

for i in range(1, 32):
    for j in range(1, 10):
        if i ** j == x:
            print(x)
            exit()
        elif i ** j < x and i ** j not in lst:
            lst.append(i ** j)
        elif i ** j > x:
            break
            
lst.append(x)
lst = sorted(lst)

print(lst[lst.index(1000) - 1])

Fixed submission:
# ABC097B - Exponential
x = int(input())
lst = []

for i in range(1, 32):
    for j in range(2, 10):
        if i ** j == x:
            print(x)
            exit()
        elif i ** j < x and i ** j not in lst:
            lst.append(i ** j)
        elif i ** j > x:
            break
            
lst.append(x)
lst = sorted(lst)

print(lst[lst.index(x) - 1])
Buggy python submission (verdict: Runtime Error):
# ABC097D - Equals (ARC097D)
"""
Union-Find: O(α(N))

Verified:
    https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/1/DSL_1_A
    https://judge.yosupo.jp/problem/unionfind
"""


class UnionFind:
    __slots__ = ["_data_size", "_first_index", "_parents"]

    def __init__(self, data_size: int, is_zero_indexed: bool = True) -> None:
        self._data_size = data_size
        self._first_index = 0 if is_zero_indexed else 1
        self._parents = [-1] * (data_size + self._first_index)

    def find(self, x: int) -> int:
        """Find the group (root) of vertex x"""
        if self._parents[x] < 0:
            return x
        self._parents[x] = self.find(self._parents[x])
        return self._parents[x]

    def is_same(self, x: int, y: int) -> bool:
        """Return whether two vertices x and y are in the same group or not."""
        return self.find(x) == self.find(y)

    def unite(self, x: int, y: int) -> None:
        """Unite two groups of vertices x and y."""
        x, y = self.find(x), self.find(y)
        if x == y:
            return
        if self._parents[x] > self._parents[y]:
            x, y = y, x
        self._parents[x] += self._parents[y]
        self._parents[y] = x


def main():
    N, _, *PXY = open(0).read().split()
    P, XY = PXY[:N], PXY[N:]
    uf = UnionFind(N, is_zero_indexed=False)
    for x, y in zip(*[iter(XY)] * 2):
        uf.unite(x, y)
    ans = sum(uf.is_same(i, p) for i, p in enumerate(P, 1))
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
# ARC097D - Equals (ABC097D)
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)


def dfs(v: int, color: int) -> None:
    seen[v] = 1  # make vertex v searched
    group[v] = color
    for u in G[v]:  # search vertices available from v recursively
        if not seen[u]:  # skip if already searched
            dfs(u, color)


def main():
    # check i and Pi are connected components or not
    global G, seen, group
    N, M = tuple(map(int, input().split()))
    P = tuple(map(int, input().split()))
    E = tuple(tuple(map(int, input().split())) for _ in range(M))
    G = [[] for _ in range(N + 1)]  # construct a graph (1-idx)
    for v, u in E:
        G[v] += [u]
        G[u] += [v]
    seen, group = [0] * (N + 1), [0] * (N + 1)
    color = 1
    for i in range(1, N + 1):  # connected components have the same color
        if not seen[i]:
            dfs(i, color)
            color += 1
    ans = sum(group[i] == group[p] for i, p in enumerate(P, 1))
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
# ARC097C - K-th Substring
def substring_getter(a: str, x: int) -> set:
    length = len(a)
    ret = set()
    for i in range(length - x + 1):
        ret.add(a[i : i + x])
    return ret


def main():
    s = input()
    k = int(input())
    ans = set()
    for i in range(1, len(s) + 1):
        ans = ans | substring_getter(s, i)
    print(sorted(ans)[k - 1])


if __name__ == "__main__":
    main()

Fixed submission:
# ARC097C - K-th Substring
def substring_getter(a: str, x: int) -> set:
    length = len(a)
    ret = set()
    for i in range(length - x + 1):
        ret.add(a[i : i + x])
    return ret


def main():
    s = input()
    k = int(input())
    ans = set()
    for i in range(1, k + 1):
        ans = ans | substring_getter(s, i)
    print(sorted(ans)[k - 1])


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# ARC097C - K-th Substring
def substring_getter(a: str, x: int) -> set:
    length = len(a)
    ret = set()
    for i in range(length - x + 1):
        ret.add(a[i : i + x])
    return ret


def main():
    s = input()
    k = int(input())
    ans = set()
    for i in range(1, len(s) + 1):
        ans = ans | substring_getter(s, i)
    print(sorted(ans)[k - 1])


if __name__ == "__main__":
    main()

Fixed submission:
# ARC097C - K-th Substring
def substring_getter(a: str, x: int) -> set:
    length = len(a)
    ret = set()
    for i in range(length - x + 1):
        ret.add(a[i : i + x])
    return ret


def main():
    s = input()
    k = int(input())
    ans = set()
    for i in range(1, k + 1):
        ans = ans | substring_getter(s, i)
    print(sorted(ans)[k - 1])


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
# ABC096B - Maximum Sum
a, b, c = sorted(list(map(int, input().rstrip().split())), reverse=True)
k = int(input())
if k == 1:
    print(a * 2 + b + c)
else:
    for i in range(1, k + 1):
        A = a * 2 + b + c
        B = a + b * 2 ++ c
        C = a + b + c * 2
        if max(A, B, C) == A:
            a *= 2
        elif max(A, B, C) == B:
            b *= 2
        else:
            c *= 2
	print(a + b + c)

Fixed submission:
# ABC096B - Maximum Sum
a, b, c = sorted(list(map(int, input().rstrip().split())), reverse=True)
k = int(input())
if k == 1:
    print(a * 2 + b + c)
else:
    for i in range(1, k + 1):
        A = a * 2 + b + c
        B = a + b * 2 ++ c
        C = a + b + c * 2
        if max(A, B, C) == A:
            a *= 2
        elif max(A, B, C) == B:
            b *= 2
        else:
            c *= 2
    print(a + b + c)
Buggy python submission (verdict: Runtime Error):
# ABC094B - Toll Gates
from bisect import bisect_left


def main():
    N, M, X, *A = map(int, open(0).read().split())
    A.sort()
    cur = bisect_left(A, x)
    ans = min(cur, M - cur)
    print(ans)


if __name__ == "__main__":
    main()

Fixed submission:
# ABC094B - Toll Gates
n, m, x = list(map(int, input().rstrip().split()))
lst = list(map(int, input().rstrip().split()))
lst.append(x)
lst = sorted(lst)
print(min(len(lst[: lst.index(x)]), len(lst[lst.index(x) + 1 :])))
Buggy python submission (verdict: Runtime Error):
# ABC094D - Binomial Coefficients (ARC095D)
from bisect import bisect_left as bs


def main():
    # pascal's triangle := mid area (nCn/2) is the biggest -> bisect
    N = int(input())
    A = sorted(map(int, input().split()))
    if N == 2:
        print(A[1], A[0])
        return
    n, idx = A[-1], bs(A[:-1], A[-1] // 2)
    cand = [abs(A[i] - n / 2), A[i] for i in (idx - 1, idx, idx + 1)]
    r = min(cand)[1]
    print(n, r)


if __name__ == "__main__":
    main()

Fixed submission:
# ABC094D - Binomial Coefficients (ARC095D)
def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    n = max(A)
    r = A[0] if A[0] != n else A[1]
    cur = r * (n - r)
    for i in A:
        if i != n:
            x = i * (n - i)
            if x > cur:
                r, cur = i, x
    print(n, r)


if __name__ == "__main__":
    main()