Input:
import queue

k = int(eval(input()))

q = queue.Queue()

for i in range(1,10):

    q.put(i)

for i in range(1,k):

    l = q.get()

    m = l % 10

    if (m != 0):

        q.put(l * 10 + m - 1)

    q.put(l * 10 + m)

    if (m != 9):

        q.put(l * 10 + m + 1)

print((q.get()))

from collections import deque

k = int(eval(input()))

q = deque([1,2,3,4,5,6,7,8,9])

for i in range(1,k):

    l = q.popleft()

    if (len(q) < k):

        m = l % 10

        if (m != 0):

            q.append(l * 10 + m - 1)

        q.append(l * 10 + m)

        if (m != 9):

            q.append(l * 10 + m + 1)

print((q.popleft()))

import queue

k = int(eval(input()))
q = queue.Queue()
for i in range(1, 10):
    q.put(i)
for i in range(1, k):
    l = q.get()
    m = l % 10
    if m != 0:
        q.put(l * 10 + m - 1)
    q.put(l * 10 + m)
    if m != 9:
        q.put(l * 10 + m + 1)
print((q.get()))

from collections import deque

k = int(eval(input()))
q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
for i in range(1, k):
    l = q.popleft()
    if len(q) < k:
        m = l % 10
        if m != 0:
            q.append(l * 10 + m - 1)
        q.append(l * 10 + m)
        if m != 9:
            q.append(l * 10 + m + 1)
print((q.popleft()))

-import queue
+from collections import deque
-q = queue.Queue()
-for i in range(1, 10):
-    q.put(i)
+q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
-    l = q.get()
-    m = l % 10
-    if m != 0:
-        q.put(l * 10 + m - 1)
-    q.put(l * 10 + m)
-    if m != 9:
-        q.put(l * 10 + m + 1)
-print((q.get()))
+    l = q.popleft()
+    if len(q) < k:
+        m = l % 10
+        if m != 0:
+            q.append(l * 10 + m - 1)
+        q.append(l * 10 + m)
+        if m != 9:
+            q.append(l * 10 + m + 1)
+print((q.popleft()))


Input:
from scipy.misc import comb

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

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

V.sort(reverse=True)

print((sum(V[:A]) / A))

Ath_CNT = V.count(V[A - 1])

V_than_Ath_CNT = len([v for v in V if v > V[A - 1]])

if max(V) == V[A - 1]:

    ans = 0

    for k in range(A, B + 1):

        ans += comb(Ath_CNT, k, 1)

else:

    ans = comb(Ath_CNT, A - V_than_Ath_CNT, 1)

print(ans)

from collections import Counter

from math import factorial

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

V = sorted(list(map(int, input().split())), reverse=True)

MAX_AVE = sum(V[:A]) / A

C = Counter(V)

def nCr(n, r):

    return int(factorial(n) / (factorial(r) * factorial(n - r)))

Ath_V = V[A - 1]

if Ath_V == max(V):

    ans = 0

    for r in range(A, min(B + 1, C[Ath_V] + 1)):

        ans += nCr(C[Ath_V], r)

    print(MAX_AVE)

    print(ans)

else:

    print(MAX_AVE)

    for i, v in enumerate(V):

        if v == Ath_V:

            used = i

            break

    print((nCr(C[Ath_V], A - used)))

-V_than_Ath_CNT = len([v for v in V if v > V[A - 1]])

+V = sorted(list(map(int, input().split())), reverse=True)

+    return int(factorial(n) / (factorial(r) * factorial(n - r)))

+    for r in range(A, min(B + 1, C[Ath_V] + 1)):

-    ans = comb(Ath_CNT, A - V_than_Ath_CNT, 1)


Input:
from collections import Counter

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

many  =[]

for i in range(n):

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

    for j in range(1,a[0]+1):

        many.append(a[j])

ans = Counter(many).most_common()

count = 0

for i in range(len(ans)):

    if ans[i][1] == n:

        count += 1

print(count)

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

data = [0 for i in range(m)]

for i in range(n):

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

    for x in a:

        data[x-1] += 1

ans = 0

for i in range(m):

    if data[i] == n:

        ans += 1

print(ans)

from collections import Counter

n, m = list(map(int, input().split()))
many = []
for i in range(n):
    a = list(map(int, input().split()))
    for j in range(1, a[0] + 1):
        many.append(a[j])
ans = Counter(many).most_common()
count = 0
for i in range(len(ans)):
    if ans[i][1] == n:
        count += 1
print(count)

n, m = list(map(int, input().split()))
data = [0 for i in range(m)]
for i in range(n):
    k, *a = list(map(int, input().split()))
    for x in a:
        data[x - 1] += 1
ans = 0
for i in range(m):
    if data[i] == n:
        ans += 1
print(ans)

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

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


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

numset = {i for i in range(1,10)}

flag = False

count = len(numset)

if count >= k:

    flag = True

arr = [numset]

index = 0

while not flag:

    beforeset = arr[index]

    tmpset = set()

    for i in beforeset:

        tail = str(i)[-1]

        if tail == "0":

            tmpset.add(int(str(i)+str(0)))

            tmpset.add(int(str(i)+str(1)))

        elif tail == "9":

            tmpset.add(int(str(i)+str(8)))

            tmpset.add(int(str(i)+str(9)))

        else:

            tmpset.add(int(str(i)+str(int(tail))))

            tmpset.add(int(str(i)+str(int(tail)+1)))

            tmpset.add(int(str(i)+str(int(tail)-1)))

    count += len(tmpset)

    if count >= k:

        flag = True

    arr.append(tmpset)

    index += 1

totalarr = []

for tmpset in arr:

    totalarr += list(tmpset)

totalarr.sort()

print((totalarr[k-1]))

k = int(eval(input()))

from collections import deque

queue = deque(list(range(1,10)))

count = 0

while count < k:

    tmp = queue.popleft()

    tail = tmp%10

    if tail != 0:

        queue.append(tmp*10+tail-1)

    queue.append(tmp*10+tail)

    if tail != 9:

        queue.append(tmp*10+tail+1)

    count += 1

print(tmp)

k = int(eval(input()))
numset = {i for i in range(1, 10)}
flag = False
count = len(numset)
if count >= k:
    flag = True
arr = [numset]
index = 0
while not flag:
    beforeset = arr[index]
    tmpset = set()
    for i in beforeset:
        tail = str(i)[-1]
        if tail == "0":
            tmpset.add(int(str(i) + str(0)))
            tmpset.add(int(str(i) + str(1)))
        elif tail == "9":
            tmpset.add(int(str(i) + str(8)))
            tmpset.add(int(str(i) + str(9)))
        else:
            tmpset.add(int(str(i) + str(int(tail))))
            tmpset.add(int(str(i) + str(int(tail) + 1)))
            tmpset.add(int(str(i) + str(int(tail) - 1)))
    count += len(tmpset)
    if count >= k:
        flag = True
    arr.append(tmpset)
    index += 1
totalarr = []
for tmpset in arr:
    totalarr += list(tmpset)
totalarr.sort()
print((totalarr[k - 1]))

k = int(eval(input()))
from collections import deque

queue = deque(list(range(1, 10)))
count = 0
while count < k:
    tmp = queue.popleft()
    tail = tmp % 10
    if tail != 0:
        queue.append(tmp * 10 + tail - 1)
    queue.append(tmp * 10 + tail)
    if tail != 9:
        queue.append(tmp * 10 + tail + 1)
    count += 1
print(tmp)

-            tmpset.add(int(str(i) + str(0)))

-            tmpset.add(int(str(i) + str(1)))

-            tmpset.add(int(str(i) + str(8)))

-            tmpset.add(int(str(i) + str(9)))

-            tmpset.add(int(str(i) + str(int(tail))))

-            tmpset.add(int(str(i) + str(int(tail) + 1)))

-            tmpset.add(int(str(i) + str(int(tail) - 1)))

+        queue.append(tmp * 10 + tail - 1)

+        queue.append(tmp * 10 + tail + 1)


Input:
import copy

s = eval(input())

ss = list(s)

sss = copy.copy(ss)

n = len(ss)

ans = "yes"

for i in range(n):

  sss = copy.copy(ss)

  sss.remove(sss[i])

  if ss[i] in sss:

    ans = "no"

print(ans)

s = list(eval(input()))

n = len(s)

ans = "yes"

for i in range(n):

  if s.count(s[i]) != 1:

    ans = "no"

print(ans)

-import copy
-s = eval(input())
-ss = list(s)
-sss = copy.copy(ss)
-n = len(ss)
+s = list(eval(input()))
+n = len(s)
-    sss = copy.copy(ss)
-    sss.remove(sss[i])
-    if ss[i] in sss:
+    if s.count(s[i]) != 1:


Input:
x,y,a,b,c=list(map(int,input().split()))

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

a_list=sorted(a_list)

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

b_list=sorted(b_list)

a_list=a_list[-x:]

b_list=b_list[-y:]

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

for i in range(c):

    c_list[i]=-c_list[i]

import heapq

heapq.heapify(a_list)

heapq.heapify(b_list)

heapq.heapify(c_list)

flag=True

while flag and c_list:

    x=heapq.heappop(c_list)

    x=x*(-1)

    #ｃ_listの中でのもっとも大きい値

    min_a=heapq.heappop(a_list)

    min_b=heapq.heappop(b_list)

    if min(min_a,min_b)>=x:

        flag=False

        heapq.heappush(a_list,min_a)

        heapq.heappush(b_list,min_b)

    else:

        if min_a>=min_b:

            heapq.heappush(a_list,min_a)

            heapq.heappush(b_list,x)

        elif min_a<min_b:

            heapq.heappush(b_list,min_b)

            heapq.heappush(a_list,x)

sum_a=sum(list(a_list))

sum_b=sum(list(b_list))

print((sum_a+sum_b))

import sys

input=sys.stdin.readline

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

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

a_list=sorted(a_list)

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

b_list=sorted(b_list)

a_list=a_list[-x:]

b_list=b_list[-y:]

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

for i in range(c):

    c_list[i]=-c_list[i]

import heapq

heapq.heapify(a_list)

heapq.heapify(b_list)

heapq.heapify(c_list)

flag=True

while flag and c_list:

    x=heapq.heappop(c_list)

    x=x*(-1)

    #ｃ_listの中でのもっとも大きい値

    min_a=heapq.heappop(a_list)

    min_b=heapq.heappop(b_list)

    if min(min_a,min_b)>=x:

        flag=False

        heapq.heappush(a_list,min_a)

        heapq.heappush(b_list,min_b)

    else:

        if min_a>=min_b:

            heapq.heappush(a_list,min_a)

            heapq.heappush(b_list,x)

        elif min_a<min_b:

            heapq.heappush(b_list,min_b)

            heapq.heappush(a_list,x)

sum_a=sum(list(a_list))

sum_b=sum(list(b_list))

print((sum_a+sum_b))

import sys

input = sys.stdin.readline
x, y, a, b, c = list(map(int, input().split()))
a_list = list(map(int, input().split()))
a_list = sorted(a_list)
b_list = list(map(int, input().split()))
b_list = sorted(b_list)
a_list = a_list[-x:]
b_list = b_list[-y:]
c_list = list(map(int, input().split()))
for i in range(c):
    c_list[i] = -c_list[i]
import heapq

heapq.heapify(a_list)
heapq.heapify(b_list)
heapq.heapify(c_list)
flag = True
while flag and c_list:
    x = heapq.heappop(c_list)
    x = x * (-1)
    # ｃ_listの中でのもっとも大きい値
    min_a = heapq.heappop(a_list)
    min_b = heapq.heappop(b_list)
    if min(min_a, min_b) >= x:
        flag = False
        heapq.heappush(a_list, min_a)
        heapq.heappush(b_list, min_b)
    else:
        if min_a >= min_b:
            heapq.heappush(a_list, min_a)
            heapq.heappush(b_list, x)
        elif min_a < min_b:
            heapq.heappush(b_list, min_b)
            heapq.heappush(a_list, x)
sum_a = sum(list(a_list))
sum_b = sum(list(b_list))
print((sum_a + sum_b))

+import sys
+
+input = sys.stdin.readline


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

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

inf = 1001001001

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

dp[0] = 0

dp[1] = abs(h[0]-h[1])

for i in range(2, n):

    dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]),

                dp[i - 1] + abs(h[i] - h[i - 1]))

print((dp[n-1]))

import sys

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

n = int(eval(input()))

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

inf = 1001001001

dp = [inf for _ in range(n + 5)]

dp[0] = 0

dp[1] = abs(h[0] - h[1])

for i in range(2, n):

    dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]),

                dp[i - 1] + abs(h[i] - h[i - 1]))

print((dp[n-1]))

n = int(eval(input()))
h = list(map(int, input().split()))
inf = 1001001001
dp = [inf for _ in range(n + 1)]
dp[0] = 0
dp[1] = abs(h[0] - h[1])
for i in range(2, n):
    dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]))
