Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import heapq
import copy

n, k = map(int, input().split())
v = list(map(int, input().split()))


def dfs(q, have, count, operate):
    if operate == 0:
        heapq.heappush(have, q[0])
        q = q[1:]
    elif operate == 1:
        heapq.heappush(have, q[-1])
        q = q[:-1]
    elif operate == 2:
        sub = heapq.heappop(have)
        q.insert(0, sub)
    elif operate == 3:
        sub = heapq.heappop(have)
        q.append(sub)

    count += 1
    if count >= k:
        return sum(have)

    a = -float('inf')
    b = -float('inf')
    c = -float('inf')
    d = -float('inf')
    e = dfs(q, have, count, -1)  # 何もしない

    if len(q) > 0:
        a = dfs(copy.deepcopy(q), copy.deepcopy(have), count, 0)
        b = dfs(copy.deepcopy(q), copy.deepcopy(have), count, 1)
    if len(have) > 0:
        c = dfs(copy.deepcopy(q), copy.deepcopy(have), count, 2)
        d = dfs(copy.deepcopy(q), copy.deepcopy(have), count, 3)

    return max(a, b, c, d, e)


print(dfs(v, [], -1, -1))


Fixed submission:
n, k = map(int, input().split())
v = list(map(int, input().split()))

ans = 0
for a in range(min(n, k) + 1):
    for b in range(min(n, k) - a + 1):
        li = v[:a]
        if b > 0:
            li += v[-b:]
        li.sort()
        count = 0
        while (a + b + count < k):
            if len(li) > 0 and li[0] < 0:
                count += 1
                li = li[1:]
            else:
                break
        ans = max(ans, sum(li))

print(ans)

Buggy python submission (verdict: Runtime Error):
import heapq
import copy

n, k = map(int, input().split())
v = list(map(int, input().split()))


def dfs(q, have, count, operate):
    if operate == 0:
        heapq.heappush(have, q[0])
        q = q[1:]
    elif operate == 1:
        heapq.heappush(have, q[-1])
        q = q[:-1]
    elif operate == 2:
        sub = heapq.heappop(have)
        q.insert(0, sub)
    elif operate == 3:
        sub = heapq.heappop(have)
        q.append(sub)

    count += 1
    if count >= k:
        return sum(have)

    a = dfs(copy.deepcopy(q), copy.deepcopy(have), count, 0)
    b = dfs(copy.deepcopy(q), copy.deepcopy(have), count, 1)
    c = -float('inf')
    d = -float('inf')
    e = dfs(q, have, count, -1)  # 何もしない
    if len(have) > 0:
        c = dfs(copy.deepcopy(q), copy.deepcopy(have), count, 2)
        d = dfs(copy.deepcopy(q), copy.deepcopy(have), count, 3)

    return max(a, b, c, d, e)


print(dfs(v, [], -1, -1))


Fixed submission:
n, k = map(int, input().split())
v = list(map(int, input().split()))

ans = 0
for a in range(min(n, k) + 1):
    for b in range(min(n, k) - a + 1):
        li = v[:a]
        if b > 0:
            li += v[-b:]
        li.sort()
        count = 0
        while (a + b + count < k):
            if len(li) > 0 and li[0] < 0:
                count += 1
                li = li[1:]
            else:
                break
        ans = max(ans, sum(li))

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
mod = 10 ** 9 + 7
n, m, k = map(int, input().split())
nm = n * m
fact = [1] * (nm + 1)

for i in range(1, nm + 1):
    fact[i] = fact[i - 1] * i


def C(n, k):
    x = fact[n]
    x *= pow(fact[n-k], mod - 2, mod)
    x %= mod
    x *= pow(fact[k], mod - 2, mod)
    x %= mod
    return x


def F(x):
    s1 = x * x * (x + 1) // 2
    s2 = x * (x + 1) * (2 * x + 1) // 6
    return (s1 - s2) % mod


res = (m ** 2 % mod * F(n) % mod + n ** 2 * F(m) % mod) % mod
res *= C(n * m - 2, k - 2)
res %= mod
print(res)


Fixed submission:
# -*- coding: utf-8 -*-
mod = 10 ** 9 + 7
n, m, k = map(int, input().split())
nm = n * m
fact = [1] * (nm + 1)

