Input:
# from collections import defaultdict

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

# price_howmany = defaultdict(int)

import sys

stdin = sys.stdin

read_int = lambda : list(map(int,stdin.readline().split()))

N,M = read_int()

price_howmany = {}

# price_list = []

price_set = set()

for _ in range(N):

    tmp = read_int()

    # if tmp[0] not in price_set:

        # price_list.append(tmp[0])

    price_set.add(tmp[0])

    if tmp[0] in price_howmany:

        price_howmany[tmp[0]] += tmp[1]

    else:

        price_howmany[tmp[0]] = tmp[1]

# price_list.sort(reverse=True)

price_list = sorted(list(price_set))

# price_howmany = dict(price_howmany)

def solve():

    price = 0

    global M

    # while M > 0:

        # low_price = min(price_howmany.keys())

        # low_price = price_list.pop()

        # many = min(M,price_howmany.pop(low_price))

        # price += many * low_price

        # M -= many

    for low_price in price_list:

        many = min(M,price_howmany.pop(low_price))

        price += many * low_price

        M -= many

        if M == 0: break

    print(price)

if __name__ == "__main__":

    solve()

# from collections import defaultdict

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

# price_howmany = defaultdict(int)

import sys

stdin = sys.stdin

read_int = lambda : list(map(int,stdin.readline().split()))

N,M = read_int()

price_howmany = {}

price_list = []

for _ in range(N):

    tmp = read_int()

    price_list.append(tmp[0])

    if tmp[0] in price_howmany:

        price_howmany[tmp[0]] += tmp[1]

    else:

        price_howmany[tmp[0]] = tmp[1]

price_list = list(set(price_list))

price_list.sort()

def solve():

    price = 0

    global M

    for low_price in price_list:

        many = min(M,price_howmany.pop(low_price))

        price += many * low_price

        M -= many

        if M == 0: break

    print(price)

if __name__ == "__main__":

    solve()

# from collections import defaultdict
# N,M = list(map(int,input().split()))
# price_howmany = defaultdict(int)
import sys

stdin = sys.stdin
read_int = lambda: list(map(int, stdin.readline().split()))
N, M = read_int()
price_howmany = {}
# price_list = []
price_set = set()
for _ in range(N):
    tmp = read_int()
    # if tmp[0] not in price_set:
    # price_list.append(tmp[0])
    price_set.add(tmp[0])
    if tmp[0] in price_howmany:
        price_howmany[tmp[0]] += tmp[1]
    else:
        price_howmany[tmp[0]] = tmp[1]
# price_list.sort(reverse=True)
price_list = sorted(list(price_set))
# price_howmany = dict(price_howmany)
def solve():
    price = 0
    global M
    # while M > 0:
    # low_price = min(price_howmany.keys())
    # low_price = price_list.pop()
    # many = min(M,price_howmany.pop(low_price))
    # price += many * low_price
    # M -= many
    for low_price in price_list:
        many = min(M, price_howmany.pop(low_price))
        price += many * low_price
        M -= many
        if M == 0:
            break
    print(price)

if __name__ == "__main__":
    solve()

# from collections import defaultdict
# N,M = list(map(int,input().split()))
# price_howmany = defaultdict(int)
import sys

stdin = sys.stdin
read_int = lambda: list(map(int, stdin.readline().split()))
N, M = read_int()
price_howmany = {}
price_list = []
for _ in range(N):
    tmp = read_int()
    price_list.append(tmp[0])
    if tmp[0] in price_howmany:
        price_howmany[tmp[0]] += tmp[1]
    else:
        price_howmany[tmp[0]] = tmp[1]
price_list = list(set(price_list))
price_list.sort()

def solve():
    price = 0
    global M
    for low_price in price_list:
        many = min(M, price_howmany.pop(low_price))
        price += many * low_price
        M -= many
        if M == 0:
            break
    print(price)

if __name__ == "__main__":
    solve()

-    # low_price = min(price_howmany.keys())

-    # many = min(M,price_howmany.pop(low_price))


Input:
import sys

sys.setrecursionlimit(10**9)

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

root=[-1]*n

def r(x):

    if root[x]<0:

        return x

    else:

        root[x]=r(root[x])

        return root[x]

def unite(x,y):

    x=r(x)

    y=r(y)

    if x==y:

        return

    root[x]+=root[y]

    root[y]=x

def size(x):

    x=r(x)

    return -root[x]

for i in range(m):

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

    x-=1

    y-=1

    unite(x,y)

ans=0

for i in range(n):

    ans=max(ans,size(i))

print(ans)

import sys

sys.setrecursionlimit(10**9)

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

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

def r(x):

    if root[x]<0:

        return x

    else:

        root[x]=r(root[x])

        return root[x]

def unite(x,y):

    x=r(x)

    y=r(y)

    if x==y:

        return

    root[x]+=root[y]

    root[y]=x

def size(x):

    x=r(x)

    return -root[x]

for i in range(m):

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

    unite(x,y)

ans=0

for i in range(n):

    ans=max(ans,size(i+1))

print(ans)

import sys

sys.setrecursionlimit(10**9)
n, m = list(map(int, input().split()))
root = [-1] * n

def r(x):
    if root[x] < 0:
        return x
    else:
        root[x] = r(root[x])
        return root[x]

def unite(x, y):
    x = r(x)
    y = r(y)
    if x == y:
        return
    root[x] += root[y]
    root[y] = x

def size(x):
    x = r(x)
    return -root[x]

for i in range(m):
    x, y = list(map(int, input().split()))
    x -= 1
    y -= 1
    unite(x, y)
ans = 0
for i in range(n):
    ans = max(ans, size(i))
print(ans)

import sys

sys.setrecursionlimit(10**9)
n, m = list(map(int, input().split()))
root = [-1] * (n + 1)

def r(x):
    if root[x] < 0:
        return x
    else:
        root[x] = r(root[x])
        return root[x]

def unite(x, y):
    x = r(x)
    y = r(y)
    if x == y:
        return
    root[x] += root[y]
    root[y] = x

def size(x):
    x = r(x)
    return -root[x]

for i in range(m):
    x, y = list(map(int, input().split()))
    unite(x, y)
ans = 0
for i in range(n):
    ans = max(ans, size(i + 1))
print(ans)


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

if X + K * D <= 0:

    print((-X - K * D))

elif X - K * D >= 0:

    print((X - K * D))

else:

    div = X // D

    mod = X % D

    if (K-div) % 2 == 0:

        print(mod)

    else:

        print((abs(mod-D)))

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

if X + K * D <= 0:

    print((-X - K * D))

elif X - K * D >= 0:

    print((X - K * D))

else:

    div = abs(X) // D

    if (K-div) % 2 == 0:

        print((abs(X) - D * div))

    else:

        print((abs(abs(X) - D * (div + 1))))

X, K, D = list(map(int, input().split()))
if X + K * D <= 0:
    print((-X - K * D))
elif X - K * D >= 0:
    print((X - K * D))
else:
    div = X // D
    mod = X % D
    if (K - div) % 2 == 0:
        print(mod)
    else:
        print((abs(mod - D)))

X, K, D = list(map(int, input().split()))
if X + K * D <= 0:
    print((-X - K * D))
elif X - K * D >= 0:
    print((X - K * D))
else:
    div = abs(X) // D
    if (K - div) % 2 == 0:
        print((abs(X) - D * div))
    else:
        print((abs(abs(X) - D * (div + 1))))

+        print((abs(abs(X) - D * (div + 1))))


Input:
#!/usr/bin/env python3

import collections

import sys

input=sys.stdin.readline

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

sy,sx=list(map(int,input().split()))

gy,gx=list(map(int,input().split()))

board=[['#']*(w+2)]+[list('#'+input().replace('\n','')+'#') for _ in range(h)]+[['#']*(w+2)]

scores=[[10**18]*(w+2) for _ in range(h+2)]

scores[sy][sx]=0

q=collections.deque()

q.append((sy,sx))

count=0

while len(q)!=0:

  y,x=q.popleft()

  for dx,dy in [[-1,0],[1,0],[0,-1],[0,1]]:

    if 1<=x+dx<=w and 1<=y+dy<=h and board[y+dy][x+dx]!='#' and scores[y+dy][x+dx]>scores[y][x]:

      scores[y+dy][x+dx]=scores[y][x]

      q.appendleft((y+dy,x+dx))

  for dy in range(-2,3):

    for dx in range(-2,3):

      if dx==0 and dy==0:

        continue

      if 1<=x+dx<=w and 1<=y+dy<=h and board[y+dy][x+dx]!='#' and scores[y+dy][x+dx]>scores[y][x]+1:

        scores[y+dy][x+dx]=scores[y][x]+1

        q.append((y+dy,x+dx))

if scores[gy][gx]==10**18:

    print((-1))

else:

    print((scores[gy][gx]))

#!/usr/bin/env python3

import collections

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

sy,sx=list(map(int,input().split()))

gy,gx=list(map(int,input().split()))

board=[['#']*(w+2)]+[list('#'+eval(input())+'#') for _ in range(h)]+[['#']*(w+2)]

checked=[[False]*(w+1) for _ in range(h+1)]

checked[sy][sx]=True

q=collections.deque()

q.append((sy,sx))

ans=0

while 1:

  cur_pos=[]

  while len(q)!=0:

    y,x=q.popleft()

    cur_pos.append((y,x))

    for dy,dx in [[-1,0],[1,0],[0,-1],[0,1]]:

      if 1<=y+dy<=h and 1<=x+dx<=w and board[y+dy][x+dx]=='.' and checked[y+dy][x+dx]==False:

        checked[y+dy][x+dx]=True

        q.append((y+dy,x+dx))

  if checked[gy][gx]==True:

    print(ans)

    exit()

  if len(cur_pos)==0:

    print((-1))

    exit()

  ans+=1

  for y,x in cur_pos:

    for dy in range(-2,3):

      for dx in range(-2,3):

        if dy==0 and dx==0:

          continue

        if 1<=y+dy<=h and 1<=x+dx<=w and board[y+dy][x+dx]=='.' and checked[y+dy][x+dx]==False:

          checked[y+dy][x+dx]=True

          q.append((y+dy,x+dx))

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

input = sys.stdin.readline
h, w = list(map(int, input().split()))
sy, sx = list(map(int, input().split()))
gy, gx = list(map(int, input().split()))
board = (
    [["#"] * (w + 2)]
    + [list("#" + input().replace("\n", "") + "#") for _ in range(h)]
    + [["#"] * (w + 2)]
)
scores = [[10**18] * (w + 2) for _ in range(h + 2)]
scores[sy][sx] = 0
q = collections.deque()
q.append((sy, sx))
count = 0
while len(q) != 0:
    y, x = q.popleft()
    for dx, dy in [[-1, 0], [1, 0], [0, -1], [0, 1]]:
        if (
            1 <= x + dx <= w
            and 1 <= y + dy <= h
            and board[y + dy][x + dx] != "#"
            and scores[y + dy][x + dx] > scores[y][x]
        ):
            scores[y + dy][x + dx] = scores[y][x]
            q.appendleft((y + dy, x + dx))
    for dy in range(-2, 3):
        for dx in range(-2, 3):
            if dx == 0 and dy == 0:
                continue
            if (
                1 <= x + dx <= w
                and 1 <= y + dy <= h
                and board[y + dy][x + dx] != "#"
                and scores[y + dy][x + dx] > scores[y][x] + 1
            ):
                scores[y + dy][x + dx] = scores[y][x] + 1
                q.append((y + dy, x + dx))
if scores[gy][gx] == 10**18:
    print((-1))
else:
    print((scores[gy][gx]))

#!/usr/bin/env python3
import collections

h, w = list(map(int, input().split()))
sy, sx = list(map(int, input().split()))
gy, gx = list(map(int, input().split()))
board = (
    [["#"] * (w + 2)]
    + [list("#" + eval(input()) + "#") for _ in range(h)]
    + [["#"] * (w + 2)]
)
checked = [[False] * (w + 1) for _ in range(h + 1)]
checked[sy][sx] = True
q = collections.deque()
q.append((sy, sx))
ans = 0
while 1:
    cur_pos = []
    while len(q) != 0:
        y, x = q.popleft()
        cur_pos.append((y, x))
        for dy, dx in [[-1, 0], [1, 0], [0, -1], [0, 1]]:
            if (
                1 <= y + dy <= h
                and 1 <= x + dx <= w
                and board[y + dy][x + dx] == "."
                and checked[y + dy][x + dx] == False
            ):
                checked[y + dy][x + dx] = True
                q.append((y + dy, x + dx))
    if checked[gy][gx] == True:
        print(ans)
        exit()
    if len(cur_pos) == 0:
        print((-1))
        exit()
    ans += 1
    for y, x in cur_pos:
        for dy in range(-2, 3):
            for dx in range(-2, 3):
                if dy == 0 and dx == 0:
                    continue
                if (
                    1 <= y + dy <= h
                    and 1 <= x + dx <= w
                    and board[y + dy][x + dx] == "."
                    and checked[y + dy][x + dx] == False
                ):
                    checked[y + dy][x + dx] = True
                    q.append((y + dy, x + dx))