print((dp[n - 1]))

import sys

input = lambda: sys.stdin.readline().rstrip()
n = int(eval(input()))
h = list(map(int, input().split()))
inf = 1001001001
dp = [inf for _ in range(n + 5)]
dp[0] = 0
dp[1] = abs(h[0] - h[1])
for i in range(2, n):
    dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]))
print((dp[n - 1]))

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


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

lun_list = [1,2,3,4,5,6,7,8,9]

for i in lun_list:

    if str(i)[-1] == '0':

        for j in range(2):

            lun_list.append(int(str(i)+str(j)))

    elif str(i)[-1] == '9':

        for j in range(8,10):

            lun_list.append(int(str(i)+str(j)))

    else:

        for j in range(int(str(i)[-1])-1,int(str(i)[-1])+2):

            lun_list.append(int(str(i)+str(j)))

    if len(lun_list) > k:

        break

print((lun_list[k-1]))

k = int(eval(input()))

num_list = [1,2,3,4,5,6,7,8,9]

num_a = ['0', '1']

num_b = ['8', '9']

for i in num_list:

    if str(i)[-1] == '0':

        for j in num_a:

            num_list.append(int(str(i)+j))

    elif str(i)[-1] == '9':

        for j in num_b:

            num_list.append(int(str(i)+j))

    else:

        num = int(str(i)[-1])

        for j in range(num-1, num+2):

            num_list.append(int(str(i)+str(j)))

    if len(num_list) > k:

        break

print((num_list[k-1]))

k = int(eval(input()))
lun_list = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for i in lun_list:
    if str(i)[-1] == "0":
        for j in range(2):
            lun_list.append(int(str(i) + str(j)))
    elif str(i)[-1] == "9":
        for j in range(8, 10):
            lun_list.append(int(str(i) + str(j)))
    else:
        for j in range(int(str(i)[-1]) - 1, int(str(i)[-1]) + 2):
            lun_list.append(int(str(i) + str(j)))
    if len(lun_list) > k:
        break
print((lun_list[k - 1]))

k = int(eval(input()))
num_list = [1, 2, 3, 4, 5, 6, 7, 8, 9]
num_a = ["0", "1"]
num_b = ["8", "9"]
for i in num_list:
    if str(i)[-1] == "0":
        for j in num_a:
            num_list.append(int(str(i) + j))
    elif str(i)[-1] == "9":
        for j in num_b:
            num_list.append(int(str(i) + j))
    else:
        num = int(str(i)[-1])
        for j in range(num - 1, num + 2):
            num_list.append(int(str(i) + str(j)))
    if len(num_list) > k:
        break
print((num_list[k - 1]))

-            lun_list.append(int(str(i) + str(j)))

+            num_list.append(int(str(i) + j))

-            lun_list.append(int(str(i) + str(j)))

+            num_list.append(int(str(i) + j))

-        for j in range(int(str(i)[-1]) - 1, int(str(i)[-1]) + 2):

-            lun_list.append(int(str(i) + str(j)))

+        for j in range(num - 1, num + 2):

+            num_list.append(int(str(i) + str(j)))


Input:
import sys

import collections

n = int(sys.stdin.readline())

a = []

for _ in range(n):

  a.append(sys.stdin.readline().strip())

c = collections.Counter(a)

maxc = max(c.values())

print((*sorted([i[0] for i in list(c.items()) if i[1] == maxc])))

from collections import Counter

def main():

  _, *A = open(0).read().split()

  c = Counter(A)

  maxc = max(c.values())

  print((*sorted([i[0] for i in list(c.items()) if i[1] == maxc])))

if __name__ == "__main__":

  main()

-    a.append(sys.stdin.readline().strip())

-print((*sorted([i[0] for i in list(c.items()) if i[1] == maxc])))

+    print((*sorted([i[0] for i in list(c.items()) if i[1] == maxc])))


Input:
import collections

n = int(eval(input()))

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

aa = collections.Counter(a)

ans = 0

for i,j in sorted(aa.items()):

	if j > i:

		ans += j-i

	elif j < i:

		ans += j

print (ans)

from collections import Counter

n = int(eval(input()))

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

c = Counter(a)

ans = 0

for i in c:

	if c[i] > i:

		ans += c[i] - i

	elif c[i] < i:

		ans += c[i]

print (ans)

import collections

n = int(eval(input()))
a = list(map(int, input().split()))
aa = collections.Counter(a)
ans = 0
for i, j in sorted(aa.items()):
    if j > i:
        ans += j - i
    elif j < i:
        ans += j
print(ans)

from collections import Counter

n = int(eval(input()))
a = list(map(int, input().split()))
c = Counter(a)
ans = 0
for i in c:
    if c[i] > i:
        ans += c[i] - i
    elif c[i] < i:
        ans += c[i]
print(ans)

-import collections
+from collections import Counter
-aa = collections.Counter(a)
+c = Counter(a)
-for i, j in sorted(aa.items()):
-    if j > i:
-        ans += j - i
-    elif j < i:
-        ans += j
+for i in c:
+    if c[i] > i:
+        ans += c[i] - i
+    elif c[i] < i:
+        ans += c[i]


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

def tobase4(num):

    ans = ''

    while num>0:

        ans += str(num%4)

        num //= 4

    return ans[::-1]

def check(s):

    if '1' in s and '2' in s and '3' in s and '0' not in s:

        return True

    return False

def conv(s):

    s = s.replace('2','5')

    s = s.replace('3','7')

    s = s.replace('1','3')

    return s

res = 0

for i in range(10**9):

    s = tobase4(i)

    if not check(s):

        continue

    s = conv(s)

    s = int(s)

    #print(s)

    if n < s:

        break

    #print(s)

    res += 1

print(res)

def dfs(N,s,a,b,c):

    if int(s)>N:

        return 0

    ret  = dfs(N,s+'3',True,b,c)

    ret += dfs(N,s+'5',a,True,c)

    ret += dfs(N,s+'7',a,b,True)

    return ret + (a and b and c)

print((dfs(int(eval(input())),'0',False,False,False)))

n = int(eval(input()))

def tobase4(num):
    ans = ""
    while num > 0:
        ans += str(num % 4)
        num //= 4
    return ans[::-1]

def check(s):
    if "1" in s and "2" in s and "3" in s and "0" not in s:
        return True
    return False

def conv(s):
    s = s.replace("2", "5")
    s = s.replace("3", "7")
    s = s.replace("1", "3")
    return s

res = 0
for i in range(10**9):
    s = tobase4(i)
    if not check(s):
        continue
    s = conv(s)
    s = int(s)
    # print(s)
    if n < s:
        break
    # print(s)
    res += 1
print(res)

def dfs(N, s, a, b, c):
    if int(s) > N:
        return 0
    ret = dfs(N, s + "3", True, b, c)
    ret += dfs(N, s + "5", a, True, c)
    ret += dfs(N, s + "7", a, b, True)
    return ret + (a and b and c)

print((dfs(int(eval(input())), "0", False, False, False)))

-    if "1" in s and "2" in s and "3" in s and "0" not in s:

+print((dfs(int(eval(input())), "0", False, False, False)))


Input:
class Factorial():

    def __init__(self, n, mod):

        self.mod = mod

        self.fct = [0 for _ in range(n + 1)]

        self.inv = [0 for _ in range(n + 1)]

        self.fct[0] = 1

        self.inv[0] = 1

        for i in range(n):

            self.fct[i + 1] = self.fct[i] * (i + 1) % mod

        self.inv[n] = pow(self.fct[n], mod - 2, mod)

        for i in range(n)[::-1]:

            self.inv[i] = self.inv[i + 1] * (i + 1) % mod

    def comb(self, m, k):

        if m < k: return 0

        return self.fct[m] * self.inv[k] * self.inv[m - k] % self.mod

def ex_euclid(x, y):

    c0, c1 = x, y

    a0, a1 = 1, 0

    b0, b1 = 0, 1

    while c1:

        a0, a1 = a1, a0 - c0 // c1 * a1

        b0, b1 = b1, b0 - c0 // c1 * b1

        c0, c1 = c1, c0 % c1

    return c0, a0, b0

MOD = 998244353

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

f = Factorial(N, MOD)

c, a, b = ex_euclid(A, B)

if K == 0:

    print((1))

elif K % c != 0:

    print((0))

else:

    lo = -10**18

    hi = 10**18

    while hi - lo > 1:

        mid = (hi + lo) // 2

        if a * K // c + mid * B // c >= 0:

            hi = mid

        else:

            lo = mid

    x0 = a * K // c + hi * B // c

    lo = -10**18

    hi = 10**18

    while hi - lo > 1:

        mid = (hi + lo) // 2

        if b * K // c - mid * A // c >= 0:

            lo = mid

        else:

            hi = mid

    y0 = b * K // c - lo * A // c

    res = 0

    x = x0

    y = (K - A * x0) // B

    while True:

        res += f.comb(N, x) * f.comb(N, y)

        res %= MOD

        if y == y0:

            break

        x += B // c

        y -= A // c

    print(res)

class Factorial():

    def __init__(self, n, mod):

        self.mod = mod

        self.fct = [0 for _ in range(n + 1)]

        self.inv = [0 for _ in range(n + 1)]

        self.fct[0] = 1

        self.inv[0] = 1

        for i in range(n):

            self.fct[i + 1] = self.fct[i] * (i + 1) % mod

        self.inv[n] = pow(self.fct[n], mod - 2, mod)

        for i in range(n)[::-1]:

            self.inv[i] = self.inv[i + 1] * (i + 1) % mod

    def comb(self, m, k):

        if m < k: return 0

        return self.fct[m] * self.inv[k] * self.inv[m - k] % self.mod

MOD = 998244353

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

f = Factorial(N, MOD)

res = 0

for i in range(N + 1):

    if (K - A * i) % B == 0:

        j = (K - A * i) // B

        if 0 <= j <= N:

            res += f.comb(N, i) * f.comb(N, j)

            res %= MOD

print(res)

class Factorial:
    def __init__(self, n, mod):
        self.mod = mod
        self.fct = [0 for _ in range(n + 1)]
        self.inv = [0 for _ in range(n + 1)]
        self.fct[0] = 1
        self.inv[0] = 1
        for i in range(n):
            self.fct[i + 1] = self.fct[i] * (i + 1) % mod
        self.inv[n] = pow(self.fct[n], mod - 2, mod)
        for i in range(n)[::-1]:
            self.inv[i] = self.inv[i + 1] * (i + 1) % mod

    def comb(self, m, k):
        if m < k:
            return 0
        return self.fct[m] * self.inv[k] * self.inv[m - k] % self.mod

def ex_euclid(x, y):
    c0, c1 = x, y
    a0, a1 = 1, 0
    b0, b1 = 0, 1
    while c1:
        a0, a1 = a1, a0 - c0 // c1 * a1
        b0, b1 = b1, b0 - c0 // c1 * b1
        c0, c1 = c1, c0 % c1
    return c0, a0, b0

MOD = 998244353
N, A, B, K = list(map(int, input().split()))
f = Factorial(N, MOD)
c, a, b = ex_euclid(A, B)
if K == 0:
    print((1))
elif K % c != 0:
    print((0))
else:
    lo = -(10**18)
    hi = 10**18
    while hi - lo > 1:
        mid = (hi + lo) // 2
        if a * K // c + mid * B // c >= 0:
            hi = mid
        else:
            lo = mid
    x0 = a * K // c + hi * B // c
    lo = -(10**18)
    hi = 10**18
    while hi - lo > 1:
        mid = (hi + lo) // 2
        if b * K // c - mid * A // c >= 0:
            lo = mid
        else:
            hi = mid
    y0 = b * K // c - lo * A // c
    res = 0
    x = x0
    y = (K - A * x0) // B
    while True:
        res += f.comb(N, x) * f.comb(N, y)
        res %= MOD
        if y == y0:
            break
        x += B // c
        y -= A // c
    print(res)

class Factorial:
    def __init__(self, n, mod):
        self.mod = mod
        self.fct = [0 for _ in range(n + 1)]
        self.inv = [0 for _ in range(n + 1)]
        self.fct[0] = 1
        self.inv[0] = 1
        for i in range(n):
            self.fct[i + 1] = self.fct[i] * (i + 1) % mod
        self.inv[n] = pow(self.fct[n], mod - 2, mod)
        for i in range(n)[::-1]:
            self.inv[i] = self.inv[i + 1] * (i + 1) % mod

    def comb(self, m, k):
        if m < k:
            return 0
        return self.fct[m] * self.inv[k] * self.inv[m - k] % self.mod

MOD = 998244353
N, A, B, K = list(map(int, input().split()))
f = Factorial(N, MOD)
res = 0
for i in range(N + 1):
    if (K - A * i) % B == 0:
        j = (K - A * i) // B
        if 0 <= j <= N:
            res += f.comb(N, i) * f.comb(N, j)
            res %= MOD
print(res)

-        res += f.comb(N, x) * f.comb(N, y)