for i in range(1, nm + 1):
    fact[i] = fact[i - 1] * i % mod


def C(n, k):
    x = fact[n]
    x *= pow(fact[n-k], mod - 2, mod)
    x %= mod
    x *= pow(fact[k], mod - 2, mod)
    x %= mod
    return x


def F(x):
    s1 = x * x * (x + 1) // 2
    s2 = x * (x + 1) * (2 * x + 1) // 6
    return (s1 - s2) % mod


res = (m ** 2 % mod * F(n) % mod + n ** 2 * F(m) % mod) % mod
res *= C(n * m - 2, k - 2)
res %= mod
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
mod = 10 ** 9 + 7
n, m, k = map(int, input().split())
nm = n * m
fact = [1] * (nm + 1)

for i in range(1, nm + 1):
    fact[i] = fact[i - 1] * i


def C(n, k):
    x = fact[n]
    x *= pow(fact[n-k], mod - 2, mod)
    x *= pow(fact[k], mod - 2, mod)
    return x


def F(x):
    s1 = x * x * (x + 1) // 2
    s2 = x * (x + 1) * (2 * x + 1) // 6
    return (s1 - s2)


res = (m ** 2 * F(n) + n ** 2 * F(m))
res *= C(n * m - 2, k - 2)
print(res % mod)


Fixed submission:
# -*- coding: utf-8 -*-
mod = 10 ** 9 + 7
n, m, k = map(int, input().split())
nm = n * m
fact = [1] * (nm + 1)

for i in range(1, nm + 1):
    fact[i] = fact[i - 1] * i % mod


def C(n, k):
    x = fact[n]
    x *= pow(fact[n-k], mod - 2, mod)
    x %= mod
    x *= pow(fact[k], mod - 2, mod)
    x %= mod
    return x


def F(x):
    s1 = x * x * (x + 1) // 2
    s2 = x * (x + 1) * (2 * x + 1) // 6
    return (s1 - s2) % mod


res = (m ** 2 % mod * F(n) % mod + n ** 2 * F(m) % mod) % mod
res *= C(n * m - 2, k - 2)
res %= mod
print(res)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
from heapq import heappush, heappop

qn = int(input())

low = []
high = []
ans = 0
num = 0

for i in range(qn):
    q = [int(i) for i in input().split()]
    if q[0] == 1:
        ans += q[2]
        a = q[1]
        if a < -low[0]:
            ans += -low[0] - a
        elif a > high[0]:
            ans += a - high[0]

        # lowは降順に並べたいので-aを入れる
        heappush(low, -a)
        heappush(high, a)
        if -low[0] > high[0]:
            low0 = heappop(low)
            high0 = heappop(high)
            # lowとhighで正負が逆なので注意する
            heappush(low, -high0)
            heappush(high, -low0)
    elif q[0] == 2:
        print(-low[0], ans)


Fixed submission:
# -*- coding: utf-8 -*-
from heapq import heappush, heappop

qn = int(input())

low = []
high = []
ans = 0
num = 0

for i in range(qn):
    q = [int(i) for i in input().split()]
    if q[0] == 1:
        # update
        ans += q[2]
        a = q[1]
        heappush(low, -a)
        heappush(high, a)
        if -low[0] > high[0]:
            low0 = heappop(low)
            high0 = heappop(high)
            heappush(low, -high0)
            heappush(high, -low0)
            ans += -low0 - high0
    if q[0] == 2:
        print(-low[0], ans)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int, input().split()))

ans = 0
count = 0
for i in range(n):
    if a[i] < 0:
        a[i] = -a[i]
        count += 1
    ans += a[i]

if count % 2 == 0:
    print(ans)
else:
    print(ans - min(a) * 2)


Fixed submission:
# -*- coding: utf-8 -*-
a, b, t = map(int, input().split())