-    + [list("#" + input().replace("\n", "") + "#") for _ in range(h)]

+    + [list("#" + eval(input()) + "#") for _ in range(h)]

+checked = [[False] * (w + 1) for _ in range(h + 1)]

-            and board[y + dy][x + dx] != "#"

-            scores[y + dy][x + dx] = scores[y][x]

-            q.appendleft((y + dy, x + dx))

-                and board[y + dy][x + dx] != "#"

-                and scores[y + dy][x + dx] > scores[y][x] + 1

+                and board[y + dy][x + dx] == "."

+                and checked[y + dy][x + dx] == False

-                scores[y + dy][x + dx] = scores[y][x] + 1

+                checked[y + dy][x + dx] = True

+                if dy == 0 and dx == 0:

+                    and 1 <= x + dx <= w

+                    and board[y + dy][x + dx] == "."

+                    and checked[y + dy][x + dx] == False

+                    checked[y + dy][x + dx] = True

+                    q.append((y + dy, x + dx))


Input:
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_B&lang=jp

#??????????????????????????????

#?????§??¬?´???°???????????????????????????????????¨????????¨?¨????????????????

def gcd(x,y):

    tmp = y

    if y > x:

        y = x

        x = tmp

    while not y == 0:

        y = x % y

        x = tmp

        tmp = y

    return x

def main():

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

    print((gcd(target[0], target[1])))

if __name__ == "__main__":

    main()

-    tmp = y
-        y = x
-        x = tmp
+        x, y = y, x
-        y = x % y
-        x = tmp
-        tmp = y
+        x, y = y, x % y


Input:
mod = 10 ** 9 + 7

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

stack = []

ans = 1

for x in X:

    stack.append(x)

    if x < 2 * len(stack) - 1:

        ans = (ans * len(stack)) % mod

        stack.pop()

    else:

        ans = (ans * len(stack)) % mod

print(ans)

mod = 10 ** 9 + 7

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

s = 0

ans = 1

for x in X:

    if x < 2 * s + 1:

        ans *= (s + 1)

    else:

        s += 1

        ans *= s

    ans %= mod

print(ans)

mod = 10**9 + 7
N, *X = list(map(int, open(0).read().split()))
stack = []
ans = 1
for x in X:
    stack.append(x)
    if x < 2 * len(stack) - 1:
        ans = (ans * len(stack)) % mod
        stack.pop()
    else:
        ans = (ans * len(stack)) % mod
print(ans)

mod = 10**9 + 7
N, *X = list(map(int, open(0).read().split()))
s = 0
ans = 1
for x in X:
    if x < 2 * s + 1:
        ans *= s + 1
    else:
        s += 1
        ans *= s
    ans %= mod
print(ans)

-stack = []
+s = 0
-    stack.append(x)
-    if x < 2 * len(stack) - 1:
-        ans = (ans * len(stack)) % mod
-        stack.pop()
+    if x < 2 * s + 1:
+        ans *= s + 1
-        ans = (ans * len(stack)) % mod
+        s += 1
+        ans *= s
+    ans %= mod


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

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

Ds = []

past = 0

for i, a in enumerate(As):

    if not i==0:

        Ds.append(a-past)

    past = a

Ds.append(As[0]+K-As[-1])

print((K-max(Ds)))

import sys

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

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

sys.setrecursionlimit(10**9)

K, N = mapint()

As = list(mapint())

lis = []

for i in range(1, N):

    lis.append(As[i]-As[i-1])

lis.append(As[0]+(K-As[-1]))

print((K-max(lis)))

K, N = list(map(int, input().split()))
As = list(map(int, input().split()))
Ds = []
past = 0
for i, a in enumerate(As):
    if not i == 0:
        Ds.append(a - past)
    past = a
Ds.append(As[0] + K - As[-1])
print((K - max(Ds)))

import sys

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

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

sys.setrecursionlimit(10**9)
K, N = mapint()
As = list(mapint())
lis = []
for i in range(1, N):
    lis.append(As[i] - As[i - 1])
lis.append(As[0] + (K - As[-1]))
print((K - max(lis)))

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

+    return list(map(int, input().split()))


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

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

count=0

for i in range(n):

    while list[i]%2==0:

        list[i]=list[i]/2

        count+=1

print(count)

n = int(eval(input()))

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

count=0

for i in range(n):

    while list[i]%2==0:

        list[i]=list[i]//2

        count+=1

print(count)

n = int(eval(input()))
list = list(map(int, input().split()))
count = 0
for i in range(n):
    while list[i] % 2 == 0:
        list[i] = list[i] / 2
        count += 1
print(count)

n = int(eval(input()))
list = list(map(int, input().split()))
count = 0
for i in range(n):
    while list[i] % 2 == 0:
        list[i] = list[i] // 2
        count += 1
print(count)

-        list[i] = list[i] / 2
+        list[i] = list[i] // 2


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

b=int(eval(input()))

print(("GREATER" if a>b else "LESS" if b>a else "EQUAL"))

a=int(eval(input()))

b=int(eval(input()))

if a>b:

  print("GREATER")

elif b>a:

  print("LESS")

else:

  print("EQUAL")

a = int(eval(input()))
b = int(eval(input()))
print(("GREATER" if a > b else "LESS" if b > a else "EQUAL"))

a = int(eval(input()))
b = int(eval(input()))
if a > b:
    print("GREATER")
elif b > a:
    print("LESS")
else:
    print("EQUAL")

-print(("GREATER" if a > b else "LESS" if b > a else "EQUAL"))


Input:
def bubble_sort(A):

    count = 0

    for i in reversed(list(range(len(A)))):

        for j in range(i):

            if A[j] > A[j+1]:

                temp = A[j]

                A[j] = A[j+1]

                A[j+1] = temp

                count += 1

    return count

N = int(eval(input()))

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

count = bubble_sort(A)

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

print(count)

def bubble_sort(A, N):

	count = 0

	flag = 1

	while flag:

		flag = 0

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

			if A[i] < A[i-1]:

				temp = A[i]

				A[i] = A[i-1]

				A[i-1] = temp

				count += 1

				flag = 1

	return A, count

N = int(eval(input()))

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

A, count = bubble_sort(A, N)

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

print(count)

def bubble_sort(A):
    count = 0
    for i in reversed(list(range(len(A)))):
        for j in range(i):
            if A[j] > A[j + 1]:
                temp = A[j]
                A[j] = A[j + 1]
                A[j + 1] = temp
                count += 1
    return count

N = int(eval(input()))
A = list(map(int, input().split()))
count = bubble_sort(A)
print((" ".join(map(str, A))))
print(count)

def bubble_sort(A, N):
    count = 0
    flag = 1
    while flag:
        flag = 0
        for i in range(N - 1, 0, -1):
            if A[i] < A[i - 1]:
                temp = A[i]
                A[i] = A[i - 1]
                A[i - 1] = temp
                count += 1
                flag = 1
    return A, count

N = int(eval(input()))
A = list(map(int, input().split()))
A, count = bubble_sort(A, N)
print((" ".join(map(str, A))))
print(count)

-    for i in reversed(list(range(len(A)))):


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

ban = N if N%2 else N+1

ans = []

for i in range(1,N):

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

        if i+j == ban: continue

        ans.append((i,j))

print((len(ans)))

for a,b in ans:

    print((a,b))

N = int(input())

ban = N if N%2 else N+1

ans = []

for i in range(1,N):

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

        if i+j == ban: continue

        ans.append(str(i) + ' ' + str(j))

print(len(ans))

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

N = int(eval(input()))
ban = N if N % 2 else N + 1
ans = []
for i in range(1, N):
    for j in range(i + 1, N + 1):
        if i + j == ban:
            continue
        ans.append((i, j))
print((len(ans)))
for a, b in ans:
    print((a, b))

N = int(input())
ban = N if N % 2 else N + 1
ans = []
for i in range(1, N):
    for j in range(i + 1, N + 1):
        if i + j == ban:
            continue
        ans.append(str(i) + " " + str(j))
print(len(ans))
print(*ans, sep="\n")

+        ans.append(str(i) + " " + str(j))


Input:
x = [0] * 3

y = [0] * 3

z = [0] * 3

for i in range(3):

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

n = int(eval(input()))

b = [int(eval(input())) for _ in range(n)]

ans = [x, y, z]

for i in range(3):

    ans.append([x[i], y[i], z[i]])

ans.append([x[0], y[1], z[2]])

ans.append([x[2], y[1], z[0]])

cnt_list = []

for i in range(len(ans)):

    cnt = 0

    for j in list(set(x + y + z) & set(b)):

        if j in ans[i]:

            cnt += 1

    cnt_list.append(cnt)

for cnt in cnt_list:

  if cnt >= 3:

    print('Yes')

    exit()

print('No')

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

b=[[0]*3 for _ in range(3)]

n = int(eval(input()))

##################

for ni in range(n):

  x = int(eval(input()))

  for i in range(3):

    for j in range(3):

      if a[i][j] == x:

        b[i][j] = 1

##################

ans = False

##################

for i in range(3):

  cnt = 0

  for j in range(3):

    cnt += b[i][j]

    if cnt == 3:

      ans = True

##################

for i in range(3):

  cnt = 0

  for j in range(3):

    cnt += b[j][i]

    if cnt == 3:

      ans = True

##################

cnt = 0

for j in range(3):

  cnt += b[j][j]

  if cnt == 3:

    ans = True

##################

cnt = 0

for j in range(3):

  cnt += b[j][2-j]

  if cnt == 3:

    ans = True

##################

if ans == True:

  print('Yes')

else:

  print('No')

x = [0] * 3
y = [0] * 3
z = [0] * 3
for i in range(3):
    x[i], y[i], z[i] = list(map(int, input().split()))
n = int(eval(input()))
b = [int(eval(input())) for _ in range(n)]
ans = [x, y, z]
for i in range(3):
    ans.append([x[i], y[i], z[i]])
ans.append([x[0], y[1], z[2]])
ans.append([x[2], y[1], z[0]])
cnt_list = []
for i in range(len(ans)):
    cnt = 0
    for j in list(set(x + y + z) & set(b)):
        if j in ans[i]:
            cnt += 1
    cnt_list.append(cnt)
for cnt in cnt_list:
    if cnt >= 3:
        print("Yes")
        exit()
print("No")

a = [list(map(int, list(input().split()))) for _ in range(3)]
b = [[0] * 3 for _ in range(3)]
n = int(eval(input()))
##################
for ni in range(n):
    x = int(eval(input()))
    for i in range(3):
        for j in range(3):
            if a[i][j] == x:
                b[i][j] = 1
##################
ans = False
##################
for i in range(3):
    cnt = 0
    for j in range(3):
        cnt += b[i][j]
        if cnt == 3:
            ans = True
##################
for i in range(3):
    cnt = 0
    for j in range(3):
        cnt += b[j][i]
        if cnt == 3:
            ans = True
##################
cnt = 0
for j in range(3):
    cnt += b[j][j]
    if cnt == 3:
        ans = True
##################
cnt = 0
for j in range(3):
    cnt += b[j][2 - j]
    if cnt == 3:
        ans = True
##################
if ans == True:
    print("Yes")
else:
    print("No")

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

-    x[i], y[i], z[i] = list(map(int, input().split()))

-b = [int(eval(input())) for _ in range(n)]

-    for j in list(set(x + y + z) & set(b)):


Input:
# ABC084D - 2017-like Number

from bisect import bisect_left as bsl, bisect_right as bsr

