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

A_sum = [0]
for i in range(N):
    A_sum.append(A_sum[i] + A[i])
B_sum = [0]
for i in range(N):
    B_sum.append(B_sum[i] + B[i])
B_sum.append(10**10)

res = 0
for i in range(len(A_sum)):
    low = 0
    high = len(B_sum)
    while high - low > 1:
        mid = (low + high) // 2
        if A_sum[i] + B_sum[mid] <= K:
            low = mid
        else:
            high = mid
    if A_sum[i] + B_sum[low] <= K:
        res = max(res, i + low)

print(res)

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

A_sum = [0]
for i in range(N):
    A_sum.append(A_sum[i] + A[i])
B_sum = [0]
for i in range(M):
    B_sum.append(B_sum[i] + B[i])
B_sum.append(10**10)

res = 0
for i in range(len(A_sum)):
    low = 0
    high = len(B_sum)
    while high - low > 1:
        mid = (low + high) // 2
        if A_sum[i] + B_sum[mid] <= K:
            low = mid
        else:
            high = mid
    if A_sum[i] + B_sum[low] <= K:
        res = max(res, i + low)

print(res)


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

b_sum = 0
for i in range(M):
    b_sum += B[i]
    if b_sum > K:
        b_sum -= B[i]
        j = i - 1
        break
result = j + 1

a_sum = 0
for i in range(N):
    a_sum += A[i]
    if a_sum > K:
        break
    while a_sum + b_sum > K:
        b_sum -= B[j]
        j -= 1
    result = max(result, (i + 1) + (j + 1))
print(result)

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

b_sum = 0
for i in range(M):
    b_sum += B[i]
    if b_sum > K:
        b_sum -= B[i]
        j = i - 1
        break
else:
    j = M - 1
result = j + 1

a_sum = 0
for i in range(N):
    a_sum += A[i]
    if a_sum > K:
        break
    while a_sum + b_sum > K:
        b_sum -= B[j]
        j -= 1
    result = max(result, (i + 1) + (j + 1))
print(result)


import numpy as np
from numba import njit

n = int(input())

@njit
def f(n):
    cnt = np.zeros(n + 1, np.int32)
    for i in range(1, n + 1):
        cnt[i::i] += 1

    return (cnt * np.arange(n + 1)).sum()

ans = f(n)
print(ans)

import numpy as np
from numba import njit

n = int(input())

@njit
def f(n):
    cnt = np.zeros(n + 1, np.int16)
    for i in range(1, n + 1):
        cnt[i::i] += 1

    return (cnt * np.arange(n + 1)).sum()

ans = f(n)
print(ans)


from numba import njit
import numpy as np

@njit("i8(i8)")
def solve(n):
    ans = 1
    res = np.ones(n + 1, dtype=np.int64)
    for i in range(2, n + 1):
        res[i::i] += 1
        res[i] *= i
        ans += res[i]
    return ans

N = int(input())
print(solve(N))

from numba import njit
import numpy as np

@njit("i8(i8)")
def solve(n):
    ans = 1
    res = np.ones(n + 1, dtype=np.int64)
    for i in range(2, n + 1):
        for j in range(i, n + 1, i):
            res[j] += 1
        ans += i * res[i]
    return ans

N = int(input())
print(solve(N))


import sys
import math

def yakusu(K):
    Y = set()
    for i in range(1, int(math.sqrt(K)) + 1):
        if K % i == 0:
            Y.add(i)
            Y.add(K // i)
    return len(Y)

def main():
    N = int(sys.stdin.readline().rstrip())

    sum_ = 0
    for k in range(1, N + 1):
        sum_ += k * yakusu(k)

    print(sum_)

main()

import sys
import math

def main():
    N = int(sys.stdin.readline().rstrip())

    sum_ = 0

    for i in range(1, int(math.sqrt(N)) + 1):

        sum_ += i**2

        k1 = N // i
        # k2 = i

        k1_sum = k1 * (k1 + 1) // 2
        k2_sum = i * (i + 1) // 2
        sum_ += 2 * i * (k1_sum - k2_sum)

    print(sum_)

main()


N = int(input())

dp = [0] * (N + 1)
for i in range(1, N + 1):
    cursor = i
    while cursor <= N:
        dp[cursor] += 1
        cursor += i

ans = 0
for i in range(1, N + 1):
    ans += i * dp[i]

print(ans)

N = int(input())

ans = 0
for i in range(1, N + 1):
    start = i
    n = N // i
    end = i * n
    ans += n * (start + end) // 2

print(ans)


import sys
from io import StringIO
import unittest
import os

# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)

# 実装を行う関数
def resolve(test_def_name=""):
    n = int(input())

    ans = 0

    for j in range(1, n + 1):
        for i in range(1, n + 1):
            if i % j == 0:
                ans += i

    print(ans)

# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """4"""
        output = """23"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """100"""
        output = """26879"""
        self.assertIO(test_input, output)

    # def test_input_3(self):
    #     test_input = """10000000"""
    #     output = """838627288460105"""
    #     self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)

# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()

import sys
from io import StringIO
import unittest
import os

sys.setrecursionlimit(999999999)

def get_arithmetic_progression(a, d, n):
    return n * (2 * a + (n - 1) * d) // 2

# 実装を行う関数
def resolve(test_def_name=""):
    n = int(input())

    ans = 0
    for i in range(1, n + 1):
        ans += get_arithmetic_progression(i, i, n // i)

    print(ans)

# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """4"""
        output = """23"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """100"""
        output = """26879"""
        self.assertIO(test_input, output)

    # def test_input_3(self):
    #     test_input = """10000000"""
    #     output = """838627288460105"""
    #     self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)

# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()


n = int(input())

ans = 0

for i in range(1, n + 1):
    for j in range(i, n + 1, i):
        ans += j

print(ans)

n = int(input())

ans = n * (n + 1) // 2

for i in range(2, n + 1):
    for j in range(i, n + 1, i):
        ans += j

print(ans)


n = int(input())
ans = 0
for i in range(1, n + 1):
    for j in range(i, n + 1, i):
        ans += j
print(ans)


n = int(input())
out = 0
for i in range(n):
    j = 1
    while (i + 1) * j <= n:
        out += (i + 1) * j
        j += 1

print(out)

n = int(input())
out = 0
for i in range(n):
    k = n // (i + 1)
    out += (i + 1) * k * (k + 1) / 2

print(int(out))


# D - Sum of Divisors
from numba import njit

@njit
def main():
    N = int(input())
    res = 0
    for a in range(1, N + 1):
        for b in range(1, N // a + 1):
            res += a * b
    print(res)

if __name__ == "__main__":
    main()

# D - Sum of Divisors
from numba import njit

@njit
def solve(N):
    res = 0
    for a in range(1, N + 1):
        for b in range(1, N // a + 1):
            res += a * b
    return res

def main():
    N = int(input())
    print(solve(N))

if __name__ == "__main__":
    main()

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02624/Python/s317956629.py", line 2, in <module>
    from numba import njit
ModuleNotFoundError: No module named 'numba'


N = int(input())
num = [1 for _ in range(N + 1)]
for i in range(2, N + 1):
    cnt = 1
    while cnt * i <= N:
        num[cnt * i] += 1
        cnt += 1
ans = 0
for i in range(1, N + 1):
    ans += num[i] * i
print(ans)

N = int(input())
ans = 0
for i in range(1, N + 1):
    largest = N // i * i
    ans += ((largest + i) * (N // i)) // 2
print(ans)


#!/usr/bin/env python3
import numpy as np

def solve(N):
    fx = np.zeros(N + 1, dtype=np.uint32)
    for i in range(1, N + 1):
        fx[i::i] += 1
    return np.sum(np.arange(0, N + 1, dtype=np.uint64) * fx)

def main():
    N = int(input())  # type: int
    answer = solve(N)
    print(answer)

if __name__ == "__main__":
    main()


import sys

def solve(n, aaa):
    if n == 2:
        h, m = divmod(sum(aaa), 2)
        if m == 1 or h > aaa[0]:
            return -1
        return aaa[0] - h

    x = 0
    for a in aaa[2:]:
        x ^= a
    a0, a1 = aaa[:2]
    s = a0 + a1

    if s & 1 != x & 1:
        return -1

    p, q = 0, 0

    b = 1 << 40
    while b:
        bx = x & b
        if bx == 0:
            # print('bx', s)
            # print(f'{b:040b}')
            # print(f'{p:040b}')
            # print(f'{q:040b}')
            # print(f'{a0:040b}')
            # print(f'{a1:040b}')
            # print()
            if s >= 2 * b:
                if p + b <= a0:
                    p |= b
                    q |= b
                    s -= 2 * b
                # else:
                #     return -1
        else:
            if s < b:
                return -1
            if p + b <= a0 and q + b > a1:
                p |= b
            else:
                q |= b
            s -= b

        # print(f'{b:040b}')
        # print(f'{p:040b}')
        # print(f'{q:040b}')
        # print(f'{a0:040b}')
        # print(f'{a1:040b}')
        # print()

        b >>= 1

    if p == 0:
        return -1
    assert s == 0
    assert p ^ q == x
    assert a0 - p == q - a1
    return a0 - p

n, *aaa = map(int, sys.stdin.buffer.read().split())
print(solve(n, aaa))

import sys

def solve(n, aaa):
    if n == 2:
        h, m = divmod(sum(aaa), 2)
        if m == 1 or h > aaa[0]:
            return -1
        return aaa[0] - h

    x = 0
    for a in aaa[2:]:
        x ^= a
    a0, a1 = aaa[:2]
    s = a0 + a1

    if s & 1 != x & 1:
        return -1

    p, q = 0, 0

    b = 1 << 40
    swappable = []
    while b:
        bx = x & b
        if bx == 0:
            # print('bx=0', s)
            # print(f'{b:040b}')
            # print(f'{p:040b}')
            # print(f'{q:040b}')
            # print(f'{a0:040b}')
            # print(f'{a1:040b}')
            # print()
            if s >= 2 * b:
                if p | b <= a0:
                    p |= b
                    q |= b
                    s -= 2 * b
                elif swappable:
                    bs = swappable.pop()
                    p ^= bs
                    q ^= bs
                    p |= b
                    q |= b
                    s -= 2 * b
                else:
                    return -1
        else:
            if s < b:
                return -1
            if p | b <= a0 and q | b > a1:
                p |= b
                swappable.append(b)
            else:
                q |= b
            s -= b

            # print('bx=1', s)
            # print(f'{b:040b}')
            # print(f'{p:040b}')
            # print(f'{q:040b}')
            # print(f'{a0:040b}')
            # print(f'{a1:040b}')
            # print()

        b >>= 1

    if p == 0:
        return -1
    assert s == 0
    assert p ^ q == x
    assert a0 - p == q - a1
    return a0 - p

n, *aaa = map(int, sys.stdin.buffer.read().split())
print(solve(n, aaa))


s = input()
if s.isuper():
    print("A")
else:
    print("a")

s = input()
if s.isupper():
    print("A")
else:
    print("a")

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02627/Python/s327847448.py", line 2, in <module>
    if s.isuper():
AttributeError: 'str' object has no attribute 'isuper'. Did you mean: 'isupper'?


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

sp = sorted(p)
print(sum(sp[:K]))

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

sp = sorted(p)
print(sum(sp[:K]))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02628/Python/s927789922.py", line 5, in <module>
    print(sum(sp[:K]))
TypeError: unsupported operand type(s) for +: 'int' and 'list'


import itertools

N, K = map(int, input().split())
P = list(map(int, input().split()))

# tmp = itertools.combinations_with_replacement(P, K)
tmp = itertools.combinations(P, K)

hoge = []
for i in tmp:
    hoge.append(sum(i))

print(min(hoge))

# import itertools

N, K = map(int, input().split())
P = list(map(int, input().split()))

# tmp = itertools.combinations_with_replacement(P, K)
# tmp = itertools.combinations(P, K)

P.sort()
print(sum(P[0:K]))

# hoge = []
# for i in tmp:
#     hoge.append(sum(i))

# print(min(hoge))


N, K = map(int, input().split())
P = list(map(int, input().split()))

ans = float("inf")
for i in range(1 << len(P)):
    sum = 0
    cnt = 0
    for j in range(len(P)):
        if (i >> j) & 1 == 1:
            sum += P[j]
            cnt += 1
            if cnt == K:
                ans = min(ans, sum)
print(ans)

N, K = map(int, input().split())
P = list(map(int, input().split()))

P = sorted(P)

print(sum(P[:K]))


import itertools

N, K = map(int, input().split())
p = list(map(int, input().split()))
ans = 10e6

for i in itertools.combinations(p, K):
    tmp = sum(list(i))
    if tmp < ans:
        ans = tmp

print(ans)

N, K = map(int, input().split())
p = list(map(int, input().split()))

ans = sum(sorted(p)[:K])
print(ans)


N, K = map(int, input().split())
P = list(map(int, input().split())).sort()
print(sum(P[:K]))

N, K = map(int, input().split())
P = sorted(list(map(int, input().split())))
print(sum(P[:K]))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02628/Python/s595641778.py", line 3, in <module>
    print(sum(P[:K]))
TypeError: 'NoneType' object is not subscriptable


import itertools

N, K = map(int, input().split())
p = list(map(int, input().split()))

ans = sum(p)
for v in itertools.permutations(p, K):
    ans = min(ans, sum(v))

print(ans)

import itertools

N, K = map(int, input().split())
p = list(map(int, input().split()))

ans = 0
for _ in range(K):
    min_index = p.index(min(p))
    minv = p.pop(min_index)
    ans += minv

print(ans)


# -*- coding: utf-8 -*-
from numba import njit, void, i8

def get_input() -> int:
    """
    標準入力を取得する.

    Returns:\\n
        int: 標準入力
    """
    N = int(input())

    return N

@njit(void(i8))
def main(N: int) -> None:
    """
    求解処理.

    Args:\\n
        N (int): 整数
    """
    # 求解処理
    ans = ""
    while N > 0:
        N -= 1
        ans += chr(ord("a") + N % 26)
        N //= 26
    ans = ans[::-1]

    # 結果出力
    print(ans)

if __name__ == "__main__":
    N = get_input()
    main(N)

# -*- coding: utf-8 -*-

def get_input() -> int:
    """
    標準入力を取得する.

    Returns:\\n
        int: 標準入力
    """
    N = int(input())

    return N

def main(N: int) -> None:
    """
    求解処理.

    Args:\\n
        N (int): 整数
    """
    # 求解処理
    ans = ""
    while N > 0:
        N -= 1
        ans += chr(ord("a") + N % 26)
        N //= 26
    ans = ans[::-1]

    # 結果出力
    print(ans)

if __name__ == "__main__":
    N = get_input()
    main(N)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02629/Python/s063087830.py", line 2, in <module>
    from numba import njit, void, i8
ModuleNotFoundError: No module named 'numba'


alphabet = "abcdefghijklmnopqrstrvwxyz"

n = int(input()) - 1

A = []
while n > 0:
    A.append(n % 26)
    n //= 26

m = len(A)

if m == 1:
    print(alphabet[A[0]])
    exit()

ANS = []
ANS.append(alphabet[A[0]])
for i in range(1, m - 1):
    if A[i] == 0:
        ANS.append("z")
        A[i + 1] -= 1
    else:
        ANS.append(alphabet[A[i] - 1])
if A[-1]:
    ANS.append(alphabet[A[-1] - 1])

print("".join(ANS[::-1]))

alphabets = "abcdefghijklmnopqrstuvwxyz"

n = int(input())

A = []
while True:
    A.append(n % 26)
    n //= 26
    if n == 0:
        break

for i in range(len(A) - 1):
    if A[i] <= 0:
        A[i] += 26
        A[i + 1] -= 1

ANS = []
for a in A[::-1]:
    if a == 0:
        continue
    ANS.append(alphabets[a - 1])

print("".join(ANS))


N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [list(map(int, input().split())) for i in range(Q)]
# print(N)
# print(A)
# print(Q)
# print(B)

total = sum(A)

for i in range(Q):
    Bi = BC[i][0]
    Ci = BC[i][1]

    diff = 0
    for j in range(len(A)):
        if A[j] == Bi:
            diff += Ci - A[j]
            A[j] = Ci

    total += diff
    print(total)

import itertools

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [list(map(int, input().split())) for i in range(Q)]
# print(N)
# print(A)
# print(Q)
# print(B)

distribution = {}
max_A = max(A)
max_BC = max(list(itertools.chain.from_iterable(BC)))
maximum = max([max_A, max_BC])
# print(max_A, max_BC, maximum)
for i in range(maximum + 1):
    distribution[i] = 0

for Ai in A:
    distribution[Ai] += 1
# print(distribution)

total = sum(A)
for i in range(Q):
    Bi = BC[i][0]
    Ci = BC[i][1]
    num_Bi = distribution.get(Bi)
    diff = (Ci - Bi) * num_Bi

    distribution[Bi] = 0
    # print(num_Bi, distribution.get(Bi), Ci)
    distribution[Ci] += num_Bi

    total += diff
    print(total)


n = int(input())
a = list(map(int, input().split()))
q = int(input())
B = [list(map(int, input().split())) for _ in range(q)]

# print(n,a,q,B)

# from collections import Counter

# _a = Counter()

for (b, c) in B:
    a = [c if x == b else x for x in a]
    print(sum(a))

n = int(input())
a = list(map(int, input().split()))
q = int(input())
B = [list(map(int, input().split())) for _ in range(q)]

from collections import Counter

ans = sum(a.copy())
a = Counter(a)

for (b, c) in B:
    ans += a[b] * (c - b)
    print(ans)
    a[c] += a[b]
    a[b] = 0


N = int(input())
A = [int(s) for s in input().split()]
Q = int(input())
B = []
C = []
for _ in range(Q):
    b, c = [int(s) for s in input().split()]
    B.append(b)
    C.append(c)

A_dict = {}
for a in A:
    A_dict[a] = A.count(a)

A_sum = sum(A)
for b, c in zip(B, C):
    if b in A_dict.keys():
        n = A_dict[b]
    else:
        n = 0
    A_dict[b] = 0
    if c in A_dict.keys():
        A_dict[c] += n
    else:
        A_dict[c] = n
    A_sum += (c - b) * n
    print(A_sum)

from collections import defaultdict

N = int(input())
A = [int(s) for s in input().split()]
Q = int(input())
B = []
C = []
for _ in range(Q):
    b, c = [int(s) for s in input().split()]
    B.append(b)
    C.append(c)

A_dict = defaultdict(int)
for a in A:
    A_dict[a] += 1

A_sum = sum(A)
for b, c in zip(B, C):
    n = A_dict[b]
    A_dict[b] = 0
    A_dict[c] += n
    A_sum += (c - b) * n
    print(A_sum)


N = int(input())
arr = list(map(int, input().split()))
Q = int(input())
que = [list(map(int, input().split())) for _ in range(Q)]

for i in que:
    for j in range(N):
        if arr[j] == i[0]:
            arr[j] = i[1]
    print(sum(arr))

N = int(input())
arr = list(map(int, input().split()))
Q = int(input())
que = [list(map(int, input().split())) for _ in range(Q)]

count_list = [0] * (10**5 + 1)

for i in range(N):
    count_list[arr[i]] += 1

ans = sum(arr)

for i in que:
    keep = count_list[i[0]]
    c_ans = ans + keep * (i[1] - i[0])
    print(c_ans)
    ans = c_ans
    if count_list[i[0]] == 0:
        continue
    if count_list[i[0]] != 0:
        count_list[i[1]] += count_list[i[0]]
        count_list[i[0]] = 0


n = int(input())
a = list(map(int, input().split()))
q = int(input())
xy = [map(int, input().split()) for _ in range(q)]
b, c = [list(i) for i in zip(*xy)]

stuck_b = []
stuck_c = []
stuck_sum = []

sum = 0

for cnt_q in range(q):
    sum = 0
    if len(stuck_b) > 0:
        if stuck_b[cnt_q] == b[cnt_q] and stuck_c[cnt_q] == c[cnt_q]:
            print(stuck_sum[cnt_q])
        else:
            for cnt_n in range(n):
                if a[cnt_n] == b[cnt_q]:
                    a[cnt_n] = c[cnt_q]
            for num in range(n):
                sum += a[num]
            print(sum)
    else:
        for cnt_n in range(n):
            if a[cnt_n] == b[cnt_q]:
                a[cnt_n] = c[cnt_q]
        for num in range(n):
            sum += a[num]
        print(sum)

n = int(input())
a = list(map(int, input().split()))
q = int(input())
xy = [map(int, input().split()) for _ in range(q)]
b, c = [list(i) for i in zip(*xy)]

ans = 0

sum_all = 0
for cnt in range(n):
    sum_all += a[cnt]

a = sorted(a)
list_a_num = [0] * (10**5 + 1)
for cnt in range(n):
    list_a_num[a[cnt]] += 1

for cnt in range(q):
    sum_all += (c[cnt] - b[cnt]) * list_a_num[b[cnt]]
    list_a_num[c[cnt]] += list_a_num[b[cnt]]
    list_a_num[b[cnt]] = 0
    print(sum_all)


N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = [list(map(int, input().split())) for _ in range(Q)]

for nums in B:
    A = [nums[1] if i == nums[0] else i for i in A]
    print(sum(A))

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
sum_res = sum(A)
counter = [0 for _ in range(10**5 + 1)]

for a in A:
    counter[a] += 1

for _ in range(Q):
    B, C = map(int, input().split())
    sum_res = sum_res - (counter[B] * B)
    sum_res = sum_res + (counter[B] * C)
    counter[C] += counter[B]
    counter[B] = 0
    print(sum_res)


from collections import Counter

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for _ in range(Q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

counter = Counter(A)
ans = 0
for num, count in counter.items():
    ans += num * count

for i in range(Q):
    if B[i] in counter:
        ans += counter[B[i]] * C[i] - counter[B[i]] * B[i]
        counter[C[i]] = counter[C[i]] + counter.pop([B[i]])
    print(ans)

from collections import Counter

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for _ in range(Q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

counter = Counter(A)
ans = 0
for num, count in counter.items():
    ans += num * count

for i in range(Q):
    if B[i] in counter:
        ans += counter[B[i]] * C[i] - counter[B[i]] * B[i]
        counter[C[i]] = counter[C[i]] + counter.pop(B[i])
    print(ans)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02630/Python/s734232725.py", line 21, in <module>
    counter[C[i]] = counter[C[i]] + counter.pop([B[i]])
TypeError: unhashable type: 'list'


n = int(input())
ls = input()
q = int(input())
for _ in range(q):
    b, q = map(str, input().split())
    ls = ls.replace(b, q)
    print(sum(map(int, ls.split())))

from collections import Counter

n = int(input())
ls = list(map(int, input().split()))
q = int(input())
count = Counter(ls)
sm = sum(ls)

for _ in range(q):
    b, q = map(int, input().split())
    if b in count:
        sm -= count[b] * b
        sm += count[b] * q
        print(sm)
    else:
        print(sm)
    if q in count:
        count[q] += count[b]

        count[b] = 0
    else:
        count[q] = count[b]

        count[b] = 0


n = int(input())
a = list(map(int, input().split()))
q = int(input())
b_c = [list(map(int, input().split())) for i in range(q)]

ans = 0

for i in range(q):
    before = b_c[i][0]
    after = b_c[i][1]
    while before in a:
        a[a.index(before)] = after
    ans = sum(a)
    print(ans)

import collections

n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = [list(map(int, input().split())) for i in range(q)]

ans = sum(a)
num = collections.Counter(a)

for i in range(q):
    before = bc[i][0]
    after = bc[i][1]
    ans += num[before] * (after - before)
    num[after] += num[before]
    num[before] = 0
    # print(a.count(before))
    # print(num(before))
    print(ans)


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

dictA = {}

for z in A:
    dictA.setdefault(z, 0)
    dictA[z] += 1

BC = [list(map(int, input().split())) for i in range(Q)]
for x in BC:
    if x[0] in dictA.keys():
        dictA.setdefault(x[1], 0)
        dictA[x[1]] += dictA[x[0]]
        dictA.pop(x[0])
        # print(dictA)

    sumA = 0
    for k, v in dictA.items():
        sumA += k * v
    print(sumA)

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

dictA = {}

for z in A:
    dictA.setdefault(z, 0)
    dictA[z] += 1

sumA = sum(A)

BC = [list(map(int, input().split())) for i in range(Q)]
for x in BC:
    if x[0] in dictA.keys():
        sumA += (x[1] - x[0]) * dictA[x[0]]
        dictA.setdefault(x[1], 0)
        dictA[x[1]] += dictA[x[0]]
        dictA.pop(x[0])
    print(sumA)


n = int(input())
a = list(input().split())
q = int(input())
for i in range(q):
    b, c = input().split()
    replace_a = [i.replace(b, c) if i == b else i for i in a]
    print(sum(map(int, replace_a)))
    a = replace_a

from collections import Counter

n = int(input())
a = list(map(int, input().split()))
sum_a = sum(a)
count_a = Counter(a)
q = int(input())
for i in range(q):
    b, c = map(int, input().split())
    tmp = count_a[b]
    new = {c: tmp}
    count_a.update(new)
    del count_a[b]
    sum_a = sum_a - b * tmp + c * tmp
    print(sum_a)


from collections import defaultdict

N = int(input())
_A = [*map(int, input().split())]
Q = int(input())
val = [[*map(int, line.split())] for line in open(0)]

A = defaultdict(int)
for _a in _A:
    A[_a] += 1

ans = sum(_A)
for v in val:
    if v[0] in A.keys():
        num = A[v[0]]
        A[v[0]] = 0
        A[v[1]] += num
        ans += (v[1] - v[0]) * num
    print(ans)

from collections import defaultdict

N, _A, Q, *val = [[*map(int, line.split())] for line in open(0)]
N = N[0]
Q = Q[0]

A = defaultdict(int)
for _a in _A:
    A[_a] += 1

ans = sum(_A)
for v in val:
    if v[0] in A.keys():
        num = A[v[0]]
        A[v[0]] = 0
        A[v[1]] += num
        ans += (v[1] - v[0]) * num
    print(ans)


import collections

N = int(input())
A = list(map(int, input().split()))  # (N,)
Q = int(input())
B, C = zip(*[list(map(int, input().split())) for _ in range(Q)])  # (Q,), (Q,)

value_count_map = collections.defaultdict(int)
value_sum_map = collections.defaultdict(int)
for a in A:
    value_count_map[a] += 1
    value_sum_map[a] += a

for b, c in zip(B, C):
    b_cnt = value_count_map[b]
    value_count_map[c] += b_cnt
    value_sum_map[c] += c * b_cnt
    if b in value_count_map:
        del value_count_map[b]
        del value_sum_map[b]
    print(sum(v for v in value_sum_map.values()))

import collections

N = int(input())
A = list(map(int, input().split()))  # (N,)
Q = int(input())
B, C = zip(*[list(map(int, input().split())) for _ in range(Q)])  # (Q,), (Q,)

cur_sum = 0
value_count_map = collections.defaultdict(int)
for a in A:
    cur_sum += a
    value_count_map[a] += 1

for b, c in zip(B, C):
    b_cnt = value_count_map.get(b, 0)
    value_count_map[b] = 0
    value_count_map[c] += b_cnt
    cur_sum += b_cnt * (c - b)
    print(cur_sum)


N = int(input())
A = list(map(str, input().split()))
Q = int(input())
L = [list(map(str, input().split())) for i in range(Q)]

for j in range(Q):
    A = [k.replace(L[j][0], L[j][1]) for k in A]
    B = sum(map(int, A))
    print(B)

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

a = [0] * (10**5 + 1)
ans = sum(A)

for i in range(N):
    a[A[i]] += 1

for i in range(Q):
    B, C = map(int, input().split())
    ans += a[B] * (C - B)
    a[C] += a[B]
    a[B] = 0
    print(ans)


N = int(input())
A = list(map(int, input().split()))
Q = int(input())
for i in range(Q):
    B, C = map(int, input().split())
    for i in range(N):
        if A[i] == B:
            A[i] = C
    print(sum(A))

from collections import Counter

n = int(input())
a = list(map(int, input().split()))
q = int(input())

cnt = Counter(a)

s = sum(a)

for i in range(q):
    b, c = map(int, input().split())
    s = s - b * cnt[b]
    s = s + c * cnt[b]
    cnt[c] += cnt[b]
    cnt[b] = 0
    print(s)


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)

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)


import sys
import numpy as np

# 実行環境(0:vscode, 1:atcoder)
MODE = 1

# 入力の次元
DIMENSION = 2

# int型に変換
INT_TYPE = 1

if not (MODE):
    with open("input.txt", "r") as f:
        s = f.read()
else:
    s = sys.stdin.read()

if DIMENSION == 0:
    if INT_TYPE == 1:
        s = int(s)
elif DIMENSION == 1:
    if INT_TYPE == 0:
        s = s.split()
    elif INT_TYPE == 1:
        s = [int(x) for x in s.split()]
elif DIMENSION == 2:
    if INT_TYPE == 0:
        s = [x.split() for x in s.splitlines()]
    elif INT_TYPE == 1:
        s = [[int(y) for y in x.split()] for x in s.splitlines()]

N = s[0][0]
A = np.array(s[1])
Q = s[2][0]
BC = np.array(s[3:])
B = BC[:, 0]
C = BC[:, 1]

A_sum = np.sum(A)

D = np.array([np.count_nonzero(A == i) for i in range(100001)])
for i in range(Q):
    b = B[i]
    c = C[i]
    A_sum += D[b] * (c - b)
    print(A_sum)
    D[c] += D[b]
    D[b] = 0

import sys
import numpy as np
from collections import Counter

# 実行環境(0:vscode, 1:atcoder)
MODE = 1

# 入力の次元
DIMENSION = 2

# int型に変換
INT_TYPE = 1

if not (MODE):
    with open("input.txt", "r") as f:
        s = f.read()
else:
    s = sys.stdin.read()

if DIMENSION == 0:
    if INT_TYPE == 1:
        s = int(s)
elif DIMENSION == 1:
    if INT_TYPE == 0:
        s = s.split()
    elif INT_TYPE == 1:
        s = [int(x) for x in s.split()]
elif DIMENSION == 2:
    if INT_TYPE == 0:
        s = [x.split() for x in s.splitlines()]
    elif INT_TYPE == 1:
        s = [[int(y) for y in x.split()] for x in s.splitlines()]

N = s[0][0]
A = np.array(s[1])
Q = s[2][0]
BC = np.array(s[3:])
B = BC[:, 0]
C = BC[:, 1]

A_sum = np.sum(A)

D = Counter(A)

for i in range(Q):
    b = B[i]
    c = C[i]
    A_sum += D[b] * (c - b)
    print(A_sum)
    D[c] += D[b]
    D[b] = 0


import bisect

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = [0] * Q
C = [0] * Q
for i in range(Q):
    B[i], C[i] = map(int, input().split())

A.sort()
Sum = sum(A)

for i in range(Q):
    L = bisect.bisect_left(A, B[i])
    R = bisect.bisect_right(A, B[i])
    num = R - L
    Sum += num * (C[i] - B[i])

    for j in range(L, R):
        A[j] = C[i]

    A.sort()
    print(Sum)

import bisect

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = [0] * Q
C = [0] * Q
for i in range(Q):
    B[i], C[i] = map(int, input().split())

DP = [0] * (10**5 + 1)

for i in range(len(A)):
    DP[A[i]] += 1

Sum = sum(A)

for i in range(Q):
    Sum += (C[i] - B[i]) * DP[B[i]]
    DP[C[i]] += DP[B[i]]
    DP[B[i]] = 0
    print(Sum)


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

B = []
C = []
for _ in range(Q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

d = [0] * 10
for a in A:
    d[a] += 1
sum_a = sum(A)
for j in range(Q):
    d[C[j]] += d[B[j]]
    sum_a -= d[B[j]] * B[j]

    sum_a += (d[C[j]] - d[B[j]]) * C[j]
    d[B[j]] = 0
    print(sum_a)

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

B = []
C = []
for _ in range(Q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

d = [0] * (10**5 + 7)
for a in A:
    d[a] += 1
sum_a = sum(A)
for j in range(Q):
    before = d[C[j]]
    d[C[j]] += d[B[j]]
    sum_a -= d[B[j]] * B[j]

    sum_a += (d[C[j]] - before) * C[j]
    d[B[j]] = 0
    print(sum_a)


import sys
import numpy as np

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
Q = int(sys.stdin.readline())
replace_map = [list(map(int, sys.stdin.readline().split())) for _ in range(Q)]

nums = {}
for a in A:
    nums[a] = nums[a] + 1 if a in nums else 1

for search, replace in replace_map:
    if search in nums:
        nums[replace] = nums[replace] + nums[search] if replace in nums else nums[search]
        del nums[search]
    print(np.dot(list(nums.keys()), list(nums.values())))

import sys
import numpy as np

_ = sys.stdin.readline()
A = list(map(int, sys.stdin.readline().split()))
Q = int(sys.stdin.readline())
replace_map = [list(map(int, sys.stdin.readline().split())) for _ in range(Q)]

nums = {}
for a in A:
    nums[a] = nums[a] + 1 if a in nums else 1

previous_sum = 0
for search, replace in replace_map:
    replaced_count = 0
    if search in nums:
        replaced_count = nums[search]
        nums[replace] = (
            nums[replace] + replaced_count if replace in nums else replaced_count
        )
        del nums[search]
    if previous_sum == 0:
        previous_sum = np.dot(list(nums.keys()), list(nums.values()))
    else:
        previous_sum += replaced_count * (replace - search)
    print(previous_sum)


from collections import Counter

n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = [list(map(int, input().split())) for _ in range(q)]

x = Counter(a)
for b, c in bc:
    x[c] += x[b]
    x[b] = 0

    ans = 0
    for key, value in x.most_common():
        ans += key * value
    print(ans)

from collections import Counter

n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = [list(map(int, input().split())) for _ in range(q)]

x = Counter(a)
ans = sum(a)
for b, c in bc:
    ans += (c - b) * x[b]
    print(ans)
    x[c] += x[b]
    x[b] = 0


from collections import Counter

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

Q = int(input())
BC = [list(map(int, input().split())) for _ in range(Q)]

d = Counter(A)

for b, c in BC:
    d[c] += d[b]
    d[b] = 0

    li = [k * v for k, v in d.items()]
    print(sum(li))

from collections import Counter

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

Q = int(input())
BC = [list(map(int, input().split())) for _ in range(Q)]

d = Counter(A)

sub_s = sum(A)

for b, c in BC:
    sub_s += d[b] * (c - b)
    d[c] += d[b]
    d[b] = 0

    print(sub_s)


from collections import Counter
import copy

N = int(input())

target_list = list(map(int, input().split()))
check = [Counter(target_list)]
result_list = [sum(target_list)]

for index in range(int(input())):
    B, C = map(int, input().split())
    if B in check[index]:
        result = copy.deepcopy(check[index])
        change = result.pop(B)
        diff = change * (C - B)
        if C in result:
            result[C] = result[C] + change
        else:
            result[C] = change

    else:
        result = copy.deepcopy(check[index])
        diff = 0
    check.append(result)
    print(result_list[index] + diff)
    result_list.append(result_list[index] + diff)

from collections import Counter

N = int(input())

target_list = list(map(int, input().split()))
check = Counter(target_list)
result = sum(target_list)

for index in range(int(input())):
    B, C = map(int, input().split())
    if B in check:
        result = result + (check[B]) * (C - B)
        if C in check:
            check[C] = check[C] + check[B]
        else:
            check[C] = check[B]
        check[B] = 0
    print(result)


N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [map(int, input().split()) for _ in range(Q)]
B, C = [list(i) for i in zip(*BC)]

for i in range(Q):
    A_replace = [C[i] if a == B[i] else a for a in A]
    A = A_replace
    print(sum(A))

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [map(int, input().split()) for _ in range(Q)]
B, C = [list(i) for i in zip(*BC)]

sum = 0
size = 10**5 + 1
list = [0] * size
for a in A:
    list[a] += 1
    sum += a

for i in range(Q):
    sum = sum + C[i] * list[B[i]] - B[i] * list[B[i]]
    list[C[i]] += list[B[i]]
    list[B[i]] = 0
    print(sum)


# import sys
# readline = sys.stdin.readline
# generator = (readline().strip() for _ in range(N))

# N, M = map(int, input().split())
# As = list(map(int, input().split()))
# queries = (input() for _ in range(N))

def solve():
    N = int(input())
    As = list(map(int, input().split()))

    digits = dict()
    for d in range(30):
        digits[d] = 0
        for a in As:
            digits[d] += a >> d & 1

    oore = dict()
    for k, v in digits.items():
        oore[k] = v % 2

    nums = [0] * N

    for i, a in enumerate(As):
        for d in range(30):
            nums[i] += ((a >> d & 1) ^ (oore[d])) << d

    return nums

def main():
    print(*solve())

if __name__ == "__main__":
    main()

# import sys
# readline = sys.stdin.readline
# generator = (readline().strip() for _ in range(N))

# N, M = map(int, input().split())
# As = list(map(int, input().split()))
# queries = (input() for _ in range(N))

def solve():
    N = int(input())
    As = list(map(int, input().split()))

    digits = dict()
    for d in range(30):
        digits[d] = 0
        for a in As:
            digits[d] += a >> d & 1

    oore = 0
    for k, v in digits.items():
        oore += (v % 2) << k

    nums = [0] * N

    for i, a in enumerate(As):
        nums[i] = a ^ oore

    return nums

def main():
    print(*solve())

if __name__ == "__main__":
    main()


n = int(input())
a = [int(i) for i in input().split()]

ans = []
for i in range(n):
    temp = 0
    for j, aa in enumerate(a):
        if j == i:
            continue
        temp = temp ^ aa
    ans.append(temp)

ans = [str(i) for i in ans]
print(" ".join(ans))

n = int(input())
a = [int(i) for i in input().split()]

ans = []
alld = 0

for aa in a:
    alld = alld ^ aa

for aa in a:
    ans.append(alld ^ aa)

ans = [str(i) for i in ans]
print(" ".join(ans))


# -*- coding: utf-8 -*-

# 入力を整数に変換して受け取る
def input_int():
    return int(input())

# マイナス1した値を返却
def int1(x):
    return int(x) - 1

# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())

# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))

# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))

def main():
    n = int(input())
    a_list = input_to_int_tuple()

    ret = ""
    for i in range(n):
        my = 0
        for j, v in enumerate(a_list):
            if i == j:
                continue

            my ^= v

        ret += str(my) + " "

    print(ret.rstrip())

if __name__ == "__main__":
    main()

# -*- coding: utf-8 -*-

# 入力を整数に変換して受け取る
def input_int():
    return int(input())

# マイナス1した値を返却
def int1(x):
    return int(x) - 1

# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())

# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))

# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))

def main():
    n = int(input())
    a_list = input_to_int_tuple()

    all = 0
    for v in a_list:
        all ^= v

    ret = ""
    for v in a_list:
        ret += str(all ^ v) + " "

    print(ret.rstrip())

if __name__ == "__main__":
    main()


import numpy as np

N = int(input())
a = np.fromstring(input(), sep=" ", dtype=np.int64)
# b = np.bitwise_xor.reduce(a)
# c = np.bitwise_xor(a, b)
# print(*c, sep=" ")
for n in range(N):
    print(np.bitwise_xor.reduce(a) ^ a[n])

import numpy as np

N = int(input())
a = np.fromstring(input(), sep=" ", dtype=np.int64)
b = np.bitwise_xor.reduce(a)
c = np.bitwise_xor(a, b)
print(*c, sep=" ")


import numpy as np
from numba import njit

def comb(n, r, p):
    r = min(r, n - r)
    ret = fac[n]
    ret = ret * facinv[r] % p
    return ret * facinv[n - r] % p

@njit
def comb_init(N_UNTIL, p):
    N_UNTIL += 1
    inv = np.empty(N_UNTIL, np.int64)
    fac = np.empty(N_UNTIL, np.int64)
    facinv = np.empty(N_UNTIL, np.int64)
    inv[0] = 0
    inv[1] = 1
    fac[0] = 1
    facinv[0] = 1
    for i in range(2, N_UNTIL):
        inv[i] = -inv[p % i] * (p // i) % p
    for i in range(1, N_UNTIL):
        fac[i] = fac[i - 1] * i % p
    for i in range(1, N_UNTIL):
        facinv[i] = facinv[i - 1] * inv[i] % p
    return inv, fac, facinv

K = int(input())
S = input()
N = len(S)
MOD = 1_000_000_007
inv, fac, facinv = comb_init(N + K - 1, MOD)
ans = 0
for i in range(K + 1):
    tmp = pow(25, K - i, MOD)
    tmp *= comb(N + K - i - 1, K - i, MOD)
    tmp %= MOD
    tmp *= pow(26, i, MOD)
    tmp %= MOD
    ans += tmp
    ans %= MOD
print(ans)

def comb(n, r, p):
    return fac[n] * facinv[r] * facinv[n - r] % p

def comb_pre(N_UNTIL, p):
    for i in range(2, N_UNTIL + 1):
        fac.append(fac[i - 1] * i % p)
        inv.append(-inv[p % i] * (p // i) % p)
        facinv.append(facinv[-1] * inv[-1] % p)

fac = [1, 1]
facinv = [1, 1]
inv = [0, 1]

K = int(input())
S = input()
N = len(S)
MOD = 1_000_000_007
comb_pre(N + K - 1, MOD)
ans = 0
for i in range(K + 1):
    tmp = pow(25, K - i, MOD)
    tmp *= comb(N + K - i - 1, K - i, MOD)
    tmp %= MOD
    tmp *= pow(26, i, MOD)
    tmp %= MOD
    ans += tmp
    ans %= MOD
print(ans)


k = int(input())
n = len(input())
p = 10**9 + 7
fct, inv = [1], [1]
a, b = 1, 1
for i in range(1, n + k + 1):
    a = (a * i) % p
    b = (b * pow(i, p - 2, p)) % p
    fct.append(a)
    inv.append(b)
ans = 0
for i in range(k + 1):
    c = fct[i + n - 1] * inv[i] * inv[n - 1]
    ans += pow(25, i, p) * pow(26, k - i, p) * c
    ans %= p
print(ans)

k = int(input())
n = len(input())
p = 10**9 + 7
a = 1
fct = [a]
for i in range(1, n + k + 1):
    a = (a * i) % p
    fct.append(a)
b = pow(fct[-1], p - 2, p)
inv = [b]
for i in range(1, n + k + 1)[::-1]:
    b = (b * i) % p
    inv.append(b)
inv.reverse()
ans = 0
pow25, pow26 = [1], [1]
for i in range(1, k + 1):
    pow25.append((pow25[-1] * 25) % p)
    pow26.append((pow26[-1] * 26) % p)
for i in range(k + 1):
    c = fct[i + n - 1] * inv[i] * inv[n - 1]
    ans += pow25[i] * pow26[k - i] * c
    ans %= p
print(ans)


import sys

def solve(k, aaa):
    min_a = min(aaa)
    max_a = max(aaa)
    if min_a * 2 < max_a:
        return [-1]

    ans = []
    while True:
        min_a = min(aaa)
        max_a1 = max(aaa[1:])
        max_a = max(aaa[0], max_a1)

        if min_a == 0:
            assert max_a == 0
            break

        if min_a * 2 == max_a:
            must_use = [i for i, a in enumerate(aaa) if a == max_a]
            next_max = max_a - 2
        elif (aaa[0] - 2) * 2 >= max_a1 - 1:
            must_use = []
            next_max = max(aaa[0] - 2, max_a1 - 1)
        else:
            ans.extend(range(1, k + 1))
            for i in range(k):
                aaa[i] -= 1
            continue

        can_use = []
        cant_use = []

        for i in range(k):
            if min_a * 2 == aaa[i]:
                pass
            elif (aaa[i] - 2) * 2 >= next_max:
                can_use.append(i)
            else:
                cant_use.append(i)

        double = []
        if len(must_use) == 0:
            double.append(can_use[0] + 1)
        else:
            max_use = must_use[-1]
            use = must_use + can_use
            use.sort()
            double = [i + 1 for i in use if i <= max_use]
        single = [i for i in range(1, k + 1) if i not in double]

        for i in double:
            aaa[i - 1] -= 2
        for i in single:
            aaa[i - 1] -= 1

        ans.extend(double)
        ans.extend(single)
        ans.extend(double)

    return ans

k, *aaa = map(int, sys.stdin.buffer.read().split())
print(*solve(k, aaa))

import sys

def find_permutation(aaa, use):
    """
    iの残り使用数がaaa[i-1]の状態で
    集合useにある文字群(1～k)を後ろに繋げる方法で
    それよりさらに後が破綻しないような繋げ方のうち
    辞書順最小のものを求める。

    ただし（この関数からは見えないが）現在確定済み配列の
    末尾 (k - |use|) 個は、useに含まれない要素が1回ずつ登場することを前提とする。
    （つまり、この関数の結果を繋げると、末尾 k 個が順列になる）

    どうやっても破綻する場合はNoneを返す。

    :param aaa:
    :param use:
    :return:
    """

    max_a = -1
    min_a = 1005
    max_fixed = -1

    for i in range(k):
        a = aaa[i]
        if i + 1 in use:
            min_a = min(min_a, a)
            max_a = max(max_a, a)
        else:
            max_fixed = max(max_fixed, a)

    if max(max_a, max_fixed + 1) > 2 * min_a:
        return None

    if max_a < 2 * min_a:
        return sorted(use)

    front = []
    rear = []
    either = []
    for i in use:
        if aaa[i - 1] == max_a:
            front.append(i)
        elif aaa[i - 1] == min_a:
            rear.append(i)
        else:
            either.append(i)

    max_front = front[-1]
    for i in either:
        if i < max_front:
            front.append(i)
        else:
            rear.append(i)
    front.sort()
    rear.sort()
    front.extend(rear)

    return front

def solve(k, aaa):
    if k == 1:
        return [1] * aaa[0]

    min_a = min(aaa)
    max_a = max(aaa)
    if min_a * 2 < max_a:
        return [-1]

    ans = []
    ans.extend(find_permutation(aaa, set(range(1, k + 1))))
    for i in range(k):
        aaa[i] -= 1

    remaining = sum(aaa)
    while remaining:
        use = set(range(1, k + 1))
        candidates = []
        for r in range(k):
            result = find_permutation(aaa, use)
            if result is not None:
                candidates.append(result)

            use.remove(ans[-r - 1])
        adopted = min(candidates)
        ans.extend(adopted)
        for i in adopted:
            aaa[i - 1] -= 1
        remaining -= len(adopted)

    return ans

k, *aaa = map(int, sys.stdin.buffer.read().split())
print(*solve(k, aaa))


# -*- coding: utf-8 -*-
a, b, c, d, e = map(int, input().split())

suuji_list = ["", a, b, c, d, e]

print(list.index(0))

# -*- coding: utf-8 -*-
a, b, c, d, e = map(int, input().split())

suuji_list = ["", a, b, c, d, e]

print(suuji_list.index(0))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02639/Python/s072466363.py", line 6, in <module>
    print(list.index(0))
TypeError: descriptor 'index' for 'list' objects doesn't apply to a 'int' object


nums = [int(x) for x in input()]

for i in range(5):
    if nums[i] == 0:
        print(i + 1)
        exit(0)

nums = [int(x) for x in input().split(" ")]

for i in range(5):
    if nums[i] == 0:
        print(i + 1)
        exit(0)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02639/Python/s316600506.py", line 1, in <module>
    nums = [int(x) for x in input()]
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02639/Python/s316600506.py", line 1, in <listcomp>
    nums = [int(x) for x in input()]
ValueError: invalid literal for int() with base 10: ' '


X, Y = map(int, input().split())

def checkY(N, count, X):
    if count == X and N == 0:
        print("Yes")
        exit(0)
    elif count == X and N != 0:
        return False

    if checkY(N - 2, count + 1, X):
        return True

    if checkY(N - 4, count + 1, X):
        return True

    return False

if 2 * X <= Y and Y <= 4 * X:
    if checkY(Y, 0, X):
        print("Yes")
    else:
        print("No")
else:
    print("No")

X, Y = map(int, input().split())

crane = (4 * X - Y) / 2
turtle = (Y - 2 * X) / 2

def is_integer_num(n):
    if isinstance(n, int):
        return True
    if isinstance(n, float):
        return n.is_integer()
    return False

if is_integer_num(crane) and crane >= 0 and is_integer_num(turtle) and turtle >= 0:
    print("Yes")

else:
    print("No")


X, Y = [int(), input().split()]

if X % 2 == 0 and 2 * X < Y < 4 * X:
    print("Yes")
else:
    print("No")

X, Y = map(int, input().split())

if Y % 2 == 0 and 2 * X <= Y <= 4 * X:
    print("Yes")
else:
    print("No")

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02640/Python/s666717578.py", line 3, in <module>
    if X % 2 == 0 and 2 * X < Y < 4 * X:
TypeError: '<' not supported between instances of 'int' and 'list'


from numba import jit

@jit
def solve(X, Y, Z):
    while X >= 0:
        if 2 * X + 4 * Z == Y:
            return True
        elif 2 * X + 4 * Z < Y:
            X -= 1
            Z += 1
    return False

def main():
    X, Y = map(int, input().split())
    Z = 0

    if solve(X, Y, Z):
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

from numba import jit

@jit
def solve(X, Y, Z):
    while X >= 0:
        if 2 * X + 4 * Z == Y:
            return True
        elif 2 * X + 4 * Z < Y:
            X -= 1
            Z += 1
        else:
            return False
    return False

def main():
    X, Y = map(int, input().split())
    Z = 0

    if solve(X, Y, Z):
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()


def actual(X, N, P):
    for i in range(X, -1, -1):
        if i not in P:
            left = i
            break

    for i in range(X, 101):
        if i not in P:
            right = i
            break

    if abs(left - X) <= abs(right - X):
        return left
    else:
        return right

X, N = map(int, input().split())

if N == 0:
    print(X)
else:
    P = list(map(int, input().split()))
    print(actual(X, N, P))

def actual(X, N, P):
    for i in range(X, -1 - 1, -1):
        if i not in P:
            left = i
            break

    for i in range(X, 101 + 1):
        if i not in P:
            right = i
            break

    if abs(left - X) <= abs(right - X):
        answer = left
    else:
        answer = right

    return answer

X, N = map(int, input().split())

if N == 0:
    P = []
    print(actual(X, N, P))
else:
    P = list(map(int, input().split()))
    print(actual(X, N, P))


X, N = map(int, input().split())
p = list(map(int, input().split()))

if p:
    x = [i for i in range(1, max(p)) if i not in p]

    c = x.pop()
    a = abs(c - X)
    for i in x:
        if abs(i - X) < a:
            c = i
    print(c)
else:
    print(X)

X, N = map(int, input().split())
p = list(map(int, input().split()))

i = 0
while True:
    if X - i not in p:
        print(X - i)
        break
    elif X + i not in p:
        print(X + i)
        break
    i += 1


import sys

X, N = map(int, input().split())
list_p = list(map(int, input().split()))

if N == 0:
    print(X)
    sys.exit()

all_list = [int(x) for x in range(min(list_p), max(list_p) + 1)]
target_list = sorted(list(set(list_p) ^ set(all_list)))

ans = [abs(num - X) for num in target_list]
# print(ans)
# print(min(ans))
# print(ans.index(min(ans)))
print(target_list[ans.index(min(ans))])

import sys

X, N = map(int, input().split())
list_p = list(map(int, input().split()))

if N == 0:
    print(X)
    sys.exit()

all_list = [int(x) for x in range(0, 102)]
target_list = sorted(list(set(list_p) ^ set(all_list)))

ans = [abs(num - X) for num in target_list]
# print(all_list)
# print(target_list)
# print(min(ans))
# print(ans.index(min(ans)))
print(target_list[ans.index(min(ans))])


X, N = input().split()
p = list(map(int, input().split()))

ans = 0
for i in range(1, 102):
    if abs(X - i) < abs(ans - i) and i not in p and i != X:
        ans = i

print(ans)

X, N = map(int, input().split())
p = list(map(int, input().split()))

ans = 0
for i in range(1, 102):
    if abs(X - i) < abs(X - ans) and i not in p:
        ans = i
print(ans)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02641/Python/s033864949.py", line 6, in <module>
    if abs(X - i) < abs(ans - i) and i not in p and i != X:
TypeError: unsupported operand type(s) for -: 'str' and 'int'


import sys

x, n = map(int, input().split())
if n == 0:
    print(x)
    sys.exit()
else:
    p = list(map(int, input().split()))
if x == 1:
    print(0)
    sys.exit()

a = []
b = []

for i in range(1, 100):
    if i not in p:
        a.append(abs(x - i))
        b.append(i)
ans = min(a)
bb = a.index(ans)
print(b[bb])

import sys

x, n = map(int, input().split())
if n == 0:
    print(x)
    sys.exit()
else:
    p = list(map(int, input().split()))

a = []
b = []

for i in range(0, 102):
    if i not in p:
        a.append((x - i) ** 2)
        b.append(i)
ans = min(a)
bb = a.index(ans)
print(b[bb])


x, n = map(int, input().split())

if n == 0:
    p = set([])
else:
    p = list(map(int, input().split()))
p = list(map(int, str.split()))
a = list(set(range(201)) - set(p))
abs_diff = [abs(i - x) for i in a]
min_abs_diff = min(abs_diff)
for i, j in zip(a, abs_diff):
    if j == min_abs_diff:
        print(i)
        break

# ABC170C

x, n = map(int, input().split())

if n == 0:
    p = set([])
else:
    p = list(map(int, input().split()))
a = list(set(range(201)) - set(p))
abs_diff = [abs(i - x) for i in a]
min_abs_diff = min(abs_diff)
for i, j in zip(a, abs_diff):
    if j == min_abs_diff:
        print(i)
        break

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02641/Python/s627877653.py", line 7, in <module>
    p = list(map(int, str.split()))
TypeError: unbound method str.split() needs an argument


def main():
    x, n = map(int, input().split())
    p = list(map(int, input().split()))

    min = 1000

    for i in range(1, 101):

        if i in p:
            continue

        elif min > abs(x - i):
            result = i
            min = abs(x - i)

    print(result)

if __name__ == "__main__":
    main()

def main():
    x, n = map(int, input().split())
    p = list(map(int, input().split()))

    min = 1000

    for i in range(-50, 150):

        if i in p:
            continue

        elif min > abs(x - i):
            result = i
            min = abs(x - i)

    print(result)

if __name__ == "__main__":
    main()


x, n = map(int, input().split())
p = list(map(int, input().split()))
ans = 0
p.sort()
for i in range(p[0], p[n - 1] + 1):
    if (i not in p) and abs(x - i) < abs(ans - x):
        ans = i

print(ans)

x, n = map(int, input().split())
p = list(map(int, input().split()))
ans = 0

if n == 0:
    print(x)
    exit()

p.sort()

for i in range(p[0] - x, p[n - 1] + x):
    if (i not in p) and abs(x - i) < abs(ans - x):
        ans = i

print(ans)


X, N = map(int, input().split())
if N == 0 and N == 100:
    print(X)

else:
    p = list(map(int, input().split()))
    abs_list = []
    re_list = []
    min = 1000
    min_index = 0

    for i in range(100):
        abs_list.append(i + 1)
    for j in p:
        abs_list.remove(j)
    for i in range(len(abs_list)):

        re_list.append(abs(abs_list[i] - X))
    for i in range(len(re_list)):
        if min > re_list[i]:
            min = re_list[i]
            min_index = i
    print(abs_list[min_index])

X, N = map(int, input().split())
if N == 0:
    print(X)
elif N == 100:
    if X <= 50:
        print(0)
    else:
        print(101)

else:
    p = list(map(int, input().split()))
    abs_list = []
    re_list = []
    min = 1000
    min_index = 0

    for i in range(250):
        abs_list.append(-100 + i)
    for j in p:
        abs_list.remove(j)
    for i in range(len(abs_list)):

        re_list.append(abs(abs_list[i] - X))
    for i in range(len(re_list)):
        if min > re_list[i]:
            min = re_list[i]
            min_index = i
    if re_list[min_index] > X:
        print(0)
    else:
        print(abs_list[min_index])


x, n = list(map(int, input().split()))
if n == 0:
    print(x)
    exit()
p_list = list(map(int, input().split()))

idx = p_list.index(x)

i = 0
while True:
    x_i = x - i
    x_j = x + i

    if x_i not in p_list:
        print(x_i)
        exit()
    if x_j not in p_list:
        print(x_j)
        exit()

    i += 1

x, n = list(map(int, input().split()))
p_list = list(map(int, input().split()))
if n == 0:
    print(x)
    exit()

i = 0
while True:
    x_i = x - i
    x_j = x + i

    if x_i not in p_list:
        print(x_i)
        exit()
    if x_j not in p_list:
        print(x_j)
        exit()

    i += 1


import numpy as np

X, N = map(int, input().split())
P = np.array(list(map(int, input().split())))

P = P - X

for i in range(0, X):
    if i not in P or -i not in P:
        if -i not in P:
            ans = X - i
        else:
            ans = X + i
        break

print(ans)

import numpy as np

X, N = map(int, input().split())
P = np.array(list(map(int, input().split())))

P = P - X

for i in range(0, X + 1):
    if i not in P or -i not in P:
        if -i not in P:
            ans = X - i
        else:
            ans = X + i
        break

print(ans)


def Qc():
    x, n = map(int, input().split())
    if 0 < n:
        p = map(int, input().split())

        targets = list(range(1, 101))
        outer = set(targets) - set(p)
        res = [abs(x - v) for v in outer]
        i = res.index(min(res))
        res = list(outer)[i]
    else:
        # 整数列がなにもない場合は自分自身が含まれていない最近値になる
        res = x
    print(res)

if __name__ == "__main__":
    Qc()

def Qc():
    x, n = map(int, input().split())
    if 0 < n:
        p = list(map(int, input().split()))
        for i in range(101):
            if x - i not in p:
                print(x - i)
                exit()
            if x + i not in p:
                res = x + 1
                print(x + i)
                exit()
    else:
        # 整数列がなにもない場合は自分自身が含まれていない最近値になる
        print(x)
        exit()

if __name__ == "__main__":
    Qc()


a = input()

t, c = int(a.split(" ")[0]), int(a.split(" ")[1])

if not c:
    print(t)

b = input()
lst = [int(x) for x in b.split(" ")]

for i in range(c):
    if t - i not in lst:
        print(t - i)
        break
    if t + i not in lst:
        print(t + i)
        break

a = input()

t, c = int(a.split(" ")[0]), int(a.split(" ")[1])

if not c:
    print(t)
else:
    b = input()
    lst = [int(x) for x in b.split(" ")]

    for i in range(c + 2):
        if t - i not in lst:
            print(t - i)
            break
        if t + i not in lst:
            print(t + i)
            break


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)

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)


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

tmp = 1000
result = []
result2 = []
for i in range(1, 101):
    if i in A:
        continue

    hoge = abs(X - i)
    if hoge <= tmp:
        tmp = hoge
        result2.append(tmp)
        result.append(i)

result3 = []
for i, v in enumerate(result2):
    if v == min(result2):
        result3.append(result[i])

print(min(result3))

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

tmp = 1000
result = []
result2 = []
for i in range(0, 102):
    if i in A:
        continue

    hoge = abs(X - i)
    if hoge <= tmp:
        tmp = hoge
        result2.append(tmp)
        result.append(i)

result3 = []
for i, v in enumerate(result2):
    if v == min(result2):
        result3.append(result[i])

print(min(result3))


X, N = map(int, input().split())
P = set(list(map(int, input().split())))

targets = set(range(1, 101)) - P
print(min([(target, abs(X - target)) for target in targets], key=lambda x: x[1])[0])

X, N = map(int, input().split())
P = set(list(map(int, input().split())))

targets = set(range(-101, 102)) - P
if targets:
    print(min([(target, abs(X - target)) for target in targets], key=lambda x: x[1])[0])
else:
    print(X)


import numpy as np

def getNearestValue(li, num):
    idx = np.abs(np.array(li) - num).argmin()
    return li[idx]

x, n = map(int, input().split())
p = list(map(int, input().split()))

ans = 0
print(p)
i = 0
while True:
    mi = getNearestValue(p, x - i)
    ma = getNearestValue(p, x + i)
    if mi or ma:
        break
    i += 1

print(mi if mi < ma else ma)

x, n = map(int, input().split())
p = set(map(int, input().split()))

ans = 0
i = 0
while True:
    if (x - i) not in p:
        ans = x - i
        break
    elif (x + i) not in p:
        ans = x + i
        break
    i += 1

print(ans)


x, n = map(int, input().split())
p = [int(_) for _ in input().split()]

not_in_p = [i for i in range(0, 102) if i not in p]
nip_temp = list(map(lambda s: abs(x - s), not_in_p))

address = nip_temp.index(min(nip_temp))
print(p[address])

x, n = map(int, input().split())
p = [int(_) for _ in input().split()]

not_in_p = [i for i in range(0, 102) if i not in p]
nip_temp = list(map(lambda s: abs(x - s), not_in_p))

address = nip_temp.index(min(nip_temp))
print(not_in_p[address])


X, N = map(int, input().split())

P = list(map(int, input().split()))

if N == 0:
    print(X)
    exit()

# high
high = 0
tmp = 0
while not high:
    if (X + tmp) in P:
        tmp += 1
        continue
    high = X + tmp

low = 0
tmp = 0
while not low:
    if (X - tmp) in P:
        tmp += 1
        continue
    low = X - tmp

if abs(X - low) == abs(X - high):
    print(low)
elif abs(X - low) < abs(X - high):
    print(low)
else:
    print(high)

X, N = map(int, input().split())

P = list(map(int, input().split()))

if N == 0:
    print(X)
    exit()

diff = 0
high = low = None
while True:
    if X + diff not in P:
        high = X + diff
    if X - diff not in P:
        low = X - diff
    if high is None and low is None:
        diff += 1
        continue

    if high == low:
        print(low)
    elif low is None:
        print(high)
    else:
        print(low)
    break


X, N = map(int, input().split())
p_int_list = []

if N == 0:
    print(X)
    exit()
else:
    p_int_list = list(map(int, input().split()))
    p_int_list = sorted(p_int_list)

ans_range = []
for i, j in zip(p_int_list[:-1], p_int_list[1:]):
    if j < 0:
        if abs(j) <= X <= abs(i):
            ans_range = [abs(j), abs(i)]
    else:
        if i <= X <= j:
            ans_range = [i, j]
            if i < 0:
                print(0)
                exit()

ans = 0
p_int_set = set(p_int_list)

if ans_range[1] - ans_range[0] != 1:
    if ans_range[1] == X:
        print(ans_range[1] - 1)
        exit()
    elif ans_range[0] == X:
        if X - 1 in p_int_set:
            print(X + 1)
            exit()
        else:
            print(X + 1)
            exit()
elif ans_range[1] - ans_range[0] == 1:
    for i in range(1, N):
        if ans_range[0] - i not in p_int_set:
            print(ans_range[0] - i)
            exit()
        elif ans_range[1] + i not in p_int_set:
            print(ans_range[1] + i)
            exit()

X, N = map(int, input().split())
p_int_list = []

if N == 0:
    print(X)
    exit()
else:
    p_int_list = list(map(int, input().split()))

p_int_set = set(p_int_list)

if X not in p_int_set:
    print(X)
    exit()

for i in range(1, 10000):
    if X - i not in p_int_set:
        print(X - i)
        exit()
    elif X + i not in p_int_set:
        print(X + i)
        exit()


x, n = map(int, input().split())

if n != 0:
    p = list(map(int, input().split()))
else:
    print(x)
    exit(1)

dif = 100
ans = 0

for i in range(min(p) - 1, max(p) + 2):
    if not (i in p):
        if dif > abs(x - i):
            dif = abs(x - i)
            ans = i

print(ans)

x, n = map(int, input().split())

if n != 0:
    p = list(map(int, input().split()))
else:
    print(x)
    exit()

dif = 100
ans = 0

for i in range(min(p) - 1, max(p) + 2):
    if not (i in p):
        if dif > abs(x - i):
            dif = abs(x - i)
            ans = i

print(ans)


X, N = map(int, input().split())
if N == 0:
    print(X)
    exit()

P = list(map(int, input().split()))
minmin = []
minn = 101
for i in range(1, 101):
    if i in P:
        continue
    abs1 = abs(i - X)
    if minn >= abs1:
        minn = abs1
        minmin.append(i)

if len(minmin) > 2 and abs(X - minmin[-1]) == abs(X - minmin[-2]):
    print(minmin[-2])
    exit()
print(minmin[-1])

X, N = map(int, input().split())
if N == 0:
    print(X)
    exit()

P = list(map(int, input().split()))

for i in range(101):
    p = X - i not in P
    p1 = X + i not in P
    if p1 or p:
        if p:
            print(X - i)
            exit()
        print(X + i)
        exit()


# coding:utf-8
x, n = map(int, input().split())
p = list(map(int, input().split()))

if n == 0:
    print(x)
else:
    ps = sorted(p)
    tmp = [_ for _ in range(ps[0], ps[-1] + 1)]
    ans_list = list(set(tmp) ^ set(ps))
    # print(tmp, ans_list)
    diff = []

    for i in ans_list:
        diff.append(abs(i - x))
    print(ans_list[diff.index(min(diff))])

# coding:utf-8
x, n = map(int, input().split())
p = list(map(int, input().split()))

if n == 0:
    print(x)
else:
    ps = sorted(p)
    tmp = list(range(-201, 200))
    ans_list = list(set(tmp) ^ set(ps))
    ans_list = sorted(ans_list)
    # print(tmp, ans_list)
    diff = []

    for i in ans_list:
        diff.append(abs(i - x))

    print(ans_list[diff.index(min(diff))])


x, n = map(int, input().split())
if n != 0:
    p = list(map(int, input().split()))
    if x in p:
        for i in range(-1000, 1001):
            print(i)
            if i == -100:
                mini = i
            if i in p:
                pass
            else:
                if abs(x - mini) > abs(x - i):
                    mini = i
                elif abs(x - mini) == abs(x - i):
                    mini = min(mini, i)
        else:
            print(mini)
    else:
        print(x)
else:
    print(x)

x, n = map(int, input().split())
if n != 0:
    p = list(map(int, input().split()))
    if x in p:
        for i in range(-1000, 1001):
            if i == -1000:
                mini = i
            if i in p:
                pass
            else:
                if abs(x - mini) > abs(x - i):
                    mini = i
                elif abs(x - mini) == abs(x - i):
                    mini = min(mini, i)
        else:
            print(mini)
    else:
        print(x)
else:
    print(x)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02641/Python/s131160105.py", line 12, in <module>
    if abs(x - mini) > abs(x - i):
NameError: name 'mini' is not defined. Did you mean: 'min'?


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

setA = set(A)
result = 0

if N == 1:
    print(0)
else:
    for i in range(N):
        tmp = A[i]
        A[i] = 0
        setA = set(A)
        A[i] = tmp
        if 1 in setA:
            continue

        for a in setA:
            if A[i] % a == 0:
                break
        else:
            result += 1

    print(result)

from collections import Counter

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

sorted_A = sorted(A)
result = 0
c = Counter(sorted_A)
# 倍数を管理するテーブル
lendp = sorted_A[-1] + 1
dp = [0] * lendp

for a in sorted_A:
    dp[a] += 1
    if dp[a] == 1:
        b = a * 2
        while b < lendp:
            dp[b] += 2
            b += a

print(dp.count(1))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02642/Python/s509349915.py", line 19, in <module>
    if A[i] % a == 0:
ZeroDivisionError: integer division or modulo by zero


# Not Divisible

N = int(input())
A = [int(n) for n in input().split()]

check = [0] * 1000000
A.sort()

ok = [-1]
p = 0
for a in A:
    if a == p:
        if ok[-1] == p:
            ok = ok[:-1]
        continue
    p = a
    if check[a] == 1:
        continue
    for i in range(a, 1000000, a):
        check[i] = 1
    ok.append(a)

print(len(ok) - 1)

# Not Divisible

N = int(input())
A = [int(n) for n in input().split()]

check = [0] * 1000001
A.sort()

ok = [-1]
p = 0
for a in A:
    if a == p:
        if ok[-1] == p:
            ok = ok[:-1]
        continue
    p = a
    if check[a] == 1:
        continue
    for i in range(a, 1000001, a):
        check[i] = 1
    ok.append(a)

print(len(ok) - 1)


n = int(input())
a = sorted(map(int, input().split()))

cnt = [0] * (max(a) + 1)
for i in a:
    cnt[i] += 1
for i in set(a):
    if cnt[i] >= 1:
        for j in range(i * 2, max(a) + 1, i):
            cnt[j] = 0
print(cnt.count(1))

n = int(input())
a = sorted(map(int, input().split()))

cnt = [0] * (a[-1] + 1)
for i in a:
    cnt[i] += 1
for i in set(a):
    if cnt[i] >= 1:
        for j in range(i * 2, a[-1] + 1, i):
            cnt[j] = 0
print(cnt.count(1))


from collections import Counter

n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
a = set(a)

cnt = 0
while a:
    min_val = min(a)
    a.remove(min_val)

    if c[min_val] == 1:
        cnt += 1

    if not a:
        break

    max_val = max(a)

    del_a = set()
    mul = 2
    while True:
        mul_val = min_val * mul

        if mul_val > max_val:
            break

        if mul_val in a:
            del_a.add(min_val * mul)

        mul += 1

    a -= del_a

print(cnt)

from collections import Counter

n = int(input())
a = list(map(int, input().split()))
a.sort()
c = Counter(a)

flags = [True] * (a[-1] + 1)

for e in a:
    for mul in range(2, a[-1] // e + 1):
        flags[e * mul] = False

print(sum([flags[a[i]] and c[a[i]] == 1 for i in range(n)]))


# coding:utf-8
n = int(input())
a = list(map(int, input().split()))
count = [0 for _ in range(max(a) + 1)]
ans = 0

for i in a:
    if count[i] != 0:
        count[i] = 1
        continue
    for j in range(2 * i, max(a) + 1, i):
        count[j] = 1
    count[i] = 2

for i in a:
    if count[i] != 1:
        ans += 1

print(ans)

# coding:utf-8
n = int(input())
a = list(map(int, input().split()))
m = max(a)
count = [0 for _ in range(m + 1)]
ans = 0

for i in a:
    if count[i] != 0:
        count[i] = 1
        continue
    for j in range(2 * i, m + 1, i):
        count[j] = 1
    count[i] = 2

for i in a:
    if count[i] != 1:
        ans += 1

print(ans)


n = int(input())
a = list(map(int, input().split()))
remain = [0 for i in range(max(a) + 1)]
for ai in a:
    remain[ai] += 1
res = 0
for i in range(1, max(a) + 1):
    if remain[i] == 1:
        res += 1
    if remain[i]:
        for j in range(i * 2, max(a) + 1, i):
            remain[j] = 0
print(res)

n = int(input())
a = list(map(int, input().split()))
remain = [0 for i in range(max(a) + 1)]
for ai in a:
    remain[ai] += 1
res = 0
max_a = max(a)
for i in range(1, max_a + 1):
    if remain[i] == 1:
        res += 1
    if remain[i]:
        for j in range(i * 2, max_a + 1, i):
            remain[j] = 0
print(res)


n = int(input())
a = list(map(int, input().split()))
a.sort()
flag = False
b = [False] * 1000010
for i in range(n - 1):
    if a[i] == a[i + 1]:
        for j in range(a[i], 1000010, a[i]):
            b[j] = True

ans = 0
for i in range(n):
    if not b[a[i]]:
        ans += 1
        for j in range(a[i], 1000010, a[i]):
            b[j] = True

print(ans)

n = int(input())
a = list(map(int, input().split()))
a.sort()
flag = False
b = [False] * 1000010
for i in range(n - 1):
    if a[i] == a[i + 1]:
        if b[a[i]]:
            continue
        for j in range(a[i], 1000010, a[i]):
            b[j] = True

ans = 0
for i in range(n):
    if not b[a[i]]:
        ans += 1
        for j in range(a[i], 1000010, a[i]):
            b[j] = True

print(ans)


from collections import Counter
import sympy

len_arr = int(input())
arr = list(map(int, input().split()))
counter = Counter(arr)
st = set(arr)

ans = 0
for value, count in counter.items():
    if count > 1:
        continue
    divs = set(sympy.divisors(value))
    if len(divs & st) == 1:
        ans += 1

print(ans)

import numpy as np
from collections import Counter

len_arr = int(input())
arr = list(map(int, input().split(" ")))
counter = Counter(arr)
x_max = max(counter.keys())

dp = np.empty(x_max + 1, dtype=np.bool_)
dp[:] = True

ans = 0

for x, count in sorted(counter.items()):
    multi = [x * y for y in range(1, x_max // x + 1)]
    if count == 1 and dp[x]:
        ans += 1
    dp[multi] = False

print(ans)


n = int(input())
A = sorted(map(int, input().split()))

B = [1] * n
for i in range(n):
    if B[i] == 0:
        continue
    a = A[i]
    for j in range(i + 1, n):
        if A[j] % a == 0:
            B[j] = 0

for i in range(n - 1):
    if B[i] == 1:
        if A[i] == A[i + 1]:
            B[i] = 0

print(sum(B))

from collections import Counter

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

ok = [False] * (10**6 + 1)
for a in A:
    ok[a] = True

for i in range(10**6 + 1):
    if ok[i]:
        j = 2
        while i * j <= 10**6:
            ok[i * j] = False
            j += 1

for a, cnt in Counter(A).items():
    if cnt >= 2:
        ok[a] = False

print(sum(ok))


from collections import Counter

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

A_sort = sorted(set(A))
A_counter = Counter(A)
# print(A_sort)

res = 0
# res_list = []
for i in range(len(A_sort)):
    # print(A_sort[i], A_sort_tmp)
    if A_counter[A_sort[i]] >= 2:
        continue

    A_sort_tmp = A_sort[:i]
    for j in range(len(A_sort_tmp)):
        if A_sort[i] % A_sort_tmp[j] == 0:
            break
    else:
        res += 1
        # res_list.append(i + 1)

print(res)
# print(res_list)

from collections import defaultdict

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

bool_list = [True] * (10**6 + 1)

duplicate_dic = defaultdict(int)
for a in A:
    duplicate_dic[a] += 1
    if duplicate_dic[a] > 1:
        bool_list[a] = False

for a in A_sort:
    for i in range(2 * a, 10**6 + 1, a):
        bool_list[i] = False

print(sum([1 for a in A_sort if bool_list[a]]))


N = int(input())
AS = [int(x) for x in input().split()]

ok = []
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        if AS[i] % AS[j] == 0:
            break
    else:
        ok.append(i)

print(len(ok))

N = int(input())
AS = [int(x) for x in input().split()]

AS.sort(reverse=True)
MAX_AS = AS[0]
table = [0] * (MAX_AS + 1)  # 1..max(AS)

alreadyVisited = {}
for i in range(N):
    x = dx = AS[i]
    if alreadyVisited.get(x, False):
        table[x] = 0
        continue
    alreadyVisited[x] = True

    table[x] = 1
    while True:
        x += dx
        if x > MAX_AS:
            break
        table[x] = 0

print(sum(table))


from collections import Counter

n = int(input())
a = list(map(int, input().split()))

new = [key for key, val in Counter(a).most_common() if val == 1]
dp = [0] * 100010

for i in new:
    for j in range(0, 100000, i):
        dp[j] += 1

ans = 0
for i in new:
    if dp[i] == 1:
        ans += 1
print(ans)

from collections import Counter

n = int(input())
a = list(map(int, input().split()))

# new = [key for key, val in Counter(a).most_common() if val == 1]
prime = [1] * 1000010

for i in set(a):
    # if prime[i]:
    for j in range(i + i, 1000001, i):
        prime[j] = 0

c = Counter(a)
ans = 0
for i in a:
    if prime[i] and c[i] == 1:
        ans += 1
print(ans)


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

count = 0
for i in range(N):
    is_ans = True
    for j in range(N):
        if i != j:
            if A[i] % A[j] == 0:
                is_ans = False
                break

    if is_ans:
        count += 1

print(count)

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

def solve2(N, A):
    A.sort()
    amax = A[-1]
    dp = [True] * (amax + 1)
    cnt = [0] * (amax + 1)

    for a in A:
        cnt[a] += 1

    for i in range(amax):
        x = i + 1
        if cnt[x] > 1:
            dp[x] = False

        if cnt[x] > 0:
            y = x * 2
            while y <= amax:
                dp[y] = False
                y += x

    ansval = [x for x in A if dp[x]]

    # print(ansval)
    ans = len(ansval)

    return ans

def solve1(N, A):
    ans = 0
    for i in range(N):
        is_ans = True
        for j in range(N):
            if i != j:
                if A[i] % A[j] == 0:
                    is_ans = False
                    break

        if is_ans:
            ans += 1

    return ans

print(solve2(N, A))


N = int(input())
A = [int(Ai) for Ai in input().split()]

count = 0
for i, Ai in enumerate(A):
    found = False
    for j, Aj in enumerate(A):
        if i != j and Ai % Aj == 0:
            found = True
            break
    if not found:
        count += 1

print(count)

from collections import Counter

N = int(input())
A = [int(Ai) for Ai in input().split()]

counter = Counter(A)

dp = [1] * (max(A) + 1)
for Ai in A:
    for j in range(Ai * 2, len(dp), Ai):
        dp[j] = 0

print(sum([dp[Ai] == 1 and counter[Ai] == 1 for Ai in A]))


n = int(input())
a = list(map(int, input().split()))
a = list(set(a))
a.sort()
ans = 0
if len(a) == 1:
    print(0)
else:
    for _ in range(n):
        m = a.pop()
        ind = True
        for i in a:
            if m % i == 0:
                ind = False
                break
        if ind:
            ans += 1
    print(ans)

n = int(input())
a = list(map(int, input().split()))
m = max(a)
y = [0] * (m + 1)
for i in a:
    x = i
    while x <= m:
        y[x] += 1
        x += i
ans = 0
for j in a:
    if y[j] == 1:
        ans += 1

print(ans)


from numba import njit

@njit(cache=True)
def fact(x):
    i = 1
    while i * i <= x:
        if x % i == 0:
            yield i
            yield x // i
        i += 1

def main():
    n = int(input())
    a = tuple(map(int, input().split()))

    c = [0] * (max(a) + 1)

    for e in a:
        c[e] += 1

    ans = n
    for e in a:
        c[e] -= 1
        for fct in fact(e):
            if c[fct]:
                ans -= 1
                break

        c[e] += 1

    print(ans)

if __name__ == "__main__":
    main()

from numba import njit

@njit(fastmath=True)
def fact(x):
    i = 1
    while i * i <= x:
        if x % i == 0:
            yield i
            yield x // i
        i += 1

def main():
    n = int(input())
    a = tuple(map(int, input().split()))

    c = [0] * (max(a) + 1)

    for e in a:
        c[e] += 1

    ans = n
    for e in a:
        c[e] -= 1
        for fct in fact(e):
            if c[fct]:
                ans -= 1
                break

        c[e] += 1

    print(ans)

if __name__ == "__main__":
    main()

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02642/Python/s936960783.py", line 1, in <module>
    from numba import njit
ModuleNotFoundError: No module named 'numba'


# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int, input().split()))

count = 0
for i in range(n):
    is_divisible = False
    for j in range(n):
        divisible_num = []
        if a[i] % a[j] == 0 and i != j:
            divisible_num.append(a[j])
            is_divisible = True
        if len(divisible_num) >= 1:
            continue
    if is_divisible:
        continue
    else:
        count += 1

print(count)

# -*- coding: utf-8 -*-
n = int(input())
a = sorted(list(map(int, input().split())))

# 探索範囲は数列aの最大値まで
max_a = a[-1]
b = [0] * (max_a + 1)
ans = set()
for i in a:
    if b[i] == 1:
        if i in ans:
            ans.remove(i)
        continue
    # 探索範囲内のiの倍数をチェック
    for j in range(i, max_a + 1, i):
        b[j] = 1
    ans.add(i)

print(len(ans))


n = int(input())
A = [int(x) for x in input().split()]
A.sort()
ans = 0
for i, a in enumerate(A):
    if i != n - 1 and A[i + 1] == a:
        continue
    do_count = True
    for j in range(i):
        b = A[j]
        if a % b == 0:
            do_count = False
            break
    if do_count:
        ans += 1
print(ans)

n = int(input())
A = [int(x) for x in input().split()]
A.sort()
lim = A[-1]
se = [True for i in range(lim + 1)]
ans = 0
for i, a in enumerate(A):
    if se[a]:
        if not ((i != n - 1 and A[i + 1] == a) or (i != 0 and A[i - 1] == a)):
            ans += 1
        tmp = a
        while not tmp > lim:
            se[tmp] = False
            tmp += a
print(ans)


n = int(input())
a = list(map(int, input().split()))

left = 0
right = n - 1
ans = 0

for i in range(n):
    left = 0
    right = n - 1
    while left <= right:
        if i == left == right:
            left, right = left + 1, right - 1
            continue

        elif i == left:
            if a[i] % a[right] == 0:
                break

        elif i == right:
            if a[i] % a[left] == 0:
                break

        else:
            if a[i] % a[left] == 0 or a[i] % a[right] == 0:
                break

        left, right = left + 1, right - 1

    if left > right:
        ans += 1

print(ans)

n = int(input())
a = sorted(list(map(int, input().split())))

ans = 0
dp = [0] * (a[-1] + 1)

for i in range(n):
    tmp = a[i]
    while tmp <= a[-1]:
        dp[tmp] += 1
        tmp += a[i]

for i in a:
    if dp[i] == 1:
        ans += 1

print(ans)


from collections import Counter

n = int(input())
alist = [int(v) for v in input().split()]
dup_set = {k for k, v in Counter(alist).items() if v >= 2}
alist = sorted(set(alist))
adict = {a: False for a in alist}
a_max = alist[-1]
max_ind = -1

count = 0
if 1 in adict:
    count = 0 if 1 in dup_set else 1
else:
    for a, f in adict.items():
        if f:
            continue
        if a not in dup_set:
            count += 1
        for k in range(a, a_max + 1, a):
            if k in adict:
                adict[k] = True
                if k == a_max:
                    max_ind -= 1
                    a_max = alist[max_ind]

print(count)

from collections import Counter

n = int(input())
alist = [int(v) for v in input().split()]
dup_set = {k for k, v in Counter(alist).items() if v >= 2}
alist = sorted(set(alist))
adict = {a: False for a in alist}
a_max = alist[-1]
max_ind = -1

count = 0
if 1 in adict:
    count = 0 if 1 in dup_set else 1
else:
    for a, f in adict.items():
        if f:
            continue
        if a not in dup_set:
            count += 1
        for k in range(a, a_max + 1, a):
            if k in adict:
                adict[k] = True
                if k == a_max:
                    max_ind -= 1
                    if abs(max_ind) <= len(alist):
                        a_max = alist[max_ind]

print(count)


N = int(input())
A = list(map(int, input().split()))
A.sort()
res = 0
while A:
    if len(A) == 1:
        res += 1
    else:
        if A[0] != A[1]:
            res += 1
    t = A[0]
    NA = []
    for a in A:
        if a % t != 0:
            NA.append(a)
    A = NA[:]
print(res)

N = int(input())
A = list(map(int, input().split()))
A.sort()
MA = max(A)
dp = [True for _ in range(MA + 1)]
flag = [False for _ in range(MA + 1)]

for i in range(N):
    a = A[i]
    if not flag[a]:
        flag[a] = True
        t = a * 2
        while t <= MA:
            dp[t] = False
            t += a
    elif flag[a] == 1:
        dp[a] = False
res = 0
for a in A:
    if dp[a]:
        res += 1
print(res)


n = int(input())
aL = sorted(list(map(int, input().split(" "))))
# aL = sorted(list(set(aLP)))

dp = [False for _ in range(1000001)]

ans = 0
for a in aL:
    if dp[a] or aL.count(a) > 1:
        continue
    ans += 1

    c = 1
    while a * c <= 1000000:
        dp[a * c] = True
        c += 1

print(ans)

n = int(input())
aL = sorted(list(map(int, input().split(" "))))
# aL = sorted(list(set(aLP)))

dp = [False for _ in range(1000001)]

d = {}
for a in aL:
    if a in d:
        d[a] += 1
    else:
        d[a] = 1

ans = 0
for a in aL:
    if dp[a]:
        continue
    if d[a] > 1:
        c = 1
        while a * c <= 1000000:
            dp[a * c] = True
            c += 1
        continue
    ans += 1

    c = 1
    while a * c <= 1000000:
        dp[a * c] = True
        c += 1

print(ans)


n = int(input())
data = list(map(int, input().split()))

ans_list = []
for i in range(n):
    f = True
    for j in range(n):
        if i == j:
            continue

        if data[i] % data[j] == 0:
            f = False
            break

    if f:
        ans_list.append(data[i])

print(len(ans_list))

from collections import Counter

n = int(input())
data = list(map(int, input().split()))

max_ = 10**6 + 1
b = [True] * (max_ + 1)
data.sort()
c = Counter(data)

ans = 0
for d in data:
    if b[d]:
        for j in range(d, max_, d):
            b[j] = False
        # 複数存在
        if c[d] > 1:
            continue
        else:
            ans += 1

print(ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()

ans = 0
for i in range(n):
    cnt = 0
    if i > 0 and a[i] == a[i - 1]:
        continue
    for j in range(i):
        if a[j] > a[i] // 2:
            break
        if a[i] % a[j] == 0:
            cnt += 1
            break
    if cnt == 0:
        if i != 0:
            # print(i, a[i])
            ans += 1
        elif a[0] != a[1]:
            # i == 0
            ans += 1

print(ans)

n = int(input())
a = list(map(int, input().split()))
a.sort()

cnt = [0] * (a[-1] + 1)
for i in range(n):
    cnt[a[i]] += 1

ans = 0
for i in range(1, a[-1] + 1):
    if cnt[i] > 0:
        if cnt[i] == 1:
            ans += 1
        for j in range(2, a[-1] + 1):
            na = i * j
            if na <= a[-1]:
                cnt[na] = 0
            else:
                break

print(ans)


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

A.sort()
count = 0
for i in range(n - 1):
    if A[i] % A[i + 1] == 0:
        count += 1
        continue
    for j in range(i):
        if A[i] % A[j] == 0:
            count += 1
            break
i = n - 1
for j in range(i):
    if A[i] % A[j] == 0:
        count += 1
        break
print(n - count)

n = int(input())
A = list(map(int, input().split()))
A.sort()

dp = [False] * (A[-1] + 1)
for a in A:
    dp[a] = True

for idx, a in enumerate(A):
    if A[idx] == A[idx - 1]:
        if idx == 0:
            None
        else:
            dp[a] = False
    for j in range(2, A[-1] // a + 1):
        dp[a * j] = False

count = 0
for d in dp:
    if d:
        count += 1
print(count)


#!/usr/bin/env python3

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

count = 0

for i in range(N):
    for j in range(N):
        if i == j:
            continue

        if A[i] % A[j] == 0:
            break

    else:
        count += 1

print(count)

#!/usr/bin/env python3

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

A.sort()
A_max = A[-1]
table = [0] * (A_max + 1)

for x in A:
    table[x] += 1
    for y in range(x * 2, A_max + 1, x):
        table[y] += 1

result = sum([1 for x in A if table[x] == 1])
print(result)


from collections import Counter

N = int(input())
a = sorted(list(map(int, input().split())))

M = 10**6 + 1

table = [1] * M

B = Counter(a)
Key = list(B.keys())

count = 0
for x in Key:
    if B[x] == 1 and table[x] == 1:
        count += 1

    for i in range(M):
        if i * x > M:
            break
        else:
            table[i * x] = 0

print(count)

from collections import Counter

N = int(input())
a = sorted(list(map(int, input().split())))

M = 10**6

table = [1] * (M + 1)

B = Counter(a)
Key = list(B.keys())

count = 0
for x in Key:
    if B[x] == 1 and table[x] == 1:
        count += 1

    for i in range(M):
        if i * x > M:
            break
        else:
            table[i * x] = 0

print(count)


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

A.sort()
A.append(-1)

x = A[0]
flag = True
for a in A:
    if a % x != 0:
        flag = False
if flag:
    print(0)
    exit()

used = [False] * A[-2]
ans = 0
for idx, a in enumerate(A):
    if used[a - 1]:
        continue
    if a != A[idx + 1]:
        ans += 1
    for j in range(a, len(used) + 1, a):
        used[j - 1] = True
print(ans)

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

A.sort()
A.append(-1)

x = A[0]
if x != 1:
    flag = True
    for a in A:
        if a % x != 0:
            flag = False
    if flag:
        print(0)
        exit()

used = [False] * A[-2]
ans = 0
for idx, a in enumerate(A[:-1]):
    if used[a - 1]:
        continue
    if a != A[idx + 1]:
        ans += 1
    for j in range(a, len(used) + 1, a):
        used[j - 1] = True
print(ans)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02642/Python/s321495509.py", line 21, in <module>
    if a != A[idx + 1]:
IndexError: list index out of range


import sys
from collections import deque

input = iter(sys.stdin.readlines()).__next__

R, C, K = [int(x) for x in input().split()]
X1, Y1, X2, Y2 = [int(x) - 1 for x in input().split()]  # 0 indexed

grid = [input().rstrip() for r in range(R)]

source = (X1, Y1)
q = deque([source])
dist = {source: 0}

def getNbr(node):
    r, c = node
    ret = []
    for dr, dc in [(0, 0), (-1, 0), (0, -1), (0, 1), (1, 0)]:
        for k in range(1, K + 1):
            nr = r + dr * k
            nc = c + dc * k
            if not (0 <= nr < R and 0 <= nc < C):
                break
            if grid[nr][nc] == "@":
                break
            ret.append((nr, nc))
    return ret

while q:
    node = q.popleft()
    d = dist[node]
    for nbr in getNbr(node):
        if nbr not in dist:
            q.append(nbr)
            dist[nbr] = d + 1

if False:
    for row in grid:
        print(row)
    print()
    for r in range(R):
        for c in range(C):
            print(dist.get((r, c), "?"), end=" ")
        print()

if (X2, Y2) in dist:
    print(dist[(X2, Y2)])
else:
    print(-1)

import sys
from collections import deque

input = iter(sys.stdin.readlines()).__next__

R, C, K = [int(x) for x in input().split()]
X1, Y1, X2, Y2 = [int(x) - 1 for x in input().split()]  # 0 indexed

grid = [input().rstrip() for r in range(R)]

source = (X1, Y1)
q = deque([source])
dist = {source: 0}

def getNbr(node, currDist):
    r, c = node
    ret = []
    for dr, dc in [(0, 0), (-1, 0), (0, -1), (0, 1), (1, 0)]:
        for k in range(1, K + 1):
            nr = r + dr * k
            nc = c + dc * k
            if not (0 <= nr < R and 0 <= nc < C):
                break
            if grid[nr][nc] == "@" or ((nr, nc) in dist and dist[(nr, nc)] <= d):
                break
            ret.append((nr, nc))
    return ret

while q:
    node = q.popleft()
    d = dist[node]
    for nbr in getNbr(node, d):
        if nbr not in dist:
            q.append(nbr)
            dist[nbr] = d + 1

if False:
    for row in grid:
        print(row)
    print()
    for r in range(R):
        for c in range(C):
            print(dist.get((r, c), "?"), end=" ")
        print()

if (X2, Y2) in dist:
    print(dist[(X2, Y2)])
else:
    print(-1)


Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02645/Python/s112750711.py", line 1, in <module>
    print(input().split().index("0") + 1)
ValueError: '0' is not in list


import sys
from itertools import accumulate

input = sys.stdin.readline

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    for _ in range(min(41, K)):
        A_cumsum = [0] * N
        for i in range(N):
            a = i - A[i]
            b = i + A[i] + 1
            if a < 0:
                A_cumsum[0] += 1
            else:
                A_cumsum[a] += 1
            if N - 1 < b:
                pass
            else:
                A_cumsum[b] -= 1
        A = list(accumulate(A_cumsum))

    print(" ".join(map(str, A)))

if __name__ == "__main__":
    main()

import sys

import numba as nb
import numpy as np

input = sys.stdin.readline

@nb.njit("i8[:](i8,i8,i8[:])", cache=True)
def solve(N, K, A):
    for _ in range(min(41, K)):
        A_cumsum = np.zeros(shape=N, dtype=np.int64)
        for i in range(N):
            A_cumsum[max(0, i - A[i])] += 1
            b = i + A[i] + 1
            if N - 1 < b:
                pass
            else:
                A_cumsum[b] -= 1
        A = np.cumsum(A_cumsum)
    return A

def main():
    N, K = map(int, input().split())
    A = np.array(input().split(), dtype=np.int64)

    ans = solve(N, K, A)

    print(" ".join(map(str, ans)))

if __name__ == "__main__":
    main()


from copy import deepcopy

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

for _ in range(k):
    if sum(As) == n * n:
        break
    As_next = [0] * n
    for i in range(n):
        for j in range(max(0, i - As[i]), min(n, i + As[i] + 1)):
            As_next[j] += 1
    As = deepcopy(As_next)

print(" ".join(map(str, As)))

from copy import deepcopy

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

for _ in range(k):
    if sum(As) == n * n:
        break
    Bs = [0] * n
    for i in range(n):
        l = max(0, i - As[i])
        r = min(n - 1, i + As[i])
        Bs[l] += 1
        if r + 1 < n:
            Bs[r + 1] -= 1
    for i in range(1, n):
        Bs[i] += Bs[i - 1]
    As = Bs

print(" ".join(map(str, As)))


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

for _ in range(k):
    b = [0] * (n + 2)
    for i in range(n):
        b[max(0, i - a[i])] += 1
        b[min(n + 1, i + a[i] + 1)] -= 1
    a[0] = b[0]
    cnt = 1 if a[0] == n else 0
    for i in range(1, n):
        a[i] = a[i - 1] + b[i]
        if a[i] == n:
            cnt += 1

    if cnt == n:
        break

print(*a)

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

for _ in range(k):
    b = [0] * (n + 2)
    for i in range(n):
        b[max(0, i - a[i])] += 1
        b[min(n + 1, i + a[i] + 1)] -= 1
    a[0] = b[0]
    cnt = a[0]
    for i in range(1, n):
        a[i] = a[i - 1] + b[i]
        cnt += a[i]

    # print(*a)
    if cnt == n**2:
        break

print(*a)


# 問題文の意味がわからんコンテスト
# 0の場合も自分自身を照らす、っての気づくところからやっと読解
# Kを5000兆回やったあとはすべての要素がNになっとる この収束はわりと早いらしい
n, k = map(int, input().split())
a = list(map(int, input().split()))

for _ in range(k):
    b = [0] * (n + 1)
    for i in range(n):
        b[max(0, i - a[i])] += 1
        b[min(n, i + a[i] + 1)] -= 1
    for i in range(n):
        b[i + 1] += b[i]
    a = b[:n]
    if b[-1] == n:
        break
print(" ".join(list(map(str, a))))

# 問題文の意味がわからんコンテスト
# 0の場合も自分自身を照らす、っての気づくところからやっと読解
# Kを5000兆回やったあとはすべての要素がNになっとる この収束はわりと早いらしい
n, k = map(int, input().split())
a = list(map(int, input().split()))

for _ in range(min(k, 100)):
    b = [0] * (n + 1)
    for i in range(n):
        b[max(0, i - a[i])] += 1
        b[min(n, i + a[i] + 1)] -= 1
    for i in range(n):
        b[i + 1] += b[i]
    a = b[:n]
print(" ".join(list(map(str, a))))


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

def query(lamps):
    start_list = []
    end_list = []
    for idx, power in enumerate(lamps):
        start, end = idx - power, idx + power
        start_list.append(start)
        end_list.append(end)

    counts = [0] * n
    start_list.sort(reverse=True)
    end_list.sort(reverse=True)

    now = 0
    for idx in range(n):
        while start_list and start_list[-1] <= idx:
            start_list.pop()
            now += 1

        while end_list and end_list[-1] < idx:
            end_list.pop()
            now -= 1

        counts[idx] = now

    return counts

def full_check(counts, full):
    for count in counts:
        if count == full:
            continue
        else:
            return False

    return True

for _ in range(k):
    A = query(A)
    if full_check(A, n):
        break

print(*A)

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

def query(lamps):
    start_list = []
    end_list = []
    for idx, power in enumerate(lamps):
        start, end = idx - power, idx + power
        start_list.append(start)
        end_list.append(end)

    start_list.sort(reverse=True)
    end_list.sort(reverse=True)

    now = 0
    for idx in range(n):
        while start_list and start_list[-1] <= idx:
            start_list.pop()
            now += 1

        while end_list and end_list[-1] < idx:
            end_list.pop()
            now -= 1

        lamps[idx] = now

def full_check(counts, full):
    for count in counts:
        if count == full:
            continue
        else:
            return False

    return True

for _ in range(k):
    query(A)
    if full_check(A, n):
        break

print(*A)