print(b * (t // a))
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
def gcd(a, b):
    if (b == 0):
        return a
    return gcd(b, a % b)


n = int(input())
a = list(map(int, input().split()))
g = [1] * n

ans = 1
for i in range(n):
    if i == 0:
        g[0] = a[1]
    else:
        g[0] = a[0]
    for j in range(1, n):
        if i == j:
            g[j] = g[j - 1]
            continue
        g[j] = gcd(g[j - 1], a[j])
    ans = max(ans, g[n - 1])

print(ans)


Fixed submission:
# -*- coding: utf-8 -*-
def gcd(a, b):
    if (b == 0):
        return a
    return gcd(b, a % b)


n = int(input())
a = list(map(int, input().split()))
li = [0] * (n + 1)
r = [0] * (n + 1)

for i in range(n):
    li[i + 1] = gcd(li[i], a[i])

for i in range(n - 1, -1, -1):
    r[i] = gcd(r[i + 1], a[i])

ans = 0
for i in range(n):
    ans = max(ans, gcd(li[i], r[i + 1]))

print(ans)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
n, k = map(int, input().split())
s = input()
bl = []

left = -1
right = 0
for i in range(len(s)):
    if s[i] == '0':
        if left < 0:
            left = i
        if i == n - 1:
            right = n
            bl.append((left, right))
    else:
        if left >= 0:
            right = i
            bl.append((left, right))
            left = -1


def change(index, count, ts):
    if count >= k or index >= len(bl):
        max_seq = 0
        seq = 0
        for i in range(len(ts)):
            if ts[i] == '1':
                seq += 1
                if i == n - 1:
                    max_seq = max(max_seq, seq)
            else:
                max_seq = max(max_seq, seq)
                seq = 0
        return max_seq

    new_s = ts[:bl[index][0]] + '1' * \
        (bl[index][1] - bl[index][0]) + ts[bl[index][1]:]
    return max(change(index + 1, count + 1, new_s),
               change(index + 1, count, ts))


if k >= len(bl):
    print(len(s))
else:
    print(change(0, 0, s))


Fixed submission:
# -*- coding: utf-8 -*-
n, k = map(int, input().split())
s = input()
nums = []
now = 1

cnt = 0
for i in range(n):
    if s[i] == str(int('0') + now):
        cnt += 1
    else:
        nums.append(cnt)
        now = 1 - now
        cnt = 1

if cnt != 0:
    nums.append(cnt)

ans = 0
left = 0
right = 0
tmp = 0

for i in range(0, len(nums), 2):
    next_left = i
    next_right = min(i + 2 * k + 1, len(nums))

    while (left < next_left):
        tmp -= nums[left]
        left += 1

    while (right < next_right):
        tmp += nums[right]
        right += 1

    ans = max(ans, tmp)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = input()

for i in range(q):
    li, ri = map(int, input().split())
    t = s[li - 1:ri]
    a_flag = False
    cnt = 0
    for j in range(len(t)):
        if t[j] == 'A':
            a_flag = True
        elif t[j] == 'C':
            if a_flag:
                cnt += 1
                a_flag = False
        else:
            a_flag = False

    print(cnt)


Fixed submission:
n, q = map(int, input().split())
s = input()

t = [0] * (n + 1)
for i in range(n):
    t[i + 1] = t[i] + (1 if s[i:i+2] == 'AC' else 0)

for i in range(q):
    l, r = map(int, input().split())
    print(t[r - 1] - t[l - 1])
Buggy python submission (verdict: Time Limit Exceeded):
a, b = map(int, input().split())

ans = 0
for i in range(a, b + 1):
    ans ^= i

print(ans)


Fixed submission:
a, b = map(int, input().split())


def f(x):
    return (x, 1, x + 1, 0)[x % 4]


print(f(b) ^ f(a - 1))
Buggy python submission (verdict: Time Limit Exceeded):
A, B, Q = map(int, input().split())

s = []
t = []
x = []
for i in range(A):
    s.append(int(input()))

for i in range(B):
    t.append(int(input()))

res = []
for i in range(Q):
    x = int(input())
    ans = 0

    minimum_ws = float('inf')
    minimum_wt = float('inf')
    minimum_es = float('inf')
    minimum_et = float('inf')
    for i in range(A):
        if s[i] < x:
            minimum_ws = x - s[i]
        else:
            minimum_es = s[i] - x
            break
    for i in range(B):
        if t[i] < x:
            minimum_wt = x - t[i]
        else:
            minimum_et = t[i] - x
            break

    # 西に突っ切る
    ans = max(minimum_ws, minimum_wt)
    # 東に突っ切る
    ans = min(ans, max(minimum_es, minimum_et))
    # 西いって東
    ans = min(ans, min(minimum_ws * 2 + minimum_et, minimum_wt * 2 + minimum_es))
    # 東いって西
    ans = min(ans, min(minimum_es * 2 + minimum_wt, minimum_et * 2 + minimum_ws))
    res.append(ans)

print('\n'.join(list(map(str, res))))


Fixed submission:
import bisect
A, B, Q = map(int, input().split())

s = [-float('inf')] + [int(input()) for i in range(A)] + [float('inf')]
t = [-float('inf')] + [int(input()) for i in range(B)] + [float('inf')]

res = []
for i in range(Q):
    x = int(input())
    b = bisect.bisect_right(s, x)
    a = b - 1
    d = bisect.bisect_right(t, x)
    c = d - 1
    ans = float('inf')
    for S in [s[a], s[b]]:
        for T in [t[c], t[d]]:
            ans = min(ans, abs(S - x) + abs(T - S), abs(T - x) + abs(S - T))
    res.append(ans)

print('\n'.join(map(str, res)))
Buggy python submission (verdict: Runtime Error):
import heapq

N, K = map(int, input().split())
sushi = []
for i in range(N):
    t, d = map(int, input().split())
    heapq.heappush(sushi, (-d, t))

total = 0
types = set()
remain = []
for i in range(K):
    d, t = heapq.heappop(sushi)
    total -= d
    if t not in types:
        types.append(t)
    else:
        # 余りの寿司はremainにappend
        heapq.heappush(remain, -d)

types_len = len(types)
ans = total + types_len ** 2

while sushi and remain:
    d, t = heapq.heappop(sushi)
    if t not in types:
        types.append(t)
        remain_d = heapq.heappop(remain)
        total = total - d - remain_d
        types_len += 1
        ans = max(ans, total + types_len ** 2)

print(ans)


Fixed submission:
import heapq

N, K = map(int, input().split())
sushi = []
for i in range(N):
    t, d = map(int, input().split())
    heapq.heappush(sushi, (-d, t))

total = 0
types = set()
remain = []
for i in range(K):
    d, t = heapq.heappop(sushi)
    total -= d
    if t not in types:
        types.add(t)
    else:
        # 余りの寿司はremainにappend
        heapq.heappush(remain, -d)

types_len = len(types)
ans = total + types_len ** 2

while sushi and remain:
    d, t = heapq.heappop(sushi)
    if t not in types:
        types.add(t)
        remain_d = heapq.heappop(remain)
        total = total - d - remain_d
        types_len += 1
        ans = max(ans, total + types_len ** 2)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq

N, K = map(int, input().split())
sushi = []
for i in range(N):
    t, d = map(int, input().split())
    heapq.heappush(sushi, (-d, t))

total = 0
types = []
remain = []
for i in range(K):
    d, t = heapq.heappop(sushi)
    total -= d
    if t not in types:
        types.append(t)
    else:
        # 余りの寿司はremainにappend
        heapq.heappush(remain, -d)

types_len = len(types)
ans = total + types_len ** 2

while sushi and remain:
    d, t = heapq.heappop(sushi)
    if t not in types:
        types.append(t)
        remain_d = heapq.heappop(remain)
        total = total - d - remain_d
        types_len += 1
        ans = max(ans, total + types_len ** 2)

print(ans)


Fixed submission:
import heapq

N, K = map(int, input().split())
sushi = []
for i in range(N):
    t, d = map(int, input().split())
    heapq.heappush(sushi, (-d, t))

total = 0
types = set()
remain = []
for i in range(K):
    d, t = heapq.heappop(sushi)
    total -= d
    if t not in types:
        types.add(t)
    else:
        # 余りの寿司はremainにappend
        heapq.heappush(remain, -d)

types_len = len(types)
ans = total + types_len ** 2

while sushi and remain:
    d, t = heapq.heappop(sushi)
    if t not in types:
        types.add(t)
        remain_d = heapq.heappop(remain)
        total = total - d - remain_d
        types_len += 1
        ans = max(ans, total + types_len ** 2)

print(ans)
Buggy python submission (verdict: Runtime Error):
S = int(input())

if S < 3:
    print(0)
    exit()

ans = [0 for _ in range(S+1)]

ans[3] = 1
ans[4] = 1
ans[5] = 1

for i in range(6, S+1):
    ans[i] = ans[i-3] + ans[i-1]

print(ans[S] % 1000000007)


Fixed submission:
S = int(input())

if S < 3:
    print(0)
    exit()

ans = [0 for _ in range(2001)]

ans[3] = 1
ans[4] = 1
ans[5] = 1

for i in range(6, S+1):
    ans[i] = ans[i-3] + ans[i-1]

print(ans[S] % 1000000007)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
ans = 0

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

print(ans)


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A2 = list(map(lambda x: x ** 2, A))

sumA = sum(A)
sumA2 = sum(A2)

ans = (((sumA ** 2) - sumA2) // 2) % 1000000007

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
ans = 0

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

print(ans % 1000000007)


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A2 = list(map(lambda x: x ** 2, A))

sumA = sum(A)
sumA2 = sum(A2)

ans = (((sumA ** 2) - sumA2) // 2) % 1000000007

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())
count = 1
rem = 7 % K

if K % 2 == 0:
    print(-1)
elif rem % K == 0:
    print(1)
else:
    while (rem % K) != 0:
        count += 1
        rem += (7 * 10 ** (count-1)) % K
    print(count)


Fixed submission:
K = int(input())
count = 1
rem = 7 % K

if K % 2 == 0:
    print(-1)
elif rem % K == 0:
    print(1)
else:
    while (rem % K) != 0 and count <= K:
        count += 1
        rem += 7 * pow(10, count-1, mod=K) % K
    if count <= K:
        print(count)
    else:
        print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())
count = 1
rem = 7 % K

if K % 2 == 0:
    print(-1)
elif rem % K == 0:
    print(1)
else:
    while (rem % K) != 0:
        count += 1
        rem += 7 * pow(10, count-1, mod=K) % K
    print(count)


Fixed submission:
K = int(input())
count = 1
rem = 7 % K

if K % 2 == 0:
    print(-1)
elif rem % K == 0:
    print(1)
else:
    while (rem % K) != 0 and count <= K:
        count += 1
        rem += 7 * pow(10, count-1, mod=K) % K
    if count <= K:
        print(count)
    else:
        print(-1)

Buggy python submission (verdict: Runtime Error):
K = int(input())
count = 1
rem = 7 % K

if K % 2 == 0:
    print(-1)
elif rem % K == 0:
    print(1)
else:
    while (rem % K) != 0:
        count += 1
        rem += 7 * pow(10, count-1, mod=K) % K
    print(count)


Fixed submission:
K = int(input())
count = 1
rem = 7 % K

if K % 2 == 0:
    print(-1)
elif rem % K == 0:
    print(1)
else:
    while (rem % K) != 0 and count <= K:
        count += 1
        rem += 7 * pow(10, count-1, mod=K) % K
    if count <= K:
        print(count)
    else:
        print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
Q = int(input())

dic = {}
for num in A:
    if num in dic:
        dic[num] += 1
    else:
        dic[num] = 1

for _ in range(Q):
    total = 0
    B, C = map(int, input().split())
    if B in dic and C in dic:
        dic[C] += dic[B]
        del dic[B]
    elif B in dic and C not in dic:
        dic[C] = dic[B]
        del dic[B]
    for mykey, myvalue in dic.items():
        total += mykey * myvalue
    print(total)


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
Q = int(input())

dic = {}
for num in A:
    if num in dic:
        dic[num] += 1
    else:
        dic[num] = 1

prev_sum = 0

for key, value in dic.items():
    prev_sum += key * value

for _ in range(Q):
    B, C = map(int, input().split())
    if B in dic and C in dic:
        dic[C] += dic[B]
        dif = (C - B) * dic[B]
        prev_sum += dif
        del dic[B]
    elif B in dic and C not in dic:
        dic[C] = dic[B]
        dif = (C - B) * dic[B]
        prev_sum += dif
        del dic[B]
    print(prev_sum)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
Q = int(input())

dic = {}
for num in A:
    if num in dic:
        dic[num] += 1
    else:
        dic[num] = 1

for _ in range(Q):
    total = 0
    B, C = map(int, input().split())
    if B in dic and C in dic:
        dic[C] += dic[B]
        del dic[B]
    elif B in dic and C not in dic:
        dic[C] = dic[B]
        del dic[B]
    for mykey, myvalue in dic.items():
        total += mykey * myvalue
    print(total)


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
Q = int(input())

dic = {}
for num in A:
    if num in dic:
        dic[num] += 1
    else:
        dic[num] = 1

prev_sum = 0

for key, value in dic.items():
    prev_sum += key * value

for _ in range(Q):
    B, C = map(int, input().split())
    if B in dic and C in dic:
        dic[C] += dic[B]
        dif = (C - B) * dic[B]
        prev_sum += dif
        del dic[B]
    elif B in dic and C not in dic:
        dic[C] = dic[B]
        dif = (C - B) * dic[B]
        prev_sum += dif
        del dic[B]
    print(prev_sum)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

numbers = []

num = A[1]
for i in range(2, N):
    num = num ^ A[i]
numbers.append(num)

for i in range(1, N):
    num = A[0]
    for j in range(1,N):
        if j == i:
            continue
        else:
            num = num ^ A[j]
    numbers.append(num)

print(*numbers)


Fixed submission:
N = int(input())
A = list(map(int, input().split()))

numbers = []

s = A[0]
for i in range(1, N):
    s = s ^ A[i]
for i in range(N):
    numbers.append(s ^ A[i])

print(*numbers)
Buggy python submission (verdict: Runtime Error):
X, N = map(int, input().split())

if N == 0:
    print(X)

else:
    p = list(map(int, input().split()))
    q = [i for i in range(-1, 102)]

    for r in p:
        idx = q.index(r)
        del q[idx]

    if X in q:
        print(X)

    else:
        q.sort()
        mindif = 100

        for num in q:
            dif = abs(X - num)
            if mindif <= dif:
                break
            else:
                mindif = dif
                ans = num
        print(ans)


Fixed submission:
X, N = map(int, input().split())

if N == 0:
    print(X)

else:
    p = list(map(int, input().split()))
    q = [i for i in range(-1, 102)]

    for r in p:
        idx = q.index(r)
        del q[idx]

    if X in q:
        print(X)

    else:
        q.sort()
        mindif = 1000

        for num in q:
            dif = abs(X - num)
            if mindif <= dif:
                break
            else:
                mindif = dif
                ans = num
        print(ans)

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

if N == 0:
    print(X)

else:
    p = list(map(int, input().split()))
    q = [i for i in range(0, 101)]

    for r in p:
        idx = q.index(r)
        del q[idx]

    if X in q:
        print(X)

    else:
        q.sort()
        mindif = 100

        for num in q:
            dif = abs(X - num)
            if mindif <= dif:
                break
            else:
                mindif = dif
                ans = num
        print(ans)


Fixed submission:
X, N = map(int, input().split())

if N == 0:
    print(X)

else:
    p = list(map(int, input().split()))
    q = [i for i in range(-1, 102)]

    for r in p:
        idx = q.index(r)
        del q[idx]

    if X in q:
        print(X)

    else:
        q.sort()
        mindif = 1000

        for num in q:
            dif = abs(X - num)
            if mindif <= dif:
                break
            else:
                mindif = dif
                ans = num
        print(ans)
Buggy python submission (verdict: Runtime Error):
import copy

N = int(input())
A = list(map(int, input().split()))

A.sort()


def div_by_min(a: list, start: int):
    dic = {k: 0 for k in a}
    for i in range(start+1, len(a)):
        if not dic:
            break
        if a[i] % a[start] == 0:
            del dic[a[i]]
    ans_list = list(dic.keys())
    return ans_list


Start = 0
prev_len = 1000000
tmp = A

while True:
    if Start >= len(tmp):
        break
    else:
        tmp = div_by_min(tmp, Start)
        if prev_len == len(tmp):
            Start += 1
        else:
            prev_len = len(tmp)
            Start = 0

print(len(tmp))


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A.sort()

max_A = A[-1] + 1
ans = [0] * max_A

for i in A:
    ans[i] += 1
    if ans[i] == 1:
        for j in range(i*2, max_A, i):
            ans[j] = 2

print(ans.count(1))