def get_primes(n: int) -> list:

    # return a list of primes <= n

    sieve = [1] * n

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

        if sieve[i]:

            sieve[i * i :: 2 * i] = [0] * ((n - i * i - 1) // (2 * i) + 1)

    return [2] + [i for i in range(3, n, 2) if sieve[i]]

def main():

    Q, *LR = map(int, open(0).read().split())

    P = get_primes(10 ** 5 + 1)

    S = set(P)

    sel = [p for p in P if (p + 1) // 2 in S]  # 2017-like primes (selected P)

    # the number of 2017-like primes b/w l, r -> bisect[r] - bisect[l]

    ans = [bsr(sel, r) - bsl(sel, l) for l, r in zip(*[iter(LR)] * 2)]

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

if __name__ == "__main__":

    main()

# D - 2017-like Number

from itertools import accumulate

from math import sqrt

def get_primes(n: int) -> set:

    """Return a list of prime numbers < n in O(N)."""

    if n < 2:

        return set()

    sieve = [1] * n

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

        if sieve[i]:

            sieve[i * i:: 2 * i] = [0] * ((n - i ** 2 - 1) // (2 * i) + 1)

    return {2} | {i for i in range(3, n, 2) if sieve[i]}

def main():

    Q, *LR = list(map(int, open(0).read().split()))

    primes = get_primes(10 ** 5 + 1)

    is_2017_like = [1 if i in primes and (i + 1) // 2 in primes else 0 for i in range(10 ** 5 + 1)]

    cumsum = tuple(accumulate(is_2017_like))

    ans = []

    for l, r in zip(*[iter(LR)] * 2):

        ans.append(cumsum[r] - cumsum[l - 1])

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

if __name__ == "__main__":

    main()

# ABC084D - 2017-like Number
from bisect import bisect_left as bsl, bisect_right as bsr

def get_primes(n: int) -> list:
    # return a list of primes <= n
    sieve = [1] * n
    for i in range(3, int(n**0.5) + 1, 2):
        if sieve[i]:
            sieve[i * i :: 2 * i] = [0] * ((n - i * i - 1) // (2 * i) + 1)
    return [2] + [i for i in range(3, n, 2) if sieve[i]]

def main():
    Q, *LR = map(int, open(0).read().split())
    P = get_primes(10**5 + 1)
    S = set(P)
    sel = [p for p in P if (p + 1) // 2 in S]  # 2017-like primes (selected P)
    # the number of 2017-like primes b/w l, r -> bisect[r] - bisect[l]
    ans = [bsr(sel, r) - bsl(sel, l) for l, r in zip(*[iter(LR)] * 2)]
    print(*ans, sep="\n")

if __name__ == "__main__":
    main()

# D - 2017-like Number
from itertools import accumulate
from math import sqrt

def get_primes(n: int) -> set:
    """Return a list of prime numbers < n in O(N)."""
    if n < 2:
        return set()
    sieve = [1] * n
    for i in range(3, int(sqrt(n)) + 1, 2):
        if sieve[i]:
            sieve[i * i :: 2 * i] = [0] * ((n - i**2 - 1) // (2 * i) + 1)
    return {2} | {i for i in range(3, n, 2) if sieve[i]}

def main():
    Q, *LR = list(map(int, open(0).read().split()))
    primes = get_primes(10**5 + 1)
    is_2017_like = [
        1 if i in primes and (i + 1) // 2 in primes else 0 for i in range(10**5 + 1)
    ]
    cumsum = tuple(accumulate(is_2017_like))
    ans = []
    for l, r in zip(*[iter(LR)] * 2):
        ans.append(cumsum[r] - cumsum[l - 1])
    print(("\n".join(map(str, ans))))

if __name__ == "__main__":
    main()

-from bisect import bisect_left as bsl, bisect_right as bsr

+    """Return a list of prime numbers < n in O(N)."""

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

-    return [2] + [i for i in range(3, n, 2) if sieve[i]]

+    return {2} | {i for i in range(3, n, 2) if sieve[i]}

-    Q, *LR = map(int, open(0).read().split())

-    sel = [p for p in P if (p + 1) // 2 in S]  # 2017-like primes (selected P)

-    # the number of 2017-like primes b/w l, r -> bisect[r] - bisect[l]

-    ans = [bsr(sel, r) - bsl(sel, l) for l, r in zip(*[iter(LR)] * 2)]

+    Q, *LR = list(map(int, open(0).read().split()))

+        1 if i in primes and (i + 1) // 2 in primes else 0 for i in range(10**5 + 1)

+    cumsum = tuple(accumulate(is_2017_like))

+        ans.append(cumsum[r] - cumsum[l - 1])


Input:
r, c = map(int, input().split())

table = []

for _ in range(r):

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

for i in range(r):

    print(' '.join(map(str, table[i])), end='')

    print(' {}'.format(sum(table[i])))

total = 0

for j in range(c):

    column_sum = 0

    column_sum = sum([row[j] for row in table])

    print('{} '.format(column_sum), end='')

    total += column_sum

print(total)

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

table = []

for i in range(r):

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

    row.append(sum(row))

    table.append(row)

total_row = []

for col in range(c+1):

    column_sum = 0

    for row in range(r):

        column_sum += table[row][col]

    total_row.append(column_sum)

table.append(total_row)

for i in range(r+1):

    print((' '.join(map(str, table[i]))))

r, c = map(int, input().split())
table = []
for _ in range(r):
    table.append(list(map(int, input().split())))
for i in range(r):
    print(" ".join(map(str, table[i])), end="")
    print(" {}".format(sum(table[i])))
total = 0
for j in range(c):
    column_sum = 0
    column_sum = sum([row[j] for row in table])
    print("{} ".format(column_sum), end="")
    total += column_sum
print(total)

r, c = list(map(int, input().split()))
table = []
for i in range(r):
    row = list(map(int, input().split()))
    row.append(sum(row))
    table.append(row)
total_row = []
for col in range(c + 1):
    column_sum = 0
    for row in range(r):
        column_sum += table[row][col]
    total_row.append(column_sum)
table.append(total_row)
for i in range(r + 1):
    print((" ".join(map(str, table[i]))))

-    table.append(list(map(int, input().split())))

-    print(" ".join(map(str, table[i])), end="")

+    row = list(map(int, input().split()))

-    column_sum = sum([row[j] for row in table])

-    print("{} ".format(column_sum), end="")

+    print((" ".join(map(str, table[i]))))


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

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

A_max = A.pop()

print((A_max, min(A, key=lambda x:abs(A_max-x*2))))

n = int(eval(input()))

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

A_max = max(A)

A.remove(A_max)

print((A_max, min(A, key=lambda x:abs(A_max-x*2))))

n = int(eval(input()))
A = sorted([int(i) for i in input().split()])
A_max = A.pop()
print((A_max, min(A, key=lambda x: abs(A_max - x * 2))))

n = int(eval(input()))
A = [int(i) for i in input().split()]
A_max = max(A)
A.remove(A_max)
print((A_max, min(A, key=lambda x: abs(A_max - x * 2))))

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


Input:
import numpy as np

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

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

a=[np.array(i[1:]) for i in ca]

c=[i[0] for i in ca]

xx=np.array([x]*m)

ans=pow(10,9)

for i in range(2**n):

  count=0

  aa=np.array([0]*m)

  for j in range(n):

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

      aa+=a[j]

      count+=c[j]

    if all(i>=x for i in aa):

      ans=min(ans,count)

print((ans if ans<pow(10,9) else -1))

from itertools import product

import numpy as np

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

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

a,c=np.array([i[1:] for i in ca]).T,np.array([i[0] for i in ca])

ans=pow(10,9)

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

  i=np.array(i)

  if all(np.dot(a,i)>=x):

    s=np.dot(i,c)

    ans=s if s<ans else ans

print((ans if ans<pow(10,9) else -1))

import numpy as np

n, m, x = list(map(int, input().split()))
ca = [list(map(int, input().split())) for _ in range(n)]
a = [np.array(i[1:]) for i in ca]
c = [i[0] for i in ca]
xx = np.array([x] * m)
ans = pow(10, 9)
for i in range(2**n):
    count = 0
    aa = np.array([0] * m)
    for j in range(n):
        if (i >> j) & 1:
            aa += a[j]
            count += c[j]
        if all(i >= x for i in aa):
            ans = min(ans, count)
print((ans if ans < pow(10, 9) else -1))

from itertools import product
import numpy as np

n, m, x = list(map(int, input().split()))
ca = [list(map(int, input().split())) for _ in range(n)]
a, c = np.array([i[1:] for i in ca]).T, np.array([i[0] for i in ca])
ans = pow(10, 9)
for i in product([0, 1], repeat=n):
    i = np.array(i)
    if all(np.dot(a, i) >= x):
        s = np.dot(i, c)
        ans = s if s < ans else ans
print((ans if ans < pow(10, 9) else -1))

+a, c = np.array([i[1:] for i in ca]).T, np.array([i[0] for i in ca])


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

count = 0

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

    if c % i == 0:

        count += 1

print(count)

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

result = []

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

    if c % i == 0:

        result.append(i)

print((len(result)))

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

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

-count = 0
+result = []
-        count += 1
-print(count)
+        result.append(i)
+print((len(result)))


Input:
# 差が1か0のみ隣り合わない 適当に毎回割る再帰

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

if abs(n - m) > 1:

    print((0))

elif n == m:

    ans = 1

    while n > 0:

        ans *= n

        n -= 1

        ans %= (10 ** 9 + 7)

    ans = (ans * ans * 2) % (10 ** 9 + 7)

    print(ans)

else:

    ans = max(n, m)

    t = 1

    x = min(n, m)

    while x > 0:

        t *= x

        x -= 1

        t %= (10 ** 9 + 7)

    ans = (ans * t * t) % (10 ** 9 + 7)

    print(ans)

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

MOD = 10**9 + 7

if abs(n - m) > 1:

    print((0))

elif n == m:

    ans = 1

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

        ans *= i

        ans %= MOD

    # xoxoxo... とoxoxox... 、どっちを先にするかで2種類

    print((2 * ans * ans % MOD))

else:

    ans = 1

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

        ans *= i

        ans %= MOD

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

        ans *= i

        ans %= MOD

    print(ans)

# 差が1か0のみ隣り合わない 適当に毎回割る再帰
n, m = list(map(int, input().split()))
if abs(n - m) > 1:
    print((0))
elif n == m:
    ans = 1
    while n > 0:
        ans *= n
        n -= 1
        ans %= 10**9 + 7
    ans = (ans * ans * 2) % (10**9 + 7)
    print(ans)
else:
    ans = max(n, m)
    t = 1
    x = min(n, m)
    while x > 0:
        t *= x
        x -= 1
        t %= 10**9 + 7
    ans = (ans * t * t) % (10**9 + 7)
    print(ans)

-# 差が1か0のみ隣り合わない 適当に毎回割る再帰

+    # xoxoxo... とoxoxox... 、どっちを先にするかで2種類


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

t = X

ans = 0

while t <= Y:

    t *= 2

    ans += 1

print(ans)

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

ans = 0

while X <= Y:

    X *= 2

    ans += 1

print(ans)

X, Y = list(map(int, input().split()))
ans = 0
while X <= Y:
    X *= 2
    ans += 1
print(ans)

-t = X
-while t <= Y:
-    t *= 2
+while X <= Y:
+    X *= 2


Input:
import math

pi = math.atan(1)*4

def andrange(a, b):

    if a == (0, 0) or b == (0, 0): return (0, 0)

    if a == (0, 1): return b

    if b == (0, 1): return a

    if a[0] > b[0]: a, b = b, a

    if b[1] < a[1]:

        return b

    if b[0] < a[1] and b[1] >= a[1]:

        return (b[0], a[1])

    if b[0] >= a[1] and b[1] < a[0] + 1:

        return (0, 0)

    if b[1] >= a[0] + 1 and b[1] < a[1] + 1:

        return (a[0], b[1] - 1)

    if b[1] >= a[0] + 1 and b[1] >= a[1] + 1:

        return a

def calcrange(P, Q):

    c = calc(P, Q)

    if c > 0:

        return (c, c+0.5)

    else:

        return (c+1, c+1.5)

def calc(P, Q):

    x = P[0] - Q[0]

    y = P[1] - Q[1]

    if x == 0:

        return 0.25 if y > 0 else -0.25

    t = math.atan(y/x)

    return t/(2*pi) if x > 0 else (t/(2*pi) % 1) - 0.5

N = int(eval(input()))

X = []

for _ in range(N):

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

    X.append((x, y))

A = [(0, 1) for _ in range(N)]

for i in range(N):

    for j in range(N):

        if i != j:

            A[i] = andrange(A[i], calcrange(X[i], X[j]))

for a in A:

    print(("{:.20f}".format(a[1] - a[0])))

from math import pi, atan2

def andrange(a, b):

    if a == (0, 0) or b == (0, 0): return (0, 0)

    if a == (0, 1): return b

    if b == (0, 1): return a

    if a[0] > b[0]: a, b = b, a

    if b[1] < a[1]: return b

    if b[0] < a[1]: return (b[0], a[1])

    if b[1] < a[0] + 1: return (0, 0)

    if b[1] < a[1] + 1: return (a[0], b[1] - 1)

    return a

def calcrange(P, Q):

    c = atan2(P[1]-Q[1], P[0]-Q[0]) / (2*pi)

    if c > 0: return (c, c+0.5)

    else: return (c+1, c+1.5)

N = int(eval(input()))

X = []

for _ in range(N):

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

    X.append((x, y))

A = [(0, 1) for _ in range(N)]

for i in range(N):

    for j in range(N):

        if i != j:

            A[i] = andrange(A[i], calcrange(X[i], X[j]))

for a in A:

    print(("{:.15f}".format(a[1] - a[0])))

import math

pi = math.atan(1) * 4

def andrange(a, b):
    if a == (0, 0) or b == (0, 0):
        return (0, 0)
    if a == (0, 1):
        return b
    if b == (0, 1):
        return a
    if a[0] > b[0]:
        a, b = b, a
    if b[1] < a[1]:
        return b
    if b[0] < a[1] and b[1] >= a[1]:
        return (b[0], a[1])
    if b[0] >= a[1] and b[1] < a[0] + 1:
        return (0, 0)
    if b[1] >= a[0] + 1 and b[1] < a[1] + 1:
        return (a[0], b[1] - 1)
    if b[1] >= a[0] + 1 and b[1] >= a[1] + 1:
        return a

def calcrange(P, Q):
    c = calc(P, Q)
    if c > 0:
        return (c, c + 0.5)
    else:
        return (c + 1, c + 1.5)

def calc(P, Q):
    x = P[0] - Q[0]
    y = P[1] - Q[1]
    if x == 0:
        return 0.25 if y > 0 else -0.25
    t = math.atan(y / x)
    return t / (2 * pi) if x > 0 else (t / (2 * pi) % 1) - 0.5

N = int(eval(input()))
X = []
for _ in range(N):
    x, y = list(map(int, input().split()))
    X.append((x, y))
A = [(0, 1) for _ in range(N)]
for i in range(N):
    for j in range(N):
        if i != j:
            A[i] = andrange(A[i], calcrange(X[i], X[j]))
for a in A:
    print(("{:.20f}".format(a[1] - a[0])))

from math import pi, atan2

def andrange(a, b):
    if a == (0, 0) or b == (0, 0):
        return (0, 0)
    if a == (0, 1):
        return b
    if b == (0, 1):
        return a
    if a[0] > b[0]:
        a, b = b, a
    if b[1] < a[1]:
        return b
    if b[0] < a[1]:
        return (b[0], a[1])
    if b[1] < a[0] + 1:
        return (0, 0)
    if b[1] < a[1] + 1:
        return (a[0], b[1] - 1)
    return a

def calcrange(P, Q):
    c = atan2(P[1] - Q[1], P[0] - Q[0]) / (2 * pi)
    if c > 0:
        return (c, c + 0.5)
    else:
        return (c + 1, c + 1.5)

N = int(eval(input()))
X = []
for _ in range(N):
    x, y = list(map(int, input().split()))
    X.append((x, y))
A = [(0, 1) for _ in range(N)]
for i in range(N):
    for j in range(N):
        if i != j:
            A[i] = andrange(A[i], calcrange(X[i], X[j]))
for a in A:
    print(("{:.15f}".format(a[1] - a[0])))

-        return 0.25 if y > 0 else -0.25


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

d = set(sorted([int(eval(input())) for _ in range(N)]))

print((len(d)))

n = int(eval(input()))

d = [int(eval(input())) for _ in range(n)]

d = sorted(list(set(d)))

print((len(d)))

-d = set(sorted([int(eval(input())) for _ in range(N)]))

+d = [int(eval(input())) for _ in range(n)]


Input:
s = ''.join(input().split('ST'))

cnts = 0

cnt = 0

for i in s:

    if i == 'S' :

        cnts += 1

    elif cnts > 0:

        cnts -= 1

        cnt += 1

print((len(s)-cnt*2))

def main():

    s = input().replace('ST', '')

    cnts = 0

    cnt = 0

    for i in s:

        if i == 'S':

            cnts += 1

        elif cnts > 0:

            cnts -= 1

            cnt += 1

    print((len(s)-cnt*2))

if __name__ == '__main__':

    main()

s = "".join(input().split("ST"))
cnts = 0
cnt = 0
for i in s:
    if i == "S":
        cnts += 1
    elif cnts > 0:
        cnts -= 1
        cnt += 1
print((len(s) - cnt * 2))

def main():
    s = input().replace("ST", "")
    cnts = 0
    cnt = 0
    for i in s:
        if i == "S":
            cnts += 1
        elif cnts > 0:
            cnts -= 1
            cnt += 1
    print((len(s) - cnt * 2))

if __name__ == "__main__":
    main()

-s = "".join(input().split("ST"))
-cnts = 0
-cnt = 0
-for i in s:
-    if i == "S":
-        cnts += 1
-    elif cnts > 0:
-        cnts -= 1
-        cnt += 1
-print((len(s) - cnt * 2))
+def main():
+    s = input().replace("ST", "")
+    cnts = 0
+    cnt = 0
+    for i in s:
+        if i == "S":
+            cnts += 1
+        elif cnts > 0:
+            cnts -= 1
+            cnt += 1
+    print((len(s) - cnt * 2))
+
+
+if __name__ == "__main__":
+    main()


Input:
class SCC:

  '''

  SCC class with non-recursive DFS.

  '''

  def __init__(self,N):

    self.N = N

    self.G1 = [[] for _ in range(N)]

    self.G2 = [[] for _ in range(N)]

  def add_edge(self,a,b):

    self.G1[a].append(b)

    self.G2[b].append(a)

  def scc(self):

    self.seen = [0]*self.N

    self.postorder=[-1]*self.N

    self.order = 0

    for i in range(self.N):

      if self.seen[i]:continue

      self._dfs(i)

    self.seen = [0]*self.N

    scclist = []

    for i in self._argsort(self.postorder,reverse=True):

      if self.seen[i]:continue

      cc = self._dfs2(i)

      scclist.append(cc)

    return scclist

  def _argsort(self,arr,reverse=False):

    shift = self.N.bit_length()+2

    tmp = sorted([arr[i]<<shift | i for i in range(len(arr))],reverse=reverse)

    mask = (1<<shift) - 1

    return [tmp[i] & mask for i in range(len(arr))]

  def _dfs(self,v0):

    todo = [~v0, v0]

    while todo:

      v = todo.pop()

      if v >= 0:

        self.seen[v] = 1

        for next_v in self.G1[v]:

          if self.seen[next_v]: continue

          todo.append(~next_v)

          todo.append(next_v)

      else:

        if self.postorder[~v] == -1:

          self.postorder[~v] = self.order

          self.order += 1

    return

  def _dfs2(self,v):

    todo = [v]

    self.seen[v] = 1

    cc = [v]

    while todo:

      v = todo.pop()

      for next_v in self.G2[v]:

        if self.seen[next_v]: continue

        self.seen[next_v] = 1

        todo.append(next_v)

        cc.append(next_v)

    return cc

def main():

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

  sc = SCC(N)

  for i in range(M):

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

    sc.add_edge(a,b)

  scclist = sc.scc()

  print((len(scclist)))

  for cc in scclist:

    print((len(cc),*cc))

if __name__=="__main__":

  main()

class SCC:

  '''

  SCC class with non-recursive DFS.

  '''

  def __init__(self,N):

    self.N = N

    self.G1 = [[] for _ in range(N)]

    self.G2 = [[] for _ in range(N)]

  def add_edge(self,a,b):

    self.G1[a].append(b)

    self.G2[b].append(a)

  def scc(self):

    self.seen = [0]*self.N

    self.postorder=[-1]*self.N

    self.order = 0

    for i in range(self.N):

      if self.seen[i]:continue

      self._dfs(i)

    self.seen = [0]*self.N

    scclist = []

    for i in self._argsort(self.postorder,reverse=True):

      if self.seen[i]:continue

      cc = self._dfs2(i)

      scclist.append(cc)

    return scclist

  def _argsort(self,arr,reverse=False):

    shift = self.N.bit_length()+2

    tmp = sorted([arr[i]<<shift | i for i in range(len(arr))],reverse=reverse)

    mask = (1<<shift) - 1

    return [tmp[i] & mask for i in range(len(arr))]

  def _dfs(self,v0):

    todo = [~v0, v0]

    while todo:

      v = todo.pop()

      if v >= 0:

        self.seen[v] = 1

        for next_v in self.G1[v]:

          if self.seen[next_v]: continue

          todo.append(~next_v)

          todo.append(next_v)

      else:

        if self.postorder[~v] == -1:

          self.postorder[~v] = self.order

          self.order += 1

    return

  def _dfs2(self,v):

    todo = [v]

    self.seen[v] = 1

    cc = [v]

    while todo:

      v = todo.pop()

      for next_v in self.G2[v]:

        if self.seen[next_v]: continue

        self.seen[next_v] = 1

        todo.append(next_v)

        cc.append(next_v)

    return cc

def main():

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

  scc = SCC(N)

  for i in range(M):

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

    scc.add_edge(a,b)

  scclist = scc.scc()

  print((len(scclist)))

  for cc in scclist:

    print((len(cc),*cc))

if __name__=="__main__":

  main()

class SCC:
    """
    SCC class with non-recursive DFS.
    """

    def __init__(self, N):
        self.N = N
        self.G1 = [[] for _ in range(N)]
        self.G2 = [[] for _ in range(N)]

    def add_edge(self, a, b):
        self.G1[a].append(b)
        self.G2[b].append(a)

    def scc(self):
        self.seen = [0] * self.N
        self.postorder = [-1] * self.N
        self.order = 0
        for i in range(self.N):
            if self.seen[i]:
                continue
            self._dfs(i)
        self.seen = [0] * self.N
        scclist = []
        for i in self._argsort(self.postorder, reverse=True):
            if self.seen[i]:
                continue
            cc = self._dfs2(i)
            scclist.append(cc)
        return scclist

    def _argsort(self, arr, reverse=False):
        shift = self.N.bit_length() + 2
        tmp = sorted([arr[i] << shift | i for i in range(len(arr))], reverse=reverse)
        mask = (1 << shift) - 1
        return [tmp[i] & mask for i in range(len(arr))]

    def _dfs(self, v0):
        todo = [~v0, v0]
        while todo:
            v = todo.pop()
            if v >= 0:
                self.seen[v] = 1
                for next_v in self.G1[v]:
                    if self.seen[next_v]:
                        continue
                    todo.append(~next_v)
                    todo.append(next_v)
            else:
                if self.postorder[~v] == -1:
                    self.postorder[~v] = self.order
                    self.order += 1
        return

    def _dfs2(self, v):
        todo = [v]
        self.seen[v] = 1
        cc = [v]
        while todo:
            v = todo.pop()
            for next_v in self.G2[v]:
                if self.seen[next_v]:
                    continue
                self.seen[next_v] = 1
                todo.append(next_v)
                cc.append(next_v)
        return cc

def main():
    N, M = list(map(int, input().split()))
    sc = SCC(N)
    for i in range(M):
        a, b = list(map(int, input().split()))
        sc.add_edge(a, b)
    scclist = sc.scc()
    print((len(scclist)))
    for cc in scclist:
        print((len(cc), *cc))

if __name__ == "__main__":
    main()

class SCC:
    """
    SCC class with non-recursive DFS.
    """

    def __init__(self, N):
        self.N = N
        self.G1 = [[] for _ in range(N)]
        self.G2 = [[] for _ in range(N)]

    def add_edge(self, a, b):
        self.G1[a].append(b)
        self.G2[b].append(a)

    def scc(self):
        self.seen = [0] * self.N
        self.postorder = [-1] * self.N
        self.order = 0
        for i in range(self.N):
            if self.seen[i]:
                continue
            self._dfs(i)
        self.seen = [0] * self.N
        scclist = []
        for i in self._argsort(self.postorder, reverse=True):
            if self.seen[i]:
                continue
            cc = self._dfs2(i)
            scclist.append(cc)
        return scclist

    def _argsort(self, arr, reverse=False):
        shift = self.N.bit_length() + 2
        tmp = sorted([arr[i] << shift | i for i in range(len(arr))], reverse=reverse)
        mask = (1 << shift) - 1
        return [tmp[i] & mask for i in range(len(arr))]

    def _dfs(self, v0):
        todo = [~v0, v0]
        while todo:
            v = todo.pop()
            if v >= 0:
                self.seen[v] = 1
                for next_v in self.G1[v]:
                    if self.seen[next_v]:
                        continue
                    todo.append(~next_v)
                    todo.append(next_v)
            else:
                if self.postorder[~v] == -1:
                    self.postorder[~v] = self.order
                    self.order += 1
        return

    def _dfs2(self, v):
        todo = [v]
        self.seen[v] = 1
        cc = [v]
        while todo:
            v = todo.pop()
            for next_v in self.G2[v]:
                if self.seen[next_v]:
                    continue
                self.seen[next_v] = 1
                todo.append(next_v)
                cc.append(next_v)
        return cc

def main():
    N, M = list(map(int, input().split()))
    scc = SCC(N)
    for i in range(M):
        a, b = list(map(int, input().split()))
        scc.add_edge(a, b)
    scclist = scc.scc()
    print((len(scclist)))
    for cc in scclist:
        print((len(cc), *cc))

if __name__ == "__main__":
    main()

-    sc = SCC(N)
+    scc = SCC(N)
-        sc.add_edge(a, b)
-    scclist = sc.scc()
+        scc.add_edge(a, b)
+    scclist = scc.scc()


Input:
from sys import stdin

k,s = list(map(int,stdin.readline().rstrip().split()))

point = 0

for i in range(k+1):

    for j in range(k+1):

        if i+j > s:

            continue

        elif s-(i+j) <= k:

            point += 1

print(point)

from sys import stdin

k,s = list(map(int,stdin.readline().rstrip().split()))

point = 0

for i in range(k+1):

    for j in range(k+1):

        if 0 <= s-(i+j) <= k:

            point += 1

print(point)

from sys import stdin

k, s = list(map(int, stdin.readline().rstrip().split()))
point = 0
for i in range(k + 1):
    for j in range(k + 1):
        if i + j > s:
            continue
        elif s - (i + j) <= k:
            point += 1
print(point)

from sys import stdin

k, s = list(map(int, stdin.readline().rstrip().split()))
point = 0
for i in range(k + 1):
    for j in range(k + 1):
        if 0 <= s - (i + j) <= k:
            point += 1
print(point)

-        if i + j > s:
-            continue
-        elif s - (i + j) <= k:
+        if 0 <= s - (i + j) <= k:


Input:
def calc_median(X):

    #中央値計算

    Xl = len(X)

    if Xl % 2:

        ret = X[(Xl + 1) // 2 - 1]

    else:

        ret = (X[Xl // 2 - 1] + X[Xl // 2]) / 2

    return ret

N = int(eval(input()))

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

A = [AB[i][0] for i in range(N)]

B = [AB[i][1] for i in range(N)]

A.sort()

B.sort()

AM = calc_median(A)

BM = calc_median(B)

if N % 2:

    ans = BM - AM + 1

else:

    ans = int((BM - AM) * 2 + 1)

print(ans)

def calc_median(X):

    #中央値計算

    Xl = len(X)

    if Xl % 2:

        ret = X[(Xl + 1) // 2 - 1]

    else:

        ret = (X[Xl // 2 - 1] + X[Xl // 2]) / 2

    return ret

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

A = sorted(AB[::2])

B = sorted(AB[1::2])

AM = calc_median(A)

BM = calc_median(B)

if N % 2:

    ans = BM - AM + 1

else:

    ans = int((BM - AM) * 2 + 1)

print(ans)

def calc_median(X):
    # 中央値計算
    Xl = len(X)
    if Xl % 2:
        ret = X[(Xl + 1) // 2 - 1]
    else:
        ret = (X[Xl // 2 - 1] + X[Xl // 2]) / 2
    return ret

N = int(eval(input()))
AB = [list(map(int, input().split())) for _ in range(N)]
A = [AB[i][0] for i in range(N)]
B = [AB[i][1] for i in range(N)]
A.sort()
B.sort()
AM = calc_median(A)
BM = calc_median(B)
if N % 2:
    ans = BM - AM + 1
else:
    ans = int((BM - AM) * 2 + 1)
print(ans)

def calc_median(X):
    # 中央値計算
    Xl = len(X)
    if Xl % 2:
        ret = X[(Xl + 1) // 2 - 1]
    else:
        ret = (X[Xl // 2 - 1] + X[Xl // 2]) / 2
    return ret

N, *AB = list(map(int, open(0).read().split()))
A = sorted(AB[::2])
B = sorted(AB[1::2])
AM = calc_median(A)
BM = calc_median(B)
if N % 2:
    ans = BM - AM + 1
else:
    ans = int((BM - AM) * 2 + 1)
print(ans)

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

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


Input:
def is_palindrome(s: str) -> bool:

    return s[:len(s) // 2] == s[-1 * (len(s) // 2):][::-1]

N = eval(input())

print(('Yes' if is_palindrome(N) else 'No'))

def is_palindrome(s: str) -> bool:

    return s == s[::-1]

N = eval(input())

print(('Yes' if is_palindrome(N) else 'No'))

def is_palindrome(s: str) -> bool:
    return s[: len(s) // 2] == s[-1 * (len(s) // 2) :][::-1]

N = eval(input())
print(("Yes" if is_palindrome(N) else "No"))

def is_palindrome(s: str) -> bool:
    return s == s[::-1]

N = eval(input())
print(("Yes" if is_palindrome(N) else "No"))


Input:
a, b, c = list(map(str, input().split()))

print((a[0] + b[0] + c[0]))

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

print((a[0].upper() + b[0].upper() + c[0].upper()))


Input:
def solve_knapsack(s, n, v, w):

	dp = [[0 for x in range(s+1)] for x in range(n+1)]

	for i in range(n):

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

			if w[i] > j:

				dp[i+1][j] = dp[i][j]

			else:

				dp[i+1][j] = max(dp[i][j], max(dp[i+1][j-w[i]]+v[i], dp[i][j-w[i]]+v[i]))

	return dp[n][s]

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

v = [0]*n

w = [0]*n

for i in range(n):

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

print((solve_knapsack(s, n, v, w)))

def knapsack(n,W,v,w):

	dp=[[0 for x in range(W+1)] for x in range(n+1)]

	for i in range(n):

		vl = v[i]

		wt = w[i]

		for j in range(W+1):

			if j < w[i]:

				dp[i+1][j]=dp[i][j]

			else:

				dp[i+1][j]=max(dp[i][j],max(dp[i][j-wt]+vl,dp[i+1][j-wt]+vl))

	return dp[n][W]

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

v = [0]*n

w = [0]*n

for i in range(n):

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

print((knapsack(n,W,v,w)))

def solve_knapsack(s, n, v, w):
    dp = [[0 for x in range(s + 1)] for x in range(n + 1)]
    for i in range(n):
        for j in range(1, s + 1):
            if w[i] > j:
                dp[i + 1][j] = dp[i][j]
            else:
                dp[i + 1][j] = max(
                    dp[i][j], max(dp[i + 1][j - w[i]] + v[i], dp[i][j - w[i]] + v[i])
                )
    return dp[n][s]

n, s = list(map(int, input().split()))
v = [0] * n
w = [0] * n
for i in range(n):
    v[i], w[i] = list(map(int, input().split()))
print((solve_knapsack(s, n, v, w)))

def knapsack(n, W, v, w):
    dp = [[0 for x in range(W + 1)] for x in range(n + 1)]
    for i in range(n):
        vl = v[i]
        wt = w[i]
        for j in range(W + 1):
            if j < w[i]:
                dp[i + 1][j] = dp[i][j]
            else:
                dp[i + 1][j] = max(
                    dp[i][j], max(dp[i][j - wt] + vl, dp[i + 1][j - wt] + vl)
                )
    return dp[n][W]

n, W = list(map(int, input().split()))
v = [0] * n
w = [0] * n
for i in range(n):
    v[i], w[i] = list(map(int, input().split()))
print((knapsack(n, W, v, w)))

-    dp = [[0 for x in range(s + 1)] for x in range(n + 1)]

+    dp = [[0 for x in range(W + 1)] for x in range(n + 1)]

+                    dp[i][j], max(dp[i][j - wt] + vl, dp[i + 1][j - wt] + vl)


Input:
from operator import itemgetter

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

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

ab.sort(key=itemgetter(0))

result = 0

for e in ab:

  count = min(m, e[1])

  result += e[0] * count

  m = max(m-count, 0)

print(result)

n, m = [int(x) for x in input().split()]

a = sorted([[int(x) for x in input().split()] for _ in range(n)], key=lambda x: x[0])

result = 0

for x in a:

  cnt = min(m, x[1])

  result += x[0] * cnt

  m -= cnt

print(result)

from operator import itemgetter

n, m = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key=itemgetter(0))
result = 0
for e in ab:
    count = min(m, e[1])
    result += e[0] * count
    m = max(m - count, 0)
print(result)

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

+n, m = [int(x) for x in input().split()]

+a = sorted([[int(x) for x in input().split()] for _ in range(n)], key=lambda x: x[0])


Input:
S = str(eval(input()))

Q = int(eval(input()))

hanten = 0

front = ""

end = ""

for i in range(Q):

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

  if query[0] == "1":

    hanten += 1

    hanten = hanten % 2

  else:

    if query[1] == "1":

      if hanten == 0:

        front = query[2] + front

      else:

        end = end + query[2]

    else:

      if hanten == 0:

        end = end + query[2]

      else:

        front = query[2] + front

ans = front + S + end

if hanten == 1:

  ans = ans[::-1]

print(ans)

S = str(eval(input()))

Q = int(eval(input()))

hanten = 0

front = ""

end = ""

for i in range(Q):

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

  if query[0] == "1":

    hanten += 1

    hanten = hanten % 2

  else:

    if query[1] == "1":

      if hanten == 0:

        front = front + query[2]

      else:

        end = end + query[2]

    else:

      if hanten == 0:

        end = end + query[2]

      else:

        front = front + query[2]

front = front[::-1]

ans = front + S + end

if hanten == 1:

  ans = ans[::-1]

print(ans)

-                front = query[2] + front

+                front = front + query[2]

-                front = query[2] + front

+                front = front + query[2]


Input:
from math import sqrt, ceil

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

c_a = set()

c_b = set()

for i in range(1, ceil(sqrt(a))+1):

  if a % i == 0:

    c_a.add(i)

    if i > 1:

        while a % i == 0:

            a = a // i

if a != 1:

    c_a.add(a)

for j in range(1, ceil(sqrt(b))+1):

  if b % j == 0:

    c_b.add(j)

    if j > 1:

        while b % j == 0:

            b = b // j

if b != 1:

    c_b.add(b)

ans = c_a.intersection(c_b)

print((len(ans)))

from math import sqrt, ceil

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

def gcd(a, b):

  x, y = (a, b) if a > b else (b, a)

  while y > 0:

    x, y = y, x % y

  return x

d = gcd(a, b)

ans = 1

for i in range(2, ceil(sqrt(d))+1):

  if d % i == 0:

    ans += 1

    while(d % i == 0):

      d = d / i

if d != 1:

    ans += 1

print(ans)

from math import sqrt, ceil

a, b = list(map(int, input().split()))
c_a = set()
c_b = set()
for i in range(1, ceil(sqrt(a)) + 1):
    if a % i == 0:
        c_a.add(i)
        if i > 1:
            while a % i == 0:
                a = a // i
if a != 1:
    c_a.add(a)
for j in range(1, ceil(sqrt(b)) + 1):
    if b % j == 0:
        c_b.add(j)
        if j > 1:
            while b % j == 0:
                b = b // j
if b != 1:
    c_b.add(b)
ans = c_a.intersection(c_b)
print((len(ans)))

from math import sqrt, ceil

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

def gcd(a, b):
    x, y = (a, b) if a > b else (b, a)
    while y > 0:
        x, y = y, x % y
    return x

d = gcd(a, b)
ans = 1
for i in range(2, ceil(sqrt(d)) + 1):
    if d % i == 0:
        ans += 1
        while d % i == 0:
            d = d / i
if d != 1:
    ans += 1
print(ans)

-c_a = set()
-c_b = set()
-for i in range(1, ceil(sqrt(a)) + 1):
-    if a % i == 0:
-        c_a.add(i)
-        if i > 1:
-            while a % i == 0:
-                a = a // i
-if a != 1:
-    c_a.add(a)
-for j in range(1, ceil(sqrt(b)) + 1):
-    if b % j == 0:
-        c_b.add(j)
-        if j > 1:
-            while b % j == 0:
-                b = b // j
-if b != 1:
-    c_b.add(b)
-ans = c_a.intersection(c_b)
-print((len(ans)))
+
+
+def gcd(a, b):
+    x, y = (a, b) if a > b else (b, a)
+    while y > 0:
+        x, y = y, x % y
+    return x
+
+
+d = gcd(a, b)
+ans = 1
+for i in range(2, ceil(sqrt(d)) + 1):
+    if d % i == 0:
+        ans += 1
+        while d % i == 0:
+            d = d / i
+if d != 1:
+    ans += 1
+print(ans)


Input:
from collections import defaultdict

from bisect import bisect_right

def sol():

    S = eval(input())

    T = eval(input())

    setS = set(S)

    setT = set(T)

    for t in setT:

        if not t in setS:

            print('-1')

            return

    posS = defaultdict(list)

    for i, s in enumerate(S):

        posS[s].append(i)

    for s in enumerate(S):

        posS[s].sort()

    prev = -1

    ans = 0

    N = len(S)

    for t in T:

        next = bisect_right(posS[t], prev)

        if next >= len(posS[t]):

            ans += N - prev

            ans += posS[t][0]

            prev = posS[t][0]

        else:

            ans += posS[t][next] - prev

            prev = posS[t][next]

    print(ans)

sol()

from bisect import bisect_left

S = eval(input())

T = eval(input())

if not set(list(T)) <= set(list(S)):

    print((-1))

    exit()

sToI = {s: [] for s in set(list(S))}

for i, s in enumerate(S):

    sToI[s].append(i)

now = 0

R = 0

for t in T:

    I = sToI[t]

    nx = bisect_left(I, now)

    if nx == len(I):

        nx = 0

        R += 1

    now = I[nx] + 1

print((now + R * len(S)))

from collections import defaultdict
from bisect import bisect_right

def sol():
    S = eval(input())
    T = eval(input())
    setS = set(S)
    setT = set(T)
    for t in setT:
        if not t in setS:
            print("-1")
            return
    posS = defaultdict(list)
    for i, s in enumerate(S):
        posS[s].append(i)
    for s in enumerate(S):
        posS[s].sort()
    prev = -1
    ans = 0
    N = len(S)
    for t in T:
        next = bisect_right(posS[t], prev)
        if next >= len(posS[t]):
            ans += N - prev
            ans += posS[t][0]
            prev = posS[t][0]
        else:
            ans += posS[t][next] - prev
            prev = posS[t][next]
    print(ans)

sol()

-        next = bisect_right(posS[t], prev)

-            ans += posS[t][next] - prev


Input:
import sys

sys.setrecursionlimit(10**7)

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

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

def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし

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

def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり

def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

S = I()

mod = 10**9+7

kaijou = [1]

for i in range(1,S):

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

inv = [1]

for i in range(1,S):

    inv.append(pow(kaijou[i],mod-2,mod))

def nCr(n,r):

    if n < r:

        return 0

    return (kaijou[n]*inv[r]*inv[n-r]) % mod

ans = 0

for i in range(1,S//3+1):

    if S-3*i >= 0:

        ans += nCr(S-1-2*i,i-1)

        ans %= mod

print(ans)

import sys

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

S = I()

mod = 10**9+7

kaijou = [1]

for i in range(1,S):

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

inv = [1]

for i in range(1,S):

    inv.append(pow(kaijou[i],mod-2,mod))

def nCr(n,r):

    if n < r:

        return 0

    return (kaijou[n]*inv[r]*inv[n-r]) % mod

ans = 0

for i in range(1,S//3+1):

    ans += nCr(S-1-2*i,i-1)

    ans %= mod

print(ans)

import sys

sys.setrecursionlimit(10**7)

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

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

def LI():
    return list(map(int, sys.stdin.readline().rstrip().split()))  # 空白あり

def LI2():
    return list(map(int, sys.stdin.readline().rstrip()))  # 空白なし

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

def LS():
    return list(sys.stdin.readline().rstrip().split())  # 空白あり

def LS2():
    return list(sys.stdin.readline().rstrip())  # 空白なし

S = I()
mod = 10**9 + 7
kaijou = [1]
for i in range(1, S):
    kaijou.append((kaijou[-1] * i) % mod)
inv = [1]
for i in range(1, S):
    inv.append(pow(kaijou[i], mod - 2, mod))

def nCr(n, r):
    if n < r:
        return 0
    return (kaijou[n] * inv[r] * inv[n - r]) % mod

ans = 0
for i in range(1, S // 3 + 1):
    if S - 3 * i >= 0:
        ans += nCr(S - 1 - 2 * i, i - 1)
        ans %= mod
print(ans)

import sys

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

S = I()
mod = 10**9 + 7
kaijou = [1]
for i in range(1, S):
    kaijou.append((kaijou[-1] * i) % mod)
inv = [1]
for i in range(1, S):
    inv.append(pow(kaijou[i], mod - 2, mod))

def nCr(n, r):
    if n < r:
        return 0
    return (kaijou[n] * inv[r] * inv[n - r]) % mod

ans = 0
for i in range(1, S // 3 + 1):
    ans += nCr(S - 1 - 2 * i, i - 1)
    ans %= mod
print(ans)

-    return list(map(int, sys.stdin.readline().rstrip().split()))  # 空白あり

-    return list(map(int, sys.stdin.readline().rstrip()))  # 空白なし

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

-    return list(sys.stdin.readline().rstrip().split())  # 空白あり

-    return list(sys.stdin.readline().rstrip())  # 空白なし


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

l = [tuple(input().split()) for _ in range(m)]

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

for i in range(m):

    subs[int(l[i][0])-1].append(l[i][1])

ac, p = 0, 0

for j in range(n):

    if 'AC' in subs[j]:

        ac += 1

        for k in range(len(subs[j])):

                if subs[j][k] == 'WA':

                    p += 1

                else:

                    break

print((ac, p))

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

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

for i in range(m):

    x, y = input().split()

    rslts[int(x) - 1].append(y)

#print(rslts)

ac, p = 0, 0

for j in range(n):

    seq = rslts[j]

    if 'AC' in seq:

        ac += 1

        for k in seq:

            if k == 'WA':

                p += 1

            else:

                break

print((ac, p))

n, m = list(map(int, input().split()))
l = [tuple(input().split()) for _ in range(m)]
subs = [[] for _ in range(n)]
for i in range(m):
    subs[int(l[i][0]) - 1].append(l[i][1])
ac, p = 0, 0
for j in range(n):
    if "AC" in subs[j]:
        ac += 1
        for k in range(len(subs[j])):
            if subs[j][k] == "WA":
                p += 1
            else:
                break
print((ac, p))

n, m = list(map(int, input().split()))
rslts = [[] for _ in range(n)]
for i in range(m):
    x, y = input().split()
    rslts[int(x) - 1].append(y)
# print(rslts)
ac, p = 0, 0
for j in range(n):
    seq = rslts[j]
    if "AC" in seq:
        ac += 1
        for k in seq:
            if k == "WA":
                p += 1
            else:
                break
print((ac, p))

-l = [tuple(input().split()) for _ in range(m)]


Input:
from functools import lru_cache

N = int(eval(input()))

K = int(eval(input()))

@lru_cache(None)

def f(N, K):

    if K == 0: return 1

    if N < 10:

        if K == 1: return N

        return 0

    q, r = divmod(N, 10)

    ret = 0

    ret += f(q, K-1) * r

    ret += f(q-1, K-1) * (9-r)

    ret += f(q, K)

    return ret

print((f(N, K)))

S = eval(input())

n = len(S)

K = int(eval(input()))

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

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

for i in range(n):          # i:桁

    for j in range(K+1):    # j:非0の数

        for k in range(2):  # k:0->nと同じ数,1->nより小さい数

            nd = int(S[i])  #nd:nのi桁

            for d in range(10):

                ni, nj, nk = i+1, j, k

                if d != 0: nj += 1      # 非0の数が増える

                if nj > K: continue     # 非0の数がKを超えたら計算不要

                if k == 0:              # ここまでnと同じ場合

                    if d > nd: continue # nより大きくなるのでダメ

                    if d < nd: nk = 1   # nより小さくなるのでkは1に

                dp[ni][nj][nk] += dp[i][j][k]

ans = dp[n][K][0] + dp[n][K][1]

print(ans)

from functools import lru_cache

N = int(eval(input()))
K = int(eval(input()))

@lru_cache(None)
def f(N, K):
    if K == 0:
        return 1
    if N < 10:
        if K == 1:
            return N
        return 0
    q, r = divmod(N, 10)
    ret = 0
    ret += f(q, K - 1) * r
    ret += f(q - 1, K - 1) * (9 - r)
    ret += f(q, K)
    return ret

print((f(N, K)))

S = eval(input())
n = len(S)
K = int(eval(input()))
dp = [[[0] * 2 for _ in range(K + 1)] for _ in range(n + 1)]
dp[0][0][0] = 1
for i in range(n):  # i:桁
    for j in range(K + 1):  # j:非0の数
        for k in range(2):  # k:0->nと同じ数,1->nより小さい数
            nd = int(S[i])  # nd:nのi桁
            for d in range(10):
                ni, nj, nk = i + 1, j, k
                if d != 0:
                    nj += 1  # 非0の数が増える
                if nj > K:
                    continue  # 非0の数がKを超えたら計算不要
                if k == 0:  # ここまでnと同じ場合
                    if d > nd:
                        continue  # nより大きくなるのでダメ
                    if d < nd:
                        nk = 1  # nより小さくなるのでkは1に
                dp[ni][nj][nk] += dp[i][j][k]
ans = dp[n][K][0] + dp[n][K][1]
print(ans)

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

+        for k in range(2):  # k:0->nと同じ数,1->nより小さい数

+                ni, nj, nk = i + 1, j, k

+                    nj += 1  # 非0の数が増える

+                    continue  # 非0の数がKを超えたら計算不要

+                if k == 0:  # ここまでnと同じ場合

+                        continue  # nより大きくなるのでダメ

+                        nk = 1  # nより小さくなるのでkは1に


Input:
def main() :

    W, H, x, y, r = [int(i) for i in input().split()]

    if ((x-r)>=0) and ((x+r)<=W) and ((y-r)>=0) and ((y+r)<=H) :

        print("Yes")

    else :

        print("No")

if __name__ == '__main__' :

    main()

def main() :

    W, H, x, y, r = [int(i) for i in input().split()]

    if (r <= x <= W-r) and (r <= y <= H-r) :

        print("Yes")

    else :

        print("No")

if __name__ == '__main__' :

    main()

def main():
    W, H, x, y, r = [int(i) for i in input().split()]
    if ((x - r) >= 0) and ((x + r) <= W) and ((y - r) >= 0) and ((y + r) <= H):
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

def main():
    W, H, x, y, r = [int(i) for i in input().split()]
    if (r <= x <= W - r) and (r <= y <= H - r):
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()


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

x=min(K,abs(X)//D)

if X>0:

    X_=X-(D*x)

else:

    X_=X+(D*x)

k=K-x

if k%2!=0:

    ans=min(abs(X_-D),abs(X_+D))

else:

    ans=abs(X_)

print(ans)

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

X=abs(X)

k=min(K,X//D)

X_=X-(k*D)

K_=K-k

if K_%2!=0:

    ans=min(abs(X_-D),abs(X_+D))

else:

    ans=abs(X_)

print(ans)

X, K, D = list(map(int, input().split()))
x = min(K, abs(X) // D)
if X > 0:
    X_ = X - (D * x)
else:
    X_ = X + (D * x)
k = K - x
if k % 2 != 0:
    ans = min(abs(X_ - D), abs(X_ + D))
else:
    ans = abs(X_)
print(ans)

X, K, D = list(map(int, input().split()))
X = abs(X)
k = min(K, X // D)
X_ = X - (k * D)
K_ = K - k
if K_ % 2 != 0:
    ans = min(abs(X_ - D), abs(X_ + D))
else:
    ans = abs(X_)
print(ans)


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

if K == 0:

    print((N * N))

    exit()

ans = 0

for b in range(K + 1, N + 1):

    p = N // b

    ans += p * max(0,b - K) + max(0, N - p * b - K + 1)

print(ans)

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

if k==0:

    print((n**2))

    exit()

ans=0

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

    p=n//i

    q=n%i

    ans +=p*max(0,i-k)+max(0,q-k+1)

print(ans)

N, K = list(map(int, input().split()))
if K == 0:
    print((N * N))
    exit()
ans = 0
for b in range(K + 1, N + 1):
    p = N // b
    ans += p * max(0, b - K) + max(0, N - p * b - K + 1)
print(ans)

n, k = list(map(int, input().split()))
if k == 0:
    print((n**2))
    exit()
ans = 0
for i in range(k + 1, n + 1):
    p = n // i
    q = n % i
    ans += p * max(0, i - k) + max(0, q - k + 1)
print(ans)


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

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

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

MOD = 10**9 + 7

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

for si in range(n+1):

    dp[si][0] = 1

for ti in range(m+1):

    dp[0][ti] = 1

for si in range(n):

    for ti in range(m):

        if s[si] == t[ti]:

            dp[si+1][ti+1] = dp[si][ti+1] + dp[si+1][ti]

            dp[si+1][ti+1] %= MOD

        else:

            dp[si+1][ti+1] = dp[si][ti+1] + dp[si+1][ti] - dp[si][ti]

            dp[si+1][ti+1] %= MOD

print((dp[-1][-1] % MOD))

def count_cs(str1, str2, MOD):

    """文字列str1, str2の共通部分列(Common Subsequence, CS)を数え上げる。

    添字が異なる場合は異なる部分列として考える。

    計算量 O(|str1||str2|)

    """

    dp = [[0] * (len(str2) + 1) for _ in range(len(str1) + 1)]

    for i in range(len(str1)):

        for j in range(len(str2)):

            if str1[i] == str2[j]:

                dp[i + 1][j + 1] = dp[i + 1][j] + dp[i][j + 1] + 1

            else:

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

            dp[i + 1][j + 1] %= MOD

    return (dp[len(str1)][len(str2)] + 1) % MOD

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

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

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

MOD = 10 ** 9 + 7

print((count_cs(s, t, MOD)))

n, m = list(map(int, input().split()))
s = list(map(int, input().split()))
t = list(map(int, input().split()))
MOD = 10**9 + 7
dp = [[0] * (m + 1) for i in range(n + 1)]
for si in range(n + 1):
    dp[si][0] = 1
for ti in range(m + 1):
    dp[0][ti] = 1
for si in range(n):
    for ti in range(m):
        if s[si] == t[ti]:
            dp[si + 1][ti + 1] = dp[si][ti + 1] + dp[si + 1][ti]
            dp[si + 1][ti + 1] %= MOD
        else:
            dp[si + 1][ti + 1] = dp[si][ti + 1] + dp[si + 1][ti] - dp[si][ti]
            dp[si + 1][ti + 1] %= MOD
print((dp[-1][-1] % MOD))

def count_cs(str1, str2, MOD):
    """文字列str1, str2の共通部分列(Common Subsequence, CS)を数え上げる。
    添字が異なる場合は異なる部分列として考える。
    計算量 O(|str1||str2|)
    """
    dp = [[0] * (len(str2) + 1) for _ in range(len(str1) + 1)]
    for i in range(len(str1)):
        for j in range(len(str2)):
            if str1[i] == str2[j]:
                dp[i + 1][j + 1] = dp[i + 1][j] + dp[i][j + 1] + 1
            else:
                dp[i + 1][j + 1] = dp[i + 1][j] + dp[i][j + 1] - dp[i][j]
            dp[i + 1][j + 1] %= MOD
    return (dp[len(str1)][len(str2)] + 1) % MOD

n, m = list(map(int, input().split()))
s = list(map(int, input().split()))
t = list(map(int, input().split()))
MOD = 10**9 + 7
print((count_cs(s, t, MOD)))

+    """文字列str1, str2の共通部分列(Common Subsequence, CS)を数え上げる。

+    添字が異なる場合は異なる部分列として考える。

+    dp = [[0] * (len(str2) + 1) for _ in range(len(str1) + 1)]

+    return (dp[len(str1)][len(str2)] + 1) % MOD


Input:
#!/usr/bin/env python3

"""

数列777...は奇数故，Kが偶数だったら×

"""

from numba import njit

@njit(cache=True)

def func(a, b):

    return a * b

def main():

    import sys

    input = sys.stdin.readline

    K = int(eval(input()))

    # mod Kを考える(mod=module(剰余))

    x = 7 % K

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

        if x == 0:

            print(i)

            return

        x = (x * 10 + 7) % K

    print((-1))

if __name__ == '__main__':

    main()

# abc173a

def main():

    import sys

    input = sys.stdin.readline

    K = int(eval(input()))

    x = 7 % K

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

        if x == 0:

            print(i)

            return

        x = (x * 10 + 7) % K

    print((-1))

if __name__ == "__main__":

    main()

#!/usr/bin/env python3
"""
数列777...は奇数故，Kが偶数だったら×
"""
from numba import njit

@njit(cache=True)
def func(a, b):
    return a * b

def main():
    import sys

    input = sys.stdin.readline
    K = int(eval(input()))
    # mod Kを考える(mod=module(剰余))
    x = 7 % K
    for i in range(1, K + 1):
        if x == 0:
            print(i)
            return
        x = (x * 10 + 7) % K
    print((-1))

if __name__ == "__main__":
    main()

-#!/usr/bin/env python3
-"""
-数列777...は奇数故，Kが偶数だったら×
-"""
-from numba import njit
-@njit(cache=True)
-def func(a, b):
-    return a * b
+# abc173a
-    # mod Kを考える(mod=module(剰余))


Input:
def main():

    S = eval(input())

    S = set(S)

    if len(S) == 1:

        print("No")

    else:

        print("Yes")

if __name__ == '__main__':

    main()

def main():

    S = eval(input())

    if len(set(s for s in S)) == 1:

        print("No")

    else:

        print("Yes")

if __name__ == '__main__':

    main()

def main():
    S = eval(input())
    S = set(S)
    if len(S) == 1:
        print("No")
    else:
        print("Yes")

if __name__ == "__main__":
    main()

def main():
    S = eval(input())
    if len(set(s for s in S)) == 1:
        print("No")
    else:
        print("Yes")

if __name__ == "__main__":
    main()

-    S = set(S)
-    if len(S) == 1:
+    if len(set(s for s in S)) == 1:


Input:
s = list(eval(input()))

a = s.count("a")

b = s.count("b")

c = s.count("c")

if a == 1 and b == 1 and c == 1:

    print("Yes")

else:

    print("No")

s = eval(input())

if s.count('a') == 1 and s.count('b') == 1 and s.count('c'):

    print("Yes")

else:

    print("No")

s = eval(input())
if s.count("a") == 1 and s.count("b") == 1 and s.count("c"):
    print("Yes")
else:
    print("No")

+if s.count("a") == 1 and s.count("b") == 1 and s.count("c"):


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

r = N%K

print((min(r,K-r)))

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

n = N%K

print((min(n,K-n)))

N, K = list(map(int, input().split()))
r = N % K
print((min(r, K - r)))

N, K = list(map(int, input().split()))
n = N % K
print((min(n, K - n)))

-r = N % K
-print((min(r, K - r)))
+n = N % K
+print((min(n, K - n)))


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

max_n100 = int(eval(input()))

max_n50 = int(eval(input()))

amount = int(eval(input()))

count = 0

for n500 in range(max_n500 + 1):

    for n100 in range(max_n100 + 1):

        for n50 in range(max_n50 + 1):

            if n500 * 500 + n100 * 100 + n50 * 50 == amount:

                count += 1

print(count)

max_n500 = int(eval(input()))

max_n100 = int(eval(input()))

max_n50 = int(eval(input()))

target_amount = int(eval(input()))

count = 0

for n500 in range(max_n500 + 1):

    amount_500 = n500 * 500

    if amount_500 > target_amount:

        break

    for n100 in range(max_n100 + 1):

        amount_100 = n100 * 100

        amount_500_100 = amount_500 + amount_100

        if amount_500_100 > target_amount:

            break

        for n50 in range(max_n50 + 1):

            amount_50 = n50 * 50

            current_amount = amount_500_100 + amount_50

            if current_amount == target_amount:

                count += 1

print(count)

+        if amount_500_100 > target_amount:

+            current_amount = amount_500_100 + amount_50

+            if current_amount == target_amount:


Input:
def Base_10_to_n(X, n):

    X_dumy = X

    out = ''

    while X_dumy>0:

        out = str(X_dumy%n)+out

        X_dumy = int(X_dumy/n)

    return out

S = eval(input())

N = len(S)-1

ans = 0

for n in range(2**N):

	b = Base_10_to_n(n,2).rjust(N,'0')

	tmp = []

	ind = 0

	for i in range(N):

		if b[i] == '1':

			tmp.append(int(S[ind:i+1]))

			ind = i+1

	tmp.append(int(S[ind:]))

	ans += sum(tmp)

print(ans)

import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

S = readline().rstrip().decode('utf_8')

def F(S):

	yield int(S)

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

		left = S[:i+1]

		right = S[i+1:]

		x = int(left)

		for y in F(right):

			yield x+y

print((sum(F(S))))

def Base_10_to_n(X, n):
    X_dumy = X
    out = ""
    while X_dumy > 0:
        out = str(X_dumy % n) + out
        X_dumy = int(X_dumy / n)
    return out

S = eval(input())
N = len(S) - 1
ans = 0
for n in range(2**N):
    b = Base_10_to_n(n, 2).rjust(N, "0")
    tmp = []
    ind = 0
    for i in range(N):
        if b[i] == "1":
            tmp.append(int(S[ind : i + 1]))
            ind = i + 1
    tmp.append(int(S[ind:]))
    ans += sum(tmp)
print(ans)

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
S = readline().rstrip().decode("utf_8")

def F(S):
    yield int(S)
    for i in range(len(S) - 1):
        left = S[: i + 1]
        right = S[i + 1 :]
        x = int(left)
        for y in F(right):
            yield x + y

print((sum(F(S))))

-            tmp.append(int(S[ind : i + 1]))


Input:
import sys

input = sys.stdin.readline

def main():

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

    a = [K-Q]*N

    for _ in range(Q):

        a[int(eval(input()))-1] += 1

    for i in range(N):

        if a[i] > 0:

            print('Yes')

        else:

            print('No')

if __name__ == '__main__':

    main()

import sys

input = sys.stdin.readline

def main():

    ans = ''

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

    a = [K-Q]*N

    for _ in range(Q):

        a[int(eval(input()))-1] += 1

    for i in a:

        if i > 0:

          ans += 'Yes'

        else:

          ans += 'No'

        ans += '\n'

    print(ans)

if __name__ == '__main__':

    main()

import sys

input = sys.stdin.readline

def main():
    N, K, Q = list(map(int, input().split()))
    a = [K - Q] * N
    for _ in range(Q):
        a[int(eval(input())) - 1] += 1
    for i in range(N):
        if a[i] > 0:
            print("Yes")
        else:
            print("No")

if __name__ == "__main__":
    main()

import sys

input = sys.stdin.readline

def main():
    ans = ""
    N, K, Q = list(map(int, input().split()))
    a = [K - Q] * N
    for _ in range(Q):
        a[int(eval(input())) - 1] += 1
    for i in a:
        if i > 0:
            ans += "Yes"
        else:
            ans += "No"
        ans += "\n"
    print(ans)

if __name__ == "__main__":
    main()

+    ans = ""
-    for i in range(N):
-        if a[i] > 0:
-            print("Yes")
+    for i in a:
+        if i > 0:
+            ans += "Yes"
-            print("No")
+            ans += "No"
+        ans += "\n"
+    print(ans)


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

now=X

num=1

while(now<=Y):

    if now*2>Y:

        break

    now=now*2

    num+=1

print(num)

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

ans=1

while(2*X<=Y):

    X*=2

    ans+=1

print(ans)

X, Y = list(map(int, input().split()))
now = X
num = 1
while now <= Y:
    if now * 2 > Y:
        break
    now = now * 2
    num += 1
print(num)

X, Y = list(map(int, input().split()))
ans = 1
while 2 * X <= Y:
    X *= 2
    ans += 1
print(ans)

-now = X
-num = 1
-while now <= Y:
-    if now * 2 > Y:
-        break
-    now = now * 2
-    num += 1
-print(num)
+ans = 1
+while 2 * X <= Y:
+    X *= 2
+    ans += 1
+print(ans)


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

xn = [0] * N

yn = [0] * N

hn = [0] * N

xyh = [[int(j) for j in input().split()] for i in range(N)]

div = 0

for Cx in range(101):

    for Cy in range(101):

        for i in range(N):

            xi, yi, hi = xyh[i]

            if 0 < hi:

                h = abs(xi - Cx) + abs(yi - Cy) + hi

                if div in [0, 2]:

                    H = h

                    div = 1

                else:

                    if (H != h):

                        div = 2

                        break

        if div == 2:

            continue

        for i in range(N):

            xi, yi, hi = xyh[i]

            if 0 == hi:

                h = abs(xi - Cx) + abs(yi - Cy)

                if h < H:

                    div = 2

                    break

        if div == 2:

            continue

        print((Cx, Cy, H))

        break

    if div == 1:

        break

def solve():

    for Cx in range(101):

        for Cy in range(101):

            div = 0

            for i in range(N):

                xi, yi, hi = xyh[i]

                if 0 < hi:

                    h = abs(xi - Cx) + abs(yi - Cy) + hi

                    if div in [0, 2]:

                        H = h

                        div = 1

                    else:

                        if (H != h):

                            div = 2

                            break

            if div == 2:

                continue

            for i in range(N):

                xi, yi, hi = xyh[i]

                if 0 == hi:

                    h = abs(xi - Cx) + abs(yi - Cy)

                    if h < H:

                        div = 2

                        break

            if div == 2:

                continue

            return Cx, Cy, H

N = int(eval(input()))

xn = [0] * N

yn = [0] * N

hn = [0] * N

xyh = [[int(j) for j in input().split()] for i in range(N)]

Cx, Cy, H = solve()

print((Cx, Cy, H))

N = int(eval(input()))
xn = [0] * N
yn = [0] * N
hn = [0] * N
xyh = [[int(j) for j in input().split()] for i in range(N)]
div = 0
for Cx in range(101):
    for Cy in range(101):
        for i in range(N):
            xi, yi, hi = xyh[i]
            if 0 < hi:
                h = abs(xi - Cx) + abs(yi - Cy) + hi
                if div in [0, 2]:
                    H = h
                    div = 1
                else:
                    if H != h:
                        div = 2
                        break
        if div == 2:
            continue
        for i in range(N):
            xi, yi, hi = xyh[i]
            if 0 == hi:
                h = abs(xi - Cx) + abs(yi - Cy)
                if h < H:
                    div = 2
                    break
        if div == 2:
            continue
        print((Cx, Cy, H))
        break
    if div == 1:
        break

def solve():
    for Cx in range(101):
        for Cy in range(101):
            div = 0
            for i in range(N):
                xi, yi, hi = xyh[i]
                if 0 < hi:
                    h = abs(xi - Cx) + abs(yi - Cy) + hi
                    if div in [0, 2]:
                        H = h
                        div = 1
                    else:
                        if H != h:
                            div = 2
                            break
            if div == 2:
                continue
            for i in range(N):
                xi, yi, hi = xyh[i]
                if 0 == hi:
                    h = abs(xi - Cx) + abs(yi - Cy)
                    if h < H:
                        div = 2
                        break
            if div == 2:
                continue
            return Cx, Cy, H

N = int(eval(input()))
xn = [0] * N
yn = [0] * N
hn = [0] * N
xyh = [[int(j) for j in input().split()] for i in range(N)]
Cx, Cy, H = solve()
print((Cx, Cy, H))

+                    h = abs(xi - Cx) + abs(yi - Cy) + hi

+                    h = abs(xi - Cx) + abs(yi - Cy)

-                h = abs(xi - Cx) + abs(yi - Cy) + hi

-                h = abs(xi - Cx) + abs(yi - Cy)


Input:
def getN():

    return int(eval(input()))

def getNM():

    return list(map(int, input().split()))

def getList():

    return list(map(int, input().split()))

from collections import defaultdict, deque

from sys import exit

import math

import copy

from bisect import bisect_left, bisect_right

from heapq import *

import sys

# sys.setrecursionlimit(1000000)

INF = 10 ** 17

MOD = 1000000007

from fractions import *

def inverse(f):

    # return Fraction(f.denominator,f.numerator)

    return 1/f

def combmod(n, k, mod=MOD):

    ret = 1

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

        ret *= i

        ret %= mod

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

        ret *= pow(i, mod - 2, mod)

        ret %= mod

    return ret

def bunsu(n):

    ret = []

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

        if n % i == 0:

            tmp = 0

            while(True):

                if n % i == 0:

                    tmp += 1

                    n //= i

                else:

                    break

            ret.append((i, tmp))

    ret.append((n, 1))

    return ret

def solve():

    n = getN()

    bun = bunsu(n)

    # print(bun)

    acc = []

    tmp = 0

    for i in range(10000):

        tmp += i

        acc.append(tmp)

    ans = 0

    for b, cnt in bun:

        if b == 1:

            continue

        ans += bisect_right(acc, cnt) - 1

    print(ans)

def main():

    # n = getN()

    # for _ in range(n):

    solve()

if __name__ == "__main__":

    solve()

def getN():

    return int(eval(input()))

def getNM():

    return list(map(int, input().split()))

def getList():

    return list(map(int, input().split()))

from collections import defaultdict, deque, Counter

from sys import exit

import math

import copy

from bisect import bisect_left, bisect_right

from heapq import *

import sys

# sys.setrecursionlimit(1000000)

INF = 10 ** 17

MOD = 1000000007

from fractions import *

def inverse(f):

    # return Fraction(f.denominator,f.numerator)

    return 1 / f

def combmod(n, k, mod=MOD):

    ret = 1

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

        ret *= i

        ret %= mod

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

        ret *= pow(i, mod - 2, mod)

        ret %= mod

    return ret

MOD = 10 ** 9 + 7

def yaku(n):

    res = []

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

        tmp = 0

        while(True):

            if n % i == 0:

                tmp += 1

                n //= i

            else:

                break

        if tmp != 0:

            res.append((tmp, i))

    if n != 1:

        res.append((1, n))

    return res

def solve():

    n = getN()

    acc = [0]

    tmp = 0

    for i in range(1, 10**6):

        tmp += i

        acc.append(tmp)

    res = yaku(n)

    ans = 0

    for y in res:

        ans += bisect_right(acc, y[0]) - 1

    # print(res)

    print(ans)

def main():

    n = getN()

    for _ in range(n):

        solve()

if __name__ == "__main__":

    solve()

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

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

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

from collections import defaultdict, deque
from sys import exit
import math
import copy
from bisect import bisect_left, bisect_right
from heapq import *
import sys

# sys.setrecursionlimit(1000000)
INF = 10**17
MOD = 1000000007
from fractions import *

def inverse(f):
    # return Fraction(f.denominator,f.numerator)
    return 1 / f

def combmod(n, k, mod=MOD):
    ret = 1
    for i in range(n - k + 1, n + 1):
        ret *= i
        ret %= mod
    for i in range(1, k + 1):
        ret *= pow(i, mod - 2, mod)
        ret %= mod
    return ret

def bunsu(n):
    ret = []
    for i in range(2, int(math.sqrt(n)) + 1):
        if n % i == 0:
            tmp = 0
            while True:
                if n % i == 0:
                    tmp += 1
                    n //= i
                else:
                    break
            ret.append((i, tmp))
    ret.append((n, 1))
    return ret

def solve():
    n = getN()
    bun = bunsu(n)
    # print(bun)
    acc = []
    tmp = 0
    for i in range(10000):
        tmp += i
        acc.append(tmp)
    ans = 0
    for b, cnt in bun:
        if b == 1:
            continue
        ans += bisect_right(acc, cnt) - 1
    print(ans)

def main():
    # n = getN()
    # for _ in range(n):
    solve()

if __name__ == "__main__":
    solve()

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

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

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

from collections import defaultdict, deque, Counter
from sys import exit
import math
import copy
from bisect import bisect_left, bisect_right
from heapq import *
import sys

# sys.setrecursionlimit(1000000)
INF = 10**17
MOD = 1000000007
from fractions import *

def inverse(f):
    # return Fraction(f.denominator,f.numerator)
    return 1 / f

def combmod(n, k, mod=MOD):
    ret = 1
    for i in range(n - k + 1, n + 1):
        ret *= i
        ret %= mod
    for i in range(1, k + 1):
        ret *= pow(i, mod - 2, mod)
        ret %= mod
    return ret

MOD = 10**9 + 7

def yaku(n):
    res = []
    for i in range(2, int(math.sqrt(n)) + 2):
        tmp = 0
        while True:
            if n % i == 0:
                tmp += 1
                n //= i
            else:
                break
        if tmp != 0:
            res.append((tmp, i))
    if n != 1:
        res.append((1, n))
    return res

def solve():
    n = getN()
    acc = [0]
    tmp = 0
    for i in range(1, 10**6):
        tmp += i
        acc.append(tmp)
    res = yaku(n)
    ans = 0
    for y in res:
        ans += bisect_right(acc, y[0]) - 1
    # print(res)
    print(ans)

def main():
    n = getN()
    for _ in range(n):
        solve()

if __name__ == "__main__":
    solve()

-from collections import defaultdict, deque

+from collections import defaultdict, deque, Counter

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

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

-        ans += bisect_right(acc, cnt) - 1

+        ans += bisect_right(acc, y[0]) - 1


Input:
import sys

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

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

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

def L():return list(NM())

n,q=NM()

c=[0]+L()

Q=[L()+[i] for i in range(q)]

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

ans=[0]*(q)

lastapp=[0 for i in range(n+1)]

No=2

while No<=n:

    No*=2

tree=[0]*(2*No)

def update(k,x):

    k+=No-1

    tree[k]=x

    while k>0:

        k=(k-1)//2

        tree[k]=tree[k*2+1]+tree[k*2+2]

def add(k,x):

    k+=No-1

    while k>=0:

        tree[k]+=x

        k=(k-1)//2

def query(l,r):

    L=l+No-1

    R=r+No-1

    s=0

    while L<=R:

        if R&1:

            s+=tree[R]

            R-=2

        else:

            R-=1

        if L&1:

            L-=1

        else:

            s+=tree[L]

        L>>=1;R>>=1

    return s

j=1

for l,r,i in Q:

    while j<=r:

        t=c[j]

        add(lastapp[t],-1)

        add(j,1)

        lastapp[t]=j

        j+=1

    ans[i]=query(l,r)

for i in ans:

    print(i)

import sys

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

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

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

def L():return list(NM())

n,q=NM()

c=[0]+L()

Q=[L()+[i] for i in range(q)]

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

ans=[0]*(q)

lastapp=[0 for i in range(n+1)]

No=2

while No<=n:

    No*=2

BIT=[0]*(No+1)

def addbit(i,x):

    while i<=No:

        BIT[i]+=x

        i+= i&-i

def getsum(i):

    s=0

    while i:

        s+=BIT[i]

        i-= i&-i

    return s

def sumbit(l,r):

    return getsum(r)-getsum(l-1)

j=1

for l,r,i in Q:

    while j<=r:

        t=c[j]

        if lastapp[t]:

            addbit(lastapp[t],-1)

        addbit(j,1)

        lastapp[t]=j

        j+=1

    ans[i]=sumbit(l,r)

for i in ans:

    print(i)

import sys

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

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

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

def L():
    return list(NM())

n, q = NM()
c = [0] + L()
Q = [L() + [i] for i in range(q)]
Q.sort(key=lambda x: x[1])
ans = [0] * (q)
lastapp = [0 for i in range(n + 1)]
No = 2
while No <= n:
    No *= 2
tree = [0] * (2 * No)

def update(k, x):
    k += No - 1
    tree[k] = x
    while k > 0:
        k = (k - 1) // 2
        tree[k] = tree[k * 2 + 1] + tree[k * 2 + 2]

def add(k, x):
    k += No - 1
    while k >= 0:
        tree[k] += x
        k = (k - 1) // 2

def query(l, r):
    L = l + No - 1
    R = r + No - 1
    s = 0
    while L <= R:
        if R & 1:
            s += tree[R]
            R -= 2
        else:
            R -= 1
        if L & 1:
            L -= 1
        else:
            s += tree[L]
        L >>= 1
        R >>= 1
    return s

j = 1
for l, r, i in Q:
    while j <= r:
        t = c[j]
        add(lastapp[t], -1)
        add(j, 1)
        lastapp[t] = j
        j += 1
    ans[i] = query(l, r)
for i in ans:
    print(i)

import sys

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

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

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

def L():
    return list(NM())

n, q = NM()
c = [0] + L()
Q = [L() + [i] for i in range(q)]
Q.sort(key=lambda x: x[1])
ans = [0] * (q)
lastapp = [0 for i in range(n + 1)]
No = 2
while No <= n:
    No *= 2
BIT = [0] * (No + 1)

def addbit(i, x):
    while i <= No:
        BIT[i] += x
        i += i & -i

def getsum(i):
    s = 0
    while i:
        s += BIT[i]
        i -= i & -i
    return s

def sumbit(l, r):
    return getsum(r) - getsum(l - 1)

j = 1
for l, r, i in Q:
    while j <= r:
        t = c[j]
        if lastapp[t]:
            addbit(lastapp[t], -1)
        addbit(j, 1)
        lastapp[t] = j
        j += 1
    ans[i] = sumbit(l, r)
for i in ans:
    print(i)


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

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

for i in map(int, input().split()):

  h -= i

if h <= 0 :

  print("Yes")

else:

  print("No")

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

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

b = sum(a)

if h <= b:

  print('Yes')

else:

  print('No')

# -*- coding:utf-8 -*-
h, n = list(map(int, input().split()))
for i in map(int, input().split()):
    h -= i
if h <= 0:
    print("Yes")
else:
    print("No")

h, n = list(map(int, input().split()))
a = list(map(int, input().split()))
b = sum(a)
if h <= b:
    print("Yes")
else:
    print("No")

-# -*- coding:utf-8 -*-
-for i in map(int, input().split()):
-    h -= i
-if h <= 0:
+a = list(map(int, input().split()))
+b = sum(a)
+if h <= b: