Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import numpy as np

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

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

tmp = np.sum(p[:K])

max = tmp

for i in range(N-K):

    tmp = tmp-p[i]+p[i+K]

    if tmp>max:

        max = tmp

print(((max+K)/2))

# optimized version of the same code:

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

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

tmp = sum(p[:K])

max = tmp

for i in range(N-K):

    tmp = tmp-p[i]+p[i+K]

    if tmp>max:

        max = tmp

print(((max+K)/2))

import numpy as np

N, K = list(map(int, input().split()))
p = np.array(list(map(int, input().split())))
tmp = np.sum(p[:K])
max = tmp
for i in range(N - K):
    tmp = tmp - p[i] + p[i + K]
    if tmp > max:
        max = tmp
print(((max + K) / 2))

N, K = list(map(int, input().split()))
p = list(map(int, input().split()))
tmp = sum(p[:K])
max = tmp
for i in range(N - K):
    tmp = tmp - p[i] + p[i + K]
    if tmp > max:
        max = tmp
print(((max + K) / 2))

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


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import statistics

N = int(eval(input()))

A = [int(a)-i-1 for i,a in enumerate(input().split(),1)]

b = statistics.median_low(A)

c = statistics.median_high(A)

d = sum([abs(x-b) for x in A])

e = sum([abs(x-c) for x in A])

print((min(d,e)))

# optimized version of the same code:

N=int(eval(input()))

A=sorted(a-i-1 for i,a in enumerate(map(int,input().split())))

print((sum(abs(a-A[N//2]) for a in A)))

import statistics

N = int(eval(input()))
A = [int(a) - i - 1 for i, a in enumerate(input().split(), 1)]
b = statistics.median_low(A)
c = statistics.median_high(A)
d = sum([abs(x - b) for x in A])
e = sum([abs(x - c) for x in A])
print((min(d, e)))

N = int(eval(input()))
A = sorted(a - i - 1 for i, a in enumerate(map(int, input().split())))
print((sum(abs(a - A[N // 2]) for a in A)))

-A = [int(a) - i - 1 for i, a in enumerate(input().split(), 1)]

+A = sorted(a - i - 1 for i, a in enumerate(map(int, input().split())))

+print((sum(abs(a - A[N // 2]) for a in A)))


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

x = int(eval(input()))

for i in range(-200,201):

    for j in range(-200,201):

        if (i**5)-(j**5)==x:

            print((i,j))

            exit()

# optimized version of the same code:

x = int(eval(input()))

for i in range(-120,121):

    for j in range(-120,121):

        if (i**5)-(j**5)==x:

            print((i,j))

            exit()

x = int(eval(input()))
for i in range(-200, 201):
    for j in range(-200, 201):
        if (i**5) - (j**5) == x:
            print((i, j))
            exit()

x = int(eval(input()))
for i in range(-120, 121):
    for j in range(-120, 121):
        if (i**5) - (j**5) == x:
            print((i, j))
            exit()


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

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

c = 0

for i in range(a,b+1):

  new = list(reversed(list(str(i))))

  if new == list(str(i)):

    c += 1

print(c)

# optimized version of the same code:

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

c = 0

for i in range(a,b+1):

  if list(str(i)) == list(str(i))[::-1]:

    c += 1

print(c)

a, b = list(map(int, input().split()))
c = 0
for i in range(a, b + 1):
    new = list(reversed(list(str(i))))
    if new == list(str(i)):
        c += 1
print(c)

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

+    if list(str(i)) == list(str(i))[::-1]:


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import sys

input = sys.stdin.readline

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

hole = [0] * (N+1)

for i in range(M):

    hole[int(eval(input()))] = 1

if N == 1:

    print((1))

    exit()

if N == 2:

    if hole[1] == 1:

        print((1))

        exit()

    if hole[1] == 0:

        print((2))

        exit()

flg_one = False

flg_two = False

first = 1

second = 2

if hole[1] == 1:

    first = 0

    second = 1

    flg_one = True

if hole[2] == 1:

    first = 1

    second = 0

    flg_two = True

if flg_one and flg_two:

    print((0))

    exit()

for i in range(3,N):

    if hole[i] == 1:

        first = second

        second = 0

        continue

    tmp = first + second

    tmp %= 1000000007

    first = second

    second = tmp

tmp = first + second

tmp %= 1000000007

print(tmp)

# optimized version of the same code:

MOD = 10**9 + 7

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

stairs = [0]*(N+1)

for _ in range(M):

    stairs[int(eval(input()))] = 1

if N == 1:

    print((1))

    exit()

ans = [0]*(N+1)

ans[1] = 1 if stairs[1] == 0 else 0

ans[2] = 1 + ans[1] if stairs[2] == 0 else 0

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

    if stairs[i] == 1:

        ans[i] = 0

        continue

    ans[i] = (ans[i-1] + ans[i-2]) % MOD

print((ans[N]))

import sys

input = sys.stdin.readline
N, M = list(map(int, input().split()))
hole = [0] * (N + 1)
for i in range(M):
    hole[int(eval(input()))] = 1
if N == 1:
    print((1))
    exit()
if N == 2:
    if hole[1] == 1:
        print((1))
        exit()
    if hole[1] == 0:
        print((2))
        exit()
flg_one = False
flg_two = False
first = 1
second = 2
if hole[1] == 1:
    first = 0
    second = 1
    flg_one = True
if hole[2] == 1:
    first = 1
    second = 0
    flg_two = True
if flg_one and flg_two:
    print((0))
    exit()
for i in range(3, N):
    if hole[i] == 1:
        first = second
        second = 0
        continue
    tmp = first + second
    tmp %= 1000000007
    first = second
    second = tmp
tmp = first + second
tmp %= 1000000007
print(tmp)

MOD = 10**9 + 7
N, M = list(map(int, input().split()))
stairs = [0] * (N + 1)
for _ in range(M):
    stairs[int(eval(input()))] = 1
if N == 1:
    print((1))
    exit()
ans = [0] * (N + 1)
ans[1] = 1 if stairs[1] == 0 else 0
ans[2] = 1 + ans[1] if stairs[2] == 0 else 0
for i in range(3, N + 1):
    if stairs[i] == 1:
        ans[i] = 0
        continue
    ans[i] = (ans[i - 1] + ans[i - 2]) % MOD
print((ans[N]))

+ans[2] = 1 + ans[1] if stairs[2] == 0 else 0


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

#!usr/bin/env python3

from collections import defaultdict

from collections import deque

from heapq import heappush, heappop

import sys

import math

import bisect

import random

def LI(): return list(map(int, sys.stdin.readline().split()))

def I(): return int(sys.stdin.readline())

def LS():return list(map(list, sys.stdin.readline().split()))

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

def IR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = I()

    return l

def LIR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = LI()

    return l

def SR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = S()

    return l

def LSR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = SR()

    return l

mod = 1000000007

#A

def A():

    s = S()

    t = S()

    if s+t == t[::-1]+s[::-1]:

        print("YES")

    else:

        print("NO")

#B

def B():

    n = I()

    for i in range(int(n**0.5)+2)[::-1]:

        if i*i <= n:

            print((i*i))

            quit()

#C

def C():

    n = I()

    a = LI()

    b = LI()

    c = LI()

    q = [0 for i in range(n)]

    ans = 0

    a.sort()

    b.sort()

    c.sort()

    for i in range(n):

        j = bisect.bisect_left(a,b[i])

        q[i] = j

    for i in range(n-1):

        q[i+1] += q[i]

    q.insert(0,0)

    for i in range(n):

        j = bisect.bisect_left(b,c[i])

        ans += q[j]

    print(ans)

#D

def D():

    def dijkstra():

        d = [float("inf") for i in range(k)]

        q = [[0,1]]

        d[1] = 0

        while q:

            dx,x = heappop(q)

            for y,dy in v[x]:

                if d[y] > dx+dy:

                    d[y] = dx+dy

                    heappush(q,[d[y],y])

        print((d[0]+1))

    k = I()

    if k == 1:

        print((1))

        quit()

    v = [[] for i in range(k)]

    for i in range(1,k):

        v[i].append([(i+1)%k,1])

        v[i].append([i*10%k,0])

    dijkstra()

#E

def E():

    return

#F

def F():

    return

#G

def G():

    return

#H

def H():

    return

#Solve

if __name__ == "__main__":

    D()

# optimized version of the same code:

#!usr/bin/env python3

from collections import defaultdict,deque

from heapq import heappush, heappop

from itertools import permutations

import sys

import math

import bisect

def LI(): return [int(x) for x in sys.stdin.readline().split()]

def I(): return int(sys.stdin.readline())

def LS():return [list(x) for x in sys.stdin.readline().split()]

def S():

    res = list(sys.stdin.readline())

    if res[-1] == "\n":

        return res[:-1]

    return res

def IR(n):

    return [I() for i in range(n)]

def LIR(n):

    return [LI() for i in range(n)]

def SR(n):

    return [S() for i in range(n)]

def LSR(n):

    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)

mod = 1000000007

def solve():

    def v(n):

        return [n*10%k, (n+1)%k]

    k = I()

    d = [float("inf")]*k

    d[1] = 1

    q = deque([1])

    while q:

        x = q.popleft()

        vx = v(x)

        dx = d[x]

        for c in range(2):

            nd = dx+c

            y = vx[c]

            if nd < d[y]:

                d[y] = nd

                if c:

                    q.append(y)

                else:

                    q.appendleft(y)

    print((d[0]))

    return

#Solve

if __name__ == "__main__":

    solve()

#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random

def LI():
    return list(map(int, sys.stdin.readline().split()))

def I():
    return int(sys.stdin.readline())

def LS():
    return list(map(list, sys.stdin.readline().split()))

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

def IR(n):
    l = [None for i in range(n)]
    for i in range(n):
        l[i] = I()
    return l

def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):
        l[i] = LI()
    return l

def SR(n):
    l = [None for i in range(n)]
    for i in range(n):
        l[i] = S()
    return l

def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):
        l[i] = SR()
    return l

mod = 1000000007
# A
def A():
    s = S()
    t = S()
    if s + t == t[::-1] + s[::-1]:
        print("YES")
    else:
        print("NO")

# B
def B():
    n = I()
    for i in range(int(n**0.5) + 2)[::-1]:
        if i * i <= n:
            print((i * i))
            quit()

# C
def C():
    n = I()
    a = LI()
    b = LI()
    c = LI()
    q = [0 for i in range(n)]
    ans = 0
    a.sort()
    b.sort()
    c.sort()
    for i in range(n):
        j = bisect.bisect_left(a, b[i])
        q[i] = j
    for i in range(n - 1):
        q[i + 1] += q[i]
    q.insert(0, 0)
    for i in range(n):
        j = bisect.bisect_left(b, c[i])
        ans += q[j]
    print(ans)

# D
def D():
    def dijkstra():
        d = [float("inf") for i in range(k)]
        q = [[0, 1]]
        d[1] = 0
        while q:
            dx, x = heappop(q)
            for y, dy in v[x]:
                if d[y] > dx + dy:
                    d[y] = dx + dy
                    heappush(q, [d[y], y])
        print((d[0] + 1))

    k = I()
    if k == 1:
        print((1))
        quit()
    v = [[] for i in range(k)]
    for i in range(1, k):
        v[i].append([(i + 1) % k, 1])
        v[i].append([i * 10 % k, 0])
    dijkstra()

# E
def E():
    return

# F
def F():
    return

# G
def G():
    return

# H
def H():
    return

# Solve
if __name__ == "__main__":
    D()

#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect

def LI():
    return [int(x) for x in sys.stdin.readline().split()]

def I():
    return int(sys.stdin.readline())

def LS():
    return [list(x) for x in sys.stdin.readline().split()]

def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res

def IR(n):
    return [I() for i in range(n)]

def LIR(n):
    return [LI() for i in range(n)]

def SR(n):
    return [S() for i in range(n)]

def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def v(n):
        return [n * 10 % k, (n + 1) % k]

    k = I()
    d = [float("inf")] * k
    d[1] = 1
    q = deque([1])
    while q:
        x = q.popleft()
        vx = v(x)
        dx = d[x]
        for c in range(2):
            nd = dx + c
            y = vx[c]
            if nd < d[y]:
                d[y] = nd
                if c:
                    q.append(y)
                else:
                    q.appendleft(y)
    print((d[0]))
    return

# Solve
if __name__ == "__main__":
    solve()

+from collections import defaultdict, deque

-    return list(map(int, sys.stdin.readline().split()))

+    return [int(x) for x in sys.stdin.readline().split()]

-    return list(map(list, sys.stdin.readline().split()))

+    return [list(x) for x in sys.stdin.readline().split()]

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

-        j = bisect.bisect_left(a, b[i])

-        j = bisect.bisect_left(b, c[i])

-        d = [float("inf") for i in range(k)]

-                    heappush(q, [d[y], y])


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import sys

import numpy as np

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

# 味

LL = np.arange(L,L+N)

m = abs(LL[0])

for i in range(N):

    if abs(m) > abs(LL[i]):

        m = LL[i]

print((np.sum(LL)-m))

# optimized version of the same code:

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

A = [i for i in range(L, L + N)]

if A[0] < 0:

    if A[-1] < 0:

        print((sum(A) - max(A)))

    else:

        print((sum(A)))

else:

    print((sum(A) - min(A)))

import sys
import numpy as np

N, L = list(map(int, input().split()))
# 味
LL = np.arange(L, L + N)
m = abs(LL[0])
for i in range(N):
    if abs(m) > abs(LL[i]):
        m = LL[i]
print((np.sum(LL) - m))

-import sys
-import numpy as np
-# 味
-LL = np.arange(L, L + N)
-m = abs(LL[0])
-for i in range(N):
-    if abs(m) > abs(LL[i]):
-        m = LL[i]
-print((np.sum(LL) - m))
+A = [i for i in range(L, L + N)]
+if A[0] < 0:
+    if A[-1] < 0:
+        print((sum(A) - max(A)))
+    else:
+        print((sum(A)))
+else:
+    print((sum(A) - min(A)))


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import math

x = int(eval(input()))

print((math.factorial(x) % (10**9 + 7)))

# optimized version of the same code:

n = int(eval(input()))

fact = 1

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

  fact = fact * i % (10**9 +7)

res = fact % (10**9 + 7)

print(res)

n = int(eval(input()))
fact = 1
for i in range(1, n + 1):
    fact = fact * i % (10**9 + 7)
res = fact % (10**9 + 7)
print(res)

-print((math.factorial(x) % (10**9 + 7)))


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import sys

input = sys.stdin.readline

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

As = [int(eval(input())) for i in range(n)]

# N: 処理する区間の長さ

INF = 0

mx = 300001

LV = (mx-1).bit_length()

N0 = 2**LV

data = [INF]*(2*N0)

lazy = [None]*(2*N0)

# 伝搬対象の区間を求める

def gindex(l, r):

    L = (l + N0) >> 1; R = (r + N0) >> 1

    lc = 0 if l & 1 else (L & -L).bit_length()

    rc = 0 if r & 1 else (R & -R).bit_length()

    for i in range(LV):

        if rc <= i:

            yield R

        if L < R and lc <= i:

            yield L

        L >>= 1; R >>= 1

# 遅延伝搬処理

def propagates(*ids):

    for i in reversed(ids):

        v = lazy[i-1]

        if v is None:

            continue

        lazy[2*i-1] = data[2*i-1] = lazy[2*i] = data[2*i] = v

        lazy[i-1] = None

# 区間[l, r)をxで更新

def update(l, r, x):

    *ids, = gindex(l, r)

    propagates(*ids)

    L = N0 + l; R = N0 + r

    while L < R:

        if R & 1:

            R -= 1

            lazy[R-1] = data[R-1] = x

        if L & 1:

            lazy[L-1] = data[L-1] = x

            L += 1

        L >>= 1; R >>= 1

    for i in ids:

        data[i-1] = max(data[2*i-1], data[2*i])

# 区間[l, r)内の最小値を求める

def query(l, r):

    propagates(*gindex(l, r))

    L = N0 + l; R = N0 + r

    s = INF

    while L < R:

        if R & 1:

            R -= 1

            s = max(s, data[R-1])

        if L & 1:

            s = max(s, data[L-1])

            L += 1

        L >>= 1; R >>= 1

    return s

ans = 0

update(As[0],As[0]+1,1)

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

    l = max(0,a-k)

    r = min(mx,a+k)

    upd = query(l,r+1)

    if upd == -1:continue

    # print("i",i,"a",a,"upd",upd,"l",l,"r",r)

    update(a, a+1, upd+1)

    ans = max(ans, upd+1)

print(ans)

# optimized version of the same code:

# セグメント木

# segment tree

import sys

input = sys.stdin.readline

class segmented_tree:

    X_unit = 0

    X_f = lambda self, a, b: max(a,b)

    def __init__(self, N):

        self.N = N

        self.X = [self.X_unit] * (2*N)

    def build(self, seq):

        for i, x in enumerate(seq, self.N):

            self.X[i] = x

        # 後ろから入れていく

        for i in range(self.N-1, 0, -1):

            self.X[i] = self.X_f(self.X[i<<1], self.X[i<<1|1])

    # 1点更新

    def set_val(self, i, x):

        i += self.N

        self.X[i] = x

        while i > 1:

            i >>= 1

            self.X[i] = self.X_f(self.X[i<<1],self.X[i<<1|1])

    # 区間取得

    def fold(self, l, r):

        l += self.N

        r += self.N

        vl = self.X_unit

        vr = self.X_unit

        # 外から決めていく

        while l < r:

            # print(l,r)

            if l & 1:

                vl = self.X_f(vl, self.X[l])

                l += 1

            if r & 1:

                r -= 1

                vr = self.X_f(vr, self.X[r])

            l >>= 1

            r >>= 1

        return self.X_f(vl,vr)

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

As = [int(eval(input())) for i in range(n)]

mx = 300001

ans = 0

sg = segmented_tree(330000)

for a in As:

    l = max(0,a-k)

    r = min(mx,a+k)

    upd = sg.fold(l,r+1)

    ans = max(ans, upd+1)

    sg.set_val(a, upd+1)

print(ans)

import sys

input = sys.stdin.readline
n, k = list(map(int, input().split()))
As = [int(eval(input())) for i in range(n)]
# N: 処理する区間の長さ
INF = 0
mx = 300001
LV = (mx - 1).bit_length()
N0 = 2**LV
data = [INF] * (2 * N0)
lazy = [None] * (2 * N0)
# 伝搬対象の区間を求める
def gindex(l, r):
    L = (l + N0) >> 1
    R = (r + N0) >> 1
    lc = 0 if l & 1 else (L & -L).bit_length()
    rc = 0 if r & 1 else (R & -R).bit_length()
    for i in range(LV):
        if rc <= i:
            yield R
        if L < R and lc <= i:
            yield L
        L >>= 1
        R >>= 1

# 遅延伝搬処理
def propagates(*ids):
    for i in reversed(ids):
        v = lazy[i - 1]
        if v is None:
            continue
        lazy[2 * i - 1] = data[2 * i - 1] = lazy[2 * i] = data[2 * i] = v
        lazy[i - 1] = None

# 区間[l, r)をxで更新
def update(l, r, x):
    (*ids,) = gindex(l, r)
    propagates(*ids)
    L = N0 + l
    R = N0 + r
    while L < R:
        if R & 1:
            R -= 1
            lazy[R - 1] = data[R - 1] = x
        if L & 1:
            lazy[L - 1] = data[L - 1] = x
            L += 1
        L >>= 1
        R >>= 1
    for i in ids:
        data[i - 1] = max(data[2 * i - 1], data[2 * i])

# 区間[l, r)内の最小値を求める
def query(l, r):
    propagates(*gindex(l, r))
    L = N0 + l
    R = N0 + r
    s = INF
    while L < R:
        if R & 1:
            R -= 1
            s = max(s, data[R - 1])
        if L & 1:
            s = max(s, data[L - 1])
            L += 1
        L >>= 1
        R >>= 1
    return s

ans = 0
update(As[0], As[0] + 1, 1)
for i, a in enumerate(As[1:]):
    l = max(0, a - k)
    r = min(mx, a + k)
    upd = query(l, r + 1)
    if upd == -1:
        continue
    # print("i",i,"a",a,"upd",upd,"l",l,"r",r)
    update(a, a + 1, upd + 1)
    ans = max(ans, upd + 1)
print(ans)

# セグメント木
# segment tree
import sys

input = sys.stdin.readline

class segmented_tree:
    X_unit = 0
    X_f = lambda self, a, b: max(a, b)

    def __init__(self, N):
        self.N = N
        self.X = [self.X_unit] * (2 * N)

    def build(self, seq):
        for i, x in enumerate(seq, self.N):
            self.X[i] = x
        # 後ろから入れていく
        for i in range(self.N - 1, 0, -1):
            self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])

    # 1点更新
    def set_val(self, i, x):
        i += self.N
        self.X[i] = x
        while i > 1:
            i >>= 1
            self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])

    # 区間取得
    def fold(self, l, r):
        l += self.N
        r += self.N
        vl = self.X_unit
        vr = self.X_unit
        # 外から決めていく
        while l < r:
            # print(l,r)
            if l & 1:
                vl = self.X_f(vl, self.X[l])
                l += 1
            if r & 1:
                r -= 1
                vr = self.X_f(vr, self.X[r])
            l >>= 1
            r >>= 1
        return self.X_f(vl, vr)

n, k = list(map(int, input().split()))
As = [int(eval(input())) for i in range(n)]
mx = 300001
ans = 0
sg = segmented_tree(330000)
for a in As:
    l = max(0, a - k)
    r = min(mx, a + k)
    upd = sg.fold(l, r + 1)
    ans = max(ans, upd + 1)
    sg.set_val(a, upd + 1)
print(ans)

+        self.X = [self.X_unit] * (2 * N)

+        for i, x in enumerate(seq, self.N):

+        # 後ろから入れていく

+        for i in range(self.N - 1, 0, -1):

+            self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])

+        # 外から決めていく

+                vl = self.X_f(vl, self.X[l])

+                vr = self.X_f(vr, self.X[r])

-# N: 処理する区間の長さ

-# 伝搬対象の区間を求める

-    lc = 0 if l & 1 else (L & -L).bit_length()

-    rc = 0 if r & 1 else (R & -R).bit_length()

-            lazy[R - 1] = data[R - 1] = x

-            lazy[L - 1] = data[L - 1] = x

-# 区間[l, r)内の最小値を求める


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

# coding: utf-8

def solve(*args: str) -> str:

    k = int(args[0])

    l = 9*(k//7 if k % 7 == 0 else k)

    if l % 2 == 0 or l % 5 == 0:

        return '-1'

    r = phi = l

    for i in range(2, int(-pow(l, 1/2))):

        if r % i == 0:

            phi = phi//i*(i-1)

            while r % i:

                r //= i

    a = 10 % l

    ret = 1

    while(a != 1):

        a = a*10 % l

        ret += 1

        if phi < ret:

            ret = -1

            break

    return str(ret)

if __name__ == "__main__":

    print((solve(*(open(0).read().splitlines()))))

# optimized version of the same code:

# coding: utf-8

from math import sqrt

def solve(*args: str) -> str:

    k = int(args[0])

    l = 9*(k//7 if 0 == k % 7 else k)

    if 0 == l % 2 or 0 == l % 5:

        return '-1'

    r = phi = l

    for i in range(2, int(sqrt(l)+1)):

        if 0 == r % i:

            phi = phi*(i-1)//i

            while 0 == r % i:

                r //= i

    if 1 < r:

        phi = phi*(r-1)//r

    D = set()

    for d in range(1, int(sqrt(phi)+1)):

        if 0 == phi % d:

            D.add(d)

            D.add(phi//d)

    ret = -1

    for m in sorted(D):

        if 1 == pow(10, m, l):

            ret = m

            break

    return str(ret)

if __name__ == "__main__":

    print((solve(*(open(0).read().splitlines()))))

# coding: utf-8
def solve(*args: str) -> str:
    k = int(args[0])
    l = 9 * (k // 7 if k % 7 == 0 else k)
    if l % 2 == 0 or l % 5 == 0:
        return "-1"
    r = phi = l
    for i in range(2, int(-pow(l, 1 / 2))):
        if r % i == 0:
            phi = phi // i * (i - 1)
            while r % i:
                r //= i
    a = 10 % l
    ret = 1
    while a != 1:
        a = a * 10 % l
        ret += 1
        if phi < ret:
            ret = -1
            break
    return str(ret)

if __name__ == "__main__":
    print((solve(*(open(0).read().splitlines()))))

# coding: utf-8
from math import sqrt

def solve(*args: str) -> str:
    k = int(args[0])
    l = 9 * (k // 7 if 0 == k % 7 else k)
    if 0 == l % 2 or 0 == l % 5:
        return "-1"
    r = phi = l
    for i in range(2, int(sqrt(l) + 1)):
        if 0 == r % i:
            phi = phi * (i - 1) // i
            while 0 == r % i:
                r //= i
    if 1 < r:
        phi = phi * (r - 1) // r
    D = set()
    for d in range(1, int(sqrt(phi) + 1)):
        if 0 == phi % d:
            D.add(d)
            D.add(phi // d)
    ret = -1
    for m in sorted(D):
        if 1 == pow(10, m, l):
            ret = m
            break
    return str(ret)

if __name__ == "__main__":
    print((solve(*(open(0).read().splitlines()))))

-    for i in range(2, int(-pow(l, 1 / 2))):

+    for i in range(2, int(sqrt(l) + 1)):

+    for d in range(1, int(sqrt(phi) + 1)):


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import sys

sys.setrecursionlimit(2147483647)

INF=float("inf")

MOD=10**9+7

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

def resolve():

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

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

    ans=-INF

    # 何も考えずやる

    dp=[0]*T

    for i in range(n):

        a,b=AB[i]

        ndp=dp[:]

        for t in range(T):

            if(t+a<T):

                ndp[t+a]=max(ndp[t+a],dp[t]+b)

            else:

                ans=max(ans,dp[t]+b)

        dp=ndp

    ans=max(ans,max(dp))

    # 時間が最もかかるもののうち、価値が最大のものを最後にする

    AB.sort()

    la,lb=AB[-1]

    dp=[0]*T

    for i in range(n-1):

        a,b=AB[i]

        ndp=dp[:]

        for t in range(T):

            if(t+a<T):

                ndp[t+a]=max(ndp[t+a],dp[t]+b)

            else:

                ans=max(ans,dp[t]+b)

        dp=ndp

    ans=max(ans,max(dp)+lb)

    # 価値が最大のもののうち、時間が最もかかるものを最後にする

    AB.sort(lambda x:(x[1],x[0]))

    la,lb=AB[-1]

    dp=[0]*T

    for i in range(n-1):

        a,b=AB[i]

        ndp=dp[:]

        for t in range(T):

            if(t+a<T):

                ndp[t+a]=max(ndp[t+a],dp[t]+b)

            else:

                ans=max(ans,dp[t]+b)

        dp=ndp

    ans=max(ans,max(dp)+lb)

    print(ans)

resolve()

# optimized version of the same code:

import sys

sys.setrecursionlimit(2147483647)

INF=float("inf")

MOD=10**9+7

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

def resolve():

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

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

    AB.sort()

    dp=[0]*T

    ans=-INF

    for i in range(n):

        a,b=AB[i]

        ndp=dp[:]

        for t in range(T):

            if(t+a<T):

                ndp[t+a]=max(ndp[t+a],dp[t]+b)

            else:

                ans=max(ans,dp[t]+b)

        dp=ndp

    print((max(ans,max(dp))))

resolve()

import sys

sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7
input = lambda: sys.stdin.readline().rstrip()

def resolve():
    n, T = list(map(int, input().split()))
    AB = [tuple(map(int, input().split())) for _ in range(n)]
    ans = -INF
    # 何も考えずやる
    dp = [0] * T
    for i in range(n):
        a, b = AB[i]
        ndp = dp[:]
        for t in range(T):
            if t + a < T:
                ndp[t + a] = max(ndp[t + a], dp[t] + b)
            else:
                ans = max(ans, dp[t] + b)
        dp = ndp
    ans = max(ans, max(dp))
    # 時間が最もかかるもののうち、価値が最大のものを最後にする
    AB.sort()
    la, lb = AB[-1]
    dp = [0] * T
    for i in range(n - 1):
        a, b = AB[i]
        ndp = dp[:]
        for t in range(T):
            if t + a < T:
                ndp[t + a] = max(ndp[t + a], dp[t] + b)
            else:
                ans = max(ans, dp[t] + b)
        dp = ndp
    ans = max(ans, max(dp) + lb)
    # 価値が最大のもののうち、時間が最もかかるものを最後にする
    AB.sort(lambda x: (x[1], x[0]))
    la, lb = AB[-1]
    dp = [0] * T
    for i in range(n - 1):
        a, b = AB[i]
        ndp = dp[:]
        for t in range(T):
            if t + a < T:
                ndp[t + a] = max(ndp[t + a], dp[t] + b)
            else:
                ans = max(ans, dp[t] + b)
        dp = ndp
    ans = max(ans, max(dp) + lb)
    print(ans)

resolve()

import sys

sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7
input = lambda: sys.stdin.readline().rstrip()

def resolve():
    n, T = list(map(int, input().split()))
    AB = [tuple(map(int, input().split())) for _ in range(n)]
    AB.sort()
    dp = [0] * T
    ans = -INF
    for i in range(n):
        a, b = AB[i]
        ndp = dp[:]
        for t in range(T):
            if t + a < T:
                ndp[t + a] = max(ndp[t + a], dp[t] + b)
            else:
                ans = max(ans, dp[t] + b)
        dp = ndp
    print((max(ans, max(dp))))

resolve()

-    # 何も考えずやる

-    # 時間が最もかかるもののうち、価値が最大のものを最後にする

-                ndp[t + a] = max(ndp[t + a], dp[t] + b)

-                ans = max(ans, dp[t] + b)

-    # 価値が最大のもののうち、時間が最もかかるものを最後にする

-                ans = max(ans, dp[t] + b)


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import sys

sys.setrecursionlimit(100000)

def intinput(): return list(map(int,sys.stdin.readline().split()))

fib={0:0,1:1,2:1}

for i in range(3,100003):

    fib[i]=fib[i-1]+fib[i-2]

  #  fib.append(fib[i-1]+fib[i-2])

n,m=intinput()

mod=10**9+7

a=[int(sys.stdin.readline()) for _ in range(m)]

if m!=0:

    l=[a[0]]

    for i in range(len(a)-1):

        l.append(a[i+1]-a[i]-1)

    l.append(n-a[-1])

    k=1

    for i in l:

        k=fib[i]*k%mod

    print((k%mod))

else:

    print((fib[n+1]%mod))

# optimized version of the same code:

import sys

sys.setrecursionlimit(100000)

def intinput(): return list(map(int,sys.stdin.readline().split()))

n, m = intinput()

a = {int(sys.stdin.readline()) for _ in range(m)}

memo = [0 for x in range(n + 4)]

memo[0] = 1

mod = 10 ** 9 + 7

for i in range(n):

    if i + 1 not in a:

        memo[i + 1] = (memo[i + 1] + memo[i]) % mod

    if i + 2 not in a:

        memo[i + 2] = (memo[i + 2] + memo[i]) % mod

print((memo[n]))

import sys

sys.setrecursionlimit(100000)

def intinput():
    return list(map(int, sys.stdin.readline().split()))

fib = {0: 0, 1: 1, 2: 1}
for i in range(3, 100003):
    fib[i] = fib[i - 1] + fib[i - 2]
#  fib.append(fib[i-1]+fib[i-2])
n, m = intinput()
mod = 10**9 + 7
a = [int(sys.stdin.readline()) for _ in range(m)]
if m != 0:
    l = [a[0]]
    for i in range(len(a) - 1):
        l.append(a[i + 1] - a[i] - 1)
    l.append(n - a[-1])
    k = 1
    for i in l:
        k = fib[i] * k % mod
    print((k % mod))
else:
    print((fib[n + 1] % mod))

import sys

sys.setrecursionlimit(100000)

def intinput():
    return list(map(int, sys.stdin.readline().split()))

n, m = intinput()
a = {int(sys.stdin.readline()) for _ in range(m)}
memo = [0 for x in range(n + 4)]
memo[0] = 1
mod = 10**9 + 7
for i in range(n):
    if i + 1 not in a:
        memo[i + 1] = (memo[i + 1] + memo[i]) % mod
    if i + 2 not in a:
        memo[i + 2] = (memo[i + 2] + memo[i]) % mod
print((memo[n]))

+a = {int(sys.stdin.readline()) for _ in range(m)}

-a = [int(sys.stdin.readline()) for _ in range(m)]

+        memo[i + 1] = (memo[i + 1] + memo[i]) % mod

+        memo[i + 2] = (memo[i + 2] + memo[i]) % mod


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import sys

mod = 10 ** 9 + 7

n, m, *a = [int(x) for x in sys.stdin.read().split()]

safe = sorted(set(range(1,n+1)) - set(a))

dp = [0] * (n + 2)

dp[0] = 0

dp[1] = 1

for i in safe:

    dp[i+1] = (dp[i] + dp[i-1]) % mod

print((dp[-1]))

# optimized version of the same code:

# 2019-11-14 10:01:24(JST)

import sys

# import collections

# import math

# from string import ascii_lowercase, ascii_uppercase, digits

# from bisect import bisect_left as bi_l, bisect_right as bi_r

# import itertools

# from functools import reduce

# import operator as op

# from scipy.misc import comb # float

# import numpy as np

mod = 10 ** 9 + 7

def main():

    n, m, *a = [int(x) for x in sys.stdin.read().split()]

    safe = sorted(set(range(1,n+1)) - set(a))

    dp = [0] * (n + 2) # dp[i+1]: i段目までいくパターン数

    dp[0] = 0  # -1段目にはいけない

    dp[1] = 1  # 初期条件(0段目にいる)

    for i in safe:

        dp[i+1] = (dp[i] + dp[i-1]) % mod

    print((dp[-1]))

if __name__ == "__main__":

    main()

import sys

mod = 10**9 + 7
n, m, *a = [int(x) for x in sys.stdin.read().split()]
safe = sorted(set(range(1, n + 1)) - set(a))
dp = [0] * (n + 2)
dp[0] = 0
dp[1] = 1
for i in safe:
    dp[i + 1] = (dp[i] + dp[i - 1]) % mod
print((dp[-1]))

# 2019-11-14 10:01:24(JST)
import sys

# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np
mod = 10**9 + 7

def main():
    n, m, *a = [int(x) for x in sys.stdin.read().split()]
    safe = sorted(set(range(1, n + 1)) - set(a))
    dp = [0] * (n + 2)  # dp[i+1]: i段目までいくパターン数
    dp[0] = 0  # -1段目にはいけない
    dp[1] = 1  # 初期条件(0段目にいる)
    for i in safe:
        dp[i + 1] = (dp[i] + dp[i - 1]) % mod
    print((dp[-1]))

if __name__ == "__main__":
    main()

+# from string import ascii_lowercase, ascii_uppercase, digits

+# from bisect import bisect_left as bi_l, bisect_right as bi_r

-n, m, *a = [int(x) for x in sys.stdin.read().split()]

-safe = sorted(set(range(1, n + 1)) - set(a))

+    n, m, *a = [int(x) for x in sys.stdin.read().split()]

+    safe = sorted(set(range(1, n + 1)) - set(a))

+    dp = [0] * (n + 2)  # dp[i+1]: i段目までいくパターン数


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

N = int(eval(input()))

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

answer = 10 ** 9

for i in range(1,101):

    tmp = 0

    for a in A:

        tmp += abs(a-i) ** 2

    answer = min(answer,tmp)

print(answer)

# optimized version of the same code:

N = int(eval(input()))

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

chushin = sum(A)//N

chushin_1 = sum(A)//N +1

answer = 0

answer_1 = 0

for a in A:

    answer += abs(a-chushin) ** 2

    answer_1 += abs(a-chushin_1) ** 2

print((min(answer,answer_1)))

N = int(eval(input()))
A = list(map(int, input().split()))
answer = 10**9
for i in range(1, 101):
    tmp = 0
    for a in A:
        tmp += abs(a - i) ** 2
    answer = min(answer, tmp)
print(answer)

N = int(eval(input()))
A = list(map(int, input().split()))
chushin = sum(A) // N
chushin_1 = sum(A) // N + 1
answer = 0
answer_1 = 0
for a in A:
    answer += abs(a - chushin) ** 2
    answer_1 += abs(a - chushin_1) ** 2
print((min(answer, answer_1)))

+    answer_1 += abs(a - chushin_1) ** 2


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

# E - This Message Will Self-Distruct in 5s

from collections import Counter

n = int(eval(input()))

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

assert len(a) == n

# Ai + Aj == j - i

# Aj - j == -Ai - i

# Aj - j の各値の個数

diff = Counter(a[j] - (j+1) for j in range(n))

# 各Aiについて Aj - j == -Ai - i となるjの個数を数える

count = 0

for i in range(n):

    diff[a[i] - (i+1)] -= 1  # i自身を取り除く

    count += diff[-a[i] - (i+1)]

print(count)

# optimized version of the same code:

# E - This Message Will Self-Distruct in 5s

from collections import Counter

n = int(eval(input()))

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

assert len(a) == n

# Aj - j の各値の個数

diff = Counter(a[j] - (j+1) for j in range(n))

# Aj - j == -Ai - i となる(i,j)の個数

count = sum(diff[-a[i] - (i+1)] for i in range(n))

print(count)

# E - This Message Will Self-Distruct in 5s
from collections import Counter

n = int(eval(input()))
a = list(map(int, input().split()))
assert len(a) == n
# Ai + Aj == j - i
# Aj - j == -Ai - i
# Aj - j の各値の個数
diff = Counter(a[j] - (j + 1) for j in range(n))
# 各Aiについて Aj - j == -Ai - i となるjの個数を数える
count = 0
for i in range(n):
    diff[a[i] - (i + 1)] -= 1  # i自身を取り除く
    count += diff[-a[i] - (i + 1)]
print(count)

# E - This Message Will Self-Distruct in 5s
from collections import Counter

n = int(eval(input()))
a = list(map(int, input().split()))
assert len(a) == n
# Aj - j の各値の個数
diff = Counter(a[j] - (j + 1) for j in range(n))
# Aj - j == -Ai - i となる(i,j)の個数
count = sum(diff[-a[i] - (i + 1)] for i in range(n))
print(count)

-# 各Aiについて Aj - j == -Ai - i となるjの個数を数える

-    diff[a[i] - (i + 1)] -= 1  # i自身を取り除く

+count = sum(diff[-a[i] - (i + 1)] for i in range(n))


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

"""

challenge case

in:

3

1 3

2 3

out:

1

1

1

"""

from collections import deque

def main():

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

	B = AB[1::2]

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

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

		E[a] += b,

	Q = deque([1])

	C = [0] * (N + 1)

	while Q:

		v = Q.popleft()

		c = 0

		for u in E[v]:

			c += 1 + (c + 1 == C[v])

			C[u] = c

			Q += u,

	print((max(C)))

	for b in B:

		print((C[b]))

main()

# optimized version of the same code:

"""

challenge case

in:

3

1 3

2 3

out:

1

1

1

"""

from collections import deque

def main():

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

	B = AB[1::2]

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

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

		E[a].append(b)

	Q = deque([1])

	C = [0] * (N + 1)

	while Q:

		v = Q.popleft()

		c = 0

		for u in E[v]:

			c += 1 + (c + 1 == C[v])

			C[u] = c

			Q.append(u)

	print((max(C)))

	for b in B:

		print((C[b]))

main()

"""
challenge case
in:
3
1 3
2 3
out:
1
1
1
"""
from collections import deque

def main():
    N, *AB = list(map(int, open(0).read().split()))
    B = AB[1::2]
    E = [[] for _ in range(N + 1)]
    for a, b in zip(*[iter(AB)] * 2):
        E[a] += (b,)
    Q = deque([1])
    C = [0] * (N + 1)
    while Q:
        v = Q.popleft()
        c = 0
        for u in E[v]:
            c += 1 + (c + 1 == C[v])
            C[u] = c
            Q += (u,)
    print((max(C)))
    for b in B:
        print((C[b]))

main()


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import sys

input = sys.stdin.buffer.readline

from collections import defaultdict

import copy

def main():

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

    d = defaultdict(int)

    MOD = 10**9+7

    R = 10**5+100

    fac = [0 for _ in range(R+1)]

    fac[0],fac[1] = 1,1

    inv = copy.deepcopy(fac)

    invfac = copy.deepcopy(fac)

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

        fac[i] = (fac[i-1]*i)%MOD

        inv[i] = MOD-(MOD//i)*inv[MOD%i]%MOD

        invfac[i] = (invfac[i-1]*inv[i])%MOD

    def coef(x,y):

        num = (((fac[x+y]*invfac[y])%MOD)*invfac[x]%MOD)

        return num

    while M%2 == 0:

        d[2] += 1

        M //= 2

    f = 3

    while f ** 2 <= M:

        if M % f == 0:

            d[f] += 1

            M //= f

        else:

            f += 2

    if M != 1:

        d[M] += 1

    l = list(d.values())

    ans = 1

    for num in l:

        ans *= coef(num,N-1)

        ans %= MOD

    print(ans)

if __name__ == "__main__":

    main()

# optimized version of the same code:

import sys

input = sys.stdin.buffer.readline

def main():

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

    MOD = 10**9+7

    def factorization(n):

        arr = []

        temp = n

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

            if temp%i==0:

                cnt=0

                while temp%i==0:

                    cnt+=1

                    temp //= i

                arr.append([i, cnt])

        if temp!=1:

            arr.append([temp, 1])

        return arr

    cl = factorization(M)

    def combinations(x,y,N):

        fac = [0]*(N+1)

        fac[0],fac[1] = 1,1

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

            fac[i] = (fac[i-1]*i)%MOD

        return (fac[x+y]*pow(fac[x],MOD-2,MOD)*pow(fac[y],MOD-2,MOD))%MOD

    ans = 1

    for pr,num in cl:

        ans *= combinations(N-1,num,N+num)

        ans %= MOD

    print(ans)

if __name__ == "__main__":

    main()

import sys

input = sys.stdin.buffer.readline
from collections import defaultdict
import copy

def main():
    N, M = list(map(int, input().split()))
    d = defaultdict(int)
    MOD = 10**9 + 7
    R = 10**5 + 100
    fac = [0 for _ in range(R + 1)]
    fac[0], fac[1] = 1, 1
    inv = copy.deepcopy(fac)
    invfac = copy.deepcopy(fac)
    for i in range(2, R + 1):
        fac[i] = (fac[i - 1] * i) % MOD
        inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD
        invfac[i] = (invfac[i - 1] * inv[i]) % MOD

    def coef(x, y):
        num = ((fac[x + y] * invfac[y]) % MOD) * invfac[x] % MOD
        return num

    while M % 2 == 0:
        d[2] += 1
        M //= 2
    f = 3
    while f**2 <= M:
        if M % f == 0:
            d[f] += 1
            M //= f
        else:
            f += 2
    if M != 1:
        d[M] += 1
    l = list(d.values())
    ans = 1
    for num in l:
        ans *= coef(num, N - 1)
        ans %= MOD
    print(ans)

if __name__ == "__main__":
    main()

import sys

input = sys.stdin.buffer.readline

def main():
    N, M = list(map(int, input().split()))
    MOD = 10**9 + 7

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

    cl = factorization(M)

    def combinations(x, y, N):
        fac = [0] * (N + 1)
        fac[0], fac[1] = 1, 1
        for i in range(2, N + 1):
            fac[i] = (fac[i - 1] * i) % MOD
        return (
            fac[x + y] * pow(fac[x], MOD - 2, MOD) * pow(fac[y], MOD - 2, MOD)
        ) % MOD

    ans = 1
    for pr, num in cl:
        ans *= combinations(N - 1, num, N + num)
        ans %= MOD
    print(ans)

if __name__ == "__main__":
    main()

-        fac[i] = (fac[i - 1] * i) % MOD

-        inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD

-        invfac[i] = (invfac[i - 1] * inv[i]) % MOD

-        num = ((fac[x + y] * invfac[y]) % MOD) * invfac[x] % MOD

+            fac[i] = (fac[i - 1] * i) % MOD

+            fac[x + y] * pow(fac[x], MOD - 2, MOD) * pow(fac[y], MOD - 2, MOD)

+        ans *= combinations(N - 1, num, N + num)


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

N, M = (int(x) for x in input().split())

edge = [tuple(int(x) for x in input().split()) for _ in range(M)]

import numpy as np

from scipy.sparse.csgraph import floyd_warshall

INF = 100

tmpl_graph = [[INF if i != j else 0 for j in range(N)] for i in range(N)]

ans = 0

for E in edge:

    edgeWithoutE = edge.copy()

    edgeWithoutE.remove(E)

    graph = np.array(tmpl_graph)

    for x in edgeWithoutE:

        graph[x[0]-1,x[1]-1] = 1

        graph[x[1]-1,x[0]-1] = 1

    graph = floyd_warshall(graph,directed=False)

    if len(graph[graph == 100]) > 0:

        ans += 1

print(ans)

# optimized version of the same code:

class node:

    def __init__(self, id):

        self.id = id

        self.root = self

    def findRoot(self):

        if self == self.root:

            return self

        else:

            self.root = self.root.findRoot()

            return self.root

    def resetRoot(self):

        self.root = self

class Tree:

    def __init__(self, num):

        self.nodes = {i:node(i) for i in range(num)}

    def union(self, one, other):

        root1 = one.findRoot()

        root2 = other.findRoot()

        root1.root = root2.root = self.nodes[min(root1.id, root2.id)]

    def resetTree(self):

        for n in list(self.nodes.values()):

            n.resetRoot()

    def makeTree(self, Edge):

        self.edge = Edge

        for x,y in Edge:

            self.union(self.nodes[x-1], self.nodes[y-1])

def main():

    with open(0) as f:

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

        Edge = [tuple(map(int, line.split())) for line in f.readlines()]

    tree = Tree(N)

    ans = 0

    for i in range(M):

        edge = [v for  v in Edge if v != Edge[i]]

        tree.makeTree(edge)

        if any(x.findRoot().id != 0 for x in list(tree.nodes.values())):

            ans += 1

        tree.resetTree()

    print(ans)

if __name__ == '__main__':

    main()

N, M = (int(x) for x in input().split())
edge = [tuple(int(x) for x in input().split()) for _ in range(M)]
import numpy as np
from scipy.sparse.csgraph import floyd_warshall

INF = 100
tmpl_graph = [[INF if i != j else 0 for j in range(N)] for i in range(N)]
ans = 0
for E in edge:
    edgeWithoutE = edge.copy()
    edgeWithoutE.remove(E)
    graph = np.array(tmpl_graph)
    for x in edgeWithoutE:
        graph[x[0] - 1, x[1] - 1] = 1
        graph[x[1] - 1, x[0] - 1] = 1
    graph = floyd_warshall(graph, directed=False)
    if len(graph[graph == 100]) > 0:
        ans += 1
print(ans)

class node:
    def __init__(self, id):
        self.id = id
        self.root = self

    def findRoot(self):
        if self == self.root:
            return self
        else:
            self.root = self.root.findRoot()
            return self.root

    def resetRoot(self):
        self.root = self

class Tree:
    def __init__(self, num):
        self.nodes = {i: node(i) for i in range(num)}

    def union(self, one, other):
        root1 = one.findRoot()
        root2 = other.findRoot()
        root1.root = root2.root = self.nodes[min(root1.id, root2.id)]

    def resetTree(self):
        for n in list(self.nodes.values()):
            n.resetRoot()

    def makeTree(self, Edge):
        self.edge = Edge
        for x, y in Edge:
            self.union(self.nodes[x - 1], self.nodes[y - 1])

def main():
    with open(0) as f:
        N, M = list(map(int, f.readline().split()))
        Edge = [tuple(map(int, line.split())) for line in f.readlines()]
    tree = Tree(N)
    ans = 0
    for i in range(M):
        edge = [v for v in Edge if v != Edge[i]]
        tree.makeTree(edge)
        if any(x.findRoot().id != 0 for x in list(tree.nodes.values())):
            ans += 1
        tree.resetTree()
    print(ans)

if __name__ == "__main__":
    main()

-N, M = (int(x) for x in input().split())

-edge = [tuple(int(x) for x in input().split()) for _ in range(M)]

-from scipy.sparse.csgraph import floyd_warshall

-tmpl_graph = [[INF if i != j else 0 for j in range(N)] for i in range(N)]

-    graph = floyd_warshall(graph, directed=False)

+            self.root = self.root.findRoot()

+        self.nodes = {i: node(i) for i in range(num)}

+        root1.root = root2.root = self.nodes[min(root1.id, root2.id)]

+        for n in list(self.nodes.values()):

+            self.union(self.nodes[x - 1], self.nodes[y - 1])

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

+        Edge = [tuple(map(int, line.split())) for line in f.readlines()]

+        edge = [v for v in Edge if v != Edge[i]]

+        if any(x.findRoot().id != 0 for x in list(tree.nodes.values())):


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

from collections import Counter

d={chr(i):0 for i in range(2)}

s=Counter(eval(input()))

d=d.update(s)

print((min(s["0"],s["1"])*2))

# optimized version of the same code:

from collections import Counter

d = {chr(i): 0 for i in range(2)}
s = Counter(eval(input()))
d = d.update(s)
print((min(s["0"], s["1"]) * 2))

s = eval(input())
print((min(s.count("0"), s.count("1")) * 2))


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import bisect

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

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

d = [-1]*(N+1) #0-index #バウンドする位置を格納するリスト

d[0] = 0 #バウンドする初期値は0

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

    d[i] = d[i-1] + l[i-1]

#print(d)

#print('left:', bisect.bisect_left(d, X))

#print('right:', bisect.bisect_right(d, X))

print((bisect.bisect_right(d, X)))

# optimized version of the same code:

import bisect

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

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

d = [-1]*(n+1)

d[0] = 0

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

    d[i] = d[i-1] + l[i-1]

res = bisect.bisect_right(sorted(d), x)

print(res)

import bisect

N, X = list(map(int, input().split()))
l = list(map(int, input().split()))
d = [-1] * (N + 1)  # 0-index #バウンドする位置を格納するリスト
d[0] = 0  # バウンドする初期値は0
for i in range(1, N + 1):
    d[i] = d[i - 1] + l[i - 1]
# print(d)
# print('left:', bisect.bisect_left(d, X))
# print('right:', bisect.bisect_right(d, X))
print((bisect.bisect_right(d, X)))

import bisect

n, x = list(map(int, input().split()))
l = tuple(map(int, input().split()))
d = [-1] * (n + 1)
d[0] = 0
for i in range(1, n + 1):
    d[i] = d[i - 1] + l[i - 1]
res = bisect.bisect_right(sorted(d), x)
print(res)

-d = [-1] * (N + 1)  # 0-index #バウンドする位置を格納するリスト

-d[0] = 0  # バウンドする初期値は0

-# print('left:', bisect.bisect_left(d, X))

-# print('right:', bisect.bisect_right(d, X))

+res = bisect.bisect_right(sorted(d), x)


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import numpy as np

x=int(eval(input()))

#ａ⁵－ｂ⁵＝(ａ－ｂ)(ａ⁴＋ａ³ｂ＋ａ²ｂ²＋ａｂ³＋ｂ⁴)

def make_divisors(n):

    divisors = []

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

        if n % i == 0:

            divisors.append(i)

            if i != n // i:

                divisors.append(n//i)

    return divisors

d=make_divisors(x)

for i in range(len(d)):

  d.append(-d[i])

flag=False

for i in d:

  if flag==True:

    break

  tui=x//i

  ans=np.roots([5,10*i,10*i**2,5*i**3,i**4-tui])

  for j in ans:

    if flag==True:

      break

    if j.imag==0:

      a=i+round(j.real)

    if a**5-(round(j.real))**5==x:

      print((int(a),int(round(j.real))))

      flag=True

      break

# optimized version of the same code:

x=int(eval(input()))

flag=True

for i in range(-118,120):

  if flag==False:

    break

  for j in range(-119,119):

    if x==(i**5-j**5):

      print((i,j))

      flag=False

      break

import numpy as np

x = int(eval(input()))
# ａ⁵－ｂ⁵＝(ａ－ｂ)(ａ⁴＋ａ³ｂ＋ａ²ｂ²＋ａｂ³＋ｂ⁴)
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    return divisors

d = make_divisors(x)
for i in range(len(d)):
    d.append(-d[i])
flag = False
for i in d:
    if flag == True:
        break
    tui = x // i
    ans = np.roots([5, 10 * i, 10 * i**2, 5 * i**3, i**4 - tui])
    for j in ans:
        if flag == True:
            break
        if j.imag == 0:
            a = i + round(j.real)
        if a**5 - (round(j.real)) ** 5 == x:
            print((int(a), int(round(j.real))))
            flag = True
            break

x = int(eval(input()))
flag = True
for i in range(-118, 120):
    if flag == False:
        break
    for j in range(-119, 119):
        if x == (i**5 - j**5):
            print((i, j))
            flag = False
            break

-# ａ⁵－ｂ⁵＝(ａ－ｂ)(ａ⁴＋ａ³ｂ＋ａ²ｂ²＋ａｂ³＋ｂ⁴)

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

-                divisors.append(n // i)

-            print((int(a), int(round(j.real))))


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

from functools import reduce
def f(a,b): return [Card[a][0], Card[b][1]]

n = int(input())

Card = [[] for _ in [0]*n]

Cost = {}

for i in range(n):

  Card[i] = list(map(int, input().split()))

  Cost[(i, i)] = 0

for i in range(1, n):

  for j in range(0, n-i):

    a = j+i

    Cost[(j, a)] = min([reduce(lambda a,b: a*b, f(j, k) + f(k+1, a)) + Cost[(j, k)] + Cost[(k+1, a)] for k in range(j, j+i)])

print(Cost[0, n-1])

# optimized version of the same code:

from functools import reduce
n = int(input())

Card = [[] for _ in [0]*n]

Cost = {}

for i in range(n):

  Card[i] = list(map(int, input().split()))

  Cost[(i, i)] = 0

for i in range(1, n):

  for j in range(0, n-i):

    a = j+i

    Cost[(j, a)] = min([reduce(lambda a,b: a*b, [Card[j][0],Card[k][1],Card[k+1][0],Card[a][1]]) + Cost[(j, k)] + Cost[(k+1, a)] for k in range(j, j+i)])

print(Cost[0, n-1])

from functools import reduce

def f(a, b):
    return [Card[a][0], Card[b][1]]

n = int(input())
Card = [[] for _ in [0] * n]
Cost = {}
for i in range(n):
    Card[i] = list(map(int, input().split()))
    Cost[(i, i)] = 0
for i in range(1, n):
    for j in range(0, n - i):
        a = j + i
        Cost[(j, a)] = min(
            [
                reduce(lambda a, b: a * b, f(j, k) + f(k + 1, a))
                + Cost[(j, k)]
                + Cost[(k + 1, a)]
                for k in range(j, j + i)
            ]
        )
print(Cost[0, n - 1])

from functools import reduce

n = int(input())
Card = [[] for _ in [0] * n]
Cost = {}
for i in range(n):
    Card[i] = list(map(int, input().split()))
    Cost[(i, i)] = 0
for i in range(1, n):
    for j in range(0, n - i):
        a = j + i
        Cost[(j, a)] = min(
            [
                reduce(
                    lambda a, b: a * b,
                    [Card[j][0], Card[k][1], Card[k + 1][0], Card[a][1]],
                )
                + Cost[(j, k)]
                + Cost[(k + 1, a)]
                for k in range(j, j + i)
            ]
        )
print(Cost[0, n - 1])

-                reduce(lambda a, b: a * b, f(j, k) + f(k + 1, a))

+                    lambda a, b: a * b,


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

def cmb(n, r, mod):

    if ( r<0 or r>n ):

        return 0

    r = min(r, n-r)

    return g1[n] * g2[r] * g2[n-r] % mod

A=2*10**5

mod = 10**9+7

g1 = [1, 1]

g2 = [1, 1]

inverse = [0, 1]

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

    g1.append( ( g1[-1] * i ) % mod )

    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )

    g2.append( (g2[-1] * inverse[-1]) % mod )

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

keisuu=cmb(N*M-2,K-2,mod)

sum_=0

for i in range(N):

    a=min(abs(i),abs(N-i-1))

    b=max(abs(i),abs(N-i-1))

    sum_+=(M**2)*((a*(a+1)//2)+(b*(b+1)//2))

for i in range(M):

    a=min(abs(i),abs(M-i-1))

    b=max(abs(i),abs(M-i-1))

    sum_+=(N**2)*((a*(a+1)//2)+(b*(b+1)//2))

print(((keisuu * (sum_//2))%mod))

# optimized version of the same code:

def power_mod(a,b,mod=10**9+7):

    i,temp,box=0,b,[]

    while(2**i<=b):

        i+=1

    for j in range(i-1,-1,-1):

        box=[[j,temp//2**j]]+box

        temp-=2**j*(temp//2**j)

    box[0].append(a)

    ans=box[0][1]*a%mod

    for j in range(1,i):

        box[j].append(box[j-1][2]**2%mod)

        if box[j][1]==1:

            ans=(ans*box[j][2])%mod

    return ans

def n_func(n,mod=10**9+7):

    ans=1

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

        ans=(ans*i)%mod

    return ans

def nPr(n,r,mod=10**9+7):

    ans=n_func(n-r,mod)

    ans=power_mod(ans,mod-2,mod)

    return ans*n_func(n,mod)%mod

def nCr(n,r,mod=10**9+7):

    ans=n_func(n-r,mod)*n_func(r,mod)%mod

    ans=power_mod(ans,mod-2,mod)

    return ans*n_func(n,mod)%mod

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

keisuu=nCr(N*M-2,K-2)

mod=10**9+7

sum_=0

for i in range(N):

    a=min(abs(i),abs(N-i-1))

    b=max(abs(i),abs(N-i-1))

    sum_+=(M**2)*((a*(a+1)//2)+(b*(b+1)//2))

for i in range(M):

    a=min(abs(i),abs(M-i-1))

    b=max(abs(i),abs(M-i-1))

    sum_+=(N**2)*((a*(a+1)//2)+(b*(b+1)//2))

print(((keisuu * (sum_//2))%mod))

def cmb(n, r, mod):
    if r < 0 or r > n:
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n - r] % mod

A = 2 * 10**5
mod = 10**9 + 7
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, A + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)
N, M, K = list(map(int, input().split()))
keisuu = cmb(N * M - 2, K - 2, mod)
sum_ = 0
for i in range(N):
    a = min(abs(i), abs(N - i - 1))
    b = max(abs(i), abs(N - i - 1))
    sum_ += (M**2) * ((a * (a + 1) // 2) + (b * (b + 1) // 2))
for i in range(M):
    a = min(abs(i), abs(M - i - 1))
    b = max(abs(i), abs(M - i - 1))
    sum_ += (N**2) * ((a * (a + 1) // 2) + (b * (b + 1) // 2))
print(((keisuu * (sum_ // 2)) % mod))

def power_mod(a, b, mod=10**9 + 7):
    i, temp, box = 0, b, []
    while 2**i <= b:
        i += 1
    for j in range(i - 1, -1, -1):
        box = [[j, temp // 2**j]] + box
        temp -= 2**j * (temp // 2**j)
    box[0].append(a)
    ans = box[0][1] * a % mod
    for j in range(1, i):
        box[j].append(box[j - 1][2] ** 2 % mod)
        if box[j][1] == 1:
            ans = (ans * box[j][2]) % mod
    return ans

def n_func(n, mod=10**9 + 7):
    ans = 1
    for i in range(1, n + 1):
        ans = (ans * i) % mod
    return ans

def nPr(n, r, mod=10**9 + 7):
    ans = n_func(n - r, mod)
    ans = power_mod(ans, mod - 2, mod)
    return ans * n_func(n, mod) % mod

def nCr(n, r, mod=10**9 + 7):
    ans = n_func(n - r, mod) * n_func(r, mod) % mod
    ans = power_mod(ans, mod - 2, mod)
    return ans * n_func(n, mod) % mod

N, M, K = list(map(int, input().split()))
keisuu = nCr(N * M - 2, K - 2)
mod = 10**9 + 7
sum_ = 0
for i in range(N):
    a = min(abs(i), abs(N - i - 1))
    b = max(abs(i), abs(N - i - 1))
    sum_ += (M**2) * ((a * (a + 1) // 2) + (b * (b + 1) // 2))
for i in range(M):
    a = min(abs(i), abs(M - i - 1))
    b = max(abs(i), abs(M - i - 1))
    sum_ += (N**2) * ((a * (a + 1) // 2) + (b * (b + 1) // 2))
print(((keisuu * (sum_ // 2)) % mod))

-    return g1[n] * g2[r] * g2[n - r] % mod

+        box[j].append(box[j - 1][2] ** 2 % mod)

+            ans = (ans * box[j][2]) % mod

+    ans = n_func(n - r, mod) * n_func(r, mod) % mod

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

-    inverse.append((-inverse[mod % i] * (mod // i)) % mod)

-    g2.append((g2[-1] * inverse[-1]) % mod)

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


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import numpy as np

n=int(eval(input()))

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

b=0

while np.all(a%2==0):

	a=a/2

	b+=1

print(b)

# optimized version of the same code:

a = int(eval(input("")))

b = input("").split(" ")

c = 0

d = []

for i in range(a):

	c = 0

	while (int(b[i]) % 2 == 0):

		b[i] = int(b[i]) / 2

		c += 1

	d.append(c)

print((min(d)))

import numpy as np

n = int(eval(input()))
a = np.array(list(map(int, input().split())))
b = 0
while np.all(a % 2 == 0):
    a = a / 2
    b += 1
print(b)

a = int(eval(input("")))
b = input("").split(" ")
c = 0
d = []
for i in range(a):
    c = 0
    while int(b[i]) % 2 == 0:
        b[i] = int(b[i]) / 2
        c += 1
    d.append(c)
print((min(d)))

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


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

def gen_d_prim(n):

    D = [n+1 if i%2 else 2 for i in range(n+1)]

    D[0] = D[1] = 0

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

        if D[i] != n+1: continue

        for j in range(i, n+1, i): D[j] = i

    return D

def is_pairwise(A):

    D = gen_d_prim(10**6)

    past = set()

    for a in A:

        now = set()

        while a != 1:

            # 素数 D[a]: 今回は未済 & 過去で済

            if not D[a] in now and D[a] in past: return False

            now.add(D[a])

            past.add(D[a])

            a //= D[a]

    return True

def gcd_all(A):

    from math import gcd

    g = 0

    for a in A: g = gcd(g, a)

    return g

def solve():

    if is_pairwise(A): return 0

    if gcd_all(A) == 1: return 1

    return 2

n = int(eval(input()))

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

print((['pairwise','setwise','not'][solve()], 'coprime'))

# optimized version of the same code:

def gen_d_prim(n):

    D = [0,0] + [-1] * (n-1)

    for i in range(2, n+1, 2): D[i] = 2

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

        if D[i] > 0: continue

        for j in range(i, n+1, i): D[j] = i

    return D

def is_pairwise(A):

    D = gen_d_prim(10**6)

    past = set()

    for a in A:

        now = set()

        while a != 1:

            # 素数 D[a]: 今回は未済 & 過去で済

            if not D[a] in now and D[a] in past: return False

            now.add(D[a])

            past.add(D[a])

            a //= D[a]

    return True

def gcd_all(A):

    from math import gcd

    g = 0

    for a in A: g = gcd(g, a)

    return g

def solve():

    if is_pairwise(A): return 0

    if gcd_all(A) == 1: return 1

    return 2

n = int(eval(input()))

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

print((['pairwise','setwise','not'][solve()], 'coprime'))

def gen_d_prim(n):
    D = [n + 1 if i % 2 else 2 for i in range(n + 1)]
    D[0] = D[1] = 0
    for i in range(3, n + 1, 2):
        if D[i] != n + 1:
            continue
        for j in range(i, n + 1, i):
            D[j] = i
    return D

def is_pairwise(A):
    D = gen_d_prim(10**6)
    past = set()
    for a in A:
        now = set()
        while a != 1:
            # 素数 D[a]: 今回は未済 & 過去で済
            if not D[a] in now and D[a] in past:
                return False
            now.add(D[a])
            past.add(D[a])
            a //= D[a]
    return True

def gcd_all(A):
    from math import gcd

    g = 0
    for a in A:
        g = gcd(g, a)
    return g

def solve():
    if is_pairwise(A):
        return 0
    if gcd_all(A) == 1:
        return 1
    return 2

n = int(eval(input()))
A = [*list(map(int, input().split()))]
print((["pairwise", "setwise", "not"][solve()], "coprime"))

def gen_d_prim(n):
    D = [0, 0] + [-1] * (n - 1)
    for i in range(2, n + 1, 2):
        D[i] = 2
    for i in range(3, n + 1, 2):
        if D[i] > 0:
            continue
        for j in range(i, n + 1, i):
            D[j] = i
    return D

def is_pairwise(A):
    D = gen_d_prim(10**6)
    past = set()
    for a in A:
        now = set()
        while a != 1:
            # 素数 D[a]: 今回は未済 & 過去で済
            if not D[a] in now and D[a] in past:
                return False
            now.add(D[a])
            past.add(D[a])
            a //= D[a]
    return True

def gcd_all(A):
    from math import gcd

    g = 0
    for a in A:
        g = gcd(g, a)
    return g

def solve():
    if is_pairwise(A):
        return 0
    if gcd_all(A) == 1:
        return 1
    return 2

n = int(eval(input()))
A = [*list(map(int, input().split()))]
print((["pairwise", "setwise", "not"][solve()], "coprime"))

-    D = [n + 1 if i % 2 else 2 for i in range(n + 1)]


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

from collections import defaultdict

n = int(eval(input()))

s = eval(input())

a = s[:n]

b = s[n:][::-1]

d = defaultdict(int)

e = defaultdict(int)

def cnt(c, d):

    for bit in range(1 << n):

        x = []

        y = []

        for i in range(n):

            if bit >> i & 1:

                x.append(c[i])

            else:

                y.append(c[i])

        d[(str(x), str(y))] += 1

cnt(a, d)

cnt(b, e)

ans = 0

for k, v in list(d.items()):

    ans += e[k] * v

print(ans)

# optimized version of the same code:

from collections import defaultdict

n = int(eval(input()))

s = eval(input())

a = s[:n]

b = s[n:][::-1]

d = defaultdict(int)

e = defaultdict(int)

for bit in range(1 << n):

    x = ""

    y = ""

    z = ""

    w = ""

    for i in range(n):

        if bit >> i & 1:

            x += a[i]

            z += b[i]

        else:

            y += a[i]

            w += b[i]

    d[x+'ω'+y] += 1

    e[z+'ω'+w] += 1

print((sum([e[k] * v for k, v in list(d.items())])))

from collections import defaultdict

n = int(eval(input()))
s = eval(input())
a = s[:n]
b = s[n:][::-1]
d = defaultdict(int)
e = defaultdict(int)
for bit in range(1 << n):
    x = ""
    y = ""
    z = ""
    w = ""
    for i in range(n):
        if bit >> i & 1:
            x += a[i]
            z += b[i]
        else:
            y += a[i]
            w += b[i]
    d[x + "ω" + y] += 1
    e[z + "ω" + w] += 1
print((sum([e[k] * v for k, v in list(d.items())])))

+print((sum([e[k] * v for k, v in list(d.items())])))


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import numpy as np

N = int(eval(input()))

A_ls = np.array(list(map(int,input().split(" "))))

B_ls = np.array(list(map(int,input().split(" "))))

S = 0

for i,b in enumerate(B_ls):

    if b > A_ls[i]:

        b -= A_ls[i]

        S += A_ls[i]

        if A_ls[i+1] >= b:

            A_ls[i+1] -=b

            S+=b

        else:

            S+=A_ls[i+1]

            A_ls[i+1] = 0

    else:

        S += b

print(S)

# optimized version of the same code:

N = int(eval(input()))

A_ls = list(map(int,input().split(" ")))

B_ls = list(map(int,input().split(" ")))

S = 0

for i,b in enumerate(B_ls):

    if b > A_ls[i]:

        b -= A_ls[i]

        S += A_ls[i]

        if A_ls[i+1] >= b:

            A_ls[i+1] -=b

            S+=b

        else:

            S+=A_ls[i+1]

            A_ls[i+1] = 0

    else:

        S += b

print(S)

import numpy as np

N = int(eval(input()))
A_ls = np.array(list(map(int, input().split(" "))))
B_ls = np.array(list(map(int, input().split(" "))))
S = 0
for i, b in enumerate(B_ls):
    if b > A_ls[i]:
        b -= A_ls[i]
        S += A_ls[i]
        if A_ls[i + 1] >= b:
            A_ls[i + 1] -= b
            S += b
        else:
            S += A_ls[i + 1]
            A_ls[i + 1] = 0
    else:
        S += b
print(S)

N = int(eval(input()))
A_ls = list(map(int, input().split(" ")))
B_ls = list(map(int, input().split(" ")))
S = 0
for i, b in enumerate(B_ls):
    if b > A_ls[i]:
        b -= A_ls[i]
        S += A_ls[i]
        if A_ls[i + 1] >= b:
            A_ls[i + 1] -= b
            S += b
        else:
            S += A_ls[i + 1]
            A_ls[i + 1] = 0
    else:
        S += b
print(S)

-A_ls = np.array(list(map(int, input().split(" "))))

-B_ls = np.array(list(map(int, input().split(" "))))

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

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


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

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

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

a.append(a[0]+k)

longd=0

for i in range(n):

    tmp=abs(a[i+1]-a[i])

    longd=max(longd,tmp)

print((k-longd))

# optimized version of the same code:

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

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

a.append(a[0]+k)

x=0

for i in range(len(a)-1):

    dis=abs(a[i+1]-a[i])

    x=max(x,dis)

print((k-x))

k, n = list(map(int, input().split()))
a = list(map(int, input().split()))
a.append(a[0] + k)
longd = 0
for i in range(n):
    tmp = abs(a[i + 1] - a[i])
    longd = max(longd, tmp)
print((k - longd))

k, n = list(map(int, input().split()))
a = list(map(int, input().split()))
a.append(a[0] + k)
x = 0
for i in range(len(a) - 1):
    dis = abs(a[i + 1] - a[i])
    x = max(x, dis)
print((k - x))

-longd = 0
-for i in range(n):
-    tmp = abs(a[i + 1] - a[i])
-    longd = max(longd, tmp)
-print((k - longd))
+x = 0
+for i in range(len(a) - 1):
+    dis = abs(a[i + 1] - a[i])
+    x = max(x, dis)
+print((k - x))


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

X = int(eval(input()))

for a in range(-200, 200):

    find = False

    for b in range(-200, 200):

        x = a**5-b**5

        if x == X:

            find = True

            print((a, b))

            break

    if find:

        break

# optimized version of the same code:

X = int(eval(input()))

for a in range(-120, 120):

    find = False

    for b in range(-120, 120):

        x = a**5-b**5

        if x == X:

            find = True

            print((a, b))

            break

    if find:

        break

X = int(eval(input()))
for a in range(-200, 200):
    find = False
    for b in range(-200, 200):
        x = a**5 - b**5
        if x == X:
            find = True
            print((a, b))
            break
    if find:
        break

X = int(eval(input()))
for a in range(-120, 120):
    find = False
    for b in range(-120, 120):
        x = a**5 - b**5
        if x == X:
            find = True
            print((a, b))
            break
    if find:
        break


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import sys

import itertools

from operator import itemgetter #sortedの対象を決めたい

from fractions import gcd #最大公約数

from math import ceil, floor, sqrt, isinf #小数点切り上げ、切り捨て、平方根

from copy import deepcopy #参照で影響されないコピー

from collections import Counter, deque #要素ごとの出現回数、双方向アクセス可能データ型

import heapq

import numpy as np

from functools import reduce

sys.setrecursionlimit(200000)

input = sys.stdin.readline

# template

def retmax(a, b):

    if a > b:

        return a

    else:

        return b

def main():

    n = int(eval(input()))

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

    dp = np.zeros([3, n+1])

    for i, a_l in enumerate(a):

        for j in range(3):

            for k in range(3):

                if j != k:

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

    print((int(np.max(dp[:, n], axis=0))))

if __name__ == "__main__":

    main()

# optimized version of the same code:

import sys

import itertools

from operator import itemgetter #sortedの対象を決めたい

from fractions import gcd #最大公約数

from math import ceil, floor, sqrt, isinf #小数点切り上げ、切り捨て、平方根

from copy import deepcopy #参照で影響されないコピー

from collections import Counter, deque #要素ごとの出現回数、双方向アクセス可能データ型

import heapq

import numpy as np

from functools import reduce

sys.setrecursionlimit(200000)

input = sys.stdin.readline

# template

def main():

    n = int(eval(input()))

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

    a, b, c = 0, 0, 0

    for x, y, z in abc:

        a, b, c = max(b, c) + x, max(a, c) + y, max(a, b) + z

    print((max(a, b, c)))

if __name__ == "__main__":

    main()

import sys
import itertools
from operator import itemgetter  # sortedの対象を決めたい
from fractions import gcd  # 最大公約数
from math import ceil, floor, sqrt, isinf  # 小数点切り上げ、切り捨て、平方根
from copy import deepcopy  # 参照で影響されないコピー
from collections import Counter, deque  # 要素ごとの出現回数、双方向アクセス可能データ型
import heapq
import numpy as np
from functools import reduce

sys.setrecursionlimit(200000)
input = sys.stdin.readline
# template
def retmax(a, b):
    if a > b:
        return a
    else:
        return b

def main():
    n = int(eval(input()))
    a = [list(map(int, input().split())) for _ in range(n)]
    dp = np.zeros([3, n + 1])
    for i, a_l in enumerate(a):
        for j in range(3):
            for k in range(3):
                if j != k:
                    dp[k, i + 1] = retmax(dp[k, i + 1], dp[j, i] + a_l[k])
    print((int(np.max(dp[:, n], axis=0))))

if __name__ == "__main__":
    main()

import sys
import itertools
from operator import itemgetter  # sortedの対象を決めたい
from fractions import gcd  # 最大公約数
from math import ceil, floor, sqrt, isinf  # 小数点切り上げ、切り捨て、平方根
from copy import deepcopy  # 参照で影響されないコピー
from collections import Counter, deque  # 要素ごとの出現回数、双方向アクセス可能データ型
import heapq
import numpy as np
from functools import reduce

sys.setrecursionlimit(200000)
input = sys.stdin.readline
# template
def main():
    n = int(eval(input()))
    abc = [list(map(int, input().split())) for _ in range(n)]
    a, b, c = 0, 0, 0
    for x, y, z in abc:
        a, b, c = max(b, c) + x, max(a, c) + y, max(a, b) + z
    print((max(a, b, c)))

if __name__ == "__main__":
    main()

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

-    print((int(np.max(dp[:, n], axis=0))))

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

+        a, b, c = max(b, c) + x, max(a, c) + y, max(a, b) + z


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

def ii():return int(eval(input()))

def iim():return list(map(int,input().split()))

def iil():return list(map(int,input().split()))

def ism():return list(map(str,input().split()))

def isl():return list(map(str,input().split()))

n = ii()

D = iil()

ans = 0

for i in range(n):

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

#        print(i,j)

        ans += D[i]*D[j]

print(ans)

# optimized version of the same code:

def ii():return int(eval(input()))

def iim():return list(map(int,input().split()))

def iil():return list(map(int,input().split()))

def ism():return list(map(str,input().split()))

def isl():return list(map(str,input().split()))

n = ii()

D = iil()

sumD = sum(D)

ans = 0

for i in range(n):

    ans += D[i]*(sum(D)-D[i])

print((ans//2))

def ii():
    return int(eval(input()))

def iim():
    return list(map(int, input().split()))

def iil():
    return list(map(int, input().split()))

def ism():
    return list(map(str, input().split()))

def isl():
    return list(map(str, input().split()))

n = ii()
D = iil()
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        #        print(i,j)
        ans += D[i] * D[j]
print(ans)

def ii():
    return int(eval(input()))

def iim():
    return list(map(int, input().split()))

def iil():
    return list(map(int, input().split()))

def ism():
    return list(map(str, input().split()))

def isl():
    return list(map(str, input().split()))

n = ii()
D = iil()
sumD = sum(D)
ans = 0
for i in range(n):
    ans += D[i] * (sum(D) - D[i])
print((ans // 2))

+sumD = sum(D)
-    for j in range(i + 1, n):
-        #        print(i,j)
-        ans += D[i] * D[j]
-print(ans)
+    ans += D[i] * (sum(D) - D[i])
+print((ans // 2))


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

S = eval(input())

K = int(eval(input()))

a = list(set(S))

a.sort()

k = []

l = 0

while l < len(a):

    for i in range(len(S)):

        if S[i] == a[l]:

            for j in range(1,6):

                if i+j <= len(S):

                    k.append(S[i:i+j])

                else:

                    break

    l += 1

k = list(set(k))

k.sort()

print((k[K-1]))

# optimized version of the same code:

S = eval(input())

K = int(eval(input()))

a = []

for i in range(len(S)+1):

    for j in range(1,6):

        if i+j <= len(S):

            a.append(S[i:i+j])

        else:

            break

a = list(set(a))

a.sort()

print((a[K-1]))

S = eval(input())
K = int(eval(input()))
a = list(set(S))
a.sort()
k = []
l = 0
while l < len(a):
    for i in range(len(S)):
        if S[i] == a[l]:
            for j in range(1, 6):
                if i + j <= len(S):
                    k.append(S[i : i + j])
                else:
                    break
    l += 1
k = list(set(k))
k.sort()
print((k[K - 1]))

S = eval(input())
K = int(eval(input()))
a = []
for i in range(len(S) + 1):
    for j in range(1, 6):
        if i + j <= len(S):
            a.append(S[i : i + j])
        else:
            break
a = list(set(a))
a.sort()
print((a[K - 1]))

-                    k.append(S[i : i + j])


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

s = input()[::-1]

l = len(s)

c = [0] * 2019

c[0] = 1

ten = 1

mod = 0

ans = 0

for i in range(l):

    mod = (mod + int(s[i]) * ten) % 2019

    ten = ten * 10 % 2019

    c[mod] += 1

for i in c:

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

print(ans)

# optimized version of the same code:


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import numpy as np

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

li=[]

for i in range(n):

  li.append(l+i)

s=sum(li)

p=np.array(li)

a=np.abs(p).tolist()

k=min(a)

b=a.index(k)

print((s-li[b]))

# optimized version of the same code:

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

a=0

for i in range(n):

  a+=i+l

if l>=0:

  print((a-l))

elif l+n-1<0:

  print((a-(l+n-1)))

else:

  print(a)

import numpy as np

n, l = list(map(int, input().split()))
li = []
for i in range(n):
    li.append(l + i)
s = sum(li)
p = np.array(li)
a = np.abs(p).tolist()
k = min(a)
b = a.index(k)
print((s - li[b]))

n, l = list(map(int, input().split()))
a = 0
for i in range(n):
    a += i + l
if l >= 0:
    print((a - l))
elif l + n - 1 < 0:
    print((a - (l + n - 1)))
else:
    print(a)

-import numpy as np
-li = []
+a = 0
-    li.append(l + i)
-s = sum(li)
-p = np.array(li)
-a = np.abs(p).tolist()
-k = min(a)
-b = a.index(k)
-print((s - li[b]))
+    a += i + l
+if l >= 0:
+    print((a - l))
+elif l + n - 1 < 0:
+    print((a - (l + n - 1)))
+else:
+    print(a)


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import numpy as np

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

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

kitaiti = np.array([(0.5*(p+1)) for p in plist])

ans = 0

val = sum(kitaiti[:K])

ans = max(ans, val)

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

    # print(i-1, i+K)

    val -= kitaiti[i-1]

    val += kitaiti[i+K-1]

    ans = max(ans, val)

print(ans)

# optimized version of the same code:

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

plist = [((num*(num+1))//2)/num for num in list(map(int, input().split()))]

# print(plist)

ans = 0

for i in range(K):

    ans += plist[i]

_ = ans

for i in range(N-K):

    temp = _

    temp -= plist[i]

    temp += plist[i+K]

    # print(i, i+K, ans, temp)

    ans = max(ans, temp)

    _ = temp

print(ans)

import numpy as np

N, K = list(map(int, input().split()))
plist = list(map(int, input().split()))
kitaiti = np.array([(0.5 * (p + 1)) for p in plist])
ans = 0
val = sum(kitaiti[:K])
ans = max(ans, val)
for i in range(1, N - K + 1):
    # print(i-1, i+K)
    val -= kitaiti[i - 1]
    val += kitaiti[i + K - 1]
    ans = max(ans, val)
print(ans)

N, K = list(map(int, input().split()))
plist = [((num * (num + 1)) // 2) / num for num in list(map(int, input().split()))]
# print(plist)
ans = 0
for i in range(K):
    ans += plist[i]
_ = ans
for i in range(N - K):
    temp = _
    temp -= plist[i]
    temp += plist[i + K]
    # print(i, i+K, ans, temp)
    ans = max(ans, temp)
    _ = temp
print(ans)

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

-kitaiti = np.array([(0.5 * (p + 1)) for p in plist])

+plist = [((num * (num + 1)) // 2) / num for num in list(map(int, input().split()))]


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

#ABC 130 B

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

L= [int(j) for j in input().split()]

cnt=0

import numpy as np

jump = list(np.cumsum(L))

for j in jump:

    if j <= X:

        cnt+=1

print((cnt+1))

# optimized version of the same code:

#ABC 130 B

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

L= [int(j) for j in input().split()]

cnt=0

import numpy as np

jump = list(np.cumsum(L))

for j in jump:

    if j <= X:

        cnt+=1

    else:

        break

print((cnt+1))

# ABC 130 B
N, X = list(map(int, input().split()))
L = [int(j) for j in input().split()]
cnt = 0
import numpy as np

jump = list(np.cumsum(L))
for j in jump:
    if j <= X:
        cnt += 1
print((cnt + 1))

# ABC 130 B
N, X = list(map(int, input().split()))
L = [int(j) for j in input().split()]
cnt = 0
import numpy as np

jump = list(np.cumsum(L))
for j in jump:
    if j <= X:
        cnt += 1
    else:
        break
print((cnt + 1))


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import numpy as np

num=np.array(list(eval(input())))

for bit in  range(1<<3):

  op=np.array(['-']*3)

  for i in range(3):

    if (bit>>i)&1:

      op[i]='+'

  formula=np.insert(num,[1,2,3],op)

  if eval(''.join(formula))==7:

    flag=True

    print((''.join(formula)+'=7'))

    break

# optimized version of the same code:

INF = 10 ** 9

import sys

sys.setrecursionlimit(100000000)

dy = (-1,0,1,0)

dx = (0,1,0,-1)

from  heapq import heappop,heapify,heappush

from bisect import bisect_left

def main():

    s = eval(input())

    for bit in range(8):

        op = []

        for i in range(3):

            if (bit>>i)&1:

                op.append('+')

            else:

                op.append('-')

        tmp = s[0]

        for i in range(3):

            tmp += op[i]

            tmp += s[i + 1]

        if eval(tmp) == 7:

            ans = tmp + '=7'

            break

    print(ans)

if __name__ == '__main__':

    main()

import numpy as np

num = np.array(list(eval(input())))
for bit in range(1 << 3):
    op = np.array(["-"] * 3)
    for i in range(3):
        if (bit >> i) & 1:
            op[i] = "+"
    formula = np.insert(num, [1, 2, 3], op)
    if eval("".join(formula)) == 7:
        flag = True
        print(("".join(formula) + "=7"))
        break

INF = 10**9
import sys

sys.setrecursionlimit(100000000)
dy = (-1, 0, 1, 0)
dx = (0, 1, 0, -1)
from heapq import heappop, heapify, heappush
from bisect import bisect_left

def main():
    s = eval(input())
    for bit in range(8):
        op = []
        for i in range(3):
            if (bit >> i) & 1:
                op.append("+")
            else:
                op.append("-")
        tmp = s[0]
        for i in range(3):
            tmp += op[i]
            tmp += s[i + 1]
        if eval(tmp) == 7:
            ans = tmp + "=7"
            break
    print(ans)

if __name__ == "__main__":
    main()

-    formula = np.insert(num, [1, 2, 3], op)

-        print(("".join(formula) + "=7"))

+from heapq import heappop, heapify, heappush


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

S=eval(input())

print((S.rfind('Z')-S.find('A')+1))

# optimized version of the same code:

s=input().strip()

a = s.find('A')

z = s.rfind('Z')

print((z-a+1))

S = eval(input())
print((S.rfind("Z") - S.find("A") + 1))

s = input().strip()
a = s.find("A")
z = s.rfind("Z")
print((z - a + 1))

-print((S.rfind("Z") - S.find("A") + 1))


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

#!usr/bin/env python3

from collections import defaultdict

from collections import deque

from heapq import heappush, heappop

import sys

import math

import bisect

import random

def LI(): return list(map(int, sys.stdin.readline().split()))

def I(): return int(sys.stdin.readline())

def LS():return list(map(list, sys.stdin.readline().split()))

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

def IR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = I()

    return l

def LIR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = LI()

    return l

def SR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = S()

    return l

def LSR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = LS()

    return l

sys.setrecursionlimit(1000000)

mod = 1000000007

#A

def A():

    return

#B

def B():

    return

#C

def C():

    return

#D

def D():

    return

#E

def E():

    return

#F

def F():

    a,b,c,X,Y = LI()

    ans = float("inf")

    for z in range(300001):

        if z%2 == 0:

            m = c*z

            x = z//2

            y = z//2

            m += a*max(0,X-x)

            m += b*max(0,Y-y)

            if m < ans:

                ans = m

    print(ans)

    return

#G

def G():

    n = I()

    x = LI()

    f = [(i,x[i]) for i in range(n)]

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

    g = [(f[i][0],i) for i in range(n)]

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

    for i in range(n):

        if g[i][1] < n//2:

            print((f[n//2][1]))

        else:

            print((f[n//2-1][1]))

    return

#H

def H():

    return

#I

def I_():

    return

#J

def J():

    return

#Solve

if __name__ == "__main__":

    F()

# optimized version of the same code:

#!usr/bin/env python3

from collections import defaultdict,deque

from heapq import heappush, heappop

from itertools import permutations

import sys

import math

import bisect

def LI(): return [int(x) for x in sys.stdin.readline().split()]

def I(): return int(sys.stdin.readline())

def LS():return [list(x) for x in sys.stdin.readline().split()]

def S():

    res = list(sys.stdin.readline())

    if res[-1] == "\n":

        return res[:-1]

    return res

def IR(n):

    return [I() for i in range(n)]

def LIR(n):

    return [LI() for i in range(n)]

def SR(n):

    return [S() for i in range(n)]

def LSR(n):

    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)

mod = 1000000007

def solve():

    A,B,C,x,y = LI()

    ans = float("inf")

    for c in range(200001)[::2]:

        a = b = c >> 1

        a = max(0,x-a)

        b = max(0,y-b)

        s = A*a+B*b+C*c

        if s < ans:

            ans = s

    print(ans)

    return

#Solve

if __name__ == "__main__":

    solve()

#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random

def LI():
    return list(map(int, sys.stdin.readline().split()))

def I():
    return int(sys.stdin.readline())

def LS():
    return list(map(list, sys.stdin.readline().split()))

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

def IR(n):
    l = [None for i in range(n)]
    for i in range(n):
        l[i] = I()
    return l

def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):
        l[i] = LI()
    return l

def SR(n):
    l = [None for i in range(n)]
    for i in range(n):
        l[i] = S()
    return l

def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):
        l[i] = LS()
    return l

sys.setrecursionlimit(1000000)
mod = 1000000007
# A
def A():
    return

# B
def B():
    return

# C
def C():
    return

# D
def D():
    return

# E
def E():
    return

# F
def F():
    a, b, c, X, Y = LI()
    ans = float("inf")
    for z in range(300001):
        if z % 2 == 0:
            m = c * z
            x = z // 2
            y = z // 2
            m += a * max(0, X - x)
            m += b * max(0, Y - y)
            if m < ans:
                ans = m
    print(ans)
    return

# G
def G():
    n = I()
    x = LI()
    f = [(i, x[i]) for i in range(n)]
    f.sort(key=lambda x: x[1])
    g = [(f[i][0], i) for i in range(n)]
    g.sort(key=lambda x: x[0])
    for i in range(n):
        if g[i][1] < n // 2:
            print((f[n // 2][1]))
        else:
            print((f[n // 2 - 1][1]))
    return

# H
def H():
    return

# I
def I_():
    return

# J
def J():
    return

# Solve
if __name__ == "__main__":
    F()

#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect

def LI():
    return [int(x) for x in sys.stdin.readline().split()]

def I():
    return int(sys.stdin.readline())

def LS():
    return [list(x) for x in sys.stdin.readline().split()]

def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res

def IR(n):
    return [I() for i in range(n)]

def LIR(n):
    return [LI() for i in range(n)]

def SR(n):
    return [S() for i in range(n)]

def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    A, B, C, x, y = LI()
    ans = float("inf")
    for c in range(200001)[::2]:
        a = b = c >> 1
        a = max(0, x - a)
        b = max(0, y - b)
        s = A * a + B * b + C * c
        if s < ans:
            ans = s
    print(ans)
    return

# Solve
if __name__ == "__main__":
    solve()

+from collections import defaultdict, deque

-    return list(map(int, sys.stdin.readline().split()))

+    return [int(x) for x in sys.stdin.readline().split()]

-    return list(map(list, sys.stdin.readline().split()))

+    return [list(x) for x in sys.stdin.readline().split()]

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

-    g = [(f[i][0], i) for i in range(n)]


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

n = int(eval(input())) % 1000

if n == 0:

    print((0))

else:

    print((1000 - n))

# optimized version of the same code: