from heapq import heappush, heappushpop, heappop

N, K = map(int, input().split())
A = list(map(lambda x: -int(x), input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort()

hq = []
for a, f in zip(A, F):
    heappush(hq, (a * f, f))

c, f = heappop(hq)
while K > 0:
    c += f
    K -= 1
    c, f = heappushpop(hq, (c, f))

print(-c)

N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort(reverse=True)
F.sort()

C = [None] * N
for i, (a, f) in enumerate(zip(A, F)):
    C[i] = (a * f, f)

def solve(x):
    global K, N
    t = 0
    for c, f in C:
        temp = ((c - x) + f - 1) // f
        t += max(0, temp)
        if t > K:
            result = False
            break
    else:
        result = True
    return result

ok = A[0] * F[N - 1]
ng = -1
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if solve(mid):
        ok = mid
    else:
        ng = mid

print(ok)


#!/usr/bin/env python3

def is_ok(mid, K, A, F):
    used = 0
    for a, f in zip(A, F):
        upper = int(mid / f)
        if upper < a:
            used += a - upper
        if K < used:
            return False
    return True

def main():
    N, K = input_line(int, int)
    A = input_line([int])
    F = input_line([int])
    A.sort()
    F.sort(reverse=True)

    ng = -1
    ok = int(1e12)
    while ok - ng > 1:
        mid = (ng + ok) // 2
        if is_ok(mid, K, A, F):
            ok = mid
        else:
            ng = mid
    print(ok)

def input_line(*types):
    if isinstance(types[0], list):
        return list(map(types[0][0], input().split()))
    elif len(types) == 1:
        return types[0](input())
    else:
        return [t(x) for t, x in zip(types, input().split())]

if __name__ == "__main__":
    main()

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

def is_ok(mid, K, A, F):
    return np.maximum(A - mid // F, 0).sum() <= K

def main():
    N, K = input_line(int, int)
    A = input_line([int])
    F = input_line([int])
    A = np.array(sorted(A))
    F = np.array(sorted(F, reverse=True))

    ng = -1
    ok = int(1e12)
    while ok - ng > 1:
        mid = (ng + ok) // 2
        if is_ok(mid, K, A, F):
            ok = mid
        else:
            ng = mid
    print(ok)

def input_line(*types):
    if isinstance(types[0], list):
        return [types[0][0](x) for x in input().split()]
    elif len(types) == 1:
        return types[0](input())
    else:
        return [t(x) for t, x in zip(types, input().split())]

if __name__ == "__main__":
    main()


def is_ok(x, A, F):
    trainings = 0
    for i in range(N):
        t = A[i] - x // F[i]
        if t > 0:
            trainings += t
    return trainings <= K

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

A.sort()
F.sort(reverse=True)

ng = -1
ok = A[-1] * F[0]
while ok - ng > 1:
    m = ng + (ok - ng) // 2
    if is_ok(m, A, F):
        ok = m
    else:
        ng = m
print(ok)

def is_ok(x):
    trainings = 0
    for i in range(N):
        t = A[i] - x // F[i]
        if t > 0:
            trainings += t
    return trainings <= K

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

A.sort()
F.sort(reverse=True)

ng = -1
ok = A[-1] * F[0]
while ok - ng > 1:
    m = ng + (ok - ng) // 2
    if is_ok(m):
        ok = m
    else:
        ng = m
print(ok)


import sys

import numpy as np

n, m = map(int, input().split())
links = [[] for _ in range(n)]
for line in sys.stdin:
    s, t = map(int, line.split())
    s -= 1
    t -= 1
    links[s].append(t)

not_omitted = np.zeros(n, dtype=np.float64)
for j in range(n - 2, -1, -1):
    exp = not_omitted[links[j]]
    not_omitted[j] = exp.mean() + 1

ans = not_omitted[0]

for i in range(n - 1):
    expected = not_omitted.copy()

    exp = expected[links[i]]
    if exp.size == 1:
        expected[i] = exp.mean() + 1
    else:
        expected[i] = (exp.sum() - exp.max()) / (exp.size - 1) + 1

    for j in range(i - 1, -1, -1):
        exp = expected[links[j]]
        expected[j] = exp.mean() + 1

    ans = min(ans, expected[0])

print(ans)

import sys

n, m = map(int, input().split())
links = [set() for _ in range(n)]
counts = [0] * n
for line in sys.stdin:
    s, t = map(int, line.split())
    s -= 1
    t -= 1
    links[s].add(t)
    counts[s] += 1

not_omitted = [0.0] * n
exp_get = not_omitted.__getitem__
for j in range(n - 2, -1, -1):
    not_omitted[j] = sum(map(exp_get, links[j])) / counts[j] + 1

ans = 1e6

for i in range(n - 1):
    expected = [0.0] * n
    expected[i + 1 :] = not_omitted[i + 1 :]
    e_get = expected.__getitem__

    if counts[i] == 1:
        expected[i] = sum(map(e_get, links[i])) / counts[i] + 1
    else:
        exp = list(map(e_get, links[i]))
        expected[i] = (sum(exp) - max(exp)) / (counts[i] - 1) + 1

    for j in range(i - 1, -1, -1):
        expected[j] = sum(map(e_get, links[j])) / counts[j] + 1

    ans = min(ans, expected[0])

print(ans)


A = int(input())
B = int(input())

remain = max(0, A - B * 2)

print(remain)

data = input().split()
A = int(data[0])
B = int(data[1])

remain = max(0, A - B * 2)

print(remain)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02885/Python/s165633108.py", line 1, in <module>
    A = int(input())
ValueError: invalid literal for int() with base 10: '12 4'


a = int(input())
b = int(input())

if a > b * 2:
    print(a - b * 2)
else:
    print(0)

list = input().split()

a = int(list[0])
b = int(list[1])

if a > b * 2:
    print(a - b * 2)
else:
    print(0)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02885/Python/s894876689.py", line 1, in <module>
    a = int(input())
ValueError: invalid literal for int() with base 10: '12 4'


a = int(input())
b = int(input())

ans = a // (b * 2)

if ans <= 0:
    ans = 0

print(ans)

a, b = map(int, input().split())
ans = a - (b * 2)

if ans <= 0:
    ans = 0

print(ans)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02885/Python/s927098253.py", line 1, in <module>
    a = int(input())
ValueError: invalid literal for int() with base 10: '12 4'


N, *D = map(int, open(0).read().split())

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

print(ans)

from itertools import groupby

N = int(input())
S = input()

G = [len(tuple(v)) for k, v in groupby(S)]
print(len(G))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02887/Python/s984716346.py", line 1, in <module>
    N, *D = map(int, open(0).read().split())
ValueError: invalid literal for int() with base 10: 'aabbbbaaca'


#!/usr/bin/env python3
import sys
import re

def solve(N: int, S: str):
    result = 0
    for s in set(S):
        regex = re.compile(f"{s}+")
        # print(regex.findall(S))
        result += len(regex.findall(S))
    print(result)

    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == "__main__":
    main()

#!/usr/bin/env python3
import sys
import re

def solve(N: int, S: str):
    result = 0
    for s in set(S):
        regex = re.compile(s + "+")
        # print(regex.findall(S))
        result += len(regex.findall(S))
    print(result)

    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == "__main__":
    main()


N = int(input())
L = sorted(map(int, input().split()))
ans = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        for k in range(j + 1, N):
            if L[k] < L[i] + L[j]:
                ans += 1
print(ans)

import bisect

N = int(input())
L = sorted(map(int, input().split()))
ans = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        k = bisect.bisect_left(L, L[i] + L[j])
        if k > j:
            ans += k - j - 1
print(ans)


#!/usr/bin/env python3
import bisect

N = int(input().split()[0])
l_list = list(map(int, input().split()))
l_list = sorted(l_list)
p_list = []

for a_i, a in enumerate(l_list):
    for b_i, b in enumerate(l_list):
        if a_i == b_i:
            continue

        c_kouho = a + b
        c_i = bisect.bisect_left(l_list, c_kouho)
        p_list += [
            sorted([a, b, c])
            for c_i, c in enumerate(l_list[: c_i + 1])
            if c_i != a_i and c_i != b_i and abs(b - c) < a < b + c
        ]

p_list = ["{}_{}_{}".format(p[0], p[1], p[2]) for p in p_list]
ans = len(set(p_list))

print(ans)

#!/usr/bin/env python3
import bisect

N = int(input().split()[0])
l_list = list(map(int, input().split()))
l_list = sorted(l_list)
total = 0

for a_i, a in enumerate(l_list):
    # 一番長い辺を固定
    for b_i, b in enumerate(l_list[:a_i]):
        # 2番目に長い辺を固定
        c_i = bisect.bisect_right(l_list, abs(a - b))
        total += max(b_i - c_i, 0)

ans = total
print(ans)


n = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(n - 2):
    a = L[i]
    for j in range(i + 1, n - 1):
        b = L[j]
        for k in range(j + 1, n):
            c = L[k]
            if c >= a + b:
                break
            ans += 1
print(ans)

n = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(n - 2):
    a = L[i]
    k = i
    for j in range(i + 1, n - 1):
        b = L[j]
        while k < n and L[k] < a + b:
            k += 1
        ans += k - (j + 1)
print(ans)


from itertools import combinations

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

ans = 0
for a, b, c in combinations(L, 3):
    if c < a + b:
        ans += 1

print(ans)

from bisect import bisect_left, bisect_right

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

ans = 0
for i in range(N):
    for j in range(i + 1, N):
        ans += bisect_left(L, L[i] + L[j]) - j - 1

print(ans)


N = int(input())

L = list(sorted(map(int, input().split()), key=lambda x: -x))

ret = 0

def is_ok(a, b, c):
    return a < b + c and b < a + c and c < a + b

for i in range(N - 2):
    for j in range(i + 1, N - 1):
        p = j + 1
        q = N + 1
        while q - p > 2:
            k = (p + q) // 2
            if is_ok(L[i], L[j], L[k]):
                p = k
            else:
                q = k

        if is_ok(L[i], L[j], L[p]):
            ret += p - j

print(ret)

from bisect import bisect_left

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

res = 0

for i in range(N):
    for j in range(i + 1, N):
        k = bisect_left(L, L[i] + L[j])

        res += k - j - 1

print(res)


from sys import stdin

N = int(stdin.readline().rstrip())
L = [int(x) for x in stdin.readline().rstrip().split()]
ans = 0
L.sort()

for i in range(2, N):
    for j in range(1, i):
        for k in range(j):
            if L[j] + L[k] > L[i]:
                ans += 1

print(ans)

from sys import stdin
import bisect

N = int(stdin.readline().rstrip())
L = [int(x) for x in stdin.readline().rstrip().split()]
ans = 0
L.sort()
for i in range(1, N):
    for j in range(i):
        ans += max(bisect.bisect_left(L, L[i] + L[j]) - i - 1, 0)

print(ans)


N = int(input())
L = list(map(int, input().split()))
L.sort()
cnt = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        left = j
        right = N
        v = L[i] + L[j]
        while right - left > 1:
            mid = (left + right) // 2
            if L[mid] < v:
                left = mid
            else:
                right = mid
        cnt += left - j
print(cnt)

import bisect

N = int(input())
L = sorted(list(map(int, input().split())))
cnt = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        a = L[i]
        b = L[j]
        v = bisect.bisect_left(L, a + b)
        cnt += v - j - 1
print(cnt)


import bisect

N = int(input())
L = list(map(int, input().split()))
assert len(L) == N

L.sort()

n = 0

# Choose two edges
for i in range(N):
    for j in range(i + 1, N):
        a = L[i] + L[j]
        k = bisect.bisect_left(L, a, lo=j + 1)
        #   assert all(v < a for v in L[:k]) and all(v >= a for v in L[k:])
        # the number of candidates of the third edge
        n += k - (j + 1)

print(n)


import collections

N = int(input())
L = [int(i) for i in input().split()]
c = collections.Counter(L)

ans = 0
for i in c:
    for j in c:
        for k in c:
            if i + j <= k or j + k <= i or k + i <= j or i > j or j > k:
                continue
            if i == j and j == k:
                ans += c[i] * (c[i] - 1) * (c[i] - 2) / 6
            elif i == j:
                ans += c[k] * c[i] * (c[i] - 1) / 2
            elif j == k:
                ans += c[i] * c[j] * (c[j] - 1) / 2
            elif i == k:
                ans += c[j] * c[i] * (c[i] - 1) / 2
            else:
                ans += c[i] * c[j] * c[k]
print(int(ans))

import collections

N = int(input())
L = [int(i) for i in input().split()]
M = max(L)
c = collections.Counter(L)
li = [c[i] for i in range(M + 1)]

ans = 0
for i in range(1, M + 1):
    for j in range(i, M + 1):
        if i == j:
            ans += int(li[i] * (li[i] - 1) * (li[i] - 2) / 6)
            ans += int(sum(li[j + 1 : min(M + 1, i + j)]) * li[i] * (li[i] - 1) / 2)
        else:
            ans += int(li[i] * li[j] * (li[j] - 1) / 2)
            ans += li[i] * li[j] * sum(li[j + 1 : min(M + 1, i + j)])
print(int(ans))


N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        for k in range(j + 1, N):
            if L[i] + L[j] <= L[k]:
                break
            ans += 1
print(ans)

import bisect

N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        index = bisect.bisect_left(L, L[i] + L[j])
        ans += max(0, index - j - 1)
print(ans)


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

Ls.sort()
S = 0
for i in range(N - 2):
    A = Ls[i]
    for j in range(i + 1, N - 1):
        B = Ls[j]
        for k in range(j + 1, N):
            C = Ls[k]
            if A + B <= C:
                break
            else:
                S += 1
print(S)

import bisect

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

Ls.sort()
S = 0
for i in range(N - 2):
    A = Ls[i]
    for j in range(i + 1, N - 1):
        B = Ls[j]
        k = bisect.bisect_left(Ls, A + B, j + 1)
        S += k - j - 1
print(S)


n = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(n - 2):
    a = L[i]
    for j in range(i + 1, n - 1):
        b = L[j]
        for k in range(j + 1, n):
            c = L[k]
            if c < a + b:
                ans += 1
            else:
                break
print(ans)

import bisect

n = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(n - 2):
    a = L[i]
    for j in range(i + 1, n - 1):
        b = L[j]
        k = bisect.bisect_left(L[j + 1 :], a + b)
        ans += k
print(ans)


from bisect import bisect_left
from functools import lru_cache

n = int(input())
lll = list(map(int, input().split()))
lll.sort()
ans = 0

@lru_cache()
def bisect_left_cache(x):
    return bisect_left(lll, x)

for i in range(n - 2):
    li = lll[i]
    for j in range(i + 1, n - 1):
        k = bisect_left_cache(li + lll[j])
        ans += k - j - 1
print(ans)

from bisect import bisect_left

n = int(input())
lll = list(map(int, input().split()))
lll.sort()
ans = 0

def get_bisect_left():
    cache = {}

    def _f(x):
        if x in cache:
            return cache[x]
        cache[x] = bisect_left(lll, x)
        return cache[x]

    return _f

bisect_left_cache = get_bisect_left()

for i in range(n - 2):
    li = lll[i]
    for j in range(i + 1, n - 1):
        k = bisect_left_cache(li + lll[j])
        ans += k - j - 1
print(ans)


import itertools

def main():
    _ = int(input())
    L = list(map(int, input().split()))

    comb = itertools.combinations(L, 3)

    ans = 0
    dp = []
    for v in comb:
        if dp.__contains__(sum(v)):
            ans += 1
        elif v[0] < v[1] + v[2] and v[1] < v[2] + v[0] and v[2] < v[0] + v[1]:
            ans += 1
            dp.append(sum(v))

    print(ans)

if __name__ == "__main__":
    main()

import bisect

def main():
    N = int(input())
    L = list(map(int, input().split()))
    L.sort()

    ans = 0
    for i in range(N - 2):
        for j in range(i + 1, N - 1):
            index = bisect.bisect_left(L, L[i] + L[j]) - j - 1
            ans += index

    print(ans)

if __name__ == "__main__":
    main()


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

ans = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        for k in range(j + 1, n):
            if li[i] < li[j] + li[k] and li[j] < li[k] + li[i] and li[k] < li[i] + li[j]:
                # print(li[i], li[j], li[k])
                ans += 1

print(ans)

import bisect

n = int(input())
li = sorted(list(map(int, input().split())))
ans = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        ans += bisect.bisect_left(li, li[i] + li[j]) - j - 1
print(ans)


N = int(input())
L = sorted(list(map(int, input().split())))
ans = 0
for i in range(N):
    for j in range(i + 1, N):
        for k in range(j + 1, N):
            if L[i] < L[j] + L[k] and L[j] < L[k] + L[i] and L[k] < L[i] + L[j]:
                ans += 1
print(ans)

from bisect import bisect_left

n = int(input())
l = sorted(list(map(int, input().split())))
ans = 0

# a<b<c として、aとbを固定する
# 残る条件は c<a+b のみ
# aとbの固定方法がO(N^2), cの二分探索がO(logN)、結局O(N^2logN)
# 二分探索は事前にソートが必要

# ex. 2, 4(a), 4, 7(b), | 8, 9, 9 | (ここにa+b=11が挿入される), 12, 14
# cとして適切なのは8,9,9の3通り
# bisect_rightだとa+bが存在した時にバグる

for ai in range(n):
    for bi in range(ai + 1, n):
        ans += bisect_left(l, l[ai] + l[bi]) - bi - 1
print(ans)


import sys
from io import StringIO
import unittest
import os

# 検索用タグ、尺取り、3つの内2つを固定
# https://drken1215.hatenablog.com/entry/2019/10/20/032700

# 実装を行う関数
def resolve():
    n = int(input())
    ls = list(map(int, input().split()))

    ls.sort()

    ans = 0
    # 尺取り
    for i in range(n - 2):
        a = ls[i]
        for j in range(i + 1, n - 1, 1):
            b = ls[j]
            for k in range(j + 1, n, 1):
                c = ls[k]
                if not c < a + b:
                    break
                ans += 1

    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.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
3 4 2 1"""
        output = """1"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """3
1 1000 1"""
        output = """0"""
        self.assertIO(test_input, output)

    def test_input_3(self):
        test_input = """7
218 786 704 233 645 728 389"""
        output = """23"""
        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
import bisect

# 検索用タグ、尺取り、3つの内2つを固定
# https://drken1215.hatenablog.com/entry/2019/10/20/032700

# 実装を行う関数
def resolve():
    n = int(input())
    ls = list(map(int, input().split()))

    ls.sort()

    ans = 0
    # 尺取り
    for i in range(n - 2):
        a = ls[i]
        for j in range(i + 1, n - 1, 1):
            b = ls[j]
            # 以下がサンプル通りだが、TLE。
            # for k in range(j + 1, n, 1):
            #     c = ls[k]
            #     if not c < a + b:
            #         break
            #     ans += 1
            cnt = bisect.bisect_left(ls, a + b, j)
            ans += cnt - j - 1

    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.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
3 4 2 1"""
        output = """1"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """3
1 1000 1"""
        output = """0"""
        self.assertIO(test_input, output)

    def test_input_3(self):
        test_input = """7
218 786 704 233 645 728 389"""
        output = """23"""
        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()


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

# input
N = int(input())
L = list(map(int, input().split()))

# solve
ans = 0
L.sort()
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        for k in range(j + 1, N):
            if L[k] < L[j] + L[i]:
                ans += 1

# output
print(ans)

# -*- coding: utf-8 -*-
import bisect

# input
N = int(input())
L = list(map(int, input().split()))

# solve
ans = 0
L.sort()
for i in range(N):
    for j in range(i + 1, N):
        r = bisect.bisect_left(L, L[i] + L[j])
        l = j + 1
        ans += max(0, r - l)

# output
print(ans)


from collections import Counter
from copy import deepcopy

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

for k in range(1, n + 1):
    cx = deepcopy(c)

    count = 0

    while k <= len(cx):
        # print(cx)
        mc = cx.most_common()
        for key, _ in mc[:k]:
            cx[key] -= 1
            if cx[key] < 1:
                del cx[key]
        count += 1

    print(count)

from collections import Counter
from itertools import accumulate

# from copy import deepcopy

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

# for k in range(1, n + 1):
#     cx = deepcopy(c)

#     count = 0

#     while k <= len(cx):
#         # print(cx)
#         mc = cx.most_common()
#         for key, _ in mc[:k]:
#             cx[key] -= 1
#             if cx[key] < 1:
#                 del cx[key]
#         count += 1

#     print(count)

cv = Counter(c.values())
max_take = max(cv.keys())

lx = list(accumulate(cv[i] for i in range(max_take + 1)))
rx = list(accumulate(cv[i] * i for i in range(max_take + 1)))
ax = [rx[i] + (lx[-1] - lx[i]) * i for i in range(max_take + 1)]

def bisec(l0, r0, predicate):
    l, r = l0, r0

    while abs(l - r) > 1:
        mid = (l + r) // 2
        if predicate(mid):
            r = mid
        else:
            l = mid

    return r

for k in range(1, n + 1):
    print(bisec(n + 1, 0, lambda x: x * k <= ax[min(x, max_take)]))


from itertools import groupby

s = input()
k = int(input())
a = [sum(1 for _ in g) for _, g in groupby(s)]
if s[0] == s[-1]:
    a[0] += a.pop()
print(sum(x // 2 for x in a) * k)

from itertools import groupby

s = input()
k = int(input())
a = [sum(1 for _ in g) for _, g in groupby(s)]
if len(a) == 1:
    print(len(s) * k // 2)
else:
    x, y = a[0], a[-1]
    b = (x + y) // 2 if s[0] == s[-1] else x // 2 + y // 2
    print(x // 2 + y // 2 + sum(x // 2 for x in a[1:-1]) * k + b * (k - 1))


S = input()
N = len(S)
K = int(input())

i = 0
T = []
U = []
while i <= N - 1:
    if i == N - 1:
        T.append(S[-1])
        if S[-2] == S[-1]:
            U.append("?")
        else:
            U.append(S[-1])
        break
    if S[i] == S[i + 1]:
        T.append(S[i] + "?")
        U.append("?" + S[i])
        i += 2
    else:
        T.append(S[i])
        U.append(S[i])
        i += 1

T = "".join(T)
U = "".join(U)
if T[0] == T[-1]:
    print((K + 1) // 2 * T.count("?") + K // 2 * U.count("?"))
else:
    print(K * T.count("?"))

def run_length_compress(S):
    res = [[S[0], 1]]
    for c in S[1:]:
        if c == res[-1][0]:
            res[-1][1] += 1
        else:
            res.append([c, 1])
    return res

S = input()
N = len(S)
K = int(input())
T = run_length_compress(S)
if T[0][1] == N:
    print(N * K // 2)
    exit()
ans = sum(l // 2 for _, l in T) * K
if T[0][0] == T[-1][0]:
    head, tail = T[0][1], T[-1][1]
    ans += ((head + tail) // 2 - head // 2 - tail // 2) * (K - 1)
print(ans)


def main():
    S = input()
    K = int(input())
    ans = 0

    if S[0] is S[-1]:
        length = len(S)
    else:
        length = len(S) - 1

    i = 0
    while i < length:
        if S[i] is S[i + 1]:
            ans += 1
            i += 1
        i += 1

    print(ans * K)

if __name__ == "__main__":
    main()

def main():
    S = input()
    K = int(input())
    ans = 0

    if len(set(S)) is 1:
        print(len(S) * K // 2)
        return

    i = 0
    cnt = [1]
    while i < len(S) - 1:
        if S[i] is S[i + 1]:
            cnt[-1] += 1
        else:
            cnt.append(1)
        i += 1

    for v in cnt:
        ans += (v // 2) * K

    if S[0] is S[-1]:
        if cnt[0] % 2 == cnt[-1] % 2 == 1:
            ans += K - 1

    print(ans)

if __name__ == "__main__":
    main()


S = input()
K = int(input())

print(S * K)

X = []
b = S[0]
cnt = 1
for i in range(1, len(S)):
    s = S[i]
    if b == s:
        cnt += 1
    else:
        X.append([b, cnt])
        cnt = 1
        b = s
X.append([b, cnt])

result = 0
for x in X:
    result += x[1] // 2

result = result * K
if X[0][0] == X[-1][0]:
    result += 1
print(result)

S = input()
K = int(input())

X = []
b = S[0]
cnt = 1
for i in range(1, len(S)):
    s = S[i]
    if b == s:
        cnt += 1
    else:
        X.append([b, cnt])
        cnt = 1
        b = s
X.append([b, cnt])

result = 0
if len(X) == 1:
    print(X[0][1] * K // 2)
elif X[0][0] == X[-1][0]:
    s = X.pop(0)
    e = X.pop()
    for x in X:
        result += x[1] // 2
    result *= K

    result += s[1] // 2
    result += e[1] // 2
    x = (s[1] + e[1]) // 2
    result += x * (K - 1)
    print(result)
else:
    for x in X:
        result += x[1] // 2
    result *= K
    print(result)


n = int(input())
s = []
for _ in range(n):
    s.append(input())
check = []
testc = 1000
for i in range(n):
    test = 0
    for c in s[i]:
        test += int(c)
    if test == testc:
        check.append(i)
    elif test < testc:
        check.clear()
        testc = test
        check.append(i)

res = -1
if testc > 1:
    check = check[0]

for i in check:
    tres = 1
    flag = [-2 for i in range(n)]

    flag[i] = 1
    que = [i]
    while que:
        target = que.pop()
        for j in range(n):
            if s[target][j] == "1":
                if flag[j] == -2:
                    flag[j] = flag[target] + 1
                    que.append(j)
                elif flag[j] != flag[target] + 1 and flag[j] != flag[target] - 1:
                    tres = -1
                    break
        if tres == -1:
            break

    if tres == -1:
        continue
    else:
        res = max(res, max(flag))

print(res)

import collections

n = int(input())
s = []
for _ in range(n):
    ch = input()
    s.append([int(c) for c in ch])

def graph(i, n, s):
    flag = [-2 for _ in range(n)]
    flag[i] = 1
    que = collections.deque([i])
    while que:
        target = que.popleft()
        for j in range(n):
            if s[target][j] == 1:
                if flag[j] == -2:
                    flag[j] = flag[target] + 1
                    que.append(j)
                elif flag[j] != flag[target] + 1 and flag[j] != flag[target] - 1:
                    return [-1, -1]
    mf = max(flag)
    return [flag.index(mf), mf]

r1 = graph(0, n, s)
if r1[0] == -1:
    print(-1)
else:
    res = r1[1]
    for i in range(1, n):
        r = graph(i, n, s)
        res = max(res, r[1])
    print(res)


N = int(input())
nums = filter(lambda x: x % 2 != 0, range(1, N + 1))
print(len(nums) / float(N))

N = int(input())
odds = list(filter(lambda x: x % 2 != 0, range(1, N + 1)))
print("{:.10f}".format(len(odds) / float(N)))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02897/Python/s177857539.py", line 3, in <module>
    print(len(nums) / float(N))
TypeError: object of type 'filter' has no len()


if int(input()) == 1:
    print(1)
elif int(input()) % 2 == 0:
    print(0.5)
else:
    print(0.6)

x = int(input())
if x == 1:
    print(1)
elif x % 2 == 0:
    print(0.5)
else:
    print((x // 2 + 1) / x)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02897/Python/s963162599.py", line 3, in <module>
    elif int(input()) % 2 == 0:
EOFError: EOF when reading a line


N = int(input())

if N % 2 == 0:
    print((N / 2) / N)

else:
    print(((N + 1) / 2) / N)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02897/Python/s639132796.py", line 3, in <module>
    if N % 2 == 0:
TypeError: not all arguments converted during string formatting


n = input()

a = int(n / 2)
b = n % 2

c = a + b

print(c)

n = int(input())

a = int(n / 2)
b = n % 2

c = a + b

print(c / n)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02897/Python/s076405761.py", line 3, in <module>
    a = int(n / 2)
TypeError: unsupported operand type(s) for /: 'str' and 'int'


n, k = map(int, input().split())
H = list(map(int, input().split()))
cnt = 0
for i in n:
    if H[i] >= k:
        cnt += 1
print(cnt)

n, k = map(int, input().split())
H = list(map(int, input().split()))
cnt = 0
for i in range(n):
    if H[i] >= k:
        cnt += 1
print(cnt)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02898/Python/s127858228.py", line 4, in <module>
    for i in n:
TypeError: 'int' object is not iterable


N = int(input())
K = int(input())
h = []
a = 0
for i in range(N):
    b = int(input())
    h.append(b)
    if h[i] >= K:
        a += 1
print(a)

NK_lis = list(map(int, input().split()))
h_lis = list(map(int, input().split()))
a = 0
for i in range(NK_lis[0]):
    if h_lis[i] >= NK_lis[1]:
        a += 1
print(a)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02898/Python/s286734935.py", line 1, in <module>
    N = int(input())
ValueError: invalid literal for int() with base 10: '4 150'


n, k = map(int, input().split())
a = list(map(int, input().split()))
i = 0
ans = 0
while i < n:
    if a[i] >= k:
        ans += 1
        i += 1
print(ans)

n, k = map(int, input().split())
h = list(map(int, input().split()))
i = 0
ans = 0
for i in range(n):
    if h[i] >= k:
        ans += 1
print(ans)


n = int(input())
min_height = int(input())

height = []
for _ in range(n):
    height.append(int(input()))
height.sort(reverse=True)

cnt = 0
for h in height:
    if h < min_height:
        break
    cnt += 1
print(cnt)

n, min_height = map(int, input().split())
height = list(map(int, input().split()))
height.sort(reverse=True)

cnt = 0
for h in height:
    if h < min_height:
        break
    cnt += 1
print(cnt)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02898/Python/s709157737.py", line 1, in <module>
    n = int(input())
ValueError: invalid literal for int() with base 10: '4 150'


n, k = map(int, input().split())
h = list(map(int, input().split()))
print(len(filter(lambda x: x >= k, h)))

n, k = map(int, input().split())
h = list(map(int, input().split()))
print(len(list(filter(lambda x: x >= k, h))))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02898/Python/s747999474.py", line 3, in <module>
    print(len(filter(lambda x: x >= k, h)))
TypeError: object of type 'filter' has no len()


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

count = 0
for i in range(N):
    if ar[i] >= K:
        count += 1

print(count)

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

count = 0
for i in range(N):
    if ar[i] >= K:
        count += 1

print(count)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02898/Python/s440277663.py", line 2, in <module>
    ar = list(map, input().split())
TypeError: list expected at most 1 argument, got 2


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

count = 0
for i in h:
    if i >= K:
        count += 1

print(count)

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

count = 0
for i in h:
    if i >= K:
        count += 1

print(count)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02898/Python/s129159641.py", line 1, in <module>
    N = int(input())
ValueError: invalid literal for int() with base 10: '4 150'


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

order = [0] * N
flag = 0
for i in range(0, N):
    flag = A.index(min(A))
    order[i] = flag + 1
    A[flag] = N + 1

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

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

lis = []
for i in range(N):
    lis.append([A[i], i + 1])

lis.sort()
ans = []
for i in range(N):
    ans.append(lis[i][1])

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


n = int(input())
a = list(map(int, input().split()))
x = []
x = [0 for i in range(n)]
for j in range(n):
    x.pop(a[j] - 1)
    x.insert(a[j] - 1, j + 1)
print(" ".join(map(str, x)))

n = int(input())
a = list(map(int, input().split()))
x = []
for i in range(n):
    x.append((a[i], i + 1))
x.sort()
y = []
for i in range(n):
    y.append(x[i][1])
print(" ".join(map(str, y)))


# #!/usr/bin/env python3
# # -*- coding: utf-8 -*-

def main():
    N = int(input())
    S = list(map(int, input().split()))
    print(*[S.index(i + 1) + 1 for i in range(N)])

if __name__ == "__main__":
    main()

# #!/usr/bin/env python3
# # -*- coding: utf-8 -*-

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

    result = []
    for i, a in enumerate(A, start=1):
        result.append([i, a])
    result = sorted(result, key=lambda x: x[1])

    print(*[i for i, a in result])

if __name__ == "__main__":
    main()


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

    for v in range(1, N + 1):
        print(A.index(v) + 1, end=" ")

    print()

if __name__ == "__main__":
    main()

def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans_list = [None for _ in range(N)]

    for i in range(N):
        ans_list[A[i] - 1] = i

    for v in ans_list:
        print(v + 1, end=" ")

    print()

if __name__ == "__main__":
    main()


n = int(input())
a = list(map(int, input().split()))
ans = [str(a.index(i + 1) + 1) for i in range(n)]
print(" ".join(ans))

# https://atcoder.jp/contests/abc142/tasks/abc142_c
n = int(input())
a = list(map(int, input().split()))
#### TLE ####
# ans = [str(a.index(i + 1) + 1) for i in range(n)]
# print(" ".join(ans))

b = [" "] * n
for i in range(n):
    b[a[i] - 1] = str(i + 1)

print(" ".join(b))


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

for i in range(1, n + 1):
    print(a.index(i) + 1)

n = int(input())
a = list(map(int, input().split()))
output = [0] * n
for i, a in enumerate(a):
    output[a - 1] = i + 1

print(*output)


import numpy as np

N = int(input())
A = list(map(int, input().split()))
T = [0] * N
for i in range(N):
    t = np.argmin(A)
    T[i] = t + 1
    A[t] = N + 1
print(*T)

import numpy as np

N = int(input())
A = list(map(int, input().split()))
T = [0] * N
for i in range(N):
    T[A[i] - 1] = i + 1
print(*T)


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

ans = [0] * len(A)

for i in A:
    ans[i - 1] = A.index(i) + 1

print(*ans)

N = int(input())
A = list(map(int, input().split()))
ans = [0] * N

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

print(*ans)


import numpy as np

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

AA = np.argsort(A) + 1

print(AA.to_list())

import numpy as np

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

AA = np.argsort(A) + 1

print(*AA)


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

ans = []
for i in range(1, N + 1):
    ans.append(A.index(i) + 1)

print(*ans)

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

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

print(*ans)


def resolve():
    N = int(input())
    A = [int(i) for i in input().split()]
    for i in range(N):
        if i > 0:
            print(" ", end="")
        print(A.index(i + 1) + 1, end="")
    print()

resolve()

def resolve():
    N = int(input())
    A = [int(i) for i in input().split()]
    ans = [0] * N
    for i in range(N):
        ans[A[i] - 1] = i + 1
    print(*ans)

resolve()


n = input()
a = input().split()

result = []

for i in range(len(a)):
    result.append(a.index(str(i + 1)) + 1)

print(*result)

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

ans = [0] * n

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

print(*ans)


N = int(input())
A = list(map(list, input().split()))
for i in range(N):
    A[i].append(i + 1)  # 出席番号をそれぞれ追加している
A = sorted(A)  # 人数でソート
ans = []
for ai in range(N):
    ans.append(A[ai][1])  # 人数順に出席番号で出力
print(" ".join(map(str, ans)))

N = int(input())
A = list(map(int, input().split()))
B = []
for i in range(N):
    B.append([A[i]])
    B[i].append(i + 1)  # 出席番号をそれぞれ追加している
B = sorted(B)  # 人数でソート
ans = []
for ai in range(N):
    ans.append(B[ai][1])  # 人数順に出席番号で出力
print(" ".join(map(str, ans)))


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

B_i = []

for i in range(1, N + 1):
    B_i.append(str(A_i.index(i) + 1))

print(" ".join(B_i))

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

B_i = [0 for s in range(N)]

for i in range(1, N + 1):
    B_i[A_i[i - 1] - 1] = str(i)

print(" ".join(B_i))


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

d = {}
for a in A:
    d[A.index(a) + 1] = a

ans = [str(k) for k, _ in sorted(d.items(), key=lambda x: x[1])]
print(" ".join(ans))

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

d = dict(zip(range(N), A))

ans = [str(k + 1) for k, _ in sorted(d.items(), key=lambda x: x[1])]
print(" ".join(ans))


n = int(input())
a = list(map(int, input().split()))
out = [""] * n
count = 0
out_str = ""
for i in range(n):
    out_str += str(a.index(i + 1) + 1) + " "

print(out_str[:-1])

n = int(input())
a = list(map(int, input().split()))
out = [""] * n
out_str = ""
for i in range(n):
    out[a[i] - 1] = str(i + 1)

out_str = " ".join(out)

print(out_str)


n = int(input())
a = list(map(int, input().split()))
b = [None] * n
print(str(a.index(1) + 1), end=" ")
for i in range(1, n):
    print(str(a.index(i + 1) + 1), end=" ")
print()

import sys
import collections
import bisect

def main():
    n = int(input())
    A = list(map(int, input().split()))
    B = [0] * n
    for i in range(n):
        B[A[i] - 1] = str(i + 1)
    print(" ".join(B))

if __name__ == "__main__":
    main()


import sys

def main():
    n = int(input())
    a = [int(i) for i in sys.stdin.readline().split()]
    ans = []
    ans_append = ans.append
    for i in range(n):
        ans_append(a.index(i + 1) + 1)
    print(*ans)

if __name__ == "__main__":
    main()

import sys

def main():
    n = int(input())
    a = [int(i) for i in sys.stdin.readline().split()]
    ans = [0] * n
    for i in range(n):
        ans[a[i] - 1] = i + 1
    print(*ans)

if __name__ == "__main__":
    main()


aa, bb = map(int, input().split())
A = max(aa, bb)
B = min(aa, bb)

def get_max(a, b):
    while True:
        c = a % b
        if c == 0:
            return b
        a = b
        b = c

B = get_max(A, B)

temp = []
for i in range(1, B + 1):
    if B % i == 0:
        temp.append(i)

flag = [0] * len(temp)
count = len(temp)
for i in range(0, len(temp)):
    for j in range(i + 1, len(temp)):
        if flag[j] == 0:
            max_ = get_max(temp[i], temp[j])
            if max_ != 1:
                flag[j] = 1
                count -= 1

print(count)

aa, bb = map(int, input().split())
A = max(aa, bb)
B = min(aa, bb)

def get_max(a, b):
    while True:
        c = a % b
        if c == 0:
            return b
        a = b
        b = c

def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

B = get_max(A, B)
factors = factorize(B)

if len(factors) == 0:
    print(1)
else:
    count = 1
    for i in range(0, len(factors) - 1):
        if factors[i] != factors[i + 1]:
            count += 1
    print(count + 1)


import fractions
import sys

input = sys.stdin.readline

def factorization(n):
    primes = []
    while n % 2 == 0:
        n //= 2
        primes.append(2)
    for i in range(3, n + 1, 2):
        while n % i == 0:
            n //= i
            primes.append(i)
        if n == 1:
            break
    return primes

def main():
    a, b = list(map(int, input().split()))

    # 素因数分解
    g = fractions.gcd(a, b)
    print(len(set(factorization(g))) + 1)

if __name__ == "__main__":
    main()

import fractions
import sys

input = sys.stdin.readline

def factorization(n):
    primes = []
    while n % 2 == 0:
        primes.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            primes.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        primes.append(n)
    return primes

def main():
    a, b = list(map(int, input().split()))

    # 素因数分解
    g = fractions.gcd(a, b)
    print(len(set(factorization(g))) + 1)

if __name__ == "__main__":
    main()


import numpy as np

def is_prime(n):
    return n != 1 and not np.any(n % np.arange(2, n) == 0)

A, B = [int(x) for x in input().split()]

N = np.arange(1, min(A, B) + 1)

cd = np.argwhere((A % N == 0) & (B % N == 0)).ravel() + 1
primes = [n for n in cd if is_prime(n)]

print(len(primes) + 1)

from fractions import gcd

def prime_factors(n):
    i = 2

    factors = []

    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)

    return factors

A, B = [int(x) for x in input().split()]

print(len(set(prime_factors(gcd(A, B)))) + 1)


# D - Disjoint Set of Common Divisors

import math

A, B = map(int, input().split())
C = math.gcd(A, B)

primes = []
i = 2
while i * i <= C:
    while C % i == 0:
        C //= i
        primes.append(i)
    i += 1
if C > 1:
    primes.append(C)

print(len(set(primes)) + 1)

# D - Disjoint Set of Common Divisors

import fractions

A, B = map(int, input().split())
C = fractions.gcd(A, B)

primes = []
i = 2
while i * i <= C:
    while C % i == 0:
        C //= i
        primes.append(i)
    i += 1
if C > 1:
    primes.append(C)

print(len(set(primes)) + 1)


from sys import stdin

a, b = [int(x) for x in stdin.readline().split()]

while b != 0:
    a, b = b, a % b

c = 1
lim = a // 2
n = 0
i = 2
while a > 1 and i <= lim:
    n = 0
    while a % i == 0:
        a //= i
        n += 1
    if n > 0:
        c += 1
    i += 1
if a > 1:
    c += 1

print(c)

from sys import stdin

a, b = [int(x) for x in stdin.readline().split()]

while b != 0:
    a, b = b, a % b

c = 1
lim = a**0.5 + 10
n = 0
i = 2
while a > 1 and i <= lim:
    n = 0
    while a % i == 0:
        a //= i
        n += 1
    if n > 0:
        c += 1
    i += 1
if a > 1:
    c += 1

print(c)


from sys import stdin
import fractions

A, B = [int(x) for x in stdin.readline().rstrip().split()]
gcd = fractions.gcd(A, B)

x = 2
ans = 1
g = 1

while gcd > 1:
    if gcd % x == 0:
        gcd //= x
        if g != x:
            ans += 1
        g = x
    else:
        x += 1

print(ans)

from sys import stdin
import fractions

A, B = [int(x) for x in stdin.readline().rstrip().split()]
gcd = fractions.gcd(A, B)
C = []
y = 1
while y**2 <= gcd:
    if gcd % y == 0:
        if y >= 2:
            C.append(y)
        if y**2 != gcd:
            C.append(gcd // y)
    y += 1

ans = 1
g = 1
C.sort()
for c in C:
    while gcd % c == 0:
        gcd //= c
        if g != c:
            ans += 1
        g = c

print(ans)


def make_divisors(n):
    divisors = []
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    return divisors

def furui(data):
    for d in data:
        data = [x for x in data if (x == d or x % d != 0)]
    return data

a, b = map(int, input().split())
# a, b = 100000000000000, 1000000000000000
a = make_divisors(a)
a = furui(a)
b = make_divisors(b)
b = furui(b)
print(len(set(a) & set(b)) + 1)

from collections import defaultdict

A, B = map(int, input().split())

def gcd(a, b):
    return a if b == 0 else gcd(b, a % b)

d = gcd(A, B)
# print(d)

def f(v):
    dic = defaultdict(int)
    if v == 1:
        dic[1] = 1
        return dic
    for i in range(2, v):
        if i * i > v:
            break
        while v % i == 0:
            v //= i
            dic[i] += 1
    if v != 1:
        dic[v] += 1
    dic[1] = 1
    return dic

divisor = f(d)
# print(divisor)
print(len(divisor))


from fractions import gcd

A, B = map(int, input().split())

d = gcd(A, B)
ans = 1
k = 2
while d > 2:
    plus = 0
    while d % k == 0:
        d //= k
        plus = 1
    ans += plus
    k += 1
print(ans)

from fractions import gcd

A, B = map(int, input().split())

d = gcd(A, B)
d_ori = d
ans = 1
k = 2
while d > 2:
    plus = 0
    while d % k == 0:
        d //= k
        plus = 1
    ans += plus
    k += 1
    if k > d_ori ** (1 / 2):
        ans += 1
        break
print(ans)


import math

A, B = map(int, input().split())

N = math.gcd(A, B)
primes = []
if N % 2 == 0:
    primes.append(2)
for i in range(3, int(math.sqrt(N)) + 2, 2):
    if N % i == 0:
        for p in primes:
            if i % p == 0:
                break
        else:
            primes.append(i)
print(len(primes) + 1)

import math

A, B = map(int, input().split())

while B > 0:
    A, B = B, A % B
N = A

ans = 1
for i in [2] + list(range(3, int(math.sqrt(N)) + 2, 2)):
    if N % i == 0:
        while N % i == 0:
            N //= i
        ans += 1
if N > 1:
    ans += 1
print(ans)


from math import gcd

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

A, B = tuple(map(int, input().split(" ")))

print(len(set(prime_factorize(gcd(A, B)))) + 1)

from fractions import gcd

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

A, B = tuple(map(int, input().split(" ")))

print(len(set(prime_factorize(gcd(A, B)))) + 1)


def gcd(g1, g2):
    x = min(g1, g2)
    y = max(g1, g2)

    if y % x == 0:
        return x
    else:
        return gcd(x, y % x)

def prime_factorize(n):
    p = []
    while n % 2 == 0:
        if 2 not in p:
            p.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            if f not in p:
                p.append(f)
                n //= f
        else:
            f += 2
    if n != 1 and n not in p:
        p.append(n)
    return p

a, b = map(int, input().split())
q = prime_factorize(gcd(a, b))
# print(q)
print(len(q) + 1)

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

def prime_factorize(n):
    p = []
    while n % 2 == 0:
        if 2 not in p:
            p.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            if f not in p:
                p.append(f)
            n //= f
        else:
            f += 2
    if n != 1 and n not in p:
        p.append(n)
    return p

a, b = map(int, input().split())
q = prime_factorize(gcd(a, b))
# print(q)
print(len(q) + 1)


import math

d = math.gcd(*map(int, input().split()))
r = 1
i = 2
while i * i <= d:
    if d % i == 0:
        d //= i
        r += 1
    while d % i == 0:
        d //= i
    i += 1
print(r + (d > 1))

from fractions import gcd

d = gcd(*map(int, input().split()))
r = 1
i = 2
while i * i <= d:
    if d % i == 0:
        d //= i
        r += 1
    while d % i == 0:
        d //= i
    i += 1
print(r + (d > 1))


import fractions

primes = [2]

def is_prime(n):
    for p in primes:
        if p * p > n:
            break
        if n % p == 0:
            return False

    return True

A, B = map(int, input().split())

G = int(fractions.gcd(A, B))

res = 1

if G % 2 == 0:
    res += 1
    G //= 2

for i in range(3, G, 2):
    if i > G:
        break
    if not is_prime(i):
        continue
    primes.append(i)
    if G % i == 0:
        res += 1
        G //= i

if G > 1 and is_prime(G) and G not in primes:
    res += 1

print(res)

import fractions

A, B = map(int, input().split())

G = fractions.gcd(A, B)

res = 1

for i in [2] + list(range(3, int(G**0.5) + 1, 2)):
    if G % i == 0:
        res += 1
        while G % i == 0:
            G //= i

if G > 2:
    res += 1

print(res)


a, b = map(int, input().split())
i = 1
common = []
while True:
    if a % i == 0 and b % i == 0:
        a //= i
        b //= i
        common.append(i)
    if min(a, b) < i:
        break
    i += 1

count = 1
for i in range(1, len(common)):
    for j in range(1, i):
        if common[i] % common[j] == 0:
            break
    else:
        count += 1
print(count)

import fractions
import math

a, b = map(int, input().split())
greatest = fractions.gcd(a, b)

factor = [1]
max_iter = int(math.sqrt(greatest)) + 1
for i in range(2, max_iter):
    while greatest % i == 0:
        greatest //= i
        factor.append(i)
if greatest != 1:
    factor.append(greatest)
factor = set(factor)
print(len(factor))


def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)

A, B = map(int, input().split())
C = gcd(A, B)

ans = []
i = 2
while True:
    if C == 1:
        break
    if C % i != 0:
        i += 1
        continue
    ans.append(i)
    C //= i
print(len(set(ans)) + 1)

def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)

A, B = map(int, input().split())
C = gcd(A, B)

ans = []
while C % 2 == 0:
    ans.append(2)
    C //= 2
i = 3
while C >= i * i:
    if C % i == 0:
        ans.append(i)
        C //= i
    else:
        i += 2
if C != 1:
    ans.append(C)
print(len(set(ans)) + 1)


from math import gcd

H, W, A, B = map(int, input().split())
gcd_hw = gcd(H, W)
gcd_ab = gcd(A, B)
if H == 1:
    print("1" * A + "0" * (W - A))
    exit()
if W == 1:
    print(*("1" * B + "0" * (H - B)), sep="\\n")
    exit()

if H // gcd_hw == B // gcd_ab and W // gcd_hw == A // gcd_ab:
    ans = [[0] * W for _ in range(H)]
    for i in range(H):
        for j in range(A):
            ans[i][(j + B * i) % W] = 1
    [print("".join(map(str, row))) for row in ans]
else:
    print("No")

H, W, A, B = map(int, input().split())
for _ in range(B):
    print("0" * A + "1" * (W - A))
for _ in range(H - B):
    print("1" * A + "0" * (W - A))


import sys

def prepare(n, MOD):
    f = 1
    factorials = [1]
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv

    solo_invs = [0] + [f * i % MOD for f, i in zip(factorials, invs[1:])]

    return factorials, invs, solo_invs

def decompose_inverses(solo_invs, MOD):
    # 各整数 g に対して、g の約数である各 i について dcm[i] を全て足すと 1/g になるような数列を作成
    n = len(solo_invs)
    dcm = solo_invs.copy()
    for i in range(1, n):
        d = dcm[i]
        for j in range(2 * i, n, i):
            dcm[j] -= d
    for i in range(1, n):
        dcm[i] %= MOD
    return dcm

n, *aaa = map(int, sys.stdin.buffer.read().split())
MOD = 998244353
LIMIT = max(aaa)
count = [0] * (LIMIT + 1)
double = [0] * (LIMIT + 1)
for a in aaa:
    count[a] += a
    double[a] += a * a
_, _, solo_invs = prepare(LIMIT, MOD)
dcm = decompose_inverses(solo_invs, MOD)

ans = 0
inv2 = solo_invs[2]
for d in range(1, LIMIT + 1):
    ans = (ans + dcm[d] * (sum(count[d::d]) ** 2 - sum(double[d::d])) * inv2) % MOD
print(ans)

import sys

def prepare(n, MOD):
    f = 1
    factorials = [1]
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv

    solo_invs = [0] + [f * i % MOD for f, i in zip(factorials, invs[1:])]

    return factorials, invs, solo_invs

def decompose_inverses(solo_invs, MOD):
    # 各整数 g に対して、g の約数である各 i について dcm[i] を全て足すと 1/g になるような数列を作成
    n = len(solo_invs)
    dcm = solo_invs[:]
    for i in range(1, n):
        d = dcm[i]
        for j in range(2 * i, n, i):
            dcm[j] -= d
    for i in range(1, n):
        dcm[i] %= MOD
    return dcm

n, *aaa = map(int, sys.stdin.buffer.read().split())
MOD = 998244353
LIMIT = max(aaa)
count = [0] * (LIMIT + 1)
double = [0] * (LIMIT + 1)
for a in aaa:
    count[a] += a
    double[a] += a * a
_, _, solo_invs = prepare(LIMIT, MOD)
dcm = decompose_inverses(solo_invs, MOD)

ans = 0
inv2 = solo_invs[2]
for d in range(1, LIMIT + 1):
    ans = (ans + dcm[d] * (sum(count[d::d]) ** 2 - sum(double[d::d])) * inv2) % MOD
print(ans)


S = input().strip()

weather = ["Sunny", "Cloudy", "Rainy"]

idx = weather.index(S) + 1
if idx > len(weather):
    print(weather[0])
else:
    print(weather[idx])

S = input().strip()

weather = ["Sunny", "Cloudy", "Rainy"]

idx = weather.index(S) + 1
if idx >= len(weather):
    print(weather[0])
else:
    print(weather[idx])


import sys

S = sys.stdin.readline().rstrip()

WS = ["Sunny", "Cloudy", "Rainy"]

i = WS.index(S)
i += 1
if i == 2:
    i = 0

print(WS[i])

import sys

S = sys.stdin.readline().rstrip()

WS = ["Sunny", "Cloudy", "Rainy"]

i = WS.index(S)
i += 1
if i == 3:
    i = 0

print(WS[i])


w = input()
weather = ["Sunny", "Cloudy", "Rainy"]

index = weather.index(w)
index += 1
if index == 2:
    index = 0

print(weather[index])

w = input()
weather = ["Sunny", "Cloudy", "Rainy"]

index = weather.index(w)
index += 1
if index == 3:
    index = 0

print(weather[index])


s = input()

weather = ["Sunny", "Cloudy", "Rainy"]
print(weather[weather.index(s) + 1])

s = input()

weather = ["Sunny", "Cloudy", "Rainy"]
print(weather[(weather.index(s) + 1) % 3])


li = list(input())

for i in range(len(li)):
    if i % 2 == 0:
        if len[i] == "R":
            print("No")
            quit()
    else:
        if len[i] == "L":
            print("No")
            quit()
print("Yes")

li = list(input())

for i in range(len(li)):
    if i % 2 == 1:
        if li[i] == "R":
            print("No")
            quit()
        else:
            continue
    else:
        if li[i] == "L":
            print("No")
            quit()
        else:
            continue
print("Yes")

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02910/Python/s460535863.py", line 5, in <module>
    if len[i] == "R":
TypeError: 'builtin_function_or_method' object is not subscriptable


n, k, q = map(int, input().split())
arr = [k for _ in range(n)]

for _ in range(q):
    winner_id = int(input()) - 1
    arr = [ele - 1 for ele in arr]
    arr[winner_id] += 1

for ele in arr:
    if ele > 0:
        print("Yes")
    else:
        print("No")

n, k, q = map(int, input().split())
arr = [k - q] * n

for _ in range(q):
    winner_id = int(input()) - 1
    arr[winner_id] += 1

for ele in arr:
    if ele > 0:
        print("Yes")
    else:
        print("No")


def main():
    N, K, Q, *A = map(int, open(0).read().split())
    A = [K + A.count(i) for i in range(1, N + 1)]
    print("\\n".join(["Yes" if Q < a else "No" for a in A]))
    return

main()

def main():
    N, K, Q, *A = map(int, open(0).read().split())
    ans = [0] * N
    for a in A:
        ans[a - 1] += 1
    print("\\n".join(["Yes" if Q < K + a else "No" for a in ans]))
    return

main()


n, k, q = map(int, input().split())
a = [int(input()) for _ in range(q)]
p = k - q
s = [[i, p] for i in range(n)]
for i in a:
    s[i][1] += 1

for i in s:
    if i[1] < 1:
        print("No")
    else:
        print("Yes")

n, k, q = map(int, input().split())
a = [int(input()) for _ in range(q)]
p = k - q
s = [p] * n
for i in a:
    s[i - 1] += 1

for i in s:
    if i < 1:
        print("No")
    else:
        print("Yes")


n, k, q = map(int, input().split())
a = [int(input()) for _ in range(q)]
for i in range(n):
    print("Yes" if k + a.count(i + 1) - q > 0 else "No")

n, k, q = map(int, input().split())
nList = [0] * n
for _ in range(q):
    nList[int(input()) - 1] += 1
for j in range(n):
    print("Yes" if k + nList[j] - q > 0 else "No")


nkq = list(map(int, input().split()))
n, k, q = nkq[0], nkq[1], nkq[2]
attendees = dict()
for i in range(n):
    attendees[i] = k

attendees = [(i, k) for i in range(n)]

respondents = [int(input()) for i in range(q)]

for r in respondents:
    r_index = r - 1
    for a in attendees:
        i, p = a
        if i != r_index:
            attendees[i] = (i, p - 1)

for a in attendees:
    i, p = a
    if p > 0:
        print("Yes")
    else:
        print("No")

nkq = list(map(int, input().split()))
n, k, q = nkq[0], nkq[1], nkq[2]
attendees = dict()
for i in range(n):
    attendees[i] = 0

respondents = [int(input()) for i in range(q)]

for r in respondents:
    r_index = r - 1
    attendees[r_index] += 1

for i, p in attendees.items():
    point = p + k - q
    if point > 0:
        print("Yes")
    else:
        print("No")


import numpy as np

N, K, Q = map(int, input().split())
A = [int(input()) for i in range(Q)]
N_array = [K] * N
np = np.array(N_array)
for x in A:
    np -= 1
    np[x - 1] += 1
for z in np:
    if z > 0:
        print("Yes")
    else:
        print("No")

N, K, Q = map(int, input().split())
A = [int(input()) for i in range(Q)]
N_array = [K - Q] * N
for x in A:
    N_array[x - 1] += 1
for z in N_array:
    if z > 0:
        print("Yes")
    else:
        print("No")


def update_points(points, current_ansewr):
    return list(
        map(
            lambda x: x[1] if (x[0] + 1) == current_ansewr else x[1] - 1,
            enumerate(points),
        )
    )

N, K, Q = [int(i) for i in input().split()]
points = [K] * N
for _ in range(Q):
    answer = int(input())
    points = update_points(points, answer)
for p in points:
    print("Yes" if p > 0 else "No")

N, K, Q = [int(i) for i in input().split()]
points = [(K - Q)] * N
for _ in range(Q):
    answer = int(input())
    points[answer - 1] += 1
for p in points:
    print("Yes" if p > 0 else "No")


def main():
    N, K, Q = map(int, input().split())
    A = [int(input()) for _ in range(Q)]

    points = [K for _ in range(N)]

    for i in A:
        points = list(map(lambda x: x - 1, points))
        points[i - 1] += 1

    for i in points:
        if i <= 0:
            print("No")
        else:
            print("Yes")

if __name__ == "__main__":
    main()

def main():
    N, K, Q = map(int, input().split())
    A = [int(input()) for _ in range(Q)]

    points = [K for _ in range(N)]
    points = list(map(lambda x: x - Q, points))

    for i in A:
        points[i - 1] += 1

    for i in points:
        if i <= 0:
            print("No")
        else:
            print("Yes")

if __name__ == "__main__":
    main()


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

points = [K for _ in range(N)]

for i in range(Q):
    points[A[i] - 1] += 1
    for j in range(N):
        points[j] -= 1

for j in range(N):
    if points[j] >= 1:
        print("Yes")
    else:
        print("No")

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

points = [K for _ in range(N)]

for i in range(Q):
    points[A[i] - 1] += 1

for j in range(N):
    points[j] -= Q

for j in range(N):
    if points[j] >= 1:
        print("Yes")
    else:
        print("No")


n, k, q = map(int, input().split())
a = []
for i in range(q):
    a[i] = int(input()) - 1
score = [0 for _ in range(n)]

for a_i in a:
    score[a_i] += 1

for i in range(n):
    result = k - q + score[i]
    print("Yes" if result > 0 else "No")

n, k, q = map(int, input().split())
a = []
for i in range(q):
    a.append(int(input()) - 1)
score = [0 for _ in range(n)]

for a_i in a:
    score[a_i] += 1

for i in range(n):
    result = k - q + score[i]
    print("Yes" if result > 0 else "No")

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02911/Python/s560201752.py", line 4, in <module>
    a[i] = int(input()) - 1
IndexError: list assignment index out of range


N, K, Q = map(int, input().split())
ans_r = [K] * N
cor = list(map(int, [input() for i in range(Q)]))
for i in cor:
    ans_r[i - 1] += 1
    ans_r = list(map(lambda x: x - 1, ans_r))
ans_r = list(map(lambda x: "No" if x <= 0 else "Yes", ans_r))
for i in ans_r:
    print(i)

N, K, Q = map(int, input().split())
ans_r = [K - Q] * N
cor = list(map(int, [input() for i in range(Q)]))
for i in cor:
    ans_r[i - 1] += 1
for i in ans_r:
    if i <= 0:
        print("No")
    else:
        print("Yes")


# -*- coding: utf-8 -*-
N, K, Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]

dp = [K] * N

def calc_dp(n):
    return n - 1

for i in A:
    dp = list(map(calc_dp, dp))
    dp[i - 1] += 1

for j in dp:
    if j > 0:
        print("Yes")
    else:
        print("No")

# -*- coding: utf-8 -*-
N, K, Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]

dp = [K] * N

def calc_dp(n):
    return n - Q

for i in A:
    # dp = list(map(calc_dp, dp))
    dp[i - 1] += 1

dp = list(map(calc_dp, dp))

for j in dp:
    if j > 0:
        print("Yes")
    else:
        print("No")


import numpy as np

N, K, Q = list(map(int, input().strip().split()))
As = [int(input()) for _ in range(Q)]

points = np.asarray([K for _ in range(N)])
for A in As:
    points -= 1
    points[A - 1] += 1

for p in points:
    if p > 0:
        print("Yes")
    else:
        print("No")

import numpy as np

N, K, Q = list(map(int, input().strip().split()))
As = [int(input()) for _ in range(Q)]

points = np.asarray([K for _ in range(N)])

points -= Q
for A in As:
    points[A - 1] += 1

for p in points:
    if p > 0:
        print("Yes")
    else:
        print("No")


N, K, Q = map(int, input().split())
A = list(int(input()) for i in range(Q))
for i in range(N):
    if Q - A.count(i + 1) < K:
        print("Yes")
    else:
        print("No")

from collections import Counter

N, K, Q = map(int, input().split())
A = list(int(input()) for i in range(Q))
c = Counter(A)
for i in range(N):
    if Q - c[i + 1] < K:
        print("Yes")
    else:
        print("No")


N, M = map(int, input().split())
A = list(sorted(map(int, input().split()), key=lambda x: -x))

for _ in range(M):
    A[0] /= 2

    p = 0
    while p < N - 1 and A[p] < A[p + 1]:
        A[p], A[p + 1] = A[p + 1], A[p]
        p += 1

print(sum(map(int, A)))

import heapq

N, M = map(int, input().split())
A = list(map(lambda x: -1 * int(x), input().split()))

heapq.heapify(A)
for _ in range(M):
    a = -1 * heapq.heappop(A)
    a //= 2
    heapq.heappush(A, -1 * a)

print(-1 * sum(A))


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

for _ in range(m):
    a[-1] //= 2
    a.sort()

print(sum(a))

import heapq

n, m = map(int, input().split())
a = list(map(lambda x: int(x) * (-1), input().split()))
heapq.heapify(a)

for _ in range(m):
    y = heapq.heappop(a)
    heapq.heappush(a, (-1) * (-y // 2))

print(-sum(a))


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

for _ in range(m):
    a[0] = a[0] // 2
    a.sort(reverse=True)

print(sum(a))

# priority queueで楽勝だった
import heapq

n, m = map(int, input().split())
a = list(map(lambda x: int(x) * -1, input().split()))
heapq.heapify(a)

for _ in range(m):
    x = -(-a[0] // 2)
    heapq.heapreplace(a, x)
    # print(a)
print(sum(a) * -1)


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

while M > 0:
    max_index = A.index(max(A))
    A[max_index] = A[max_index] // 2
    M -= 1
print(sum(A))

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

while M > 0:
    A.sort(reverse=True)
    if A[0] == 0:
        break
    ham = A[0] // 2
    for i, a in enumerate(A):
        if ham < a and M > 0:
            A[i] = A[i] // 2
            M -= 1
        else:
            break
print(sum(A))


n, m = map(int, input().split())
a_list = list(map(int, input().split()))

a_list.sort(reverse=True)
swapped = False
while m > 0:
    a_list[0] = a_list[0] // 2
    m -= 1
    if (n > 1) and (a_list[0] < a_list[1]) and not swapped:
        temp = a_list[0]
        a_list[0] = a_list[1]
        a_list[1] = temp
        swapped = True
    else:
        a_list.sort(reverse=True)
        swapped = False

cost_sum = 0
for a in a_list:
    cost_sum += a

print(cost_sum)

from heapq import heappush, heappop

n, m = map(int, input().split())
a_list = list(map(int, input().split()))

hqueue = []
for a in a_list:
    heappush(hqueue, -a)

for i in range(m):
    max_item = -(-heappop(hqueue) // 2)
    heappush(hqueue, max_item)

cost = 0
for i in range(n):
    cost += -heappop(hqueue)

print(cost)


import bisect as b
import math

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

for _ in range(m):
    half = a.pop(-1) / 2
    a.insert(b.bisect_left(a, half), half)

print(sum(list(map(lambda x: math.floor(x), a))))

import heapq
import math

n, m = list(map(int, input().split()))
a = list(map(lambda x: int(x) * (-1), input().split()))
heapq.heapify(a)

for _ in range(m):
    heapq.heappush(a, math.ceil(heapq.heappop(a) / 2))

print(-sum(a))


N, M = map(int, input().split())
A_list = list(map(int, input().split()))
A_list.sort()
if N == 1:
    A_list[-1] = A_list[-1] // (2**M)
elif N > 1:
    while M > 0:
        A_list[-1] = A_list[-1] // 2
        if A_list[-1] < A_list[-2]:
            A_list.sort()
        M -= 1
print(sum(A_list))

# 優先度付きキューの考え方が必須
import heapq

N, M = map(int, input().split())
# 読み込み時に * -1 を乗算している
A_list = list(map(lambda x: int(x) * (-1), input().split()))
# A_listを優先度付きキューにする
heapq.heapify(A_list)

while M > 0:
    temp_max = heapq.heappop(A_list)
    # //2 で余りは切り捨てのため -1 を 2回 乗算している
    heapq.heappush(A_list, (-1) * ((-1 * temp_max) // 2))
    M -= 1
print(-1 * sum(A_list))


N, M = map(int, input().split())
A = list(map(int, input().split()))
while M > 0:
    M -= 1
    A[A.index(max(A))] //= 2
print(sum(A))

import heapq

n, m = map(int, input().split())
a = list(map(lambda x: int(x) * (-1), input().split()))
heapq.heapify(a)  # aを優先度付きキューに

for _ in range(m):
    tmp_min = heapq.heappop(a)
    heapq.heappush(a, (-1) * (-tmp_min // 2))  # 計算誤差の関係で-1を2回かけてます
print(-sum(a))


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

for _ in range(M):
    i = max(range(len(A)), key=A.__getitem__)
    A[i] /= 2
A = list(map(int, A))
print(sum(A))

import heapq

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

heap = [-Ai for Ai in A]
heapq.heapify(heap)
for _ in range(M):
    heapq.heapreplace(heap, heap[0] / 2)
A = [int(-p) for p in heap]
print(sum(A))


N, M = map(int, input().split())  # 品物の数、割引券の枚数
A = list(map(int, input().split()))  # 品物の値段
for _ in range(M):
    tmp = A.index(max(A))
    A[tmp] = A[tmp] // 2
print(str(sum(A)))

N, M = map(int, input().split())  # 品物の数、割引券の枚数
A = list(map(int, input().split()))  # 品物の値段
A.sort(reverse=True)
i = 0
for _ in range(M):
    A[i] = A[i] // 2
    if i <= N - 2 and A[i] < A[i + 1] and A[0] < A[i + 1]:
        i += 1
    else:
        A.sort(reverse=True)
        i = 0
print(str(sum(A)))


n, m = map(int, input().split())
a = list(map(int, input().split()))
while m > 0:
    M = max(a)
    tmp = a.index(M)
    a[tmp] = a[tmp] // 2
    m -= 1
print(sum(a))

import heapq

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

pq = []
for a in A:
    heapq.heappush(pq, -a)  #'-'にすることで最大値を考えることができる！
# print(pq)
for _ in range(m):
    a = (-heapq.heappop(pq)) // 2
    heapq.heappush(pq, -a)
print(-sum(pq))


N, M = map(int, input().split())
A = [int(i) for i in input().split()]

A = sorted(A, reverse=True)

for _ in range(M):
    A[0] = A[0] / 2
    A = sorted(A, reverse=True)

ans = 0
for a in A:
    ans += int(a)

print(ans)

import heapq

N, M = map(int, input().split())
A = [-int(i) for i in input().split()]

heapq.heapify(A)

for _ in range(M):
    x = heapq.heappop(A) / 2
    heapq.heappush(A, x)

ans = 0
for a in A:
    ans -= int(a)

print(ans)


import numpy as np

N, M = map(int, input().split())
A = np.array([int(n) for n in input().split()])

for _ in range(M):
    A[np.argmax(A)] //= 2

print(int(np.sum(A)))

import heapq

N, M = map(int, input().split())
A = [-int(n) for n in input().split()]
heapq.heapify(A)

for _ in range(M):
    a = heapq.heappop(A)
    a = a // 2 if a % 2 == 0 else a // 2 + 1
    heapq.heappush(A, a)

print(-sum(A))


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

for _ in range(M):
    A.sort()
    A[-1] //= 2

print(sum(A))

import heapq

N, M = map(int, input().split())
A = list(map(lambda x: int(x) * -1, input().split()))

heapq.heapify(A)

for _ in range(M):
    heapq.heappush(A, (heapq.heappop(A) + 1) // 2)

ans = sum(A) * -1

print(ans)


import heapq  # heapqライブラリのimoprt

N, M = map(int, input().split())
A = map(lambda x: int(x) * (-1), input().split())
heapq.heapify(A)

for _ in range(N):
    a = heapq.heappop(A)
    a = (-a // 2) * (-1)
    heapq.heappush(A, a)
print(-sum(A))

from heapq import heapify, heappop, heappush

N, M = map(int, input().split())
A = []
for i in input().split():
    A.append(-int(i))
heapify(A)
for _ in range(M):
    a = -heappop(A)
    heappush(A, (a // 2) * -1)
# print('A', A)
ans = -sum(A)
print(ans)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02912/Python/s538766589.py", line 5, in <module>
    heapq.heapify(A)
TypeError: heapify() argument must be list, not map


#!/usr/bin/env python3

N, M = list(map(int, input().split()))
a_list = list(map(int, input().split()))

for _ in range(M):
    a_list = sorted(a_list, reverse=True)
    a_list[0] = a_list[0] // 2

ans = sum(a_list)
print(ans)

#!/usr/bin/env python3
import heapq

N, M = list(map(int, input().split()))
a_list = list(map(int, input().split()))

# Pythonのheapqは最小値しかとれないので、負の値に変換して扱う
a_list = list(map(lambda x: x * (-1), a_list))
heapq.heapify(a_list)

for _ in range(M):
    max_value = -heapq.heappop(a_list)
    heapq.heappush(a_list, -(max_value // 2))

ans = -sum(a_list)
print(ans)


N, M = map(int, input().split())
a_list = sorted(map(int, input().split()))
for _ in range(M):
    a_list[-1] //= 2
    a_list.sort()
print(sum(a_list))

import heapq

N, M = map(int, input().split())
a_list = list(map(lambda x: int(x) * (-1), input().split()))
heapq.heapify(a_list)
for _ in range(M):
    min_num = heapq.heappop(a_list)
    heapq.heappush(a_list, (-1) * (-min_num // 2))
print(-sum(a_list))


from sys import stdin
from bisect import insort

def main():
    N, M = [int(x) for x in stdin.readline().rstrip().split()]
    As = [int(x) for x in stdin.readline().rstrip().split()]
    As.sort()
    for _ in range(M):
        x = As[-1] / 2
        insort(As, x)
        del As[-1]
    sum_ = 0
    for x in As:
        sum_ += int(x)
    print(sum_)

if __name__ == "__main__":
    main()

from sys import stdin
import heapq

def main():
    N, M = [int(x) for x in stdin.readline().rstrip().split()]
    As = []
    for i in [int(x) for x in stdin.readline().rstrip().split()]:
        heapq.heappush(As, -i)
    for _ in range(M):
        x = heapq.heappop(As)
        heapq.heappush(As, x / 2)
    print(sum([-1 * int(x) for x in As]))

if __name__ == "__main__":
    main()


n, m = input().split()
N = int(n)
M = int(m)

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

for _ in range(M):
    A[0] = A[0] // 2
    A.sort(reverse=True)
print(sum(A))

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
it = 0
for i in range(M):
    A[it] = A[it] // 2
    if it < N - 1:
        if A[it] < A[it + 1] and A[0] < A[it + 1]:
            it += 1
        else:
            A.sort(reverse=True)
            it = 0
    if it == N - 1:
        A.sort(reverse=True)
        it = 0
print(sum(A))


#!/usr/bin/env python3

from bisect import insort_right
from collections import deque

n, m, *a = map(int, open(0).read().split())

a = deque(sorted(a))
for _ in range(m):
    insort_right(a, a.pop() >> 1)
print(sum(a))

#!/usr/bin/env python3

from bisect import insort_right

n, m, *a = map(int, open(0).read().split())
a.sort()
for _ in range(m):
    insort_right(a, a.pop() >> 1)
print(sum(a))


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

for _ in range(m):
    a[a.index(max(a))] = a[a.index(max(a))] // 2

print(sum(a))

import heapq

n, m = map(int, input().split())
a = []
for i in list(map(int, input().split())):
    heapq.heappush(a, -i)

for _ in range(m):
    p = heapq.heappop(a)
    heapq.heappush(a, int(p / 2))

print(-sum(a))


N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)

while M > 0:
    A[0] //= 2
    for i in range(1, N):
        if A[0] > A[i]:
            A = A[1:i] + [A[0]] + A[i:]
            break
    else:
        A = A[1:] + [A[0]]
    M -= 1
print(sum(A))

import heapq

class Reverse:
    def __init__(self, val):
        self.val = val

    def __lt__(self, other):
        return self.val > other.val

    def __repr__(self):
        return repr(self.val)

class Heapq:
    def __init__(self, arr, desc=False):
        if desc:
            for i in range(len(arr)):
                arr[i] = Reverse(arr[i])
        self.desc = desc
        self.hq = arr
        heapq.heapify(self.hq)

    def pop(self):
        if len(self.hq) == 0:
            return None
        if self.desc:
            return heapq.heappop(self.hq).val
        else:
            return heapq.heappop(self.hq)

    def push(self, a):
        if self.desc:
            heapq.heappush(self.hq, Reverse(a))
        else:
            heapq.heappush(self.hq, a)

N, M = map(int, input().split())
q = Heapq(list(map(int, input().split())), desc=True)

while M > 0:
    a = q.pop() // 2
    q.push(a)
    M -= 1

tmp = 0
while True:
    try:
        a = q.pop()
        tmp += a
    except:
        break
print(tmp)


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

while M > 0:
    maxv = max(A)
    max_index = A.index(maxv)
    A[max_index] = A[max_index] // 2
    M -= 1

print(sum(A))

import heapq

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

A = [a * -1 for a in A]

heapq.heapify(A)
for _ in range(M):
    a = heapq.heappop(A)
    heapq.heappush(A, (-a // 2) * (-1))

print(-sum(A))


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

for _ in range(M):
    A.sort(reverse=True)
    A[0] //= 2

print(sum(A))

import sys
from heapq import heappush, heappop

def input():
    return sys.stdin.readline().strip()

N, M = map(int, input().split())
A = []
for i in input().split():
    heappush(A, -1 * int(i))
# print(A)

for _ in range(M):
    val = heappop(A)
    if val == 0:
        break
    heappush(A, (val + 1) // 2)

print(-1 * sum(A))


from sys import stdin, setrecursionlimit
from bisect import insort

def main():
    input = stdin.buffer.readline
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()

    for _ in range(m):
        tmp = a[n - 1] // 2
        insort(a, tmp)

    print(sum(a[:n]))

if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

from sys import stdin, setrecursionlimit
from heapq import heapify, heappop, heappush

def main():
    input = stdin.buffer.readline
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    a = [-ai for ai in a]
    heapify(a)

    for _ in range(m):
        tmp = -heappop(a)
        heappush(a, -(tmp // 2))

    print(-sum(a))

if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


import math
import numpy as np

n, m = map(int, input().split())
prices = np.array(list(map(int, input().split())))

for _ in range(m):
    max_index = np.argmax(prices)
    prices[max_index] = prices[max_index] / 2

total = 0
for price in prices:
    total += math.floor(price)

print(total)

import math
import heapq

n, m = map(int, input().split())
prices = list(map(int, input().split()))
hq = []

def _heappush_max(heap, item):
    heap.append(item)
    heapq._siftdown_max(heap, 0, len(heap) - 1)

def _heappop_max(heap):
    """Maxheap version of a heappop."""
    lastelt = heap.pop()  # raises appropriate IndexError if heap is empty
    if heap:
        returnitem = heap[0]
        heap[0] = lastelt
        heapq._siftup_max(heap, 0)
        return returnitem
    return lastelt

# 優先度付キューの作成
for price in prices:
    _heappush_max(hq, price)

# 割引適用
for _ in range(m):
    target = _heappop_max(hq)
    _heappush_max(hq, target / 2)

total = 0
for price in hq:
    total += math.floor(price)

print(total)


# 毎回ソートしても別にいいんじゃないの -> ダメでした

n, m = map(int, input().split())
arr = list(map(int, input().split()))

while m > 0:
    arr = list(sorted(arr))
    arr[-1] = arr[-1] // 2
    m -= 1

print(sum(arr))

# 毎回ソートしても別にいいんじゃないの -> ダメでした
# 毎回最大のものがほしいならheapq使うか
import heapq

n, m = map(int, input().split())
# heapは最小のものを取り出すので予め-1をかけて大小を見かけ上逆転しておく
arr = list(map(lambda x: int(x) * -1, input().split()))
heapq.heapify(arr)
for _ in range(m):
    a = heapq.heappop(arr)
    # 負数にしたときの誤差がめんどくさい
    a *= -1
    a //= 2
    heapq.heappush(arr, a * -1)
print(sum(arr) * -1)


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

for _ in range(m):
    i = A.index(max(A))
    A[i] /= 2
A = [int(a) for a in A]

print(sum(A))

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

A = [a * (-1) for a in A]
import heapq

heapq.heapify(A)

for _ in range(m):
    a = heapq.heappop(A) * (-1)
    heapq.heappush(A, a // 2 * (-1))

print(abs(sum(A)))


N = int(input())
S = input()

ans = 0
for i in range(N):
    for j in range((N + i) // 2, i, -1):
        if S[i:j] in S[j:]:
            ans = max(ans, j - i)
            break

print(ans)

def z_algo(S):
    N = len(S)

    A = [0] * N
    A[0] = N
    i = 1
    j = 0

    while i < N:
        while i + j < N and S[j] == S[i + j]:
            j += 1
        if not j:
            i += 1
            continue
        A[i] = j
        k = 1
        while N - i > k < j - A[k]:
            A[i + k] = A[k]
            k += 1
        i += k
        j -= k
    return A

N = int(input())
S = input()

ans = 0
for i in range(N):
    A = z_algo(S[i:])
    for idx, ls in enumerate(A):
        if idx - ls >= 0:
            ans = max(ans, ls)

print(ans)


N = int(input())
S = input()

ans = 0
left, right = 0, 1

while right < N:
    s = S[left:right]
    if s in S[right:]:
        right += 1
        ans = max(ans, len(s))
    else:
        left = right - 1

print(ans)

N = int(input())
S = input()

ans = 0
left, right = 0, 1

while right < N:
    s = S[left:right]
    if s in S[right:]:
        right += 1
        ans = max(ans, len(s))
    else:
        left += 1

print(ans)


def Z_algo(S):
    n = len(S)
    LCP = [0] * n
    i = 1
    j = 0
    c = 0  # 最も末尾側までLCPを求めたインデックス
    for i in range(1, n):
        # i番目からのLCPが以前計算したcからのLCPに含まれている場合
        if i + LCP[i - c] < c + LCP[c]:
            LCP[i] = LCP[i - c]
        else:
            j = max(0, c + LCP[c] - i)
            while i + j < n and S[j] == S[i + j]:
                j += 1
            LCP[i] = j
            c = i
    LCP[0] = n
    return LCP

n = int(input())
s = input()
ans = 0
for i in range(n):
    lcp = Z_algo(s[i:])
    for j in range(len(lcp)):
        tmp = min(j, lcp[j])
        ans = max(ans, tmp)
print(ans)

def Z_algo(S):
    n = len(S)
    LCP = [0] * n
    c = 0  # 最も末尾側までLCPを求めたインデックス
    for i in range(1, n):
        # i番目からのLCPが以前計算したcからのLCPに含まれている場合
        if i + LCP[i - c] < c + LCP[c]:
            LCP[i] = LCP[i - c]
        else:
            j = max(0, c + LCP[c] - i)
            while i + j < n and S[j] == S[i + j]:
                j += 1
            LCP[i] = j
            c = i
    LCP[0] = n
    return LCP

n = int(input())
s = input()
ans = 0
for i in range(n):
    lcp = Z_algo(s[i:])
    for j, p in enumerate(lcp):
        tmp = min(j, p)
        ans = max(ans, tmp)
print(ans)


def z_algorithm(s):
    n = len(s)
    prefix = [0] * n
    j = 0
    ret = 0
    for i in range(1, n):
        if i + prefix[i - j] < j + prefix[j]:
            prefix[i] = prefix[i - j]
        else:
            k = max(0, j + prefix[j] - i)
            while i + k < n and s[k] == s[i + k]:
                k += 1
            prefix[i] = k
            ret = min(i, k)
            j = i
    return ret

n = int(input())
s = input()
print(max(z_algorithm(s[i:]) for i in range(n - 1)))

def z_algorithm(s):
    n = len(s)
    prefix = [0] * n
    j = 0
    ret = 0
    for i in range(1, n):
        if i + prefix[i - j] < j + prefix[j]:
            prefix[i] = prefix[i - j]
        else:
            k = max(0, j + prefix[j] - i)
            while i + k < n and s[k] == s[i + k]:
                k += 1
            prefix[i] = k
            ret = max(ret, min(i, k))
            j = i
    return ret

n = int(input())
s = input()
print(max(z_algorithm(s[i:]) for i in range(n - 1)))


from sys import stdin

N = int(stdin.readline().rstrip())
S = stdin.readline().rstrip()
dp = [[0] * (N + 1) for _ in range(N + 1)]
res = 0

for i in range(N - 1, -1, -1):
    for j in range(N - 1, i, -1):
        if S[i] == S[j]:
            dp[i][j] = dp[i + 1][j + 1] + 1, dp[i][j]
        res = max(res, min(j - i, dp[i][j]))

print(res)

from sys import stdin

N = int(stdin.readline().rstrip())
S = stdin.readline().rstrip()
dp = [[0] * (N + 1) for _ in range(N + 1)]
res = 0

for i in range(N - 1, -1, -1):
    for j in range(N - 1, i, -1):
        if S[i] == S[j]:
            dp[i][j] = dp[i + 1][j + 1] + 1
        res = max(res, min(j - i, dp[i][j]))

print(res)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02913/Python/s512048354.py", line 12, in <module>
    res = max(res, min(j - i, dp[i][j]))
TypeError: '<' not supported between instances of 'tuple' and 'int'


n = int(input())
s = input()

dp = [[0] * (n + 1) for _ in range(n + 1)]

res = 0
for i in range(n - 1, -1, -1):
    for j in range(n - 1, i, -1):
        if s[i] == s[j]:
            dp[i][j] = max(dp[i][j], dp[i + 1][j + 1] + 1)
        res = max(res, min(dp[i][j], j - i))
print(res)

n = int(input())
s = input()

dp = [[0] * (n + 1) for _ in range(n + 1)]

res = 0
for i in range(n - 1, -1, -1):
    for j in range(n - 1, i, -1):
        if s[i] == s[j]:
            dp[i][j] = dp[i + 1][j + 1] + 1
            # dp[i][j] = max(dp[i][j], dp[i + 1][j + 1] + 1)
        res = max(res, min(dp[i][j], j - i))
print(res)


import numpy as np

def Z_algorithm(s):
    n = len(s)
    Z = [0] * n  # z[i] = sum(s[0::n - i], s[i::n])
    Z[0] = n
    i, j = 1, 0
    while i < n:
        # 共通部分を見つけるパート
        while i + j < n and s[j] == s[i + j]:
            j += 1
        Z[i] = j

        if j == 0:
            i += 1
            continue
        # 計算の再利用パート
        # k + Z[k] < j なら再利用できる
        k = 1
        while k < j and k + Z[k] < j:
            Z[i + k] = Z[k]
            k += 1
        # k個先まで見たのでk個先にバトンを渡す
        i += k
        j -= k
    return Z

n, s = int(input()), input()
print(max((np.minimum(Z_algorithm(s[i:]), range(n - i))).max() for i in range(n)))

def Z_algorithm(s):
    n = len(s)
    Z = [0] * n  # z[i] = sum(s[0::n - i], s[i::n])
    Z[0] = n
    i, j = 1, 0
    while i < n:
        # 共通部分を見つけるパート
        while i + j < n and s[j] == s[i + j]:
            j += 1
        Z[i] = j

        if j == 0:
            i += 1
            continue
        # 計算の再利用パート
        # k + Z[k] < j なら再利用できる
        k = 1
        while k < j and k + Z[k] < j:
            Z[i + k] = Z[k]
            k += 1
        # k個先まで見たのでk個先にバトンを渡す
        i += k
        j -= k
    return Z

def solve(k):
    a = Z_algorithm(s[k:])
    ans = 0
    for i in range(n - k):
        ans = max(ans, min(i, a[i]))
    return ans

n, s = int(input()), input()
print(max(solve(i) for i in range(n)))


def z_algorithm(s):
    n = len(s)
    prefix = [0] * n
    j = 0
    ret = 0
    for i in range(1, n):
        if i + prefix[i - j] < j + prefix[j]:
            prefix[i] = prefix[i - j]
        else:
            k = max(0, j + prefix[j] - i)
            while i + k < n and s[k] == s[i + k]:
                k += 1
            prefix[i] = k
            ret = max(ret, min(i, k))
            j = i
    return ret

n = int(input())
s = input()
print(max(z_algorithm(s[i:]) for i in range(n - 1)))

def solve(n, s, d, MOD):
    ttt = [ord(c) - 97 for c in s]

    ttx = []
    c = 1
    for t in ttt[::-1]:
        ttx.append(t * c % MOD)
        c = c * d % MOD
    ttx.reverse()
    ttc = [0]
    for t in ttx:
        ttc.append((ttc[-1] + t) % MOD)

    l, r = 0, n
    while l < r:
        m = (l + r + 1) // 2
        if search(m, d, ttc, MOD):
            l = m
        else:
            r = m - 1

    return l

def search(w, d, ttc, MOD):
    appeared = []
    comparing = set()
    w2 = w * 2
    p = 1

    for i in range(w, n + 1):
        t = (ttc[i] - ttc[i - w]) * p % MOD
        if i >= w2:
            comparing.add(appeared[i - w2])
            if t in comparing:
                return True
        appeared.append(t)
        p = p * d % MOD

    return False

n = int(input())
s = input()
MOD = 10**9 + 7
print(min(solve(n, s, d, MOD) for d in (26, 29, 31)))


# -*- coding: utf-8 -*-
from itertools import combination_with_replacement

n = int(input())
print(len(list(combination_with_replacement(n, 3))))

# -*- coding: utf-8 -*-
import itertools

n = int(input())
print(len(list(itertools.product(range(1, n + 1), repeat=3))))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02915/Python/s250145116.py", line 2, in <module>
    from itertools import combination_with_replacement
ImportError: cannot import name 'combination_with_replacement' from 'itertools' (unknown location)


N = int(input().split())

print(N * N * N)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02915/Python/s074412118.py", line 1, in <module>
    N = int(input().split())
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'list'


Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02915/Python/s203905734.py", line 2, in <module>
    print(N**3)
TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'


Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02915/Python/s357662058.py", line 2, in <module>
    print(len**3)
TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'


Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02915/Python/s464353610.py", line 2, in <module>
    print(a**3)
TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'


n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
if len(c) == 1:
    print(sum(b) + sum(c))
else:
    print(sum(b) + sum(c) - c[a[n - 1] - 1])

n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
ans = b[a[0] - 1]
for i in range(1, n):
    ans += b[a[i] - 1]
    if a[i] == a[i - 1] + 1:
        ans += c[a[i - 1] - 1]
print(ans)


n = int(input())
B = list(map(int, input().split()))
ans = 0
ans += B[0]
for i in range(n - 2):
    if B[i] > B[i + 1]:
        ans += B[i + i]
    else:
        ans += B[i]
ans += B[-1]
print(ans)

n = int(input())
B = list(map(int, input().split()))
ans = 0
ans += B[0]
for i in range(n - 2):
    if B[i] > B[i + 1]:
        ans += B[i + 1]
    else:
        ans += B[i]
ans += B[-1]
print(ans)


N = int(input())
B = [int(i) for i in input().split()][::-1]
ret = B[0] + B[N - 2]
for i in range(1, N - 1):
    ret += min(B[i - 1], B[i])
print(ret)


N = int(input())

B = list(map(int, input().split()))
B.append(max(B[0], B[-1]))

ans = 0
for i in range(N):
    ans += min(B[i], B[i - 1])

print(ans)

N, K = map(int, input().split())
S = input()
T = []

g = S[0]
cnt = 0
for s in S:
    if s == g:
        cnt += 1
    else:
        T.append(cnt)
        cnt = 1
        g = s
else:
    T.append(cnt)

t = len(T)
for k in range(K):
    t -= 2

if t <= 1:
    print(N - 1)
else:
    print(N - t)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02918/Python/s122225482.py", line 1, in <module>
    N = int(input())
ValueError: invalid literal for int() with base 10: '6 1'


import bisect

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

place = [-1] * (N + 1)
for i in range(N):
    p = P[i]
    place[p] = i

ans = 0
big_place = [place[N]]
for i in range(N - 1, 0, -1):
    pos = bisect.bisect_left(big_place, place[i])
    if pos < len(big_place):
        right = big_place[pos]
    else:
        right = N
    if pos + 1 < len(big_place):
        right2 = big_place[pos + 1]
    else:
        right2 = N
    if pos - 1 >= 0:
        left = big_place[pos - 1]
    else:
        left = -1
    if pos - 2 >= 0:
        left2 = big_place[pos - 2]
    else:
        left2 = -1

    if left >= 0:
        left_cand = left - left2
    else:
        left_cand = 0
    right_cand = right - place[i]

    ans += i * left_cand * right_cand

    if right < N:
        right_cand = right2 - right
    else:
        right_cand = 0
    left_cand = place[i] - left
    ans += i * left_cand * right_cand

    big_place1 = big_place[:pos]
    big_place2 = big_place[pos:]
    big_place = big_place1 + [place[i]] + big_place2

print(ans)

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    # i+1番目からR番目まで足すとt以上となるような最小のRを返す
    def bisect_plus(self, i, t):
        L = i
        R = self.size
        R_prev = R
        sum_i = self.sum(i)
        while True:
            range_sum = self.sum(R) - sum_i
            if range_sum < t:
                if R == self.size:
                    return self.size + 1
                L, R = R, R_prev
            else:
                R_prev = R
                R = (L + R + 1) // 2
                if R == R_prev:
                    return R

    # L番目からi-1番目まで足すとt以上となるような最小のRを返す
    def bisect_minus(self, i, t):
        L = 1
        R = i
        L_prev = L
        sum_i = self.sum(i - 1)
        while True:
            range_sum = sum_i - self.sum(L - 1)
            if range_sum < t:
                if L == 1:
                    return 0
                L, R = L_prev, L
            else:
                L_prev = L
                L = (L + R) // 2
                if L == L_prev:
                    return L

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

place = [-1] * (N + 1)
for i in range(N):
    p = P[i]
    place[p] = i

ans = 0
big_place = Bit(N)
big_place.add(place[N] + 1, 1)
for i in range(N - 1, 0, -1):
    pos = place[i] + 1
    right = big_place.bisect_plus(pos, 1)
    right2 = big_place.bisect_plus(pos, 2)
    left = big_place.bisect_minus(pos, 1)
    left2 = big_place.bisect_minus(pos, 2)
    if left > 0:
        left_cand = left - left2
    else:
        left_cand = 0
    right_cand = right - pos
    ans += i * left_cand * right_cand

    if right < N + 1:
        right_cand = right2 - right
    else:
        right_cand = 0
    left_cand = pos - left
    ans += i * left_cand * right_cand

    big_place.add(pos, 1)

print(ans)


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

leftMax = [0] * N
rightMax = [0] * N
leftMax[0] = P[0]
rightMax[-1] = P[-1]
for i in range(N - 1):
    leftMax[i + 1] = max(leftMax[i], P[i + 1])
    rightMax[N - 1 - (i + 1)] = max(rightMax[N - 1 - i], P[N - 1 - i])

ans = 0
for i in range(N):
    a, b, c, d = -1, -1, N, N
    p = P[i]
    if leftMax[i] != p:
        for L in range(i - 1, -1, -1):
            if P[L] > p:
                if b == -1:
                    b = L
                elif a == -1:
                    a = L
                else:
                    break
    if rightMax[i] != p:
        for R in range(i + 1, N):
            if P[R] > p:
                if c == N:
                    c = R
                elif d == N:
                    d = R
                else:
                    break
    left = (b - a) * (c - i)
    right = (d - c) * (i - b)
    ans += p * (left + right)

print(ans)

class SegmentTree:
    """
    update, get を提供するSegmentTree

    Attributes
    ----------
    __n : int
        葉の数。2 ^ i - 1
    __dot :
        Segment function
    __e: int
        単位元
    __node: list
        Segment Tree
    """

    def __init__(self, A, dot, e):
        """
        Parameters
        ----------
        A : list
            対象の配列
        dot :
            Segment function
        e : int
            単位元
        """
        n = 2 ** (len(A) - 1).bit_length()
        self.__n = n
        self.__dot = dot
        self.__e = e
        self.__node = [e] * (2 * n)
        # for i in range(len(A)):
        #     self.__node[i + n] = A[i]
        # for i in range(n - 1, 0, -1):
        #     self.__node[i] = self.__dot(self.__node[2 * i], self.__node[2 * i + 1])

    def update(self, i, c):
        i += self.__n
        node = self.__node
        node[i] = c
        while i > 0:
            i //= 2
            node[i] = self.__dot(node[2 * i], node[2 * i + 1])

    def get(self, l, r):
        vl, vr = self.__e, self.__e
        l += self.__n
        r += self.__n
        while l < r:
            if l & 1:
                vl = self.__dot(vl, self.__node[l])
                l += 1
            l //= 2
            if r & 1:
                r -= 1
                vr = self.__dot(vr, self.__node[r])
            r //= 2
        return self.__dot(vl, vr)

def solve():
    N = int(input())
    P = map(int, input().split())
    plist = []
    for i, p in enumerate(P):
        plist.append((p, i))
    plist.sort(reverse=True)

    maxSeg = SegmentTree([-1] * N, max, -1)
    minSeg = SegmentTree([N] * N, min, N)

    cnt = 0
    for p, c in plist:
        l2 = maxSeg.get(0, c)
        l1 = -1 if l2 <= 0 else maxSeg.get(0, l2)

        r1 = minSeg.get(c + 1, N)
        r2 = N if r1 >= N - 1 else minSeg.get(r1 + 1, N)

        a = (l2 - l1) * (r1 - c)
        b = (r2 - r1) * (c - l2)
        cnt += p * (a + b)

        maxSeg.update(c, c)
        minSeg.update(c, c)

    print(cnt)

solve()


from bisect import bisect_left
import sys

input = sys.stdin.readline

n = int(input())
p = tuple(map(int, input().split()))

pos = [[] for _ in range(n + 1)]
for ind, pp in enumerate(p):
    for j in range(pp + 1):
        pos[j].append(ind)

ans = 0
for i, pp in enumerate(p):
    ind = bisect_left(pos[pp], i)

    left = 1
    if ind - 1 >= 0:
        left = i - pos[pp][ind - 1]
    else:
        left = i + 1
    right = 0
    if ind + 1 < len(pos[pp]):
        i_right = pos[pp][ind + 1]
        right = 1
        if ind + 2 < len(pos[pp]):
            right = pos[pp][ind + 2] - i_right
        else:
            right = n - i_right

    # print(i, pp, left * right, left, right)
    ans += left * right * pp

    left = 0
    if ind - 1 >= 0:
        i_left = pos[pp][ind - 1]
        left = 1
        if ind - 2 >= 0:
            left = i_left - pos[pp][ind - 2]
        else:
            left = i_left + 1
    right = 1
    if ind + 1 < len(pos[pp]):
        right = pos[pp][ind + 1] - i
    else:
        right = n - i

    # print(i, pp, left * right, left, right)
    ans += left * right * pp

print(ans)

# https://atcoder.jp/contests/abc140/submissions/7411285
# 写経

def main():
    N = int(input())
    (*p,) = map(int, input().split())

    xtoi = [-1] * (N + 1)
    for i, x in enumerate(p):
        xtoi[x] = i

    L = [-1] * (N + 2)
    R = [N] * (N + 2)
    for i in range(N):
        L[i] = i - 1
        R[i] = i + 1

    iter_inds = iter(xtoi)
    next(iter_inds)

    ans = 0
    for x, ind in enumerate(iter_inds, start=1):
        # l2, ..., l1, ..., x, ..., r1, ..., r2
        # (l2,r1) or (l1,r2)
        l1 = L[ind]
        l2 = L[l1]
        r1 = R[ind]
        r2 = R[r1]
        ans += x * ((l1 - l2) * (r1 - ind) + (r2 - r1) * (ind - l1))
        L[r1] = l1
        R[l1] = r1
    print(ans)

if __name__ == "__main__":
    main()