+            res += f.comb(N, i) * f.comb(N, j)


Input:
#import sys

#from collections import deque

#from collections import defaultdict

#import math

#sys.setrecursionlimit(20000000)

#input = sys.stdin.readline

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

a = [int(eval(input())) for i in range(m)]

a = set(a)

mod = 10**9+7

dp = [0]*(n+1)

dp[0] = 1

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

        if i in a:

                continue

        if i == 1:

                dp[i] = 1

                continue

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

        dp[i] %= mod

print((dp[n]%mod))

import sys

from collections import deque

from collections import defaultdict

import math

sys.setrecursionlimit(20000000)

input = sys.stdin.readline

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

a = [int(eval(input())) for i in range(m)]

a = set(a)

mod = 10**9+7

dp = [0]*(n+5)

dp[0] = 1

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

        if i in a:

                continue

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

        dp[i] %= mod

print((dp[n]%mod))

# import sys
# from collections import deque
# from collections import defaultdict
# import math
# sys.setrecursionlimit(20000000)
# input = sys.stdin.readline
n, m = list(map(int, input().split()))
a = [int(eval(input())) for i in range(m)]
a = set(a)
mod = 10**9 + 7
dp = [0] * (n + 1)
dp[0] = 1
for i in range(1, n + 1):
    if i in a:
        continue
    if i == 1:
        dp[i] = 1
        continue
    dp[i] = dp[i - 1] + dp[i - 2]
    dp[i] %= mod
print((dp[n] % mod))

import sys
from collections import deque
from collections import defaultdict
import math

sys.setrecursionlimit(20000000)
input = sys.stdin.readline
n, m = list(map(int, input().split()))
a = [int(eval(input())) for i in range(m)]
a = set(a)
mod = 10**9 + 7
dp = [0] * (n + 5)
dp[0] = 1
for i in range(1, n + 1):
    if i in a:
        continue
    dp[i] = dp[i - 1] + dp[i - 2]
    dp[i] %= mod
print((dp[n] % mod))

-# import sys
-# from collections import deque
-# from collections import defaultdict
-# import math
-# sys.setrecursionlimit(20000000)
-# input = sys.stdin.readline
+import sys
+from collections import deque
+from collections import defaultdict
+import math
+
+sys.setrecursionlimit(20000000)
+input = sys.stdin.readline
-dp = [0] * (n + 1)
+dp = [0] * (n + 5)
-    if i == 1:
-        dp[i] = 1
-        continue


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

print((x/y))

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

print((t/x))

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

t, x = list(map(int, input().split()))
print((t / x))

-x, y = list(map(int, input().split()))
-print((x / y))
+t, x = list(map(int, input().split()))
+print((t / x))


Input:
def route_num(stairs):

    if stairs <= 1:

        return 1

    else:

        return route_num(stairs - 1) + route_num(stairs - 2)

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

a = [int(eval(input())) for _ in range(m)]

broken = {i:False for i in range(n + 1)}

for a_i in a:

    broken[a_i] = True

route_num = {}

for i in range(n + 1):

    if broken[i]:

        route_num[i] = 0

    elif i <= 1:

        route_num[i] = 1

    else:

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

print((route_num[n] % 1000000007))

def route_num(stairs):

    if stairs <= 1:

        return 1

    else:

        return route_num(stairs - 1) + route_num(stairs - 2)

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

a = [int(eval(input())) for _ in range(m)]

broken = {i:False for i in range(n + 1)}

for a_i in a:

    broken[a_i] = True

route_num = {}

for i in range(n + 1):

    if broken[i]:

        route_num[i] = 0

    elif i <= 1:

        route_num[i] = 1

    else:

        route_num[i] = (route_num[i-1] + route_num[i-2]) % 1000000007

print((route_num[n]))

def route_num(stairs):
    if stairs <= 1:
        return 1
    else:
        return route_num(stairs - 1) + route_num(stairs - 2)

n, m = list(map(int, input().split()))
a = [int(eval(input())) for _ in range(m)]
broken = {i: False for i in range(n + 1)}
for a_i in a:
    broken[a_i] = True
route_num = {}
for i in range(n + 1):
    if broken[i]:
        route_num[i] = 0
    elif i <= 1:
        route_num[i] = 1
    else:
        route_num[i] = route_num[i - 1] + route_num[i - 2]
print((route_num[n] % 1000000007))

def route_num(stairs):
    if stairs <= 1:
        return 1
    else:
        return route_num(stairs - 1) + route_num(stairs - 2)

n, m = list(map(int, input().split()))
a = [int(eval(input())) for _ in range(m)]
broken = {i: False for i in range(n + 1)}
for a_i in a:
    broken[a_i] = True
route_num = {}
for i in range(n + 1):
    if broken[i]:
        route_num[i] = 0
    elif i <= 1:
        route_num[i] = 1
    else:
        route_num[i] = (route_num[i - 1] + route_num[i - 2]) % 1000000007
print((route_num[n]))

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


Input:
X, Y, Z, K = list(map(int, input().split()))

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

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

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

D = []

for a in A:

    for b in B:

        D.append(a + b)

D.sort(reverse=True)

if len(D) > K:

    D = D[:K]

E = []

for d in D:

    for c in C:

        E.append(c + d)

E.sort(reverse=True)

for i, e in enumerate(E):

    if i >= K:

        break

    print(e)

X, Y, Z, K = list(map(int, input().split()))

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

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

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

A.sort(reverse=True)

B.sort(reverse=True)

C.sort(reverse=True)

D = []

for i in range(X):

    for j in range(Y):

        for k in range(Z):

            if i * j * k > K:

                break

            D.append(A[i] + B[j] + C[k])

D.sort(reverse=True)

for d in D[:K]:

    print(d)

+            D.append(A[i] + B[j] + C[k])


Input:
import random

s_given = list(eval(input()))

t_given = list(eval(input()))

s_len = len(s_given)

t_len = len(t_given)

s_sorted = sorted(s_given)

t_sorted = sorted(t_given, reverse=True)

for i in range(t_len):

    if s_sorted[i] < t_sorted[i]:

        print('Yes')

        break

    elif s_sorted[i] > t_sorted[i]:

        print('No')

        break

    if i == t_len - 1:

        print('No')

        break

    elif i == s_len - 1 :

        print('Yes')

        break

s_given = list(eval(input()))

t_given = list(eval(input()))

s_len = len(s_given)

t_len = len(t_given)

s_sorted = sorted(s_given)

t_sorted = sorted(t_given, reverse=True)

for i in range(t_len):

    if s_sorted[i] < t_sorted[i]:

        print('Yes')

        break

    elif s_sorted[i] > t_sorted[i]:

        print('No')

        break

    #s_sortedとt_sortedが同一の場合にNoと出力するため、この順序でifとelifを書く

    if i == t_len - 1:

        print('No')

        break

    elif i == s_len - 1 :

        print('Yes')

        break

import random

s_given = list(eval(input()))
t_given = list(eval(input()))
s_len = len(s_given)
t_len = len(t_given)
s_sorted = sorted(s_given)
t_sorted = sorted(t_given, reverse=True)
for i in range(t_len):
    if s_sorted[i] < t_sorted[i]:
        print("Yes")
        break
    elif s_sorted[i] > t_sorted[i]:
        print("No")
        break
    if i == t_len - 1:
        print("No")
        break
    elif i == s_len - 1:
        print("Yes")
        break

s_given = list(eval(input()))
t_given = list(eval(input()))
s_len = len(s_given)
t_len = len(t_given)
s_sorted = sorted(s_given)
t_sorted = sorted(t_given, reverse=True)
for i in range(t_len):
    if s_sorted[i] < t_sorted[i]:
        print("Yes")
        break
    elif s_sorted[i] > t_sorted[i]:
        print("No")
        break
    # s_sortedとt_sortedが同一の場合にNoと出力するため、この順序でifとelifを書く
    if i == t_len - 1:
        print("No")
        break
    elif i == s_len - 1:
        print("Yes")
        break

+    # s_sortedとt_sortedが同一の場合にNoと出力するため、この順序でifとelifを書く


Input:
import sys

input = sys.stdin.readline

def ceil(a, b):

    if a%b == 0:

        return a//b

    else:

        return a//b + 1

def main():

    D, G = list(map(int, input().split()))

    G //= 100

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

    ans = int(1e9)

    for i in range(2**D):

        tmp = 0

        rest = []

        count = 0

        for j in range(D):

            if i&1:# コンプリートする問題

                tmp += (j+1) * pc[j][0] + pc[j][1]//100

                count += pc[j][0]

            else:

                rest.append((j+1, pc[j][0]))

            i >>= 1

        rest = sorted(rest, reverse=True)

        rest_point = G - tmp

        if rest_point <= 0:# すでに足りている

            ans = min(ans, count)

        elif len(rest) > 0:# 不足分を補う必要がある

            plus = ceil(rest_point, rest[0][0])

            if plus < rest[0][1]:# p-1問以内ですむ

                ans = min(ans, count + plus)

        else:# すべて使っても足りない

            pass

    print(ans)

if __name__ == "__main__":

    main()

import sys

input = sys.stdin.readline

def ceil(a, b):

    if a%b == 0:

        return a//b

    else:

        return (a//b) + 1

def main():

    D, G = list(map(int, input().split()))

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

    ans = int(1e9)

    for i in range(2**D):

        score = 0

        count = 0

        check = [False] * D

        for j in range(D):

            p, c = pc[j]

            if i&1:# 問題jを全て解く

                score += 100 * (j+1) * p + c

                count += p

                check[j] = True

            i >>= 1

        if score < G:

            for j in range(D):

                if not check[D-1-j]:

                    check[D-1-j] = True

                    p, c = pc[D-1-j]

                    tmp = ceil(G - score, (D-j) * 100)

                    if tmp < p:

                        count += tmp

                        score += tmp * (D-j) * 100

                    break

        if score >= G:

            # print(score, check, count)

            ans = min(ans, count)

    print(ans)

if __name__ == "__main__":

    main()

import sys

input = sys.stdin.readline

def ceil(a, b):
    if a % b == 0:
        return a // b
    else:
        return a // b + 1

def main():
    D, G = list(map(int, input().split()))
    G //= 100
    pc = [list(map(int, input().split())) for i in range(D)]
    ans = int(1e9)
    for i in range(2**D):
        tmp = 0
        rest = []
        count = 0
        for j in range(D):
            if i & 1:  # コンプリートする問題
                tmp += (j + 1) * pc[j][0] + pc[j][1] // 100
                count += pc[j][0]
            else:
                rest.append((j + 1, pc[j][0]))
            i >>= 1
        rest = sorted(rest, reverse=True)
        rest_point = G - tmp
        if rest_point <= 0:  # すでに足りている
            ans = min(ans, count)
        elif len(rest) > 0:  # 不足分を補う必要がある
            plus = ceil(rest_point, rest[0][0])
            if plus < rest[0][1]:  # p-1問以内ですむ
                ans = min(ans, count + plus)
        else:  # すべて使っても足りない
            pass
    print(ans)

if __name__ == "__main__":
    main()

import sys

input = sys.stdin.readline

def ceil(a, b):
    if a % b == 0:
        return a // b
    else:
        return (a // b) + 1

def main():
    D, G = list(map(int, input().split()))
    pc = [list(map(int, input().split())) for i in range(D)]
    ans = int(1e9)
    for i in range(2**D):
        score = 0
        count = 0
        check = [False] * D
        for j in range(D):
            p, c = pc[j]
            if i & 1:  # 問題jを全て解く
                score += 100 * (j + 1) * p + c
                count += p
                check[j] = True
            i >>= 1
        if score < G:
            for j in range(D):
                if not check[D - 1 - j]:
                    check[D - 1 - j] = True
                    p, c = pc[D - 1 - j]
                    tmp = ceil(G - score, (D - j) * 100)
                    if tmp < p:
                        count += tmp
                        score += tmp * (D - j) * 100
                    break
        if score >= G:
            # print(score, check, count)
            ans = min(ans, count)
    print(ans)

if __name__ == "__main__":
    main()

-            if i & 1:  # コンプリートする問題

-                rest.append((j + 1, pc[j][0]))

-        rest = sorted(rest, reverse=True)

-        if rest_point <= 0:  # すでに足りている

+                if not check[D - 1 - j]:

+                    check[D - 1 - j] = True

+                    tmp = ceil(G - score, (D - j) * 100)

+            # print(score, check, count)

-        elif len(rest) > 0:  # 不足分を補う必要がある

-            plus = ceil(rest_point, rest[0][0])

-            if plus < rest[0][1]:  # p-1問以内ですむ

-                ans = min(ans, count + plus)

-        else:  # すべて使っても足りない


Input:
def main():

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

  inf=10**9

  dp=[inf]*(1<<n)

  dp[0]=0

  #cost=[inf for i in range(m)]

  for i in range(m):

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

    c=[1<<(int(x)-1) for x in input().split()]

    t=sum(c)

    #cost[i]=[s,a]

    for s in range(1<<n):

      dp[t|s]=min(dp[t|s], dp[s]+a)

  #print(cost)

  """

  dp=[inf]*(1<<n)

  dp[0]=0

  for s in range(1<<n):

    for bit,c in cost:

      dp[s|bit]=min(dp[s|bit], dp[s]+c)

  #print(dp)

  """

  #print(dp)

  print((-1 if dp[-1]==inf else dp[-1]))

if __name__=='__main__':

  main()

def main():

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

  inf=10**9

  dp=[inf]*(1<<n)

  dp[0]=0

  #cost=[inf for i in range(m)]

  for i in range(m):

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

    c=[1<<(int(x)-1) for x in input().split()]

    t=sum(c)

    #cost[i]=[s,a]

    for s in range(1<<n):

      if dp[t|s]>dp[s]+a:

        dp[t|s]=dp[s]+a

      #dp[t|s]=min(dp[t|s], dp[s]+a)

  #print(cost)

  """

  dp=[inf]*(1<<n)

  dp[0]=0

  for s in range(1<<n):

    for bit,c in cost:

      dp[s|bit]=min(dp[s|bit], dp[s]+c)

  #print(dp)

  """

  #print(dp)

  print((-1 if dp[-1]==inf else dp[-1]))

if __name__=='__main__':

  main()

def main():
    n, m = list(map(int, input().split()))
    inf = 10**9
    dp = [inf] * (1 << n)
    dp[0] = 0
    # cost=[inf for i in range(m)]
    for i in range(m):
        a, b = list(map(int, input().split()))
        c = [1 << (int(x) - 1) for x in input().split()]
        t = sum(c)
        # cost[i]=[s,a]
        for s in range(1 << n):
            dp[t | s] = min(dp[t | s], dp[s] + a)
    # print(cost)
    """
  dp=[inf]*(1<<n)
  dp[0]=0
  for s in range(1<<n):
    for bit,c in cost:
      dp[s|bit]=min(dp[s|bit], dp[s]+c)
  #print(dp)
  """
    # print(dp)
    print((-1 if dp[-1] == inf else dp[-1]))

if __name__ == "__main__":
    main()

def main():
    n, m = list(map(int, input().split()))
    inf = 10**9
    dp = [inf] * (1 << n)
    dp[0] = 0
    # cost=[inf for i in range(m)]
    for i in range(m):
        a, b = list(map(int, input().split()))
        c = [1 << (int(x) - 1) for x in input().split()]
        t = sum(c)
        # cost[i]=[s,a]
        for s in range(1 << n):
            if dp[t | s] > dp[s] + a:
                dp[t | s] = dp[s] + a
            # dp[t|s]=min(dp[t|s], dp[s]+a)
    # print(cost)
    """
  dp=[inf]*(1<<n)
  dp[0]=0
  for s in range(1<<n):
    for bit,c in cost:
      dp[s|bit]=min(dp[s|bit], dp[s]+c)
  #print(dp)
  """
    # print(dp)
    print((-1 if dp[-1] == inf else dp[-1]))

if __name__ == "__main__":
    main()

-            dp[t | s] = min(dp[t | s], dp[s] + a)

+            # dp[t|s]=min(dp[t|s], dp[s]+a)


Input:
import string

S = eval(input())

T = eval(input())

for a in string.ascii_lowercase:

    if S + a == T:

        print('Yes')

        exit()

print('No')

S = eval(input())

T = eval(input())

print(('Yes' if S == T[:-1] else 'No'))

import string

S = eval(input())
T = eval(input())
for a in string.ascii_lowercase:
    if S + a == T:
        print("Yes")
        exit()
print("No")

S = eval(input())
T = eval(input())
print(("Yes" if S == T[:-1] else "No"))

+print(("Yes" if S == T[:-1] else "No"))


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

mod=10**9+7

ans=pow(10,n,mod)

ans-=2*pow(9,n,mod)

ans+=pow(8,n,mod)

ans%=mod

print(ans)

n = int(eval(input()))
mod = 10**9 + 7
ans = pow(10, n, mod)
ans -= 2 * pow(9, n, mod)
ans += pow(8, n, mod)
ans %= mod
print(ans)


Input:
_,*s=open(0)

b,q='.'*101,list(range(101))

for i,s in enumerate(s):

  a=[i]

  for x,y,z,c in zip(b,'.'+s,s,q):a+=min(c+(x=='.'>z),a[-1]+(y=='.'>z)),

  b,q=s,a[1:]

print((a[-2]))

def main():

  _,*s=open(0)

  b,q='.'*101,list(range(101))

  for i,s in enumerate(s):

    a=[]

    for x,y,z,c in zip(b,'.'+s,s,q):

      c+=x=='.'>z

      i+=y=='.'>z

      if i>c:i=c

      a+=i,

    b,q=s,a

  print((a[-2]))

main()

def main():
    _, *s = open(0)
    b, q = "." * 101, list(range(101))
    for i, s in enumerate(s):
        a = []
        for x, y, z, c in zip(b, "." + s, s, q):
            c += x == "." > z
            i += y == "." > z
            if i > c:
                i = c
            a += (i,)
        b, q = s, a
    print((a[-2]))

main()

-    for x, y, z, c in zip(b, "." + s, s, q):

+        for x, y, z, c in zip(b, "." + s, s, q):


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

tmp = abs(x) % d

cal = abs(x) // d

if tmp > abs(tmp - d):

    cal += 1

    tmp = abs(tmp - d)

if cal == k:

    print(tmp)

elif cal > k:

    print((abs(x) - k*d))

else:

    if (k - cal) % 2 == 0:

        print(tmp)

    else:

        print((min(abs(tmp-d),abs(tmp+d))))

x,k,d = list(map(int,input().split()))

ans = abs(x) % d

cal = abs(x) // d

if ans > abs(ans - d):

    cal += 1

    ans = abs(ans - d)

if cal > k:

    ans = abs(x) - k*d

else:

    if (k - cal) % 2 == 1:

        ans = min(abs(ans-d),abs(ans+d))

print(ans)

x, k, d = list(map(int, input().split()))
tmp = abs(x) % d
cal = abs(x) // d
if tmp > abs(tmp - d):
    cal += 1
    tmp = abs(tmp - d)
if cal == k:
    print(tmp)
elif cal > k:
    print((abs(x) - k * d))
else:
    if (k - cal) % 2 == 0:
        print(tmp)
    else:
        print((min(abs(tmp - d), abs(tmp + d))))

x, k, d = list(map(int, input().split()))
ans = abs(x) % d
cal = abs(x) // d
if ans > abs(ans - d):
    cal += 1
    ans = abs(ans - d)
if cal > k:
    ans = abs(x) - k * d
else:
    if (k - cal) % 2 == 1:
        ans = min(abs(ans - d), abs(ans + d))
print(ans)

-        print((min(abs(tmp - d), abs(tmp + d))))

+        ans = min(abs(ans - d), abs(ans + d))


Input:
import collections as c

eval(input());a=c.Counter(i//400 for i in [*list(map(int,input().split()))])

b,c=len(set([i for i,j in list(a.items())if i<8])),sum([j for i,j in list(a.items())if i>=8])

print(([b,1][b==0],b+c))

import collections as c

eval(input());a=c.Counter(i//400 for i in [*list(map(int,input().split()))])

b,c=len(set([i for i in list(a.keys())if i<8])),sum([j for i,j in list(a.items())if i>=8])

print(([b,1][b==0],b+c))

import collections as c

eval(input())
a = c.Counter(i // 400 for i in [*list(map(int, input().split()))])
b, c = len(set([i for i, j in list(a.items()) if i < 8])), sum(
    [j for i, j in list(a.items()) if i >= 8]
)
print(([b, 1][b == 0], b + c))

import collections as c

eval(input())
a = c.Counter(i // 400 for i in [*list(map(int, input().split()))])
b, c = len(set([i for i in list(a.keys()) if i < 8])), sum(
    [j for i, j in list(a.items()) if i >= 8]
)
print(([b, 1][b == 0], b + c))

-b, c = len(set([i for i, j in list(a.items()) if i < 8])), sum(

+b, c = len(set([i for i in list(a.keys()) if i < 8])), sum(


Input:
import heapq as hq

class UnionFind(object):

    def __init__(self, size):

        self.parent = [i for i in range(size)]

        self.rank = [0]*size

    def find(self, x):

        if self.parent[x] == x:

            return x

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

        return self.parent[x]

    def unite(self, x, y):

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

        if x == y:

            return

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

            self.parent[x] = y

        else:

            self.parent[y] = x

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

                self.rank[x] += 1

    def same(self, x, y):

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

N = int(eval(input()))

ls = []

rs = []

ind = 0

inds = dict()

for _ in range(N):

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

    if (x,y) not in list(inds.keys()):

        ls.append((x,y))

        rs.append((y,x))

        inds[(x,y)] = ind

        ind += 1

N = ind

ls.sort()

rs.sort()

uf = UnionFind(N)

edges = []

for i in range(N-1):

    x = ls[i][0]

    a = ls[i+1][0]

    y = ls[i][1]

    b = ls[i+1][1]

    d = min(abs(x-a), abs(y-b))

    edges.append((d,(x,y),(a,b)))

    x = rs[i][1]

    a = rs[i+1][1]

    y = rs[i][0]

    b = rs[i+1][0]

    d = min(abs(x-a), abs(y-b))

    edges.append((d,(x,y),(a,b)))

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

ans = 0

for d,i,j in edges:

        # 閉路ができない場合追加する

        if not uf.same(inds[i],inds[j]):

            uf.unite(inds[i],inds[j])

            ans += d

print(ans)

import sys

input = sys.stdin.readline

class UnionFind(object):

    def __init__(self, size):

        self.parent = [i for i in range(size)]

        self.rank = [0]*size

    def find(self, x):

        if self.parent[x] == x:

            return x

        # path compression

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

        return self.parent[x]

    def unite(self, x, y):

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

        if x == y:

            return

        # union by rank

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

            self.parent[x] = y

        else:

            self.parent[y] = x

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

                self.rank[x] += 1

    def same(self, x, y):

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

if __name__ == "__main__":

    N = int(eval(input()))

    vs = []

    for i in range(N):

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

        vs.append((x,y,i))

    vs.sort()

    edges = []

    for k in range(1, N):

        x,y,i = vs[k]

        a,b,j = vs[k-1]

        edges.append((i, j, min(abs(x-a),abs(y-b))))

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

    for k in range(1, N):

        x,y,i = vs[k]

        a,b,j = vs[k-1]

        edges.append((i, j, min(abs(x-a),abs(y-b))))

    uf = UnionFind(N)

    edges.sort(key=lambda x:x[2])

    ans = 0

    for i,j,w in edges:

        if not uf.same(i,j):

            uf.unite(i,j)

            ans += w

    print(ans)

import heapq as hq

class UnionFind(object):
    def __init__(self, size):
        self.parent = [i for i in range(size)]
        self.rank = [0] * size

    def find(self, x):
        if self.parent[x] == x:
            return x
        self.parent[x] = self.find(self.parent[x])
        return self.parent[x]

    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)

N = int(eval(input()))
ls = []
rs = []
ind = 0
inds = dict()
for _ in range(N):
    x, y = list(map(int, input().split()))
    if (x, y) not in list(inds.keys()):
        ls.append((x, y))
        rs.append((y, x))
        inds[(x, y)] = ind
        ind += 1
N = ind
ls.sort()
rs.sort()
uf = UnionFind(N)
edges = []
for i in range(N - 1):
    x = ls[i][0]
    a = ls[i + 1][0]
    y = ls[i][1]
    b = ls[i + 1][1]
    d = min(abs(x - a), abs(y - b))
    edges.append((d, (x, y), (a, b)))
    x = rs[i][1]
    a = rs[i + 1][1]
    y = rs[i][0]
    b = rs[i + 1][0]
    d = min(abs(x - a), abs(y - b))
    edges.append((d, (x, y), (a, b)))
edges.sort(key=lambda x: x[0])
ans = 0
for d, i, j in edges:
    # 閉路ができない場合追加する
    if not uf.same(inds[i], inds[j]):
        uf.unite(inds[i], inds[j])
        ans += d
print(ans)

import sys

input = sys.stdin.readline

class UnionFind(object):
    def __init__(self, size):
        self.parent = [i for i in range(size)]
        self.rank = [0] * size

    def find(self, x):
        if self.parent[x] == x:
            return x
        # path compression
        self.parent[x] = self.find(self.parent[x])
        return self.parent[x]

    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y:
            return
        # union by rank
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)

if __name__ == "__main__":
    N = int(eval(input()))
    vs = []
    for i in range(N):
        x, y = list(map(int, input().split()))
        vs.append((x, y, i))
    vs.sort()
    edges = []
    for k in range(1, N):
        x, y, i = vs[k]
        a, b, j = vs[k - 1]
        edges.append((i, j, min(abs(x - a), abs(y - b))))
    vs.sort(key=lambda x: x[1])
    for k in range(1, N):
        x, y, i = vs[k]
        a, b, j = vs[k - 1]
        edges.append((i, j, min(abs(x - a), abs(y - b))))
    uf = UnionFind(N)
    edges.sort(key=lambda x: x[2])
    ans = 0
    for i, j, w in edges:
        if not uf.same(i, j):
            uf.unite(i, j)
            ans += w
    print(ans)

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

-    if (x, y) not in list(inds.keys()):

-    # 閉路ができない場合追加する

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

+        edges.append((i, j, min(abs(x - a), abs(y - b))))


Input:
import sys

#sys.stdin=open("data.txt")

input=sys.stdin.readline

n=int(eval(input()))

s=input().strip()

memo={}

def getans(a,b,c):

    while a and c and a[0]==c[-1]:

        a=a[1:]

        c=c[:-1]

    if b=="":

        if a=="" and c=="": return 1

        else: return 0

    key=a+"/"+b+"/"+c

    if key in memo: return memo[key]

    # select first letter

    ans=0

    for i in range(1,len(b)):

        if b[0]==b[i]:

            ans+=getans(a,b[1:i],b[i+1:]+c)

    # don't select first letter

    ans+=getans(a+b[0],b[1:],c)

    memo[key]=ans

    #print(key,ans)

    return ans

print((getans("",s,"")*2))

#print(len(memo))

import sys

#sys.stdin=open("data.txt")

input=sys.stdin.readline

n=int(eval(input()))

s=input().strip()

memo={}

def getans(a,b,c):

    while a and c and a[0]==c[-1]:

        a=a[1:]

        c=c[:-1]

    if a and c: return 0

    if b=="":

        if a=="" and c=="": return 1

        else: return 0

    key=a+"/"+b+"/"+c

    if key in memo: return memo[key]

    # select first letter

    ans=0

    for i in range(1,len(b)):

        if b[0]==b[i]:

            ans+=getans(a,b[1:i],b[i+1:]+c)

    # don't select first letter

    ans+=getans(a+b[0],b[1:],c)

    memo[key]=ans

    #print(key,ans)

    return ans

print((getans("",s,"")*2))

#print(len(memo))

import sys

# sys.stdin=open("data.txt")
input = sys.stdin.readline
n = int(eval(input()))
s = input().strip()
memo = {}

def getans(a, b, c):
    while a and c and a[0] == c[-1]:
        a = a[1:]
        c = c[:-1]
    if b == "":
        if a == "" and c == "":
            return 1
        else:
            return 0
    key = a + "/" + b + "/" + c
    if key in memo:
        return memo[key]
    # select first letter
    ans = 0
    for i in range(1, len(b)):
        if b[0] == b[i]:
            ans += getans(a, b[1:i], b[i + 1 :] + c)
    # don't select first letter
    ans += getans(a + b[0], b[1:], c)
    memo[key] = ans
    # print(key,ans)
    return ans

print((getans("", s, "") * 2))
# print(len(memo))

import sys

# sys.stdin=open("data.txt")
input = sys.stdin.readline
n = int(eval(input()))
s = input().strip()
memo = {}

def getans(a, b, c):
    while a and c and a[0] == c[-1]:
        a = a[1:]
        c = c[:-1]
    if a and c:
        return 0
    if b == "":
        if a == "" and c == "":
            return 1
        else:
            return 0
    key = a + "/" + b + "/" + c
    if key in memo:
        return memo[key]
    # select first letter
    ans = 0
    for i in range(1, len(b)):
        if b[0] == b[i]:
            ans += getans(a, b[1:i], b[i + 1 :] + c)
    # don't select first letter
    ans += getans(a + b[0], b[1:], c)
    memo[key] = ans
    # print(key,ans)
    return ans

print((getans("", s, "") * 2))
# print(len(memo))


Input:
from copy import deepcopy

from collections import deque

def main():

    def find(x):

        if par[x] < 0:

            return x

        else:

            par[x] = find(par[x])

            return par[x]

    def unite(x, y):

        x = find(x)

        y = find(y)

        if x == y:

            return False

        else:

            if par[x] > par[y]:

                x, y = y, x

            par[x] += par[y]

            par[y] = x

            return True

    def roots():

        return [i for i, x in enumerate(par) if x < 0]

    n = int(input())

    par = [-1] * n

    uvw = {e:[] for e in range(n)}

    for _ in range(n - 1):

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

        u -= 1

        v -= 1

        uvw[u].append((u, v, w))

        uvw[v].append((v, u, w))

        unite(u, v)

    root_node = roots()[0]

    color = [-1] * n

    color[root_node] = 0

    node_next = deque()

    node_next.append(root_node)

    node_next_next = deque()

    node_seen = set()

    while len(node_seen) < n:

        while node_next:

            node_togo = node_next.popleft()

            if node_togo in node_seen:

                continue

            else:

                node_seen.add(node_togo)

            # 次の層のノード群情報を取得し、「次にみるノードlist」にいれる。

            node_adj = uvw[node_togo]

            node_next_next += [i[1] for i in node_adj]

            # 次の層を処理＝色塗りする

            for adj in node_adj:

                if adj[1] in node_seen or color[adj[1]] != -1:

                    continue

                if adj[2] % 2 == 0:

                    color[adj[1]] = color[node_togo]

                else:

                    color[adj[1]] = color[node_togo] ^ 1

        node_next = deepcopy(node_next_next)

        node_next_next = deque()

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

if __name__ == '__main__':

    main()

import sys

sys.setrecursionlimit(10**6)

read = sys.stdin.read

readlines = sys.stdin.readlines

def main():

    def dfs(node):

        for adjnode in edges[node]:

            if colors[adjnode[0]] == -1:

                if adjnode[1] % 2 == 0:

                    colors[adjnode[0]] = colors[node]

                else:

                    colors[adjnode[0]] = colors[node] ^ 1

                dfs(adjnode[0])

    # input

    n = int(input())

    edges = {e: [] for e in range(n)}

    for _ in range(n - 1):

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

        u -= 1

        v -= 1

        edges[u].append((v, w))

        edges[v].append((u, w))

    # process

    colors = [-1] * n

    colors[0] = 0

    dfs(0)

    # output

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

if __name__ == '__main__':

    main()

from copy import deepcopy
from collections import deque

def main():
    def find(x):
        if par[x] < 0:
            return x
        else:
            par[x] = find(par[x])
            return par[x]

    def unite(x, y):
        x = find(x)
        y = find(y)
        if x == y:
            return False
        else:
            if par[x] > par[y]:
                x, y = y, x
            par[x] += par[y]
            par[y] = x
            return True

    def roots():
        return [i for i, x in enumerate(par) if x < 0]

    n = int(input())
    par = [-1] * n
    uvw = {e: [] for e in range(n)}
    for _ in range(n - 1):
        u, v, w = map(int, input().split())
        u -= 1
        v -= 1
        uvw[u].append((u, v, w))
        uvw[v].append((v, u, w))
        unite(u, v)
    root_node = roots()[0]
    color = [-1] * n
    color[root_node] = 0
    node_next = deque()
    node_next.append(root_node)
    node_next_next = deque()
    node_seen = set()
    while len(node_seen) < n:
        while node_next:
            node_togo = node_next.popleft()
            if node_togo in node_seen:
                continue
            else:
                node_seen.add(node_togo)
            # 次の層のノード群情報を取得し、「次にみるノードlist」にいれる。
            node_adj = uvw[node_togo]
            node_next_next += [i[1] for i in node_adj]
            # 次の層を処理＝色塗りする
            for adj in node_adj:
                if adj[1] in node_seen or color[adj[1]] != -1:
                    continue
                if adj[2] % 2 == 0:
                    color[adj[1]] = color[node_togo]
                else:
                    color[adj[1]] = color[node_togo] ^ 1
        node_next = deepcopy(node_next_next)
        node_next_next = deque()
    print(*color, sep="\n")

if __name__ == "__main__":
    main()

import sys

sys.setrecursionlimit(10**6)
read = sys.stdin.read
readlines = sys.stdin.readlines

def main():
    def dfs(node):
        for adjnode in edges[node]:
            if colors[adjnode[0]] == -1:
                if adjnode[1] % 2 == 0:
                    colors[adjnode[0]] = colors[node]
                else:
                    colors[adjnode[0]] = colors[node] ^ 1
                dfs(adjnode[0])

    # input
    n = int(input())
    edges = {e: [] for e in range(n)}
    for _ in range(n - 1):
        u, v, w = map(int, input().split())
        u -= 1
        v -= 1
        edges[u].append((v, w))
        edges[v].append((u, w))
    # process
    colors = [-1] * n
    colors[0] = 0
    dfs(0)
    # output
    print(*colors, sep="\n")

if __name__ == "__main__":
    main()

+            if colors[adjnode[0]] == -1:

+                    colors[adjnode[0]] = colors[node]

+                    colors[adjnode[0]] = colors[node] ^ 1

-        return [i for i, x in enumerate(par) if x < 0]

-            node_togo = node_next.popleft()

-                node_seen.add(node_togo)

-            # 次の層のノード群情報を取得し、「次にみるノードlist」にいれる。

-            node_next_next += [i[1] for i in node_adj]

-            # 次の層を処理＝色塗りする

-                if adj[1] in node_seen or color[adj[1]] != -1:

-                    color[adj[1]] = color[node_togo]

-                    color[adj[1]] = color[node_togo] ^ 1

-        node_next = deepcopy(node_next_next)


Input:
import bisect

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

fox = [None]*n

for i in range(n):

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

  fox[i] = (x, h)

fox.sort()

x = [int(fox[i][0]) for i in range(n)]

h = [int(fox[i][1]) for i in range(n)]

ans = 0

bit = [0]*n

for i in range(n):

  if i != 0:

    bit[i] += bit[i-1]

  if bit[i] >= h[i]:

    continue

  sub = (h[i]-bit[i]-1)//a+1

  ans += sub

  bit[i] += sub*a

  index = bisect.bisect_right(x, x[i]+2*d)

  if index == n:

    continue

  bit[index] -= sub*a

print(ans)

import bisect

import sys

def main():

  input = sys.stdin.readline

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

  fox = [None]*n

  for i in range(n):

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

    fox[i] = (x, h)

  fox.sort()

  x = [int(fox[i][0]) for i in range(n)]

  h = [int(fox[i][1]) for i in range(n)]

  ans = 0

  bit = [0]*n

  for i in range(n):

    if i != 0:

      bit[i] += bit[i-1]

    sub = max([(h[i]-bit[i]-1)//a+1, 0])

    ans += sub

    bit[i] += sub*a

    index = bisect.bisect_right(x, x[i]+2*d)

    if index != n:

      bit[index] -= sub*a

  print(ans)

if __name__ == "__main__":

  main()

import bisect

n, d, a = list(map(int, input().split()))
fox = [None] * n
for i in range(n):
    x, h = list(map(int, input().split()))
    fox[i] = (x, h)
fox.sort()
x = [int(fox[i][0]) for i in range(n)]
h = [int(fox[i][1]) for i in range(n)]
ans = 0
bit = [0] * n
for i in range(n):
    if i != 0:
        bit[i] += bit[i - 1]
    if bit[i] >= h[i]:
        continue
    sub = (h[i] - bit[i] - 1) // a + 1
    ans += sub
    bit[i] += sub * a
    index = bisect.bisect_right(x, x[i] + 2 * d)
    if index == n:
        continue
    bit[index] -= sub * a
print(ans)

import bisect
import sys

def main():
    input = sys.stdin.readline
    n, d, a = list(map(int, input().split()))
    fox = [None] * n
    for i in range(n):
        x, h = list(map(int, input().split()))
        fox[i] = (x, h)
    fox.sort()
    x = [int(fox[i][0]) for i in range(n)]
    h = [int(fox[i][1]) for i in range(n)]
    ans = 0
    bit = [0] * n
    for i in range(n):
        if i != 0:
            bit[i] += bit[i - 1]
        sub = max([(h[i] - bit[i] - 1) // a + 1, 0])
        ans += sub
        bit[i] += sub * a
        index = bisect.bisect_right(x, x[i] + 2 * d)
        if index != n:
            bit[index] -= sub * a
    print(ans)

if __name__ == "__main__":
    main()

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

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

-    index = bisect.bisect_right(x, x[i] + 2 * d)

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

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

+    x = [int(fox[i][0]) for i in range(n)]

+    h = [int(fox[i][1]) for i in range(n)]

+        index = bisect.bisect_right(x, x[i] + 2 * d)


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

s = eval(input())

if len(s) <= k:

    print(s)

else:

    print((s[0:k] + "..."))

k = int(input())

s = input()

if len(s) <= k:

    print(s)

else:

    S = s[:k]

    print(S, end="")

    print("...")

-k = int(eval(input()))
-s = eval(input())
+k = int(input())
+s = input()
-    print((s[0:k] + "..."))
+    S = s[:k]
+    print(S, end="")
+    print("...")


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

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

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

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

A.sort()

B.sort()

C.sort()

B += [10 ** 9 + 1] + [0]    # B[-1] = 0, B[N] = 10**9 + 1となるようにする

C += [10 ** 9 + 1] + [0]    # C[-1] = 0, C[N] = 10**9 + 1となるようにする

# For each j = 0, 1, ..., N-1,

# find k such that B[j] < C[k] and (C[k-1] <= B[j] or k = 0)

# Let K[j] = k for such k.

# If such k doesn't exist, let K[j] := N

K = [0] * N

for j in range(N):

    ng = -1 # C[ng] <= B[j]

    ok = N  # B[j] < C[ok]

    while ok - ng > 1:

        mid = (ok + ng) // 2

        if B[j] < C[mid]:

            ok = mid

        else:

            ng = mid

    K[j] = ok

# Let

# f[j] := B[j]より大きいC[k]の数 + B[j + 1]より大きいC[k]の数

#           ... + B[N-1]より大きいC[k]の数

f = [0] * (N - 1) + [N - K[N - 1]]

for j in range(N - 2, -1, -1):

    f[j] = f[j + 1] + N - K[j]

ans = 0

for i in range(N):

    # find j such that B[j - 1] <= A[i] < B[j]

    ng = -1  # B[ng] <= A[i]

    ok = N   # A[i] < B[ok]

    while ok - ng > 1:

        mid = (ok + ng) // 2

        if A[i] < B[mid]:

            ok = mid

        else:

            ng = mid

    if ok >= N: continue

    # 0 <= ok <= N - 1

    ans += f[ok]

print(ans)

import bisect

N = int(eval(input()))

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

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

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

A.sort()

B.sort()

C.sort()

ans = 0

for j in range(N):

    i = bisect.bisect_left(A, B[j])

    k = bisect.bisect_right(C, B[j])

    ans += i * (N - k)

print(ans)

N = int(eval(input()))
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
A.sort()
B.sort()
C.sort()
B += [10**9 + 1] + [0]  # B[-1] = 0, B[N] = 10**9 + 1となるようにする
C += [10**9 + 1] + [0]  # C[-1] = 0, C[N] = 10**9 + 1となるようにする
# For each j = 0, 1, ..., N-1,
# find k such that B[j] < C[k] and (C[k-1] <= B[j] or k = 0)
# Let K[j] = k for such k.
# If such k doesn't exist, let K[j] := N
K = [0] * N
for j in range(N):
    ng = -1  # C[ng] <= B[j]
    ok = N  # B[j] < C[ok]
    while ok - ng > 1:
        mid = (ok + ng) // 2
        if B[j] < C[mid]:
            ok = mid
        else:
            ng = mid
    K[j] = ok
# Let
# f[j] := B[j]より大きいC[k]の数 + B[j + 1]より大きいC[k]の数
#           ... + B[N-1]より大きいC[k]の数
f = [0] * (N - 1) + [N - K[N - 1]]
for j in range(N - 2, -1, -1):
    f[j] = f[j + 1] + N - K[j]
ans = 0
for i in range(N):
    # find j such that B[j - 1] <= A[i] < B[j]
    ng = -1  # B[ng] <= A[i]
    ok = N  # A[i] < B[ok]
    while ok - ng > 1:
        mid = (ok + ng) // 2
        if A[i] < B[mid]:
            ok = mid
        else:
            ng = mid
    if ok >= N:
        continue
    # 0 <= ok <= N - 1
    ans += f[ok]
print(ans)

-# find k such that B[j] < C[k] and (C[k-1] <= B[j] or k = 0)

-# If such k doesn't exist, let K[j] := N

-# f[j] := B[j]より大きいC[k]の数 + B[j + 1]より大きいC[k]の数

-    # find j such that B[j - 1] <= A[i] < B[j]


Input:
import copy

from typing import List, Tuple

def main():

    d, g = list(map(int, input().split()))

    v = []

    for _ in range(d):

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

        v.append((p, c))

    print((ag(v, g)))

def ag(v: List[Tuple[int, int]], g: int) -> int:

    # ex. [(3, 500), (5, 800)] -> [(1, 3, 500), (2, 5, 800)]

    v = [(i, p, c) for i, (p, c) in enumerate(v, 1)]

    result = 100 ** 10

    for j in range(2 ** len(v)):

        cb = []

        for k in range(len(v)):

            if ((j >> k) & 1):

                cb.append(v[k])

        sc = 0

        cnt = 0

        # calc bonus score

        for (i, p, c) in cb:

            sc += i * 100 * p + c

            cnt += p

        for idx in reversed(list(range(len(v)))):

            if sc >= g:

                break

            if v[idx] in cb:

                continue

            i, p, _ = v[idx]

            for _ in range(p - 1):

                if sc >= g:

                    break

                sc += i * 100

                cnt += 1

        if sc >= g:

            result = min(result, cnt)

    return result

if __name__ == '__main__':

    main()

import itertools

from typing import List, Tuple

def main():

    d, g = list(map(int, input().split()))

    v = []

    for _ in range(d):

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

        v.append((p, c))

    print((ag(v, g)))

def ag(v: List[Tuple[int, int]], g: int) -> int:

    # ex. [(3, 500), (5, 800)] -> [(1, 3, 500), (2, 5, 800)]

    v = [(i + 1, v[i][0], v[i][1]) for i in range(len(v))]

    result = 100 ** 10

    for j in range(len(v) + 1):

        for cb in itertools.combinations(v, j):

            sc = 0

            cnt = 0

            # calc bonus score

            for (i, p, c) in cb:

                sc += i * 100 * p + c

                cnt += p

            for idx in reversed(list(range(len(v)))):

                if sc >= g:

                    break

                if v[idx] in cb:

                    continue

                i, p, _ = v[idx]

                for _ in range(p - 1):

                    if sc >= g:

                        break

                    sc += i * 100

                    cnt += 1

            if sc >= g:

                result = min(result, cnt)

    return result

if __name__ == '__main__':

    main()

import copy
from typing import List, Tuple

def main():
    d, g = list(map(int, input().split()))
    v = []
    for _ in range(d):
        p, c = list(map(int, input().split()))
        v.append((p, c))
    print((ag(v, g)))

def ag(v: List[Tuple[int, int]], g: int) -> int:
    # ex. [(3, 500), (5, 800)] -> [(1, 3, 500), (2, 5, 800)]
    v = [(i, p, c) for i, (p, c) in enumerate(v, 1)]
    result = 100**10
    for j in range(2 ** len(v)):
        cb = []
        for k in range(len(v)):
            if (j >> k) & 1:
                cb.append(v[k])
        sc = 0
        cnt = 0
        # calc bonus score
        for (i, p, c) in cb:
            sc += i * 100 * p + c
            cnt += p
        for idx in reversed(list(range(len(v)))):
            if sc >= g:
                break
            if v[idx] in cb:
                continue
            i, p, _ = v[idx]
            for _ in range(p - 1):
                if sc >= g:
                    break
                sc += i * 100
                cnt += 1
        if sc >= g:
            result = min(result, cnt)
    return result

if __name__ == "__main__":
    main()

import itertools
from typing import List, Tuple

def main():
    d, g = list(map(int, input().split()))
    v = []
    for _ in range(d):
        p, c = list(map(int, input().split()))
        v.append((p, c))
    print((ag(v, g)))

def ag(v: List[Tuple[int, int]], g: int) -> int:
    # ex. [(3, 500), (5, 800)] -> [(1, 3, 500), (2, 5, 800)]
    v = [(i + 1, v[i][0], v[i][1]) for i in range(len(v))]
    result = 100**10
    for j in range(len(v) + 1):
        for cb in itertools.combinations(v, j):
            sc = 0
            cnt = 0
            # calc bonus score
            for (i, p, c) in cb:
                sc += i * 100 * p + c
                cnt += p
            for idx in reversed(list(range(len(v)))):
                if sc >= g:
                    break
                if v[idx] in cb:
                    continue
                i, p, _ = v[idx]
                for _ in range(p - 1):
                    if sc >= g:
                        break
                    sc += i * 100
                    cnt += 1
            if sc >= g:
                result = min(result, cnt)
    return result

if __name__ == "__main__":
    main()

-    v = [(i, p, c) for i, (p, c) in enumerate(v, 1)]

-        for idx in reversed(list(range(len(v)))):

+        for cb in itertools.combinations(v, j):

+            for idx in reversed(list(range(len(v)))):

+                result = min(result, cnt)


Input:
import collections

n=int(eval(input()))

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

arr=sorted(arr)

s=set()

cnt=collections.Counter(arr)

for i in range(n):

  if arr[i] in s:

    continue

  if cnt[arr[i]]>=2:

    s.add(arr[i])

  for j in range(2,10**6//arr[i]+1):

    s.add(arr[i]*j)

ans=0

for i in range(n):

  if arr[i] in s:

    continue

  if cnt[arr[i]]>=2:

    continue

  ans+=1

print(ans)

import collections

n=int(eval(input()))

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

arr=sorted(arr)

s=set()

cnt=collections.Counter(arr)

for i in range(n):

  if arr[i] in s:

    continue

  if cnt[arr[i]]>=2:

    s.add(arr[i])

  for j in range(2,10**6//arr[i]+1):

    s.add(arr[i]*j)

ans=0

for i in range(n):

  if arr[i] in s:

    continue

  ans+=1

print(ans)

import collections

n = int(eval(input()))
arr = list(map(int, input().split()))
arr = sorted(arr)
s = set()
cnt = collections.Counter(arr)
for i in range(n):
    if arr[i] in s:
        continue
    if cnt[arr[i]] >= 2:
        s.add(arr[i])
    for j in range(2, 10**6 // arr[i] + 1):
        s.add(arr[i] * j)
ans = 0
for i in range(n):
    if arr[i] in s:
        continue
    if cnt[arr[i]] >= 2:
        continue
    ans += 1
print(ans)

import collections

n = int(eval(input()))
arr = list(map(int, input().split()))
arr = sorted(arr)
s = set()
cnt = collections.Counter(arr)
for i in range(n):
    if arr[i] in s:
        continue
    if cnt[arr[i]] >= 2:
        s.add(arr[i])
    for j in range(2, 10**6 // arr[i] + 1):
        s.add(arr[i] * j)
ans = 0
for i in range(n):
    if arr[i] in s:
        continue
    ans += 1
print(ans)

-    if cnt[arr[i]] >= 2:
-        continue


Input:
from collections import deque

N = int(input())

S, T = input().split()

char = deque()

for i in range(N):

    char.append(S[i])

    char.append(T[i])

print(*char, sep='')

N = int(input())

S, T = input().split()

char = []

for i in range(N):

    char.append(S[i])

    char.append(T[i])

print(*char, sep='')

from collections import deque

N = int(input())
S, T = input().split()
char = deque()
for i in range(N):
    char.append(S[i])
    char.append(T[i])
print(*char, sep="")

N = int(input())
S, T = input().split()
char = []
for i in range(N):
    char.append(S[i])
    char.append(T[i])
print(*char, sep="")

-from collections import deque
-char = deque()
+char = []


Input:
import math

def eratosthenes(limit):

    A = [i for i in range(2, limit+1)]

    P = []

    while True:

        prime = min(A)

        if prime > math.sqrt(limit):

            break

        P.append(prime)

        i = 0

        while i < len(A):

            if A[i] % prime == 0:

                A.pop(i)

                continue

            i += 1

    for a in A:

        P.append(a)

    return list(P)

a = eratosthenes(100000)

b = set([2*i-1 for i in a])

a = set(a)

chk = sorted(list(a&b))

from bisect import bisect,bisect_left

import sys

input = sys.stdin.readline

q = int(eval(input()))

for i in range(q):

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

  print((bisect(chk,r)-bisect_left(chk,l)))

def is_prime(q):

    if q == 2: return True

    if q < 2 or q&1 == 0: return False

    return pow(5, q-1, q)*pow(7, q-1, q) == 1

s = [561, 11041, 29341, 38081, 46657, 50737, 75361, 79381, 88831]

b = [5,7]

for i in range(2,10**5):

  if i in s:

    continue

  if is_prime(i):

    b.append(i)

a = set([2*i-1 for i in b])

b = set(b)

chk = sorted(list(a&b))

from bisect import bisect,bisect_left

import sys

input = sys.stdin.readline

q = int(eval(input()))

for i in range(q):

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

  print((bisect(chk,r)-bisect_left(chk,l)))

import math

def eratosthenes(limit):
    A = [i for i in range(2, limit + 1)]
    P = []
    while True:
        prime = min(A)
        if prime > math.sqrt(limit):
            break
        P.append(prime)
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
    for a in A:
        P.append(a)
    return list(P)

a = eratosthenes(100000)
b = set([2 * i - 1 for i in a])
a = set(a)
chk = sorted(list(a & b))
from bisect import bisect, bisect_left
import sys

input = sys.stdin.readline
q = int(eval(input()))
for i in range(q):
    l, r = list(map(int, input().split()))
    print((bisect(chk, r) - bisect_left(chk, l)))

def is_prime(q):
    if q == 2:
        return True
    if q < 2 or q & 1 == 0:
        return False
    return pow(5, q - 1, q) * pow(7, q - 1, q) == 1

s = [561, 11041, 29341, 38081, 46657, 50737, 75361, 79381, 88831]
b = [5, 7]
for i in range(2, 10**5):
    if i in s:
        continue
    if is_prime(i):
        b.append(i)
a = set([2 * i - 1 for i in b])
b = set(b)
chk = sorted(list(a & b))
from bisect import bisect, bisect_left
import sys

input = sys.stdin.readline
q = int(eval(input()))
for i in range(q):
    l, r = list(map(int, input().split()))
    print((bisect(chk, r) - bisect_left(chk, l)))

-    A = [i for i in range(2, limit + 1)]


Input:
import networkx as nx

N = int(eval(input()))

AB = [[int(_) for _ in input().split()] for _ in range(N)]

CD = [[int(_) for _ in input().split()] for _ in range(N)]

G = nx.DiGraph()

for a, b in AB:

    G.add_edge(-1, a * 1000 + b, capacity=1)

for c, d in CD:

    G.add_edge(c * 1000 + d, -2, capacity=1)

for a, b in AB:

    for c, d in CD:

        if a < c and b < d:

            G.add_edge(a * 1000 + b, c * 1000 + d, capacity=1)

flow_value, flow_dict = nx.maximum_flow(G, -1, -2)

print(flow_value)

import collections, itertools

class MaximumFlow:

    def __init__(self, G):

        self.G = G

    def ford_fulkerson(self, s, t):

        def dfs(start, used):

            G = self.G

            if start == t:

                return [start]

            for end, cap in list(G[start].items()):

                if cap > 0 and end not in used:

                    used.add(end)

                    ret = dfs(end, used)

                    if ret:

                        return ret + [start]

            return []

        fmax = 0

        cnt = 0

        while True:

            G = self.G

            cnt += 1

            root = dfs(s, set([s]))

            if root:

                root = root[::-1]

                residue = min([G[a][b] for a, b in zip(root, root[1:])])

                fmax += residue

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

                    G[a][b] -= residue

                    G[b][a] += residue

            else:

                return (fmax, G)

N = int(eval(input()))

AB = [[int(_) for _ in input().split()] for _ in range(N)]

CD = [[int(_) for _ in input().split()] for _ in range(N)]

G = collections.defaultdict(lambda: collections.defaultdict(int))

for a, b in AB:

    G[-1][1000 * a + b] = 1

for c, d in CD:

    G[1000 * c + d][-2] = 1

for ab, cd in itertools.product(AB, CD):

    a, b = ab

    c, d = cd

    if a < c and b < d:

        G[1000 * a + b][1000 * c + d] = 1

flow = MaximumFlow(G)

fmax, Gres = flow.ford_fulkerson(-1, -2)

print(fmax)

+            for end, cap in list(G[start].items()):

+                if cap > 0 and end not in used:

+                    ret = dfs(end, used)

+                        return ret + [start]

+                residue = min([G[a][b] for a, b in zip(root, root[1:])])

+                for a, b in zip(root, root[1:]):

+G = collections.defaultdict(lambda: collections.defaultdict(int))

-    G.add_edge(-1, a * 1000 + b, capacity=1)

-    G.add_edge(c * 1000 + d, -2, capacity=1)

-flow_value, flow_dict = nx.maximum_flow(G, -1, -2)

+for ab, cd in itertools.product(AB, CD):

+fmax, Gres = flow.ford_fulkerson(-1, -2)


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

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

for _ in range(n-1):

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

    es[a-1].append((b-1,c))

    es[b-1].append((a-1,c))

from heapq import heappush, heappop

def dijkstra(edges, size, source):

    distance = [float('inf')] * size

    distance[source] = 0

    visited = [False] * size

    pq = []

    heappush(pq, (0, source))

    while pq:

        dist_v, v = heappop(pq)

        visited[v] = True

        for u, weight in edges[v]:

            if not visited[u]:

                new_dist = dist_v + weight

                if distance[u] > new_dist:

                    distance[u] = new_dist

                    heappush(pq, (new_dist, u))

    return distance

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

k-=1

dist=dijkstra(es,n,k)

for _ in range(q):

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

    x-=1

    y-=1

    print((dist[x]+dist[y]))

n=int(eval(input()))

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

for _ in range(n-1):

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

    es[a-1].append((b-1,c))

    es[b-1].append((a-1,c))

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

k-=1

dist=[float('inf')]*n

dist[k]=0

stack=[k]

while stack:

    now=stack.pop()

    for e,w in es[now]:

        if dist[e]==float('inf'):

            dist[e]=dist[now]+w

            stack.append(e)

for _ in range(q):

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

    x-=1

    y-=1

    print((dist[x]+dist[y]))

n = int(eval(input()))
es = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b, c = list(map(int, input().split()))
    es[a - 1].append((b - 1, c))
    es[b - 1].append((a - 1, c))
from heapq import heappush, heappop

def dijkstra(edges, size, source):
    distance = [float("inf")] * size
    distance[source] = 0
    visited = [False] * size
    pq = []
    heappush(pq, (0, source))
    while pq:
        dist_v, v = heappop(pq)
        visited[v] = True
        for u, weight in edges[v]:
            if not visited[u]:
                new_dist = dist_v + weight
                if distance[u] > new_dist:
                    distance[u] = new_dist
                    heappush(pq, (new_dist, u))
    return distance

q, k = list(map(int, input().split()))
k -= 1
dist = dijkstra(es, n, k)
for _ in range(q):
    x, y = list(map(int, input().split()))
    x -= 1
    y -= 1
    print((dist[x] + dist[y]))

n = int(eval(input()))
es = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b, c = list(map(int, input().split()))
    es[a - 1].append((b - 1, c))
    es[b - 1].append((a - 1, c))
q, k = list(map(int, input().split()))
k -= 1
dist = [float("inf")] * n
dist[k] = 0
stack = [k]
while stack:
    now = stack.pop()
    for e, w in es[now]:
        if dist[e] == float("inf"):
            dist[e] = dist[now] + w
            stack.append(e)
for _ in range(q):
    x, y = list(map(int, input().split()))
    x -= 1
    y -= 1
    print((dist[x] + dist[y]))

-                new_dist = dist_v + weight

-                if distance[u] > new_dist:

-                    distance[u] = new_dist

-                    heappush(pq, (new_dist, u))


Input:
def sb(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])

    if arr==[]:

        arr.append([n, 1])

    return arr

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

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

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

num[2]+=1

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

    if i%2==1:

        n=sb(i)

        if len(n)==1 and n[0][1]==1:

            num[i]+=1

        if num[i]==1 and num[(i+1)//2]==1:

            num2[i]+=1

for i in range(1,len(num2)):

    cnt[i]=cnt[i-1]+num2[i]

q=int(eval(input()))

for i in range(q):

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

    print((cnt[r]-cnt[l-1]))

import math

q=int(eval(input()))

num=[0]*(10**5+5)

ans=[0]*(10**5+5)

num[2]=1

for i in range(3,10**5+2,2):

    yn=0

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

        if i%j==0:

            yn=1

            break

    if yn==0:

        num[i]=1

        if num[(i+1)//2]==1:

            ans[i]=1

for i in range(1,len(num)):

    ans[i]=ans[i-1]+ans[i]

for i in range(q):

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

    print((ans[r]-ans[l-1]))

def sb(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])
    if arr == []:
        arr.append([n, 1])
    return arr

num = [0] * (10**5 + 1)
num2 = [0] * (10**5 + 1)
cnt = [0] * (10**5 + 1)
num[2] += 1
for i in range(2, 10**5 + 1):
    if i % 2 == 1:
        n = sb(i)
        if len(n) == 1 and n[0][1] == 1:
            num[i] += 1
        if num[i] == 1 and num[(i + 1) // 2] == 1:
            num2[i] += 1
for i in range(1, len(num2)):
    cnt[i] = cnt[i - 1] + num2[i]
q = int(eval(input()))
for i in range(q):
    l, r = list(map(int, input().split()))
    print((cnt[r] - cnt[l - 1]))

import math

q = int(eval(input()))
num = [0] * (10**5 + 5)
ans = [0] * (10**5 + 5)
num[2] = 1
for i in range(3, 10**5 + 2, 2):
    yn = 0
    for j in range(2, int(math.sqrt(i)) + 1):
        if i % j == 0:
            yn = 1
            break
    if yn == 0:
        num[i] = 1
        if num[(i + 1) // 2] == 1:
            ans[i] = 1
for i in range(1, len(num)):
    ans[i] = ans[i - 1] + ans[i]
for i in range(q):
    l, r = list(map(int, input().split()))
    print((ans[r] - ans[l - 1]))

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


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

s = eval(input())

left_dp = []

right_dp = []

i = 0

while len(left_dp)<k:

    if s[i] == "o":

        left_dp.append(i+1)

        i += c+1

    else: i += 1

i = n-1

while len(right_dp)<k:

    if s[i] == "o":

        right_dp.append(i+1)

        i -= c+1

    else: i -= 1

for i in range(k):

    if left_dp[i] == right_dp[k-i-1]:

        print((left_dp[i]))

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

s = input()

dpl = []

dpr = []

ans = []

count = 0

i = 0

while count < k:

    if s[i]=="o":

        dpl.append(i)

        count += 1

        i += c+1

    else: i += 1

count = 0

i = n-1

while count < k:

    if s[i]=="o":

        dpr.append(i)

        count += 1

        i += -c-1

    else: i -= 1

dpr.sort()

for i in range(len(dpl)):

    if dpl[i] == dpr[i]: ans.append(dpl[i]+1)

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

n, k, c = list(map(int, input().split()))
s = eval(input())
left_dp = []
right_dp = []
i = 0
while len(left_dp) < k:
    if s[i] == "o":
        left_dp.append(i + 1)
        i += c + 1
    else:
        i += 1
i = n - 1
while len(right_dp) < k:
    if s[i] == "o":
        right_dp.append(i + 1)
        i -= c + 1
    else:
        i -= 1
for i in range(k):
    if left_dp[i] == right_dp[k - i - 1]:
        print((left_dp[i]))

n, k, c = map(int, input().split())
s = input()
dpl = []
dpr = []
ans = []
count = 0
i = 0
while count < k:
    if s[i] == "o":
        dpl.append(i)
        count += 1
        i += c + 1
    else:
        i += 1
count = 0
i = n - 1
while count < k:
    if s[i] == "o":
        dpr.append(i)
        count += 1
        i += -c - 1
    else:
        i -= 1
dpr.sort()
for i in range(len(dpl)):
    if dpl[i] == dpr[i]:
        ans.append(dpl[i] + 1)
print(*ans, sep="\n")

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

-    if left_dp[i] == right_dp[k - i - 1]:


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

dp = [0]*(W + 1)

def solve_knapsack(capacity):

    # basic checks

    # populate the capacity = 0 columns, with '0' capacity we have '0' profit

    for i in range(0, N):

        weights,profits = list(map(int,input().split()))

        for c in range(capacity, weights-1, -1):

            tmp = profits + dp[c - weights]

            if tmp > dp[c]: dp[c] = tmp

    # maximum profit will be at the bottom-right corner.

    return dp[capacity]

def main():

    res = solve_knapsack(W)

    print(res)

if __name__ == "__main__":

	main()

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

def solve_knapsack(capacity):

    # basic checks

    # populate the capacity = 0 columns, with '0' capacity we have '0' profit

    dp = [0]*(W + 1)

    weights, profits = [0]*(N+1), [0]*(N+1)

    for i in range(0, N):

        weights,profits = list(map(int,input().split()))

        for c in range(capacity, weights-1, -1):

            tmp = profits + dp[c - weights]

            if tmp > dp[c]: dp[c] = tmp

    # maximum profit will be at the bottom-right corner.

    return dp[capacity]

def main():

    res = solve_knapsack(W)

    print(res)

if __name__ == "__main__":

	main()

N, W = list(map(int, input().split()))
dp = [0] * (W + 1)

def solve_knapsack(capacity):
    # basic checks
    # populate the capacity = 0 columns, with '0' capacity we have '0' profit
    for i in range(0, N):
        weights, profits = list(map(int, input().split()))
        for c in range(capacity, weights - 1, -1):
            tmp = profits + dp[c - weights]
            if tmp > dp[c]:
                dp[c] = tmp
    # maximum profit will be at the bottom-right corner.
    return dp[capacity]

def main():
    res = solve_knapsack(W)
    print(res)

if __name__ == "__main__":
    main()

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

def solve_knapsack(capacity):
    # basic checks
    # populate the capacity = 0 columns, with '0' capacity we have '0' profit
    dp = [0] * (W + 1)
    weights, profits = [0] * (N + 1), [0] * (N + 1)
    for i in range(0, N):
        weights, profits = list(map(int, input().split()))
        for c in range(capacity, weights - 1, -1):
            tmp = profits + dp[c - weights]
            if tmp > dp[c]:
                dp[c] = tmp
    # maximum profit will be at the bottom-right corner.
    return dp[capacity]

def main():
    res = solve_knapsack(W)
    print(res)

if __name__ == "__main__":
    main()


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

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

cnt = 0

for i in range(100):

    if sum(list(1 for x in a if x % 2 == 1)) != 0:

        print(cnt)

        exit()

    a = list(x // 2 for x in a)

    cnt += 1

print(cnt)

n = int(eval(input()))

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

cnt = 0

while True:

    if sum(list(1 for x in a if x % 2 == 1)) != 0:

        print(cnt)

        exit()

    a = list(x // 2 for x in a)

    cnt += 1

print(cnt)

n = int(eval(input()))
a = list(map(int, input().split()))
cnt = 0
for i in range(100):
    if sum(list(1 for x in a if x % 2 == 1)) != 0:
        print(cnt)
        exit()
    a = list(x // 2 for x in a)
    cnt += 1
print(cnt)

n = int(eval(input()))
a = list(map(int, input().split()))
cnt = 0
while True:
    if sum(list(1 for x in a if x % 2 == 1)) != 0:
        print(cnt)
        exit()
    a = list(x // 2 for x in a)
    cnt += 1
print(cnt)


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

s = set(list(map(int, input().split())) if n != 0 else "")

i = 0

while True:

    k = x + i

    if k not in s:

        print(k)

        break

    if i >= 0: i += 1

    i *= -1

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

s = set(list(map(int, input().split())) if n != 0 else "")

i = 0

while x + i in s:

    if i >= 0: i += 1

    i *= -1

print((x + i))

-while True:
-    k = x + i
-    if k not in s:
-        print(k)
-        break
+while x + i in s:
+print((x + i))


Input:
while True:

    try:

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

        kind = list(set(hand))

        rank =[]

        for card in kind:

            rank.append(hand.count(card))

            rank.sort()

            rank.reverse()

        if rank[0] == 4:

            print("four card")

        elif rank[0] == 3:

            if rank[1] == 2:

                print("full house")

            else:

                print("three card")

        elif rank[0] == 2:

            if rank[1] == 2:

                print("two pair")

            else:

                print("one pair")

        else:

            hand.sort()

            if hand[4] - hand[0] == 4 or (hand[0] == 1 and hand[1] == 10):

                print("straight")

            else:

                print("null")

    except:

        break

while True:

      try:

            hand = sorted(map(int, input().split(",")))

            kind = len(set(hand))

            ma = max([hand.count(i) for i in hand])

            if kind == 4:

                  print("one pair")

            elif kind == 3:

                  if ma == 2:

                        print("two pair")

                  else:

                        print("three card")

            elif kind == 2:

                  if ma==4:

                        print("four card")

                  else:

                        print("full house")

            else:

                  if hand==[1,10,11,12,13] or hand[4] - hand[0] == 4:

                        print("straight")

                  else:

                        print("null")

      except:

            break

while True:
    try:
        hand = list(map(int, input().split(",")))
        kind = list(set(hand))
        rank = []
        for card in kind:
            rank.append(hand.count(card))
            rank.sort()
            rank.reverse()
        if rank[0] == 4:
            print("four card")
        elif rank[0] == 3:
            if rank[1] == 2:
                print("full house")
            else:
                print("three card")
        elif rank[0] == 2:
            if rank[1] == 2:
                print("two pair")
            else:
                print("one pair")
        else:
            hand.sort()
            if hand[4] - hand[0] == 4 or (hand[0] == 1 and hand[1] == 10):
                print("straight")
            else:
                print("null")
    except:
        break

while True:
    try:
        hand = sorted(map(int, input().split(",")))
        kind = len(set(hand))
        ma = max([hand.count(i) for i in hand])
        if kind == 4:
            print("one pair")
        elif kind == 3:
            if ma == 2:
                print("two pair")
            else:
                print("three card")
        elif kind == 2:
            if ma == 4:
                print("four card")
            else:
                print("full house")
        else:
            if hand == [1, 10, 11, 12, 13] or hand[4] - hand[0] == 4:
                print("straight")
            else:
                print("null")
    except:
        break

-        hand = list(map(int, input().split(",")))

-            rank.append(hand.count(card))

+        hand = sorted(map(int, input().split(",")))

+        ma = max([hand.count(i) for i in hand])


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

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

Q=int(eval(input()))

y=[[-1,-1] for i in range(H*W+1)]

for i in range(H):

    for j in range(W):

        y[a[i][j]]=[i,j]

x=[ [0] for i in range(D)]

for i in range(D):

    j=H*W-i-D

    while j>0:

        tmp1,tmp2=abs(y[j][0]-y[j+D][0]),abs(y[j][1]-y[j+D][1])

        x[i].append(x[i][-1]+tmp1+tmp2)

        j-=D

for q in range(Q):

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

    i=(H*W-R)%D

    l=(H*W-i-R)//D

    r=(H*W-i-L)//D

    print((x[i][r]-x[i][l]))

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

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

Q=int(eval(input()))

y=[[-1,-1] for i in range(H*W+1)]

for i in range(H):

    for j in range(W):

        y[a[i][j]]=[i,j]

x=[0 for i in range(H*W+1)]

for i in range(D+1,H*W+1):

    x[i]=x[i-D]+abs(y[i][0]-y[i-D][0])+abs(y[i][1]-y[i-D][1])

for q in range(Q):

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

    print((x[R]-x[L]))

H, W, D = list(map(int, input().split()))
a = [list(map(int, input().split())) for i in range(H)]
Q = int(eval(input()))
y = [[-1, -1] for i in range(H * W + 1)]
for i in range(H):
    for j in range(W):
        y[a[i][j]] = [i, j]
x = [[0] for i in range(D)]
for i in range(D):
    j = H * W - i - D
    while j > 0:
        tmp1, tmp2 = abs(y[j][0] - y[j + D][0]), abs(y[j][1] - y[j + D][1])
        x[i].append(x[i][-1] + tmp1 + tmp2)
        j -= D
for q in range(Q):
    L, R = list(map(int, input().split()))
    i = (H * W - R) % D
    l = (H * W - i - R) // D
    r = (H * W - i - L) // D
    print((x[i][r] - x[i][l]))

H, W, D = list(map(int, input().split()))
a = [list(map(int, input().split())) for i in range(H)]
Q = int(eval(input()))
y = [[-1, -1] for i in range(H * W + 1)]
for i in range(H):
    for j in range(W):
        y[a[i][j]] = [i, j]
x = [0 for i in range(H * W + 1)]
for i in range(D + 1, H * W + 1):
    x[i] = x[i - D] + abs(y[i][0] - y[i - D][0]) + abs(y[i][1] - y[i - D][1])
for q in range(Q):
    L, R = list(map(int, input().split()))
    print((x[R] - x[L]))

-        x[i].append(x[i][-1] + tmp1 + tmp2)


Input:
from operator import mul

from functools import reduce

MOD = 10 ** 9 + 7

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

def cmb(n, r):

    if n < r:

        return 0

    r = min(r, n-r)

    if r == 0:

        return 1

    nume = reduce(mul, list(range(n, n-r, -1)))

    deno = reduce(mul, list(range(1, r+1)))

    return nume // deno % MOD

# 赤いボールの間と両端（N-K+1）の中からi個を選ぶ

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

    print((cmb((N-K+1), i) * cmb((K-1), i-1) % MOD))

import sys

import numpy as np

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

ir = lambda: int(sr())

lr = lambda: list(map(int, sr().split()))

def cmb(n, k):

    return fact[n] * fact_inv[k] % MOD * fact_inv[n-k] % MOD

def cumprod(arr, MOD):

    L = len(arr); Lsq = int(L**.5+1)

    arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq)

    for n in range(1, Lsq):

        arr[:, n] *= arr[:, n-1]; arr[:, n] %= MOD

    for n in range(1, Lsq):

        arr[n] *= arr[n-1, -1]; arr[n] %= MOD

    return arr.ravel()[:L]

def make_fact(U, MOD):

    x = np.arange(U, dtype=np.int64); x[0] = 1

    fact = cumprod(x, MOD)

    x = np.arange(U, 0, -1, dtype=np.int64); x[0] = pow(int(fact[-1]), MOD-2, MOD)

    fact_inv = cumprod(x, MOD)[::-1]

    return fact, fact_inv

N, K = lr()

MOD = 10 ** 9 + 7

U = 2010 # 階乗テーブルの上限

fact, fact_inv = make_fact(U, MOD)

red = N-K

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

    # (red+1)Ci

    answer = 0 if red+1 < i else cmb(red+1, i)

    #print(answer)

    remain = K - i

    # remainをiの中に自由にいれる、i-1の壁を用意

    # (remain+(i-1)) C remain

    answer *= cmb(remain+i-1, remain)

    print((answer%MOD))

# 15

from operator import mul
from functools import reduce

MOD = 10**9 + 7
N, K = list(map(int, input().split()))

def cmb(n, r):
    if n < r:
        return 0
    r = min(r, n - r)
    if r == 0:
        return 1
    nume = reduce(mul, list(range(n, n - r, -1)))
    deno = reduce(mul, list(range(1, r + 1)))
    return nume // deno % MOD

# 赤いボールの間と両端（N-K+1）の中からi個を選ぶ
for i in range(1, K + 1):
    print((cmb((N - K + 1), i) * cmb((K - 1), i - 1) % MOD))

import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

def cmb(n, k):
    return fact[n] * fact_inv[k] % MOD * fact_inv[n - k] % MOD

def cumprod(arr, MOD):
    L = len(arr)
    Lsq = int(L**0.5 + 1)
    arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq)
    for n in range(1, Lsq):
        arr[:, n] *= arr[:, n - 1]
        arr[:, n] %= MOD
    for n in range(1, Lsq):
        arr[n] *= arr[n - 1, -1]
        arr[n] %= MOD
    return arr.ravel()[:L]

def make_fact(U, MOD):
    x = np.arange(U, dtype=np.int64)
    x[0] = 1
    fact = cumprod(x, MOD)
    x = np.arange(U, 0, -1, dtype=np.int64)
    x[0] = pow(int(fact[-1]), MOD - 2, MOD)
    fact_inv = cumprod(x, MOD)[::-1]
    return fact, fact_inv

N, K = lr()
MOD = 10**9 + 7
U = 2010  # 階乗テーブルの上限
fact, fact_inv = make_fact(U, MOD)
red = N - K
for i in range(1, K + 1):
    # (red+1)Ci
    answer = 0 if red + 1 < i else cmb(red + 1, i)
    # print(answer)
    remain = K - i
    # remainをiの中に自由にいれる、i-1の壁を用意
    # (remain+(i-1)) C remain
    answer *= cmb(remain + i - 1, remain)
    print((answer % MOD))
# 15

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

+lr = lambda: list(map(int, sr().split()))

-    nume = reduce(mul, list(range(n, n - r, -1)))

-    deno = reduce(mul, list(range(1, r + 1)))

+    return fact[n] * fact_inv[k] % MOD * fact_inv[n - k] % MOD

-# 赤いボールの間と両端（N-K+1）の中からi個を選ぶ

+    arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq)

+    x = np.arange(U, 0, -1, dtype=np.int64)

+    x[0] = pow(int(fact[-1]), MOD - 2, MOD)

+U = 2010  # 階乗テーブルの上限

+    answer = 0 if red + 1 < i else cmb(red + 1, i)

+    # remainをiの中に自由にいれる、i-1の壁を用意

+    answer *= cmb(remain + i - 1, remain)


Input:
S = eval(input())

N = len(S)

a = [0] * (N+1)

index = 0

while index < N:

  tmp = S[index]

  count = 1

  if index < N-1:

    while S[index+count] == tmp:

      count += 1

      if index+count == N:

        break

  if tmp == '<':

    for j in range(count+1):

      a[index+j] = max(a[index+j],j)

  else:

    for j in range(count+1):

      a[index+count-j] = max(a[index+count-j],j)

  index += count

print((sum(a)))

S = eval(input())
N = len(S)
a = [0] * (N + 1)
index = 0
while index < N:
    tmp = S[index]
    count = 1
    if index < N - 1:
        while S[index + count] == tmp:
            count += 1
            if index + count == N:
                break
    if tmp == "<":
        for j in range(count + 1):
            a[index + j] = max(a[index + j], j)
    else:
        for j in range(count + 1):
            a[index + count - j] = max(a[index + count - j], j)
    index += count
print((sum(a)))

-            a[index + j] = max(a[index + j], j)

-            a[index + count - j] = max(a[index + count - j], j)

+    while i < N - 2 and s[i] == s[i + 1]: