Input:
import sys

from itertools import accumulate

sys.setrecursionlimit(10 ** 9)

INF = 1 << 60

N, M, Q = map(int, input().split())

G = [[0] * N for _ in range(N)]

for _ in range(M):

    l, r = map(int, input().split())

    G[l - 1][r - 1] += 1

csum = [[0] * (N + 1) for _ in range(N + 1)]

for i in range(N):

    for j in range(N):

        csum[i + 1][j + 1] = csum[i + 1][j] + csum[i][j + 1] - csum[i][j] + G[i][j]

ans = []

for _ in range(Q):

    p, q = map(int, input().split())

    ans.append(csum[q][q] - csum[q][p - 1] - csum[p - 1][q] + csum[p - 1][p - 1])

print(*ans, sep='\n')

import sys

from itertools import accumulate

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

sys.setrecursionlimit(10 ** 9)

INF = 1 << 60

N, M, Q = map(int, readline().split())

G = [[0] * N for _ in range(N)]

for _ in range(M):

    l, r = map(int, readline().split())

    G[l - 1][r - 1] += 1

csum = [[0] * (N + 1) for _ in range(N + 1)]

for i in range(N):

    for j in range(N):

        csum[i + 1][j + 1] = csum[i + 1][j] + csum[i][j + 1] - csum[i][j] + G[i][j]

ans = []

for _ in range(Q):

    p, q = map(int, readline().split())

    ans.append(csum[q][q] - csum[q][p - 1] - csum[p - 1][q] + csum[p - 1][p - 1])

print(*ans, sep='\n')

import sys
from itertools import accumulate

sys.setrecursionlimit(10**9)
INF = 1 << 60
N, M, Q = map(int, input().split())
G = [[0] * N for _ in range(N)]
for _ in range(M):
    l, r = map(int, input().split())
    G[l - 1][r - 1] += 1
csum = [[0] * (N + 1) for _ in range(N + 1)]
for i in range(N):
    for j in range(N):
        csum[i + 1][j + 1] = csum[i + 1][j] + csum[i][j + 1] - csum[i][j] + G[i][j]
ans = []
for _ in range(Q):
    p, q = map(int, input().split())
    ans.append(csum[q][q] - csum[q][p - 1] - csum[p - 1][q] + csum[p - 1][p - 1])
print(*ans, sep="\n")

import sys
from itertools import accumulate

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
N, M, Q = map(int, readline().split())
G = [[0] * N for _ in range(N)]
for _ in range(M):
    l, r = map(int, readline().split())
    G[l - 1][r - 1] += 1
csum = [[0] * (N + 1) for _ in range(N + 1)]
for i in range(N):
    for j in range(N):
        csum[i + 1][j + 1] = csum[i + 1][j] + csum[i][j + 1] - csum[i][j] + G[i][j]
ans = []
for _ in range(Q):
    p, q = map(int, readline().split())
    ans.append(csum[q][q] - csum[q][p - 1] - csum[p - 1][q] + csum[p - 1][p - 1])
print(*ans, sep="\n")

+    l, r = map(int, readline().split())

+    p, q = map(int, readline().split())


Input:
n=int(eval(input()))

a=list(map(str,input().split()))

f=True

for i in range(n):

  if a[i] == "Y":

    f=False

    print("Four")

    break

if f :

  print("Three")

import sys

n = int(eval(input()))

s = sys.stdin.readline().rstrip().split()

print(('Three' if len(set(s)) == 3 else 'Four'))

n = int(eval(input()))
a = list(map(str, input().split()))
f = True
for i in range(n):
    if a[i] == "Y":
        f = False
        print("Four")
        break
if f:
    print("Three")

import sys

n = int(eval(input()))
s = sys.stdin.readline().rstrip().split()
print(("Three" if len(set(s)) == 3 else "Four"))

+print(("Three" if len(set(s)) == 3 else "Four"))


Input:
# coding: utf-8

import sys

#from operator import itemgetter

sysread = sys.stdin.readline

read = sys.stdin.read

#from heapq import heappop, heappush

#from collections import defaultdict

sys.setrecursionlimit(10**7)

import math

from itertools import combinations, product

#import bisect# lower_bound etc

#import numpy as np

def run():

    N,K = list(map(int, read().split()))

    k = int(math.log(N, 10))

    s = N // (10 ** k)

    tmp1, tmp2, div = 1, 1, 1

    for i in range(K-1):

        tmp1 *= k-i

        div *= i+1

        tmp2 *= 9

    ret = tmp1//div * tmp2

    ret *= s-1

    tmp1 *= k - (K-1)

    tmp2 *= 9

    div *= K

    ret += tmp1 * tmp2 // div

    lis = list(range(k))

    nums = list(range(1,10))

    base = s * 10 ** k

    for A in combinations(lis, K-1):

        for X in product(nums, repeat = K-1):

            tmp = base

            for a,x in zip(A,X):

                tmp += 10 ** a * x

            if tmp <= N:

                ret += 1

    print(ret)

if __name__ == "__main__":

    run()

# coding: utf-8

import sys

#from operator import itemgetter

sysread = sys.stdin.readline

read = sys.stdin.read

#from heapq import heappop, heappush

#from collections import defaultdict

sys.setrecursionlimit(10**7)

import math

from itertools import combinations, product

#import bisect# lower_bound etc

#import numpy as np

def run():

    N,K = read().split()

    N = list(map(int,N))

    K = int(K)

    max_i = len(N)

    dp2 = [0] * max_i

    r = 0

    for i, v in enumerate(N):

        if v != 0:

            r += 1

        dp2[i] = r

    dp1 = [[0] * (K+1) for _ in range(max_i)]

    dp1[0][1] = int(N[0]-1)

    dp1[0][0] = 1

    for i in range(1, max_i):

        for j in range(0, K+1):

            if j == 0:

                dp1[i][j] += dp1[i - 1][j]

            else:

                dp1[i][j] += dp1[i - 1][j] + dp1[i - 1][j - 1] * 9

        if N[i] == 0:continue

        if dp2[i-1] <= K:

            dp1[i][dp2[i-1]] += 1

        if dp2[i-1] < K:

            dp1[i][dp2[i-1]+1] += N[i] - 1

    plus = 0

    if dp2[-1] == K:

        plus = 1

    print((dp1[max_i-1][K] + plus))

if __name__ == "__main__":

    run()

# coding: utf-8
import sys

# from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
# from heapq import heappop, heappush
# from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
from itertools import combinations, product

# import bisect# lower_bound etc
# import numpy as np
def run():
    N, K = list(map(int, read().split()))
    k = int(math.log(N, 10))
    s = N // (10**k)
    tmp1, tmp2, div = 1, 1, 1
    for i in range(K - 1):
        tmp1 *= k - i
        div *= i + 1
        tmp2 *= 9
    ret = tmp1 // div * tmp2
    ret *= s - 1
    tmp1 *= k - (K - 1)
    tmp2 *= 9
    div *= K
    ret += tmp1 * tmp2 // div
    lis = list(range(k))
    nums = list(range(1, 10))
    base = s * 10**k
    for A in combinations(lis, K - 1):
        for X in product(nums, repeat=K - 1):
            tmp = base
            for a, x in zip(A, X):
                tmp += 10**a * x
            if tmp <= N:
                ret += 1
    print(ret)

if __name__ == "__main__":
    run()

# coding: utf-8
import sys

# from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
# from heapq import heappop, heappush
# from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
from itertools import combinations, product

# import bisect# lower_bound etc
# import numpy as np
def run():
    N, K = read().split()
    N = list(map(int, N))
    K = int(K)
    max_i = len(N)
    dp2 = [0] * max_i
    r = 0
    for i, v in enumerate(N):
        if v != 0:
            r += 1
        dp2[i] = r
    dp1 = [[0] * (K + 1) for _ in range(max_i)]
    dp1[0][1] = int(N[0] - 1)
    dp1[0][0] = 1
    for i in range(1, max_i):
        for j in range(0, K + 1):
            if j == 0:
                dp1[i][j] += dp1[i - 1][j]
            else:
                dp1[i][j] += dp1[i - 1][j] + dp1[i - 1][j - 1] * 9
        if N[i] == 0:
            continue
        if dp2[i - 1] <= K:
            dp1[i][dp2[i - 1]] += 1
        if dp2[i - 1] < K:
            dp1[i][dp2[i - 1] + 1] += N[i] - 1
    plus = 0
    if dp2[-1] == K:
        plus = 1
    print((dp1[max_i - 1][K] + plus))

if __name__ == "__main__":
    run()

-    N, K = list(map(int, read().split()))

-        for X in product(nums, repeat=K - 1):

+    dp1 = [[0] * (K + 1) for _ in range(max_i)]


Input:
# AOJ 0226: Hit and Blow

# Python3 2018.6.23 bal4u

while 1:

	r, a = input().split()

	if r == '0': break

	h, sr, sa = 0, set(), set()

	for i in range(4):

		if r[i] == a[i]: h += 1

		else:

			sr.add(r[i])

			sa.add(a[i])

	print((h, len(sr & sa)))

# AOJ 0226: Hit and Blow

# Python3 2018.6.25 bal4u

while 1:

	r, a = input().split()

	if r == '0': break

	h = 0

	for i in range(4):

		if r[i] == a[i]: h += 1

	print((h, len(set(r) & set(a))-h))

# AOJ 0226: Hit and Blow
# Python3 2018.6.23 bal4u
while 1:
    r, a = input().split()
    if r == "0":
        break
    h, sr, sa = 0, set(), set()
    for i in range(4):
        if r[i] == a[i]:
            h += 1
        else:
            sr.add(r[i])
            sa.add(a[i])
    print((h, len(sr & sa)))

# AOJ 0226: Hit and Blow
# Python3 2018.6.25 bal4u
while 1:
    r, a = input().split()
    if r == "0":
        break
    h = 0
    for i in range(4):
        if r[i] == a[i]:
            h += 1
    print((h, len(set(r) & set(a)) - h))

+    print((h, len(set(r) & set(a)) - h))


Input:
N = int(eval(input()))

t = 0

for j in range(1,N+1):

  m = N//j

  t += (1+m)*m//2 * j

#

print(t)

N = int(eval(input()))
t = 0
for j in range(1, N + 1):
    m = N // j
    t += (1 + m) * m // 2 * j
#
print(t)


Input:
S = eval(input())

N = len(S)

def f1(S):

    N = len(S)

    subset3 = S[0:(N - 2) // 2 + 1]

    subset4 = S[(N + 2) // 2:]

    return subset3, subset4

subset1, subset2 = f1(S)

_subset2 = ''.join(list(reversed(subset2)))

if subset1 != _subset2:

    print('No')

    exit()

if (N - 1) % 4 == 0:

    # print('subset1 2', subset1, subset2)

    subset3 = subset1[:((N - 1) // 4)]

    subset4 = subset1[((N - 1) // 4):]

    _subset4 = ''.join(list(reversed(subset4)))

    # print('subset3 4', subset3, subset4)

    subset5 = subset2[:((N - 1) // 4)]

    subset6 = subset2[((N - 1) // 4):]

    _subset6 = ''.join(list(reversed(subset6)))

    # print('subset5 6', subset5, subset6)

else:

    subset3, subset4 = f1(subset1)

    _subset4 = ''.join(list(reversed(subset4)))

    subset5, subset6 = f1(subset2)

    _subset6 = ''.join(list(reversed(subset6)))

if subset3 != _subset4:

    print('No')

    exit()

if subset5 != _subset6:

    print('No')

    exit()

print('Yes')

S = eval(input())

N = len(S)

def is_kaibun(s):

    _s = ''.join(list(reversed(s)))

    return s == _s

subset0 = S[0:(N - 2) // 2 + 1]

subset1 = S[(N + 2) // 2:]

ans = 'Yes' if is_kaibun(S) and is_kaibun(subset0) and is_kaibun(

    subset1) else 'No'

print(ans)

S = eval(input())
N = len(S)

def f1(S):
    N = len(S)
    subset3 = S[0 : (N - 2) // 2 + 1]
    subset4 = S[(N + 2) // 2 :]
    return subset3, subset4

subset1, subset2 = f1(S)
_subset2 = "".join(list(reversed(subset2)))
if subset1 != _subset2:
    print("No")
    exit()
if (N - 1) % 4 == 0:
    # print('subset1 2', subset1, subset2)
    subset3 = subset1[: ((N - 1) // 4)]
    subset4 = subset1[((N - 1) // 4) :]
    _subset4 = "".join(list(reversed(subset4)))
    # print('subset3 4', subset3, subset4)
    subset5 = subset2[: ((N - 1) // 4)]
    subset6 = subset2[((N - 1) // 4) :]
    _subset6 = "".join(list(reversed(subset6)))
    # print('subset5 6', subset5, subset6)
else:
    subset3, subset4 = f1(subset1)
    _subset4 = "".join(list(reversed(subset4)))
    subset5, subset6 = f1(subset2)
    _subset6 = "".join(list(reversed(subset6)))
if subset3 != _subset4:
    print("No")
    exit()
if subset5 != _subset6:
    print("No")
    exit()
print("Yes")

S = eval(input())
N = len(S)

def is_kaibun(s):
    _s = "".join(list(reversed(s)))
    return s == _s

subset0 = S[0 : (N - 2) // 2 + 1]
subset1 = S[(N + 2) // 2 :]
ans = "Yes" if is_kaibun(S) and is_kaibun(subset0) and is_kaibun(subset1) else "No"
print(ans)

-    # print('subset1 2', subset1, subset2)

-    _subset4 = "".join(list(reversed(subset4)))

-    # print('subset3 4', subset3, subset4)

-    _subset6 = "".join(list(reversed(subset6)))

-    # print('subset5 6', subset5, subset6)

+ans = "Yes" if is_kaibun(S) and is_kaibun(subset0) and is_kaibun(subset1) else "No"


Input:
from collections import Counter

N = int(eval(input()))

S = [str(sorted(eval(input()))) for _ in range(N)]

count = 0

for i in list(Counter(S).values()):

  count += i*(i-1)//2

print(count)

from collections import Counter

N = int(eval(input()))

S = [eval(input()) for _ in range(N)]

ans = 0

check_box = []

for s in S:

  s = sorted(s)

  s = ''.join(s)

  check_box.append(s)

C = Counter(check_box)

for i in C:

  ans += C[i]*(C[i]-1)//2

print(ans)

from collections import Counter

N = int(eval(input()))
S = [str(sorted(eval(input()))) for _ in range(N)]
count = 0
for i in list(Counter(S).values()):
    count += i * (i - 1) // 2
print(count)

from collections import Counter

N = int(eval(input()))
S = [eval(input()) for _ in range(N)]
ans = 0
check_box = []
for s in S:
    s = sorted(s)
    s = "".join(s)
    check_box.append(s)
C = Counter(check_box)
for i in C:
    ans += C[i] * (C[i] - 1) // 2
print(ans)

-S = [str(sorted(eval(input()))) for _ in range(N)]


Input:
a=0

for i,s in enumerate(eval(input())):a+=i%2^int(s)

print((min(a,i-a+1)))

import sys

s=sys.stdin.buffer.readline().rstrip()

n=len(s)

a=0

for i in range(n):

    a+=s[i]%2==i%2

print((min(a,n-a)))

a = 0
for i, s in enumerate(eval(input())):
    a += i % 2 ^ int(s)
print((min(a, i - a + 1)))

import sys

s = sys.stdin.buffer.readline().rstrip()
n = len(s)
a = 0
for i in range(n):
    a += s[i] % 2 == i % 2
print((min(a, n - a)))


Input:
import sys

sys.setrecursionlimit(10 ** 6)

def dfs(v):

    print(counter)

    for nv in g[v]:

        if nv in visited:

            continue

        visited.add(nv)

        counter[nv] += counter[v]

        dfs(nv)

def input():

    return sys.stdin.readline().strip()

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

g = [set() for _ in range(N)]

for _ in range(N - 1):

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

    a -= 1

    b -= 1

    g[a].add(b)

    g[b].add(a)

counter = [0] * N

for _ in range(Q):

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

    p -= 1

    counter[p] += x

stack = [0]

visited = {0}

while stack:

    v = stack.pop()

    for nv in g[v]:

        if nv in visited:

            continue

        stack.append(nv)

        visited.add(nv)

        counter[nv] += counter[v]

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

import sys

sys.setrecursionlimit(10 ** 6)

def solve():

    def dfs(v):

        print(counter)

        for nv in g[v]:

            if nv in visited:

                continue

            visited.add(nv)

            counter[nv] += counter[v]

            dfs(nv)

    def input():

        return sys.stdin.readline().strip()

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

    g = [set() for _ in range(N)]

    for _ in range(N - 1):

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

        a -= 1

        b -= 1

        g[a].add(b)

        g[b].add(a)

    counter = [0] * N

    for _ in range(Q):

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

        p -= 1

        counter[p] += x

    stack = [0]

    visited = {0}

    while stack:

        v = stack.pop()

        for nv in g[v]:

            if nv in visited:

                continue

            stack.append(nv)

            visited.add(nv)

            counter[nv] += counter[v]

    return counter

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

import sys

sys.setrecursionlimit(10**6)

def dfs(v):
    print(counter)
    for nv in g[v]:
        if nv in visited:
            continue
        visited.add(nv)
        counter[nv] += counter[v]
        dfs(nv)

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

N, Q = list(map(int, input().split()))
g = [set() for _ in range(N)]
for _ in range(N - 1):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    g[a].add(b)
    g[b].add(a)
counter = [0] * N
for _ in range(Q):
    p, x = list(map(int, input().split()))
    p -= 1
    counter[p] += x
stack = [0]
visited = {0}
while stack:
    v = stack.pop()
    for nv in g[v]:
        if nv in visited:
            continue
        stack.append(nv)
        visited.add(nv)
        counter[nv] += counter[v]
print((" ".join(map(str, counter))))

import sys

sys.setrecursionlimit(10**6)

def solve():
    def dfs(v):
        print(counter)
        for nv in g[v]:
            if nv in visited:
                continue
            visited.add(nv)
            counter[nv] += counter[v]
            dfs(nv)

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

    N, Q = list(map(int, input().split()))
    g = [set() for _ in range(N)]
    for _ in range(N - 1):
        a, b = list(map(int, input().split()))
        a -= 1
        b -= 1
        g[a].add(b)
        g[b].add(a)
    counter = [0] * N
    for _ in range(Q):
        p, x = list(map(int, input().split()))
        p -= 1
        counter[p] += x
    stack = [0]
    visited = {0}
    while stack:
        v = stack.pop()
        for nv in g[v]:
            if nv in visited:
                continue
            stack.append(nv)
            visited.add(nv)
            counter[nv] += counter[v]
    return counter

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

+        return sys.stdin.readline().strip()

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

+        a, b = list(map(int, input().split()))

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

-    return sys.stdin.readline().strip()

-    a, b = list(map(int, input().split()))

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


Input:
#!/usr/bin/env python3

import collections

import sys

input=sys.stdin.readline

def gcd(a,b):

    if b==0:

        return a

    else:

        return gcd(b,a%b)

def judge(n,arr):

    MAX=10**6

    table=[i for i in range(MAX+1)]

    for i in range(2,MAX+1):

        if table[i]<i:

            continue

        for j in range(i,MAX+1,i):

            table[j]=i

    cnt=collections.defaultdict(int)

    for val in arr:

        s=set()

        while val!=1:

            prime=table[val]

            s.add(prime)

            val//=prime

        for tmp in s:

            cnt[tmp]+=1

    for val in list(cnt.values()):

        if val>=2:

            return False

    return True

n=int(eval(input()))

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

tmp=arr[0]

for val in arr:

    tmp=gcd(tmp,val)

if tmp==1:

    is_setwise=True

else:

    is_setwise=False

is_pairwise=judge(n,arr)

if is_pairwise==True:

    print('pairwise coprime')

elif is_setwise==True:

    print('setwise coprime')

else:

    print('not coprime')

import collections

import sys

input=sys.stdin.readline

def divisors(n):

  ret=[]

  for i in range(2,int(n**0.5)+1):

    if n%i==0:

      ret.append(i)

      while n%i==0:

        n//=i

  if n!=1:

    ret.append(n)

  return ret

def gcd(a,b):

  if b==0:

    return a

  else:

    return gcd(b,a%b)

n=int(eval(input()))

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

cnt=[False]*(max(arr)+1)

is_pairwise=True

tmp=arr[0]

for val in arr:

  tmp=gcd(tmp,val)

  if is_pairwise==False:

    continue

  divisor=divisors(val)

  for val2 in divisor:

    if cnt[val2]==True:

      is_pairwise=False

      break

    cnt[val2]=True

if tmp==1:

  is_setwise=True

else:

  is_setwise=False

if is_pairwise==True:

  print('pairwise coprime')

elif is_setwise==True:

  print('setwise coprime')

else:

  print('not coprime')

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

input = sys.stdin.readline

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

def judge(n, arr):
    MAX = 10**6
    table = [i for i in range(MAX + 1)]
    for i in range(2, MAX + 1):
        if table[i] < i:
            continue
        for j in range(i, MAX + 1, i):
            table[j] = i
    cnt = collections.defaultdict(int)
    for val in arr:
        s = set()
        while val != 1:
            prime = table[val]
            s.add(prime)
            val //= prime
        for tmp in s:
            cnt[tmp] += 1
    for val in list(cnt.values()):
        if val >= 2:
            return False
    return True

n = int(eval(input()))
arr = list(map(int, input().split()))
tmp = arr[0]
for val in arr:
    tmp = gcd(tmp, val)
if tmp == 1:
    is_setwise = True
else:
    is_setwise = False
is_pairwise = judge(n, arr)
if is_pairwise == True:
    print("pairwise coprime")
elif is_setwise == True:
    print("setwise coprime")
else:
    print("not coprime")

import collections
import sys

input = sys.stdin.readline

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

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

n = int(eval(input()))
arr = list(map(int, input().split()))
cnt = [False] * (max(arr) + 1)
is_pairwise = True
tmp = arr[0]
for val in arr:
    tmp = gcd(tmp, val)
    if is_pairwise == False:
        continue
    divisor = divisors(val)
    for val2 in divisor:
        if cnt[val2] == True:
            is_pairwise = False
            break
        cnt[val2] = True
if tmp == 1:
    is_setwise = True
else:
    is_setwise = False
if is_pairwise == True:
    print("pairwise coprime")
elif is_setwise == True:
    print("setwise coprime")
else:
    print("not coprime")

+    for i in range(2, int(n**0.5) + 1):

-    table = [i for i in range(MAX + 1)]


Input:
n = int(eval(input()))

arr = {}

for i in range(n):

    s = eval(input())

    if not s in arr:

        arr[s] = 1

    else:

        arr[s] += 1

max_count = max(arr.values())

dic = [key[0] for key in list(arr.items()) if key[1] == max_count]

out_sort = sorted(dic)

for i in out_sort:

    print(i)

n = int(eval(input()))

arr = {}

for i in range(n):

    s = eval(input())

    if not s in arr:

        arr[s] = 1

    else:

        arr[s] += 1

max_count = max(arr.values())

dic = [key[0] for key in list(arr.items()) if key[1] == max_count]

out_sort = sorted(dic)

print(("\n".join(out_sort)))

-for i in out_sort:
-    print(i)
+print(("\n".join(out_sort)))


Input:
import sys

sys.setrecursionlimit(500000)

def input():

    return sys.stdin.readline()[:-1]

class BIT:

    def __init__(self, L):

        self.N = len(L)

        self.bit = [0]*self.N

        for i,l in enumerate(L):

            self.add(i,l)

    def add(self, a, w):

        x = a + 1

        for i in range(1000):

            self.bit[x-1] += w

            x += x & -x

            if x > self.N:

                break

    def sum(self, a):

        x = a+1

        ret = 0

        for i in range(1000):

            ret += self.bit[x-1]

            x -= x & -x

            if x <= 0:

                break

        return ret

def main():

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

    enemy = []

    for i in range(N):

        x,h = list(map(int,input().split()))

        if h%A==0:

            enemy.append([x,h//A])

        else:

            enemy.append([x,h//A+1])

    enemy.sort(key=lambda x:x[0])

    def bisect(index):

        x = enemy[index][0]

        if enemy[N-1][0] <= x + 2*D:

            return N-1

        l = index

        r = N-1

        while r-l>1:

            if enemy[(r+l)//2][0] <= x + 2*D:

                l = (r+l)//2

            else:

                r = (r+l)//2

        return l

    bit = BIT([0]*N)

    count1 = 0

    for i in range(N):

        if i>0:

            v = bit.sum(N-1) - bit.sum(i-1)

        else:

            v=0

        if enemy[i][1] - v>0:

            count1 += enemy[i][1] - v

            j = bisect(i)

            bit.add(j,enemy[i][1] - v)

    enemy = enemy[::-1]

    for i in range(N):

        enemy[i][0] = -enemy[i][0]

    bit = BIT([0]*N)

    count2 = 0

    for i in range(N):

        if i>0:

            v = bit.sum(N-1) - bit.sum(i-1)

        else:

            v = 0

        if enemy[i][1] - v>0:

            count2 += enemy[i][1] - v

            j = bisect(i)

            bit.add(j,enemy[i][1] - v)

    print((min(count1,count2)))

if __name__ == '__main__':

    main()

import sys

sys.setrecursionlimit(500000)

def input():

    return sys.stdin.readline()[:-1]

class DualSegmentTree:

    def __init__(self, n) :

        self.n = n

        self.N0 = 1 << n.bit_length()

        self.data = [0] * (self.N0*2)

    def update(self, l, r, val) :

        l += self.N0

        r += self.N0

        while l < r:

            if l & 1:

                self.data[l] = self.data[l] + val

                l += 1

            if r & 1:

                self.data[r-1] = self.data[r-1] + val

                r -= 1

            l //= 2

            r //= 2

    def query(self, i):

        i += len(self.data) // 2

        ret = self.data[i]

        while i > 0:

            i //= 2

            ret = ret + self.data[i]

        return ret

def main():

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

    enemy = []

    for i in range(N):

        x,h = list(map(int,input().split()))

        if h%A==0:

            enemy.append([x,h//A])

        else:

            enemy.append([x,h//A+1])

    enemy.sort(key=lambda x:x[0])

    def bisect(index):

        x = enemy[index][0]

        if enemy[N-1][0] <= x + 2*D:

            return N-1

        l = index

        r = N-1

        while r-l>1:

            if enemy[(r+l)//2][0] <= x + 2*D:

                l = (r+l)//2

            else:

                r = (r+l)//2

        return l

    ST = DualSegmentTree(N)

    for i in range(N):

        ST.update(i,i+1,enemy[i][1])

    count = 0

    for i in range(N):

        v = ST.query(i)

        if v>0:

            count += v

            j = bisect(i)

            ST.update(i,j+1,-v)

    print(count)

if __name__ == '__main__':

    main()

import sys

sys.setrecursionlimit(500000)

def input():
    return sys.stdin.readline()[:-1]

class BIT:
    def __init__(self, L):
        self.N = len(L)
        self.bit = [0] * self.N
        for i, l in enumerate(L):
            self.add(i, l)

    def add(self, a, w):
        x = a + 1
        for i in range(1000):
            self.bit[x - 1] += w
            x += x & -x
            if x > self.N:
                break

    def sum(self, a):
        x = a + 1
        ret = 0
        for i in range(1000):
            ret += self.bit[x - 1]
            x -= x & -x
            if x <= 0:
                break
        return ret

def main():
    N, D, A = list(map(int, input().split()))
    enemy = []
    for i in range(N):
        x, h = list(map(int, input().split()))
        if h % A == 0:
            enemy.append([x, h // A])
        else:
            enemy.append([x, h // A + 1])
    enemy.sort(key=lambda x: x[0])

    def bisect(index):
        x = enemy[index][0]
        if enemy[N - 1][0] <= x + 2 * D:
            return N - 1
        l = index
        r = N - 1
        while r - l > 1:
            if enemy[(r + l) // 2][0] <= x + 2 * D:
                l = (r + l) // 2
            else:
                r = (r + l) // 2
        return l

    bit = BIT([0] * N)
    count1 = 0
    for i in range(N):
        if i > 0:
            v = bit.sum(N - 1) - bit.sum(i - 1)
        else:
            v = 0
        if enemy[i][1] - v > 0:
            count1 += enemy[i][1] - v
            j = bisect(i)
            bit.add(j, enemy[i][1] - v)
    enemy = enemy[::-1]
    for i in range(N):
        enemy[i][0] = -enemy[i][0]
    bit = BIT([0] * N)
    count2 = 0
    for i in range(N):
        if i > 0:
            v = bit.sum(N - 1) - bit.sum(i - 1)
        else:
            v = 0
        if enemy[i][1] - v > 0:
            count2 += enemy[i][1] - v
            j = bisect(i)
            bit.add(j, enemy[i][1] - v)
    print((min(count1, count2)))

if __name__ == "__main__":
    main()

import sys

sys.setrecursionlimit(500000)

def input():
    return sys.stdin.readline()[:-1]

class DualSegmentTree:
    def __init__(self, n):
        self.n = n
        self.N0 = 1 << n.bit_length()
        self.data = [0] * (self.N0 * 2)

    def update(self, l, r, val):
        l += self.N0
        r += self.N0
        while l < r:
            if l & 1:
                self.data[l] = self.data[l] + val
                l += 1
            if r & 1:
                self.data[r - 1] = self.data[r - 1] + val
                r -= 1
            l //= 2
            r //= 2

    def query(self, i):
        i += len(self.data) // 2
        ret = self.data[i]
        while i > 0:
            i //= 2
            ret = ret + self.data[i]
        return ret

def main():
    N, D, A = list(map(int, input().split()))
    enemy = []
    for i in range(N):
        x, h = list(map(int, input().split()))
        if h % A == 0:
            enemy.append([x, h // A])
        else:
            enemy.append([x, h // A + 1])
    enemy.sort(key=lambda x: x[0])

    def bisect(index):
        x = enemy[index][0]
        if enemy[N - 1][0] <= x + 2 * D:
            return N - 1
        l = index
        r = N - 1
        while r - l > 1:
            if enemy[(r + l) // 2][0] <= x + 2 * D:
                l = (r + l) // 2
            else:
                r = (r + l) // 2
        return l

    ST = DualSegmentTree(N)
    for i in range(N):
        ST.update(i, i + 1, enemy[i][1])
    count = 0
    for i in range(N):
        v = ST.query(i)
        if v > 0:
            count += v
            j = bisect(i)
            ST.update(i, j + 1, -v)
    print(count)

if __name__ == "__main__":
    main()

+        self.data = [0] * (self.N0 * 2)

+                self.data[l] = self.data[l] + val

+                self.data[r - 1] = self.data[r - 1] + val

-            v = bit.sum(N - 1) - bit.sum(i - 1)

+        ST.update(i, i + 1, enemy[i][1])

-            bit.add(j, enemy[i][1] - v)

-            v = bit.sum(N - 1) - bit.sum(i - 1)

-            bit.add(j, enemy[i][1] - v)


Input:
def main():

    N = int(eval(input()))

    A, B = (int(i) for i in input().split())

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

    cnt = [0, 0, 0]

    for p in P:

        if p <= A:

            cnt[0] += 1

        elif p <= B:

            cnt[1] += 1

        else:

            cnt[2] += 1

    print((min(cnt)))

if __name__ == '__main__':

    main()

def main():

    N = int(eval(input()))

    A, B = (int(i) for i in input().split())

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

    cnt = [0]*3

    for p in P:

        if p <= A:

            cnt[0] += 1

        elif p <= B:

            cnt[1] += 1

        else:

            cnt[2] += 1

    print((min(cnt)))

if __name__ == '__main__':

    main()

def main():
    N = int(eval(input()))
    A, B = (int(i) for i in input().split())
    P = [int(i) for i in input().split()]
    cnt = [0, 0, 0]
    for p in P:
        if p <= A:
            cnt[0] += 1
        elif p <= B:
            cnt[1] += 1
        else:
            cnt[2] += 1
    print((min(cnt)))

if __name__ == "__main__":
    main()

def main():
    N = int(eval(input()))
    A, B = (int(i) for i in input().split())
    P = [int(i) for i in input().split()]
    cnt = [0] * 3
    for p in P:
        if p <= A:
            cnt[0] += 1
        elif p <= B:
            cnt[1] += 1
        else:
            cnt[2] += 1
    print((min(cnt)))

if __name__ == "__main__":
    main()


Input:
from heapq import heappop, heappush

inf = float('inf')

N = int(eval(input()))

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

# sum_max[k] : [0,k)のうちN個までの総和の最大値

# sum_min[k] : (3N-1-k,3N-1]のうちN個までの総和の最小値

sum_max = [0]*(3*N+1)

sum_min = [0]*(3*N+1)

def init_max():

    res = 0

    hq = []

    for i, a in enumerate(A):

        if len(hq) < N:

            heappush(hq,a)

            res += a

        else:

            if hq[0] < a:

                res -= heappop(hq)

                heappush(hq,a)

                res += a

        sum_max[i+1] = res

def init_min():

    res = 0

    hq = []

    for i, a in enumerate(A[::-1]):

        if len(hq) < N:

            heappush(hq,-a)

            res += a

        else:

            if -hq[0] > a:

                res -= -heappop(hq)

                heappush(hq,-a)

                res += a

        sum_min[i+1] = res

init_max()

init_min()

ans = -inf

for k in range(N,2*N+1):

    res = sum_max[k] - sum_min[3*N-k]

    ans = max(ans, res)

print(ans)

from heapq import heappop, heappush

inf = float('inf')

N = int(eval(input()))

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

l = []

res = 0

for i in range(N):

    heappush(l, A[i])

    res += A[i]

ls = []

ls.append(res)

for i in range(N, 2*N):

    heappush(l, A[i])

    res += A[i]

    res -= heappop(l)

    ls.append(res)

A.reverse()

s = []

res = 0

for i in range(N):

    heappush(s, -A[i])

    res += A[i]

ss = []

ss.append(res)

for i in range(N, 2*N):

    heappush(s, -A[i])

    res += A[i]

    res -= -heappop(s)

    ss.append(res)

ss.reverse()

ans = -inf

for i in range(N+1):

    score = ls[i] - ss[i]

    ans = max(ans, score)

print(ans)

from heapq import heappop, heappush

inf = float("inf")
N = int(eval(input()))
A = list(map(int, input().split()))
# sum_max[k] : [0,k)のうちN個までの総和の最大値
# sum_min[k] : (3N-1-k,3N-1]のうちN個までの総和の最小値
sum_max = [0] * (3 * N + 1)
sum_min = [0] * (3 * N + 1)

def init_max():
    res = 0
    hq = []
    for i, a in enumerate(A):
        if len(hq) < N:
            heappush(hq, a)
            res += a
        else:
            if hq[0] < a:
                res -= heappop(hq)
                heappush(hq, a)
                res += a
        sum_max[i + 1] = res

def init_min():
    res = 0
    hq = []
    for i, a in enumerate(A[::-1]):
        if len(hq) < N:
            heappush(hq, -a)
            res += a
        else:
            if -hq[0] > a:
                res -= -heappop(hq)
                heappush(hq, -a)
                res += a
        sum_min[i + 1] = res

init_max()
init_min()
ans = -inf
for k in range(N, 2 * N + 1):
    res = sum_max[k] - sum_min[3 * N - k]
    ans = max(ans, res)
print(ans)

from heapq import heappop, heappush

inf = float("inf")
N = int(eval(input()))
A = list(map(int, input().split()))
l = []
res = 0
for i in range(N):
    heappush(l, A[i])
    res += A[i]
ls = []
ls.append(res)
for i in range(N, 2 * N):
    heappush(l, A[i])
    res += A[i]
    res -= heappop(l)
    ls.append(res)
A.reverse()
s = []
res = 0
for i in range(N):
    heappush(s, -A[i])
    res += A[i]
ss = []
ss.append(res)
for i in range(N, 2 * N):
    heappush(s, -A[i])
    res += A[i]
    res -= -heappop(s)
    ss.append(res)
ss.reverse()
ans = -inf
for i in range(N + 1):
    score = ls[i] - ss[i]
    ans = max(ans, score)
print(ans)

-# sum_min[k] : (3N-1-k,3N-1]のうちN個までの総和の最小値

-    res = sum_max[k] - sum_min[3 * N - k]


Input:
from itertools import groupby

eval(input())

print((sum(map(bool, groupby(eval(input()))))))

from itertools import groupby

eval(input())

print((sum(1 for _ in groupby(eval(input())))))

+print((sum(1 for _ in groupby(eval(input())))))


Input:
#実験

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

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

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

a = [1]

score = 0

# 深さ優先探索(Depth First Search)

def dfs(seq):

    if len(seq) == n:

        global score

        tmp_score = 0

        for a, b, c, d in integer_set:

            if seq[b-1] - seq[a-1] == c:

                tmp_score += d

            else:

                tmp_score += 0

        score = max(score, tmp_score)

    else:

        for i in range(seq[-1], m+1):

            tmp_seq = seq.copy()

            tmp_seq.append(i)

            dfs(tmp_seq)

dfs(a)

print(score)

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

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

S=[1]*N#1がNこ入った配列

def dfs(d):

    if d==N-1:

        t=0

        for a,b,c,d in R:

            if S[b-1]-S[a-1]==c:

                t+=d

        return t

    else:

        m=0

        for i in range(S[d],M+1):

            S[d+1]=i

            m=max(m,dfs(d+1))

        return m

print((dfs(0)))

# 実験
# -*- coding: utf-8 -*-
n, m, q = list(map(int, input().split()))
integer_set = [list(map(int, input().split())) for _ in range(q)]
a = [1]
score = 0
# 深さ優先探索(Depth First Search)
def dfs(seq):
    if len(seq) == n:
        global score
        tmp_score = 0
        for a, b, c, d in integer_set:
            if seq[b - 1] - seq[a - 1] == c:
                tmp_score += d
            else:
                tmp_score += 0
        score = max(score, tmp_score)
    else:
        for i in range(seq[-1], m + 1):
            tmp_seq = seq.copy()
            tmp_seq.append(i)
            dfs(tmp_seq)

dfs(a)
print(score)

N, M, Q = list(map(int, input().split()))
R = [list(map(int, input().split())) for i in range(Q)]
S = [1] * N  # 1がNこ入った配列

def dfs(d):
    if d == N - 1:
        t = 0
        for a, b, c, d in R:
            if S[b - 1] - S[a - 1] == c:
                t += d
        return t
    else:
        m = 0
        for i in range(S[d], M + 1):
            S[d + 1] = i
            m = max(m, dfs(d + 1))
        return m

print((dfs(0)))

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

-integer_set = [list(map(int, input().split())) for _ in range(q)]

-        for i in range(seq[-1], m + 1):

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

+R = [list(map(int, input().split())) for i in range(Q)]


Input:
class UnionFind:

    def __init__(self, n):

        self.root = [i for i in range(n + 1)]

        self.rank = [0] * (n + 1)

    def find(self, x):

        if self.root[x] == x:

            return x

        else:

            self.root[x] = self.find(self.root[x])

            return self.root[x]

    def isSame(self, x, y):

        return self.find(x) == self.find(y)

    def union(self, x, y):

        x = self.find(x)

        y = self.find(y)

        if self.rank[x] < self.rank[y]:

            self.root[x] = y

        else:

            self.root[y] = x

            if self.rank[x] == self.rank[y]:

                self.rank[x] += 1

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

uf = UnionFind(n)

for _ in range(m):

    x, y, z = list(map(int, input().split()))

    uf.union(x, y)

for i in range(1, n + 1):

    uf.find(i)

n_tree = set(uf.root)

ans = len(n_tree) - 1

print(ans)

from collections import deque

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

graph = [[] * n for _ in range(n)]

for _ in range(m):

    x, y, z = list(map(int, input().split()))

    x -= 1

    y -= 1

    z %= 2

    graph[x].append((y))

    graph[y].append((x))

seen = [False] * n

ans = 0

for i in range(n):

    if not seen[i]:

        seen[i] = True

        node = deque(graph[i])

        while node:

            v = node.popleft()

            if seen[v]:

                continue

            seen[v] = True

            node.extend(graph[v])

        ans += 1

print(ans)

-        self.root = [i for i in range(n + 1)]

-            self.root[x] = self.find(self.root[x])

-        return self.find(x) == self.find(y)

-        if self.rank[x] < self.rank[y]:

-            if self.rank[x] == self.rank[y]:


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

n = (n - (n//k-1)*k) if n > k else n

n_min = 0

while n_min <= n:

    n_min = abs(n-k)

    if n_min >= n and n < k:

        print((min(n_min, n)))

        break

    n = n_min

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

n = n%k

if abs(n-k) > n:

    print(n)

else:

    print((abs(n-k)))

n, k = list(map(int, input().split()))
n = (n - (n // k - 1) * k) if n > k else n
n_min = 0
while n_min <= n:
    n_min = abs(n - k)
    if n_min >= n and n < k:
        print((min(n_min, n)))
        break
    n = n_min

n, k = list(map(int, input().split()))
n = n % k
if abs(n - k) > n:
    print(n)
else:
    print((abs(n - k)))

-n = (n - (n // k - 1) * k) if n > k else n


Input:
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools

N, M = [int(_) for _ in input().split()]

AB = [[int(_) for _ in input().split()] for _ in range(N - 1 + M)]

G = [set() for _ in range(N + 1)]

count = [0] * (N + 1)

ans = [0] * (N + 1)

for a, b in AB:

    G[a].add(b)

    count[b] += 1

for i in range(1, N):

    if count[i] == 0:

        root = collections.deque([i])

        break

while root:

    p = root.popleft()

    for c in G[p]:

        count[c] -= 1

        if count[c] == 0:

            ans[c] = p

            root.append(c)

print(*ans[1:], sep='\n')

import collections

N, M, *AB = [int(_) for _ in open(0).read().split()]

parent_children = collections.defaultdict(set)

child_parents = collections.defaultdict(set)

for a, b in zip(AB[::2], AB[1::2]):

    parent_children[a].add(b)

    child_parents[b].add(a)

root = (set(range(1, N + 1)) - set(child_parents.keys())).pop()

def bfs(root):

    Q = collections.deque([root])

    while Q:

        cur = Q.pop()

        for to in parent_children[cur]:

            if len(child_parents[to]) > 1:

                child_parents[to].remove(cur)

            else:

                Q += [to]

bfs(root)

child_parents[root] = {0}

for i in range(1, N + 1):

    print((child_parents[i].pop()))

import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools

N, M = [int(_) for _ in input().split()]
AB = [[int(_) for _ in input().split()] for _ in range(N - 1 + M)]
G = [set() for _ in range(N + 1)]
count = [0] * (N + 1)
ans = [0] * (N + 1)
for a, b in AB:
    G[a].add(b)
    count[b] += 1
for i in range(1, N):
    if count[i] == 0:
        root = collections.deque([i])
        break
while root:
    p = root.popleft()
    for c in G[p]:
        count[c] -= 1
        if count[c] == 0:
            ans[c] = p
            root.append(c)
print(*ans[1:], sep="\n")

-import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools

-N, M = [int(_) for _ in input().split()]

-AB = [[int(_) for _ in input().split()] for _ in range(N - 1 + M)]

+N, M, *AB = [int(_) for _ in open(0).read().split()]

+root = (set(range(1, N + 1)) - set(child_parents.keys())).pop()

+        for to in parent_children[cur]:

+            if len(child_parents[to]) > 1:

+                child_parents[to].remove(cur)


Input:
n=int(eval(input()))

f=[]

for i in range(n):

    tmp=0

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

    for j in range(10):

        tmp+=op[j]<<j

    f.append(tmp)

p=[]

for i in range(n):

    p.append(list(map(int,input().split())))

ans=-10**12

for i in range(1, 1<<10):

    tmp=0

    for j in range(n):

        consist=list(bin(f[j]&i)[2:])

        cnt=0

        for k in consist:

            if k=='1':

                cnt+=1

        tmp+=p[j][cnt]

    ans=max(ans,tmp)

print(ans)

n=int(eval(input()))

f=[]

for i in range(n):

    tmp=0

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

    for j in range(10):

        tmp+=op[j]<<j

    f.append(tmp)

p=[]

for i in range(n):

    p.append(list(map(int,input().split())))

ans=-10**12

for i in range(1, 1<<10):

    tmp=0

    for j in range(n):

        consist=f[j]&i

        cnt=0

        for k in range(10):

            if (consist>>k)%2:

                cnt+=1

        tmp+=p[j][cnt]

    ans=max(ans,tmp)

print(ans)

n = int(eval(input()))
f = []
for i in range(n):
    tmp = 0
    op = list(map(int, input().split()))
    for j in range(10):
        tmp += op[j] << j
    f.append(tmp)
p = []
for i in range(n):
    p.append(list(map(int, input().split())))
ans = -(10**12)
for i in range(1, 1 << 10):
    tmp = 0
    for j in range(n):
        consist = list(bin(f[j] & i)[2:])
        cnt = 0
        for k in consist:
            if k == "1":
                cnt += 1
        tmp += p[j][cnt]
    ans = max(ans, tmp)
print(ans)

n = int(eval(input()))
f = []
for i in range(n):
    tmp = 0
    op = list(map(int, input().split()))
    for j in range(10):
        tmp += op[j] << j
    f.append(tmp)
p = []
for i in range(n):
    p.append(list(map(int, input().split())))
ans = -(10**12)
for i in range(1, 1 << 10):
    tmp = 0
    for j in range(n):
        consist = f[j] & i
        cnt = 0
        for k in range(10):
            if (consist >> k) % 2:
                cnt += 1
        tmp += p[j][cnt]
    ans = max(ans, tmp)
print(ans)

-        consist = list(bin(f[j] & i)[2:])


Input:
import sys

read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines

sys.setrecursionlimit(10 ** 9)

INF = 1 << 60

def gcd(a, b):

    while b:

        a, b = b, a % b

    return a

def lcm(a, b):

    return a * b // gcd(a, b)

def main():

    N, M = list(map(int, readline().split()))

    A = list(map(int, readline().split()))

    B = A.copy()

    while not any(b % 2 for b in B):

        B = [b // 2 for b in B]

    if not all(b % 2 for b in B):

        print((0))

        return

    semi_lcm = 1

    for a in A:

        semi_lcm = lcm(semi_lcm, a // 2)

    print(((M // semi_lcm + 1) // 2))

    return

if __name__ == '__main__':

    main()

import sys

read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines

sys.setrecursionlimit(10 ** 9)

INF = 1 << 60

def gcd(a, b):

    while b:

        a, b = b, a % b

    return a

def lcm(a, b):

    return a * b // gcd(a, b)

def main():

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

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

    B = A.copy()

    while not any(b % 2 for b in B):

        B = [b // 2 for b in B]

    if not all(b % 2 for b in B):

        print((0))

        return

    semi_lcm = 1

    for a in A:

        semi_lcm = lcm(semi_lcm, a // 2)

    print(((M // semi_lcm + 1) // 2))

    return

if __name__ == '__main__':

    main()

import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd(a, b)

def main():
    N, M = list(map(int, readline().split()))
    A = list(map(int, readline().split()))
    B = A.copy()
    while not any(b % 2 for b in B):
        B = [b // 2 for b in B]
    if not all(b % 2 for b in B):
        print((0))
        return
    semi_lcm = 1
    for a in A:
        semi_lcm = lcm(semi_lcm, a // 2)
    print(((M // semi_lcm + 1) // 2))
    return

if __name__ == "__main__":
    main()

import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd(a, b)

def main():
    N, M = list(map(int, input().split()))
    A = list(set(map(int, input().split(" "))))
    B = A.copy()
    while not any(b % 2 for b in B):
        B = [b // 2 for b in B]
    if not all(b % 2 for b in B):
        print((0))
        return
    semi_lcm = 1
    for a in A:
        semi_lcm = lcm(semi_lcm, a // 2)
    print(((M // semi_lcm + 1) // 2))
    return

if __name__ == "__main__":
    main()

-    N, M = list(map(int, readline().split()))

-    A = list(map(int, readline().split()))

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

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


Input:
def main():

    s = eval(input())

    q =int(eval(input()))

    ten = 0

    r = []

    l = []

    for _ in range(q):

        ls = tuple(map(str, input().split()))

        if len(ls)==1:

            ten +=1

        else:

            if ls[1] =='1':

                if ten%2 ==0:

                    l.append(ls[2])

                else:

                    r.append(ls[2])

            else:

                if ten%2 ==1:

                    l.append(ls[2])

                else:

                    r.append(ls[2])

    s = ''.join(reversed(l))+s+''.join(r)

    if ten%2 ==1:

        s = s[::-1]

    print(s)

if __name__ == '__main__':

    main()

def main():

    import sys

    s = eval(input())

    q =int(eval(input()))

    ten = 0

    r = []

    l = []

    for _ in range(q):

        ls = tuple(map(str, sys.stdin.readline().split()))

        if len(ls)==1:

            ten +=1

        else:

            if ls[1] =='1':

                if ten%2 ==0:

                    l.append(ls[2])

                else:

                    r.append(ls[2])

            else:

                if ten%2 ==1:

                    l.append(ls[2])

                else:

                    r.append(ls[2])

    s = ''.join(reversed(l))+s+''.join(r)

    if ten%2 ==1:

        s = s[::-1]

    print(s)

if __name__ == '__main__':

    main()

def main():
    s = eval(input())
    q = int(eval(input()))
    ten = 0
    r = []
    l = []
    for _ in range(q):
        ls = tuple(map(str, input().split()))
        if len(ls) == 1:
            ten += 1
        else:
            if ls[1] == "1":
                if ten % 2 == 0:
                    l.append(ls[2])
                else:
                    r.append(ls[2])
            else:
                if ten % 2 == 1:
                    l.append(ls[2])
                else:
                    r.append(ls[2])
    s = "".join(reversed(l)) + s + "".join(r)
    if ten % 2 == 1:
        s = s[::-1]
    print(s)

if __name__ == "__main__":
    main()

def main():
    import sys

    s = eval(input())
    q = int(eval(input()))
    ten = 0
    r = []
    l = []
    for _ in range(q):
        ls = tuple(map(str, sys.stdin.readline().split()))
        if len(ls) == 1:
            ten += 1
        else:
            if ls[1] == "1":
                if ten % 2 == 0:
                    l.append(ls[2])
                else:
                    r.append(ls[2])
            else:
                if ten % 2 == 1:
                    l.append(ls[2])
                else:
                    r.append(ls[2])
    s = "".join(reversed(l)) + s + "".join(r)
    if ten % 2 == 1:
        s = s[::-1]
    print(s)

if __name__ == "__main__":
    main()

-        ls = tuple(map(str, input().split()))

+        ls = tuple(map(str, sys.stdin.readline().split()))


Input:
N , Ma, Mb = list(map(int, input().split()))

# 入力値の受け取り方を変える

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

#a = [0] * N

#b = [0] * N

#c = [0] * N

#for i in range(N):

#    a[i], b[i], c[i] = map(int, input().split())

# TLEになってしまうためinfを5000とかで設定する

INF = 5000

# さらに計算量を落とすため10 * N + 1などを定数で設定する →　関係なかったため戻す

# 最小値を求める問題なのでinfで初期化

# dp[i][sun_a][sum_b]で考えていく

dp = [[[INF] * (10 * N + 1) for _ in range(10 * N + 1)] for _ in range(N+1)]

# 初期選択状態を0とする

dp[0][0][0] = 0

for i in range(N):

    a,b,c=arr[i]

    for j in range(10*N+1):

        for k in range(10*N+1):

            if dp[i][j][k] == INF:

                continue

            # 選ばなかった場合

            dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k])

            # 選んだ場合

            dp[i+1][j+a][k+b] = min(dp[i+1][j+a][k+b], dp[i][j][k] + c)

ans = INF

# 0スタートは何を選んでいない状態となり最小値が0になってしまうため1から開始する

# TLEになったため変更

#for i in range(1,10 * N + 1):

#    for j in range(1,10 * N + 1):

#        if i * Mb != j * Ma:

#            continue

#        ans = min(ans, dp[N][i][j])

#

for i in range(1, 10*N+1):

        if i*Ma>10*N or i*Mb>10*N:

            break

        ans = min(ans, dp[N][i*Ma][i*Mb])

if ans == INF:

    print((-1))

else:

    print(ans)

def calc():

  n,ma,mb=list(map(int,input().split()))

  dp=[[[5000]*401 for _ in range(401)] for _ in range(41)]

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

  dp[0][0][0]=0

  for t in range(n):

    a,b,c=arr[t]

    for i in range(401):

      for j in range(401):

        if dp[t][i][j]==5000:

          continue

        dp[t+1][i][j]=min(dp[t+1][i][j],dp[t][i][j])

        dp[t+1][i+a][j+b]=min(dp[t+1][i+a][j+b],dp[t][i][j]+c)

  ans=5000

  for i in range(1,401):

    if i*ma>400 or i*mb>400:

      break

    ans=min(ans,dp[n][i*ma][i*mb])

  if ans==5000:

    print((-1))

  else:

    print(ans)

calc()

N, Ma, Mb = list(map(int, input().split()))
# 入力値の受け取り方を変える
arr = [list(map(int, input().split())) for _ in range(N)]
# a = [0] * N
# b = [0] * N
# c = [0] * N
# for i in range(N):
#    a[i], b[i], c[i] = map(int, input().split())
# TLEになってしまうためinfを5000とかで設定する
INF = 5000
# さらに計算量を落とすため10 * N + 1などを定数で設定する →　関係なかったため戻す
# 最小値を求める問題なのでinfで初期化
# dp[i][sun_a][sum_b]で考えていく
dp = [[[INF] * (10 * N + 1) for _ in range(10 * N + 1)] for _ in range(N + 1)]
# 初期選択状態を0とする
dp[0][0][0] = 0
for i in range(N):
    a, b, c = arr[i]
    for j in range(10 * N + 1):
        for k in range(10 * N + 1):
            if dp[i][j][k] == INF:
                continue
            # 選ばなかった場合
            dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k])
            # 選んだ場合
            dp[i + 1][j + a][k + b] = min(dp[i + 1][j + a][k + b], dp[i][j][k] + c)
ans = INF
# 0スタートは何を選んでいない状態となり最小値が0になってしまうため1から開始する
# TLEになったため変更
# for i in range(1,10 * N + 1):
#    for j in range(1,10 * N + 1):
#        if i * Mb != j * Ma:
#            continue
#        ans = min(ans, dp[N][i][j])
#
for i in range(1, 10 * N + 1):
    if i * Ma > 10 * N or i * Mb > 10 * N:
        break
    ans = min(ans, dp[N][i * Ma][i * Mb])
if ans == INF:
    print((-1))
else:
    print(ans)

def calc():
    n, ma, mb = list(map(int, input().split()))
    dp = [[[5000] * 401 for _ in range(401)] for _ in range(41)]
    arr = [list(map(int, input().split())) for _ in range(n)]
    dp[0][0][0] = 0
    for t in range(n):
        a, b, c = arr[t]
        for i in range(401):
            for j in range(401):
                if dp[t][i][j] == 5000:
                    continue
                dp[t + 1][i][j] = min(dp[t + 1][i][j], dp[t][i][j])
                dp[t + 1][i + a][j + b] = min(dp[t + 1][i + a][j + b], dp[t][i][j] + c)
    ans = 5000
    for i in range(1, 401):
        if i * ma > 400 or i * mb > 400:
            break
        ans = min(ans, dp[n][i * ma][i * mb])
    if ans == 5000:
        print((-1))
    else:
        print(ans)

calc()

-N, Ma, Mb = list(map(int, input().split()))

-# 入力値の受け取り方を変える

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

-#    a[i], b[i], c[i] = map(int, input().split())

-# TLEになってしまうためinfを5000とかで設定する

-# さらに計算量を落とすため10 * N + 1などを定数で設定する →　関係なかったため戻す

-# 最小値を求める問題なのでinfで初期化

-# 初期選択状態を0とする

-            # 選ばなかった場合

-            # 選んだ場合

-# 0スタートは何を選んでいない状態となり最小値が0になってしまうため1から開始する

-# TLEになったため変更

-    if i * Ma > 10 * N or i * Mb > 10 * N:

-    ans = min(ans, dp[N][i * Ma][i * Mb])

+    n, ma, mb = list(map(int, input().split()))

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

+        ans = min(ans, dp[n][i * ma][i * mb])


Input:
h, w = list(map(int, input().split()))

c = []

for _ in range(h):

    s = eval(input())

    c.append(s)

    c.append(s)

print(("\n".join(c)))

h, w = list(map(int, input().split()))

c = []

for i in range(h):

    s = eval(input())

    c.append(s)

    c.append(s)

print(("\n".join(c)))


Input:
H, W = list(map(int, input().split()))

ans = float('inf')

for h in range(1,H):

    S = [h * W]

    w = W // 2

    S += [(H-h) * w]

    S += [(H-h) * (W-w)]

    ans = min(ans,max(S)-min(S))

for h in range(1,H):

    S = [h * W]

    hb = (H-h) // 2

    S += [hb * W]

    S += [(H-h-hb) * W]

    ans = min(ans,max(S)-min(S))

for w in range(1,W):

    S = [H * w]

    h = H // 2

    S += [h * (W-w)]

    S += [(H-h) * (W-w)]

    ans = min(ans,max(S)-min(S))

for w in range(1,W):

    S = [w * H]

    wb = (W-w) // 2

    S += [wb * H]

    S += [(W-w-wb) * H]

    ans = min(ans,max(S)-min(S))

print(ans)

H, W = list(map(int, input().split()))

S = H * W

ans = S

for h in range(1,H):

    s1 = h * W

    s2 = W // 2 * (H-h)

    s3 = S-s1-s2

    ans = min(ans,max(s1,s2,s3)-min(s1,s2,s3))

    s2 = (H-h) // 2 * W

    s3 = S-s1-s2

    ans = min(ans,max(s1,s2,s3)-min(s1,s2,s3))

for w in range(1,W):

    s1 = H * w

    s2 = H // 2 * (W-w)

    s3 = S-s1-s2

    ans = min(ans,max(s1,s2,s3)-min(s1,s2,s3))

    s2 = (W-w) // 2 * H

    s3 = S-s1-s2

    ans = min(ans,max(s1,s2,s3)-min(s1,s2,s3))

print(ans)

H, W = list(map(int, input().split()))
ans = float("inf")
for h in range(1, H):
    S = [h * W]
    w = W // 2
    S += [(H - h) * w]
    S += [(H - h) * (W - w)]
    ans = min(ans, max(S) - min(S))
for h in range(1, H):
    S = [h * W]
    hb = (H - h) // 2
    S += [hb * W]
    S += [(H - h - hb) * W]
    ans = min(ans, max(S) - min(S))
for w in range(1, W):
    S = [H * w]
    h = H // 2
    S += [h * (W - w)]
    S += [(H - h) * (W - w)]
    ans = min(ans, max(S) - min(S))
for w in range(1, W):
    S = [w * H]
    wb = (W - w) // 2
    S += [wb * H]
    S += [(W - w - wb) * H]
    ans = min(ans, max(S) - min(S))
print(ans)

H, W = list(map(int, input().split()))
S = H * W
ans = S
for h in range(1, H):
    s1 = h * W
    s2 = W // 2 * (H - h)
    s3 = S - s1 - s2
    ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3))
    s2 = (H - h) // 2 * W
    s3 = S - s1 - s2
    ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3))
for w in range(1, W):
    s1 = H * w
    s2 = H // 2 * (W - w)
    s3 = S - s1 - s2
    ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3))
    s2 = (W - w) // 2 * H
    s3 = S - s1 - s2
    ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3))
print(ans)

+    ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3))


Input:
import numpy as np

a, b, c, d = list(map(int, input().split()))

hoge = []

hoge.append(a*c)

hoge.append(a*d)

hoge.append(b*c)

hoge.append(b*d)

if max(hoge) < 0:

  if np.sign(a) != np.sign(b) or np.sign(c) != np.sign(d):

    print((0))

  else:

    print((max(hoge)))

else:

  print((max(hoge)))

import numpy as np

a, b, c, d = list(map(int, input().split()))

hoge = []

hoge.append(a*c)

hoge.append(a*d)

hoge.append(b*c)

hoge.append(b*d)

print((max(hoge)))

import numpy as np

a, b, c, d = list(map(int, input().split()))
hoge = []
hoge.append(a * c)
hoge.append(a * d)
hoge.append(b * c)
hoge.append(b * d)
if max(hoge) < 0:
    if np.sign(a) != np.sign(b) or np.sign(c) != np.sign(d):
        print((0))
    else:
        print((max(hoge)))
else:
    print((max(hoge)))

import numpy as np

a, b, c, d = list(map(int, input().split()))
hoge = []
hoge.append(a * c)
hoge.append(a * d)
hoge.append(b * c)
hoge.append(b * d)
print((max(hoge)))

-    if np.sign(a) != np.sign(b) or np.sign(c) != np.sign(d):


Input:
import sys

from itertools import combinations_with_replacement, product

import numpy as np

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

def main():

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

    data = np.zeros((n,m),int)

    clist = np.zeros(n, int)

    ans=10**10

    for i in range(n):

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

        clist[i]=ca[0]

        data[i]=np.array(ca[1:])

    for bit in list(product([0,1],repeat=n)):

        if all(np.dot(np.array(bit), data)>=x):

            ans=min(ans,np.dot(np.array(bit),clist.T))

    if ans==10**10:

        print((-1))

    else:

        print(ans)

if __name__ == '__main__':

    main()

import sys

from itertools import combinations_with_replacement, product

import numpy as np

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

def main():

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

    data = np.zeros((n,m+1),int)

    ans=10**10

    for i in range(n):

        data[i]=np.array(list(map(int, input().split())))

    for bit in list(product([0,1],repeat=n)):

        calc=np.dot(np.array(bit), data)

        if all(calc[1:]>=x):

            ans=min(ans,calc[0])

    if ans==10**10:

        print((-1))

    else:

        print(ans)

if __name__ == '__main__':

    main()

import sys
from itertools import combinations_with_replacement, product
import numpy as np

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

def main():
    n, m, x = list(map(int, input().split()))
    data = np.zeros((n, m), int)
    clist = np.zeros(n, int)
    ans = 10**10
    for i in range(n):
        ca = list(map(int, input().split()))
        clist[i] = ca[0]
        data[i] = np.array(ca[1:])
    for bit in list(product([0, 1], repeat=n)):
        if all(np.dot(np.array(bit), data) >= x):
            ans = min(ans, np.dot(np.array(bit), clist.T))
    if ans == 10**10:
        print((-1))
    else:
        print(ans)

if __name__ == "__main__":
    main()

import sys
from itertools import combinations_with_replacement, product
import numpy as np

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

def main():
    n, m, x = list(map(int, input().split()))
    data = np.zeros((n, m + 1), int)
    ans = 10**10
    for i in range(n):
        data[i] = np.array(list(map(int, input().split())))
    for bit in list(product([0, 1], repeat=n)):
        calc = np.dot(np.array(bit), data)
        if all(calc[1:] >= x):
            ans = min(ans, calc[0])
    if ans == 10**10:
        print((-1))
    else:
        print(ans)

if __name__ == "__main__":
    main()

-        ca = list(map(int, input().split()))

+        data[i] = np.array(list(map(int, input().split())))

-        if all(np.dot(np.array(bit), data) >= x):

-            ans = min(ans, np.dot(np.array(bit), clist.T))

+        calc = np.dot(np.array(bit), data)


Input:
N = int(input())

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

def ans():

    if 0 in A:

        return print(0)

    product = 1

    for num in A:

        product = product * num

        if product > 10 ** 18:

            return print(-1)

    print(product)

ans()

N = int(eval(input()))

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

if 0 in A:

    print((0))

    exit()

product = 1

for num in A:

    product = product * num

    if product > 10 ** 18:

        print((-1))

        exit()

print(product)

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

def ans():
    if 0 in A:
        return print(0)
    product = 1
    for num in A:
        product = product * num
        if product > 10**18:
            return print(-1)
    print(product)

ans()

N = int(eval(input()))
A = list(map(int, input().split()))
if 0 in A:
    print((0))
    exit()
product = 1
for num in A:
    product = product * num
    if product > 10**18:
        print((-1))
        exit()
print(product)

-N = int(input())
+N = int(eval(input()))
-def ans():
-    if 0 in A:
-        return print(0)
-    product = 1
-    for num in A:
-        product = product * num
-        if product > 10**18:
-            return print(-1)
-    print(product)
-ans()
+if 0 in A:
+    print((0))
+    exit()
+product = 1
+for num in A:
+    product = product * num
+    if product > 10**18:
+        print((-1))
+        exit()
+print(product)


Input:
import sys

from collections import defaultdict

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

def main():

    H, W, K = list(map(int, input().split()))

    S = [eval(input()) for _ in range(H)]

    ans = 10 ** 9

    for bit in range(1 << (H-1)):

        canSolve = True

        ord = defaultdict(int)

        N = 0

        for i in range(H):

            if bit & 1 << i:

                ord[i+1] = ord[i] + 1

                N += 1

            else:

                ord[i+1] = ord[i]

        nums = defaultdict(int)

        for w in range(W):

            one = defaultdict(int)

            overK = False

            for h in range(H):

                one[ord[h]] += int(S[h][w])

                nums[ord[h]] += int(S[h][w])

                if one[ord[h]] > K:

                    canSolve = False

                if nums[ord[h]] > K:

                    overK = True

            if not canSolve:

                break

            if overK:

                N += 1

                nums = one

        if canSolve and ans > N:

            ans = N

    print(ans)

if __name__ == '__main__':

    main()

import sys

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

def main():

    H, W, K = list(map(int, input().split()))

    S = [eval(input()) for _ in range(H)]

    ans = 10 ** 9

    for bit in range(1 << (H-1)):

        canSolve = True

        ord = [0] * (H + 1)

        N = 0

        for i in range(H):

            if bit & 1 << i:

                ord[i+1] = ord[i] + 1

                N += 1

            else:

                ord[i+1] = ord[i]

        nums = [0] * (H + 1)

        for w in range(W):

            one = [0] * (H + 1)

            overK = False

            for h in range(H):

                one[ord[h]] += int(S[h][w])

                nums[ord[h]] += int(S[h][w])

                if one[ord[h]] > K:

                    canSolve = False

                if nums[ord[h]] > K:

                    overK = True

            if not canSolve:

                break

            if overK:

                N += 1

                nums = one

        if canSolve and ans > N:

            ans = N

    print(ans)

if __name__ == '__main__':

    main()

import sys
from collections import defaultdict

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

def main():
    H, W, K = list(map(int, input().split()))
    S = [eval(input()) for _ in range(H)]
    ans = 10**9
    for bit in range(1 << (H - 1)):
        canSolve = True
        ord = defaultdict(int)
        N = 0
        for i in range(H):
            if bit & 1 << i:
                ord[i + 1] = ord[i] + 1
                N += 1
            else:
                ord[i + 1] = ord[i]
        nums = defaultdict(int)
        for w in range(W):
            one = defaultdict(int)
            overK = False
            for h in range(H):
                one[ord[h]] += int(S[h][w])
                nums[ord[h]] += int(S[h][w])
                if one[ord[h]] > K:
                    canSolve = False
                if nums[ord[h]] > K:
                    overK = True
            if not canSolve:
                break
            if overK:
                N += 1
                nums = one
        if canSolve and ans > N:
            ans = N
    print(ans)

if __name__ == "__main__":
    main()

import sys

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

def main():
    H, W, K = list(map(int, input().split()))
    S = [eval(input()) for _ in range(H)]
    ans = 10**9
    for bit in range(1 << (H - 1)):
        canSolve = True
        ord = [0] * (H + 1)
        N = 0
        for i in range(H):
            if bit & 1 << i:
                ord[i + 1] = ord[i] + 1
                N += 1
            else:
                ord[i + 1] = ord[i]
        nums = [0] * (H + 1)
        for w in range(W):
            one = [0] * (H + 1)
            overK = False
            for h in range(H):
                one[ord[h]] += int(S[h][w])
                nums[ord[h]] += int(S[h][w])
                if one[ord[h]] > K:
                    canSolve = False
                if nums[ord[h]] > K:
                    overK = True
            if not canSolve:
                break
            if overK:
                N += 1
                nums = one
        if canSolve and ans > N:
            ans = N
    print(ans)

if __name__ == "__main__":
    main()

-from collections import defaultdict
-        ord = defaultdict(int)
+        ord = [0] * (H + 1)
-        nums = defaultdict(int)
+        nums = [0] * (H + 1)
-            one = defaultdict(int)
+            one = [0] * (H + 1)


Input:
H,W = list(map(int,input().split()))

#l = sorted([int(input()) for i in range(N)],reverse=True)

def three(h,w):

    ans = h*w

    for i in range(1,h):

        A = w*i

        B = w*((h-i)//2)

        C = w*((h-i+1)//2)

        ans = min(ans,max(A,B,C)-min(A,B,C))

    return ans

def onetwo(h,w):

    ans = h*w

    for i in range(1,h):

        A = w*i

        B = (h-i)*(w//2)

        C = (h-i)*((w+1)//2)

        ans = min(ans,max(A,B,C)-min(A,B,C))

    return ans

print((min(three(H,W),three(W,H),onetwo(H,W),onetwo(W,H))))

H,W = list(map(int,input().split()))

#l = sorted([int(input()) for i in range(N)],reverse=True)

def three(h,w):

    ans = h*w

    for i in range(h//3,h//3+2):

        A = w*i

        B = w*((h-i)//2)

        C = w*((h-i+1)//2)

        ans = min(ans,max(A,B,C)-min(A,B,C))

    return ans

def onetwo(h,w):

    ans = h*w

    for i in range(h//3,h//3+2):

        A = w*i

        B = (h-i)*(w//2)

        C = (h-i)*((w+1)//2)

        ans = min(ans,max(A,B,C)-min(A,B,C))

    return ans

print((min(three(H,W),three(W,H),onetwo(H,W),onetwo(W,H))))

H, W = list(map(int, input().split()))
# l = sorted([int(input()) for i in range(N)],reverse=True)
def three(h, w):
    ans = h * w
    for i in range(1, h):
        A = w * i
        B = w * ((h - i) // 2)
        C = w * ((h - i + 1) // 2)
        ans = min(ans, max(A, B, C) - min(A, B, C))
    return ans

def onetwo(h, w):
    ans = h * w
    for i in range(1, h):
        A = w * i
        B = (h - i) * (w // 2)
        C = (h - i) * ((w + 1) // 2)
        ans = min(ans, max(A, B, C) - min(A, B, C))
    return ans

print((min(three(H, W), three(W, H), onetwo(H, W), onetwo(W, H))))

H, W = list(map(int, input().split()))
# l = sorted([int(input()) for i in range(N)],reverse=True)
def three(h, w):
    ans = h * w
    for i in range(h // 3, h // 3 + 2):
        A = w * i
        B = w * ((h - i) // 2)
        C = w * ((h - i + 1) // 2)
        ans = min(ans, max(A, B, C) - min(A, B, C))
    return ans

def onetwo(h, w):
    ans = h * w
    for i in range(h // 3, h // 3 + 2):
        A = w * i
        B = (h - i) * (w // 2)
        C = (h - i) * ((w + 1) // 2)
        ans = min(ans, max(A, B, C) - min(A, B, C))
    return ans

print((min(three(H, W), three(W, H), onetwo(H, W), onetwo(W, H))))

+    for i in range(h // 3, h // 3 + 2):

+    for i in range(h // 3, h // 3 + 2):


Input:
N = int(eval(input()))

lis = []

for i in range(N):

    lis.append(list(map(int,input().split())))

lis = sorted(lis, key = lambda x:x[1])

a = 0

for j in range(N):

    a += lis[j][0]

    if a > lis[j][1]:

        print('No')

        exit()

print('Yes')

N = int(eval(input()))

lis = []

for i in range(N):

    lis.append(list(map(int,input().split())))

lis.sort(key = lambda x:x[1])

a = 0

for j in range(N):

    a += lis[j][0]

    if a > lis[j][1]:

        print('No')

        exit()

print('Yes')

N = int(eval(input()))
lis = []
for i in range(N):
    lis.append(list(map(int, input().split())))
lis = sorted(lis, key=lambda x: x[1])
a = 0
for j in range(N):
    a += lis[j][0]
    if a > lis[j][1]:
        print("No")
        exit()
print("Yes")

N = int(eval(input()))
lis = []
for i in range(N):
    lis.append(list(map(int, input().split())))
lis.sort(key=lambda x: x[1])
a = 0
for j in range(N):
    a += lis[j][0]
    if a > lis[j][1]:
        print("No")
        exit()
print("Yes")

-lis = sorted(lis, key=lambda x: x[1])
+lis.sort(key=lambda x: x[1])


Input:
import itertools as i;d=[0]*91

for _ in[0]*int(eval(input())):d[ord(input()[0])]+=1

print((sum(d[p]*d[q]*d[r]for p,q,r in i.combinations(list(map(ord,'MARCH')),3))))

import itertools as i,collections as c

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

b=c.Counter(s[0]for s in a if s[0]in"MARCH")

print((sum(p*q*r for p,q,r in i.combinations(list(b.values()),3))))

import itertools as i

d = [0] * 91
for _ in [0] * int(eval(input())):
    d[ord(input()[0])] += 1
print(
    (sum(d[p] * d[q] * d[r] for p, q, r in i.combinations(list(map(ord, "MARCH")), 3)))
)

import itertools as i, collections as c

n, *a = open(0).read().split()
b = c.Counter(s[0] for s in a if s[0] in "MARCH")
print((sum(p * q * r for p, q, r in i.combinations(list(b.values()), 3))))

+import itertools as i, collections as c

-    (sum(d[p] * d[q] * d[r] for p, q, r in i.combinations(list(map(ord, "MARCH")), 3)))

+b = c.Counter(s[0] for s in a if s[0] in "MARCH")

+print((sum(p * q * r for p, q, r in i.combinations(list(b.values()), 3))))


Input:
import heapq

n = int(eval(input()))

edges = [None] * n

for _ in range(n):

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

    edges[l[0]] = set((c, j) for j, c in (l[i:i + 2] for i in range(2, l[1] * 2 + 2, 2)))

min_costs = [0] * n

visited = [False] * n

visited[0] = True

queue = list(edges[0])

heapq.heapify(queue)

while queue:

    total_cost, vertex = heapq.heappop(queue)

    if visited[vertex]:

        continue

    visited[vertex] = True

    min_costs[vertex] = total_cost

    for cost, vertex2 in edges[vertex]:

        if not visited[vertex2]:

            heapq.heappush(queue, (total_cost + cost, vertex2))

for r in enumerate(min_costs):

    print((*r))

import heapq

n = int(eval(input()))

edges = [None] * n

for _ in range(n):

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

    edges[l[0]] = set((c, j) for j, c in (l[i:i + 2] for i in range(2, l[1] * 2 + 2, 2)))

min_costs = [0] * n

visited = [False] * n

visited[0] = True

queue = list(edges[0])

heapq.heapify(queue)

remains = n - 1

while True:

    total_cost, vertex = heapq.heappop(queue)

    if visited[vertex]:

        continue

    visited[vertex] = True

    min_costs[vertex] = total_cost

    remains -= 1

    if not remains:

        break

    for cost, vertex2 in edges[vertex]:

        if not visited[vertex2]:

            heapq.heappush(queue, (total_cost + cost, vertex2))

for r in enumerate(min_costs):

    print((*r))

import heapq

n = int(eval(input()))
edges = [None] * n
for _ in range(n):
    l = list(map(int, input().split()))
    edges[l[0]] = set(
        (c, j) for j, c in (l[i : i + 2] for i in range(2, l[1] * 2 + 2, 2))
    )
min_costs = [0] * n
visited = [False] * n
visited[0] = True
queue = list(edges[0])
heapq.heapify(queue)
while queue:
    total_cost, vertex = heapq.heappop(queue)
    if visited[vertex]:
        continue
    visited[vertex] = True
    min_costs[vertex] = total_cost
    for cost, vertex2 in edges[vertex]:
        if not visited[vertex2]:
            heapq.heappush(queue, (total_cost + cost, vertex2))
for r in enumerate(min_costs):
    print((*r))

import heapq

n = int(eval(input()))
edges = [None] * n
for _ in range(n):
    l = list(map(int, input().split()))
    edges[l[0]] = set(
        (c, j) for j, c in (l[i : i + 2] for i in range(2, l[1] * 2 + 2, 2))
    )
min_costs = [0] * n
visited = [False] * n
visited[0] = True
queue = list(edges[0])
heapq.heapify(queue)
remains = n - 1
while True:
    total_cost, vertex = heapq.heappop(queue)
    if visited[vertex]:
        continue
    visited[vertex] = True
    min_costs[vertex] = total_cost
    remains -= 1
    if not remains:
        break
    for cost, vertex2 in edges[vertex]:
        if not visited[vertex2]:
            heapq.heappush(queue, (total_cost + cost, vertex2))
for r in enumerate(min_costs):
    print((*r))

-while queue:
+remains = n - 1
+while True:
+    remains -= 1
+    if not remains:
+        break


Input:
from fractions import gcd

def f(n):

    tmp = n

    cnt = 0

    i = 2

    while i <= n**0.5 + 1:

        if tmp < i:

            break

        if tmp % i == 0:

            cnt += 1

            while tmp % i == 0:

                tmp //= i

        i += 1

    if tmp != 1:

        cnt += 1

    return cnt

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

g = gcd(A, B)

ans = f(g) + 1

print(ans)

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

# https://www.iandprogram.net/entry/2015/03/18/003511

def gcd(x, y):

    if y == 0:

        return x

    else:

        return gcd(y, x%y)

# https://qiita.com/kageyasai2/items/48ef81f39b4e31c6d396

def factorize(n):

    factor = []

    for num in range(2, int(n**0.5+1)):

        while n % num == 0:

            n //= num

            factor.append(num)

    if n != 1:

        factor.append(n)

    return set(factor)

g = gcd(A, B)

f = factorize(g)

print((len(f) + 1))

A, B = list(map(int, input().split()))
# https://www.iandprogram.net/entry/2015/03/18/003511
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

# https://qiita.com/kageyasai2/items/48ef81f39b4e31c6d396
def factorize(n):
    factor = []
    for num in range(2, int(n**0.5 + 1)):
        while n % num == 0:
            n //= num
            factor.append(num)
    if n != 1:
        factor.append(n)
    return set(factor)

g = gcd(A, B)
f = factorize(g)
print((len(f) + 1))

+    for num in range(2, int(n**0.5 + 1)):


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

mod = 10**9+7

def power(a, n, mod):

    bi=str(format(n,"b")) #2進数

    res=1

    for i in range(len(bi)):

        res=(res*res) %mod

        if bi[i]=="1":

            res=(res*a) %mod

    return res

D = [0]*(k+1)

ans = 0

for i in reversed(list(range(1, k+1))):

    a = k//i

    d = power(a, n, mod)

    j = 1

    while i*j <= k:

        d -= D[i*j]

        j += 1

    D[i] = d

    ans += (d*i)%mod

print((ans%mod))

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

mod = 10**9+7

def power(a, n, mod):

  bi=str(format(n,"b")) #2進数

  res=1

  for i in range(len(bi)):

    res=(res*res) %mod

    if bi[i]=="1":

      res=(res*a) %mod

  return res

X = [0]*(k+1)

ans = 0

for i in reversed(list(range(1, k+1))):

    temp = power(k//i, n, mod)

    j = i+i

    while j <= k:

        temp -= X[j]

        j += i

    X[i] = temp

    ans += (temp*i)%mod

print((ans%mod))

n, k = list(map(int, input().split()))
mod = 10**9 + 7

def power(a, n, mod):
    bi = str(format(n, "b"))  # 2進数
    res = 1
    for i in range(len(bi)):
        res = (res * res) % mod
        if bi[i] == "1":
            res = (res * a) % mod
    return res

D = [0] * (k + 1)
ans = 0
for i in reversed(list(range(1, k + 1))):
    a = k // i
    d = power(a, n, mod)
    j = 1
    while i * j <= k:
        d -= D[i * j]
        j += 1
    D[i] = d
    ans += (d * i) % mod
print((ans % mod))

n, k = list(map(int, input().split()))
mod = 10**9 + 7

def power(a, n, mod):
    bi = str(format(n, "b"))  # 2進数
    res = 1
    for i in range(len(bi)):
        res = (res * res) % mod
        if bi[i] == "1":
            res = (res * a) % mod
    return res

X = [0] * (k + 1)
ans = 0
for i in reversed(list(range(1, k + 1))):
    temp = power(k // i, n, mod)
    j = i + i
    while j <= k:
        temp -= X[j]
        j += i
    X[i] = temp
    ans += (temp * i) % mod
print((ans % mod))

-D = [0] * (k + 1)
+X = [0] * (k + 1)
-    a = k // i
-    d = power(a, n, mod)
-    j = 1
-    while i * j <= k:
-        d -= D[i * j]
-        j += 1
-    D[i] = d
-    ans += (d * i) % mod
+    temp = power(k // i, n, mod)
+    j = i + i
+    while j <= k:
+        temp -= X[j]
+        j += i
+    X[i] = temp
+    ans += (temp * i) % mod


Input:
from heapq import heappush, heappop, heapify

from collections import deque, defaultdict, Counter

import itertools

from itertools import permutations, combinations, accumulate

import sys

import bisect

import string

import math

import time

def I(): return int(input())

def MI(): return map(int, input().split())

def S(): return input()

def MS(): return map(str, input().split())

def LI(): return [int(i) for i in input().split()]

def LI_(): return [int(i)-1 for i in input().split()]

def StoI(): return [ord(i)-97 for i in input()]

def ItoS(nn): return chr(nn+97)

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

def show(*inp, end='\n'):

    if show_flg:

        print(*inp, end=end)

YN = {False: 'No', True: 'Yes'}

MOD = 10**9+7

inf = float('inf')

IINF = 10**10

l_alp = string.ascii_lowercase

u_alp = string.ascii_uppercase

ts = time.time()

sys.setrecursionlimit(10**6)

nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = True

show_flg = False

def main():

    H, N = MI()

    A = [0] * N

    B = [0] * N

    dp = [[IINF] * (H+2) for i in range(N+1)]

    dp[0][0] = 0

    for i in range(N):

        A[i], B[i] = MI()

        # AB[i] = (A / B, A, B)

    # print(dp)

    for i in range(N):

        for j in range(H+1):

            dp[i+1][j] = min(dp[i+1][j], dp[i][j])

            max_h = min(H, j+A[i])

            dp[i+1][max_h] = min(dp[i+1][max_h], dp[i+1][j] + B[i])

    print(dp[N][H])

if __name__ == '__main__':

    main()

from heapq import heappush, heappop, heapify

from collections import deque, defaultdict, Counter

import itertools

from itertools import permutations, combinations, accumulate

import sys

import bisect

import string

import math

import time

def I(): return int(input())

def MI(): return map(int, input().split())

def S(): return input()

def MS(): return map(str, input().split())

def LI(): return [int(i) for i in input().split()]

def LI_(): return [int(i)-1 for i in input().split()]

def StoI(): return [ord(i)-97 for i in input()]

def ItoS(nn): return chr(nn+97)

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

def show(*inp, end='\n'):

    if show_flg:

        print(*inp, end=end)

YN = {False: 'No', True: 'Yes'}

MOD = 10**9+7

inf = float('inf')

IINF = 10**10

l_alp = string.ascii_lowercase

u_alp = string.ascii_uppercase

ts = time.time()

sys.setrecursionlimit(10**6)

nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = True

show_flg = False

def main():

    H, N = MI()

    A = [0] * N

    B = [0] * N

    dp = [IINF] * (H+1)

    dp[0] = 0

    for i in range(N):

        A[i], B[i] = MI()

        # AB[i] = (A / B, A, B)

    for i in range(N):

        dp_next = [IINF] * (H + 1)

        for j in range(H+1):

            dp_next[j] = min(dp[j], dp_next[j])

            if j + A[i] <= H:

                dp_next[j+A[i]] = min(dp_next[j+A[i]], dp_next[j] + B[i])

            else:

                # print(i, j, dp_next[j] + B[i], dp_next[j])

                dp_next[H] = min(dp_next[H], dp_next[j] + B[i])

                # print(dp_next[H])

        dp = dp_next

        # print(dp)

    print(dp[H])

if __name__ == '__main__':

    main()

from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time

def I():
    return int(input())

def MI():
    return map(int, input().split())

def S():
    return input()

def MS():
    return map(str, input().split())

def LI():
    return [int(i) for i in input().split()]

def LI_():
    return [int(i) - 1 for i in input().split()]

def StoI():
    return [ord(i) - 97 for i in input()]

def ItoS(nn):
    return chr(nn + 97)

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

def show(*inp, end="\n"):
    if show_flg:
        print(*inp, end=end)

YN = {False: "No", True: "Yes"}
MOD = 10**9 + 7
inf = float("inf")
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]
show_flg = True
show_flg = False

def main():
    H, N = MI()
    A = [0] * N
    B = [0] * N
    dp = [[IINF] * (H + 2) for i in range(N + 1)]
    dp[0][0] = 0
    for i in range(N):
        A[i], B[i] = MI()
        # AB[i] = (A / B, A, B)
    # print(dp)
    for i in range(N):
        for j in range(H + 1):
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])
            max_h = min(H, j + A[i])
            dp[i + 1][max_h] = min(dp[i + 1][max_h], dp[i + 1][j] + B[i])
    print(dp[N][H])

if __name__ == "__main__":
    main()

from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time

def I():
    return int(input())

def MI():
    return map(int, input().split())

def S():
    return input()

def MS():
    return map(str, input().split())

def LI():
    return [int(i) for i in input().split()]

def LI_():
    return [int(i) - 1 for i in input().split()]

def StoI():
    return [ord(i) - 97 for i in input()]

def ItoS(nn):
    return chr(nn + 97)

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

def show(*inp, end="\n"):
    if show_flg:
        print(*inp, end=end)

YN = {False: "No", True: "Yes"}
MOD = 10**9 + 7
inf = float("inf")
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]
show_flg = True
show_flg = False

def main():
    H, N = MI()
    A = [0] * N
    B = [0] * N
    dp = [IINF] * (H + 1)
    dp[0] = 0
    for i in range(N):
        A[i], B[i] = MI()
        # AB[i] = (A / B, A, B)
    for i in range(N):
        dp_next = [IINF] * (H + 1)
        for j in range(H + 1):
            dp_next[j] = min(dp[j], dp_next[j])
            if j + A[i] <= H:
                dp_next[j + A[i]] = min(dp_next[j + A[i]], dp_next[j] + B[i])
            else:
                # print(i, j, dp_next[j] + B[i], dp_next[j])
                dp_next[H] = min(dp_next[H], dp_next[j] + B[i])
                # print(dp_next[H])
        dp = dp_next
        # print(dp)
    print(dp[H])

if __name__ == "__main__":
    main()

-    dp = [[IINF] * (H + 2) for i in range(N + 1)]

+            dp_next[j] = min(dp[j], dp_next[j])

+                dp_next[j + A[i]] = min(dp_next[j + A[i]], dp_next[j] + B[i])

+                # print(i, j, dp_next[j] + B[i], dp_next[j])

+                dp_next[H] = min(dp_next[H], dp_next[j] + B[i])


Input:
n = int(eval(input()))

g =[[] for _ in range(n)]

for i in range(n-1):

  u,v,w = list(map(int,input().split()))

  g[u-1].append((v-1,w))

  g[v-1].append((u-1,w))

distance = [-1]*n

distance[0] = 0

q = [0]

while q:

  p = q.pop()

  for a,b in g[p]:

    if distance[a] == -1:

      distance[a] = distance[p]+b

      q.append(a)

for i in range(n):

  print(((distance[i])%2))

import sys

import copy

sys.setrecursionlimit(10**7)

def dfs(graph,v,dist_mod):

    color[v] = dist_mod

    for next_v,dist in graph[v]:

        if color[next_v] != -1:

            continue

        dfs(graph,next_v,(dist_mod+dist)%2)

n = int(eval(input()))

uvw = [list(map(int,input().split())) for _ in range(n-1)]

g = [[] for _ in range(n)]

color = [-1]*n

for i in range(n-1):

    g[uvw[i][0]-1].append([uvw[i][1]-1,uvw[i][2]])

    g[uvw[i][1]-1].append([uvw[i][0]-1,uvw[i][2]])

dfs(g,0,0)

for i in range(n):

    print((color[i]))

n = int(eval(input()))
g = [[] for _ in range(n)]
for i in range(n - 1):
    u, v, w = list(map(int, input().split()))
    g[u - 1].append((v - 1, w))
    g[v - 1].append((u - 1, w))
distance = [-1] * n
distance[0] = 0
q = [0]
while q:
    p = q.pop()
    for a, b in g[p]:
        if distance[a] == -1:
            distance[a] = distance[p] + b
            q.append(a)
for i in range(n):
    print(((distance[i]) % 2))

import sys
import copy

sys.setrecursionlimit(10**7)

def dfs(graph, v, dist_mod):
    color[v] = dist_mod
    for next_v, dist in graph[v]:
        if color[next_v] != -1:
            continue
        dfs(graph, next_v, (dist_mod + dist) % 2)

n = int(eval(input()))
uvw = [list(map(int, input().split())) for _ in range(n - 1)]
g = [[] for _ in range(n)]
color = [-1] * n
for i in range(n - 1):
    g[uvw[i][0] - 1].append([uvw[i][1] - 1, uvw[i][2]])
    g[uvw[i][1] - 1].append([uvw[i][0] - 1, uvw[i][2]])
dfs(g, 0, 0)
for i in range(n):
    print((color[i]))

+        dfs(graph, next_v, (dist_mod + dist) % 2)

+uvw = [list(map(int, input().split())) for _ in range(n - 1)]

-    u, v, w = list(map(int, input().split()))

-            distance[a] = distance[p] + b


Input:
import math

mod=10**9+7

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

def f(x):

  if x<0:

    return 1

  else:

    return math.factorial(x)

def c(x,y):

  if x<y or y<0:

    return 0

  elif y==0:

    return 1

  else:

    return f(x)//f(x-y)//f(y)

if k==1:

  print(n)

elif n==k:

  print((1))

  for i in range(n-1):

    print((0))

else:

  for i in range(1,k+1):

    ans=c(k-1,i-1)

    ans*=(c(n-k-1,i)+2*c(n-k-1,i-1)+c(n-k-1,i-2))

    print((ans%mod))

import sys

input=lambda: sys.stdin.readline().rstrip()

mod=10**9+7

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

n_max=2*(10**5+1)

F,FI=[0]*(n_max+1),[0]*(n_max+1)

F[0],FI[0]=1,1

for i in range(n_max):

  F[i+1]=(F[i]*(i+1))%mod

FI[n_max-1]=pow(F[n_max-1],mod-2,mod)

for i in reversed(list(range(n_max-1))):

  FI[i]=(FI[i+1]*(i+1))%mod

def comb(x,y):

  return (F[x]*FI[x-y]*FI[y])%mod

for i in range(1,k+1):

  if n-k<i-1:

    print((0))

  else:

    print(((comb(k-i+i-1,k-i)*comb(n-k-(i-1)+i,n-k-(i-1)))%mod))

import math

mod = 10**9 + 7
n, k = list(map(int, input().split()))

def f(x):
    if x < 0:
        return 1
    else:
        return math.factorial(x)

def c(x, y):
    if x < y or y < 0:
        return 0
    elif y == 0:
        return 1
    else:
        return f(x) // f(x - y) // f(y)

if k == 1:
    print(n)
elif n == k:
    print((1))
    for i in range(n - 1):
        print((0))
else:
    for i in range(1, k + 1):
        ans = c(k - 1, i - 1)
        ans *= c(n - k - 1, i) + 2 * c(n - k - 1, i - 1) + c(n - k - 1, i - 2)
        print((ans % mod))

import sys

input = lambda: sys.stdin.readline().rstrip()
mod = 10**9 + 7
n, k = list(map(int, input().split()))
n_max = 2 * (10**5 + 1)
F, FI = [0] * (n_max + 1), [0] * (n_max + 1)
F[0], FI[0] = 1, 1
for i in range(n_max):
    F[i + 1] = (F[i] * (i + 1)) % mod
FI[n_max - 1] = pow(F[n_max - 1], mod - 2, mod)
for i in reversed(list(range(n_max - 1))):
    FI[i] = (FI[i + 1] * (i + 1)) % mod

def comb(x, y):
    return (F[x] * FI[x - y] * FI[y]) % mod

for i in range(1, k + 1):
    if n - k < i - 1:
        print((0))
    else:
        print(
            (
                (
                    comb(k - i + i - 1, k - i)
                    * comb(n - k - (i - 1) + i, n - k - (i - 1))
                )
                % mod
            )
        )

+input = lambda: sys.stdin.readline().rstrip()

+FI[n_max - 1] = pow(F[n_max - 1], mod - 2, mod)

+for i in reversed(list(range(n_max - 1))):

+    return (F[x] * FI[x - y] * FI[y]) % mod

-        return f(x) // f(x - y) // f(y)

+                    comb(k - i + i - 1, k - i)


Input:
import heapq

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

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

A = list([-x for x in A])

heapq.heapify(A)

while M > 0:

    heapq.heappush(A, -(-heapq.heappop(A) // 2))

    M -= 1

print((-sum(A)))

import heapq

def f(str):

    return -int(str)

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

A = list(map(f, input().split()))

heapq.heapify(A)

while M > 0:

    heapq.heappush(A, -(-heapq.heappop(A) // 2))

    M -= 1

print((-sum(A)))

+
+def f(str):
+    return -int(str)
+
+
-A = list(map(int, input().split()))
-A = list([-x for x in A])
+A = list(map(f, input().split()))


Input:
n = int(eval(input()))

s = eval(input())

a, b = [], []

for i in range(n):

    if s[i] == 'W':

        a.append(1)

        b.append(0)

    else:

        a.append(0)

        b.append(1)

import itertools

accum_a = [0] + list(itertools.accumulate(a))

accum_b = list(itertools.accumulate(b))

ans = float('inf')

for i in range(n):

    ans = min(ans, accum_a[i] + abs((accum_b[-1] - accum_b[i])))

print(ans)

n = int(eval(input()))

s = eval(input())

chg = [0]*n

cnt = 0

for i in range(1, n):  # 左側から

    if s[i-1] == 'W':

        cnt += 1

    chg[i] += cnt

cnt = 0

for i in range(1, n):  # 右側から

    if s[-i] == 'E':

        cnt += 1

    chg[-1-i] += cnt

print((min(chg)))

n = int(eval(input()))
s = eval(input())
a, b = [], []
for i in range(n):
    if s[i] == "W":
        a.append(1)
        b.append(0)
    else:
        a.append(0)
        b.append(1)
import itertools

accum_a = [0] + list(itertools.accumulate(a))
accum_b = list(itertools.accumulate(b))
ans = float("inf")
for i in range(n):
    ans = min(ans, accum_a[i] + abs((accum_b[-1] - accum_b[i])))
print(ans)

n = int(eval(input()))
s = eval(input())
chg = [0] * n
cnt = 0
for i in range(1, n):  # 左側から
    if s[i - 1] == "W":
        cnt += 1
    chg[i] += cnt
cnt = 0
for i in range(1, n):  # 右側から
    if s[-i] == "E":
        cnt += 1
    chg[-1 - i] += cnt
print((min(chg)))

-accum_a = [0] + list(itertools.accumulate(a))

-    ans = min(ans, accum_a[i] + abs((accum_b[-1] - accum_b[i])))


Input:
n = int(eval(input()))

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

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

ans = [0] * n

for i in range(n):

    ans[i] = sum(a1[:i+1]) + sum(a2[i:])

print((max(ans)))

n = int(eval(input()))

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

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

ans = 0

for i in range(n):

    ans = max(ans, sum(a1[:i+1]) + sum(a2[i:]))

print(ans)

n = int(eval(input()))
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
ans = [0] * n
for i in range(n):
    ans[i] = sum(a1[: i + 1]) + sum(a2[i:])
print((max(ans)))

n = int(eval(input()))
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
ans = 0
for i in range(n):
    ans = max(ans, sum(a1[: i + 1]) + sum(a2[i:]))
print(ans)