Input:
from queue import Queue

class Process:

	def __init__(self, name, time):

		self.name = name

		self.time = int(time)

	def set_time(self, time):

		self.time = time

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

queue = Queue()

for i in range(n):

	name, time = list(map(str, input().split()))

	queue.put(Process(name, time))

time_elapsed = 0

while queue.empty() != True:

	process = queue.get()

	time = process.time

	if time > q:

		process.set_time(time - q)

		time_elapsed += q

		queue.put(process)

	else:

		time_elapsed += time

		print((process.name + ' ' + str(time_elapsed)))

class Node:

	def __init__(self, value):

		self.value = value

		self.next = None

class SimpleQeueue:

	def __init__(self):

		self.size = 0

		self.head = None

		self.tail = None

		return

	def enqueue(self, value):

		node = Node(value)

		if self.head == None:

			self.head = node

			self.tail = node

		else:

			self.tail.next = node

			self.tail = node

		self.size += 1

	def dequeue(self):

		if self.is_empty() == True:

			return None

		node = self.head

		self.head = self.head.__next__

		self.size -= 1

		if self.is_empty() == True:

			self.head = None

			self.tail = None

		return node.value

	def peek(self):

		if self.is_empty() == True:

			return None

		return self.head.value

	def get_size(self):

		return self.size

	def is_empty(self):

		return self.size == 0

	def __str__(self):

		str_ = '['

		current = self.head

		while current != None:

			str_ += str(current.value)

			current = current.__next__

			if current != None:

				str_ += ', '

		str_ += ']['

		if self.tail != None:

			str_ += str(self.tail.value)

		str_ += ']'

		return str_

class Process:

	def __init__(self, name, time):

		self.name = name

		self.time = int(time)

	def set_time(self, time):

		self.time = time

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

myqueue = SimpleQeueue()

for i in range(n):

	name, time = list(map(str, input().split()))

	myqueue.enqueue(Process(name, time))

time_elapsed = 0

while myqueue.is_empty() != True:

	process = myqueue.dequeue()

	time = process.time

	if time > q:

		process.set_time(time - q)

		time_elapsed += q

		myqueue.enqueue(process)

	else:

		time_elapsed += time

		print((process.name + ' ' + str(time_elapsed)))

from queue import Queue

class Process:
    def __init__(self, name, time):
        self.name = name
        self.time = int(time)

    def set_time(self, time):
        self.time = time

n, q = list(map(int, input().split()))
queue = Queue()
for i in range(n):
    name, time = list(map(str, input().split()))
    queue.put(Process(name, time))
time_elapsed = 0
while queue.empty() != True:
    process = queue.get()
    time = process.time
    if time > q:
        process.set_time(time - q)
        time_elapsed += q
        queue.put(process)
    else:
        time_elapsed += time
        print((process.name + " " + str(time_elapsed)))

class Node:
    def __init__(self, value):
        self.value = value
        self.next = None

class SimpleQeueue:
    def __init__(self):
        self.size = 0
        self.head = None
        self.tail = None
        return

    def enqueue(self, value):
        node = Node(value)
        if self.head == None:
            self.head = node
            self.tail = node
        else:
            self.tail.next = node
            self.tail = node
        self.size += 1

    def dequeue(self):
        if self.is_empty() == True:
            return None
        node = self.head
        self.head = self.head.__next__
        self.size -= 1
        if self.is_empty() == True:
            self.head = None
            self.tail = None
        return node.value

    def peek(self):
        if self.is_empty() == True:
            return None
        return self.head.value

    def get_size(self):
        return self.size

    def is_empty(self):
        return self.size == 0

    def __str__(self):
        str_ = "["
        current = self.head
        while current != None:
            str_ += str(current.value)
            current = current.__next__
            if current != None:
                str_ += ", "
        str_ += "]["
        if self.tail != None:
            str_ += str(self.tail.value)
        str_ += "]"
        return str_

class Process:
    def __init__(self, name, time):
        self.name = name
        self.time = int(time)

    def set_time(self, time):
        self.time = time

n, q = list(map(int, input().split()))
myqueue = SimpleQeueue()
for i in range(n):
    name, time = list(map(str, input().split()))
    myqueue.enqueue(Process(name, time))
time_elapsed = 0
while myqueue.is_empty() != True:
    process = myqueue.dequeue()
    time = process.time
    if time > q:
        process.set_time(time - q)
        time_elapsed += q
        myqueue.enqueue(process)
    else:
        time_elapsed += time
        print((process.name + " " + str(time_elapsed)))

+            str_ += str(self.tail.value)

+    myqueue.enqueue(Process(name, time))


Input:
SA = eval(input())

SB = eval(input())

SC = eval(input())

pointer = SA[0]

SA = SA[1:]

d = {'a': SA, 'b': SB, 'c': SC}

while True:

    if d[pointer] == '':

        ans = pointer

        break

    tmp = d[pointer][0]

    d[pointer] = d[pointer][1:]

    pointer = tmp

print((ans.upper()))

d = { 'a':eval(input()), 'b':eval(input()), 'c':eval(input()) }

pointer = 'a'

while True:

    if 0 < len(d[pointer]):

        tmp = d[pointer][0]

        d[pointer] = d[pointer][1:]

        pointer = tmp

    else:

        print((pointer.upper()))

        break

SA = eval(input())
SB = eval(input())
SC = eval(input())
pointer = SA[0]
SA = SA[1:]
d = {"a": SA, "b": SB, "c": SC}
while True:
    if d[pointer] == "":
        ans = pointer
        break
    tmp = d[pointer][0]
    d[pointer] = d[pointer][1:]
    pointer = tmp
print((ans.upper()))

d = {"a": eval(input()), "b": eval(input()), "c": eval(input())}
pointer = "a"
while True:
    if 0 < len(d[pointer]):
        tmp = d[pointer][0]
        d[pointer] = d[pointer][1:]
        pointer = tmp
    else:
        print((pointer.upper()))
        break

+d = {"a": eval(input()), "b": eval(input()), "c": eval(input())}


Input:
n, k = input().split()

n = int(n)

k = int(k)

count = 0

while True:

    if n == 0:

        break

    else:

        n = n//k

        count += 1

print(count)

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

ans = 0

while N != 0:

    N = N//K

    ans += 1

print(ans)

n, k = input().split()
n = int(n)
k = int(k)
count = 0
while True:
    if n == 0:
        break
    else:
        n = n // k
        count += 1
print(count)

N, K = list(map(int, input().split()))
ans = 0
while N != 0:
    N = N // K
    ans += 1
print(ans)

-n, k = input().split()
-n = int(n)
-k = int(k)
-count = 0
-while True:
-    if n == 0:
-        break
-    else:
-        n = n // k
-        count += 1
-print(count)
+N, K = list(map(int, input().split()))
+ans = 0
+while N != 0:
+    N = N // K
+    ans += 1
+print(ans)


Input:
def divisors(n):

    i = 1

    table = set()

    while i * i <= n:

        if not n % i:

            table.add(i)

            table.add(n//i)

        i += 1

    table = list(table)

    return table

N = int(eval(input()))

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

temp = [0] * N

for n in reversed(list(range(1,N+1))):

    if (A[n-1] + temp[n - 1])%2 == 0:

        temp[n - 1] = 0

        continue

    for a in divisors(n):

        temp[a-1] += 1

res = list(i+1 for i, _ in enumerate(temp) if temp[i])

print((len(res)))

print((*res))

"""

4

1 1 1 1

"""

N=int(eval(input()))

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

d = [0]*N

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

    n=1

    t=0

    while i*n<=N:

        t+=d[i*n-1]

        n+=1

    d[i-1]=(t+A[i-1])%2

res = [i+1 for i,x in enumerate(d) if x]

print((len(res)))

print((*res))

def divisors(n):
    i = 1
    table = set()
    while i * i <= n:
        if not n % i:
            table.add(i)
            table.add(n // i)
        i += 1
    table = list(table)
    return table

N = int(eval(input()))
A = list(map(int, input().split()))
temp = [0] * N
for n in reversed(list(range(1, N + 1))):
    if (A[n - 1] + temp[n - 1]) % 2 == 0:
        temp[n - 1] = 0
        continue
    for a in divisors(n):
        temp[a - 1] += 1
res = list(i + 1 for i, _ in enumerate(temp) if temp[i])
print((len(res)))
print((*res))
"""
4
1 1 1 1
"""

N = int(eval(input()))
A = list(map(int, input().split()))
d = [0] * N
for i in reversed(list(range(1, N + 1))):
    n = 1
    t = 0
    while i * n <= N:
        t += d[i * n - 1]
        n += 1
    d[i - 1] = (t + A[i - 1]) % 2
res = [i + 1 for i, x in enumerate(d) if x]
print((len(res)))
print((*res))

-for n in reversed(list(range(1, N + 1))):

-res = list(i + 1 for i, _ in enumerate(temp) if temp[i])

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

+res = [i + 1 for i, x in enumerate(d) if x]


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

X, Y= [0]*n,[0]*n

for i in range(n):

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

    X[i]=x

    Y[i]=y

def kaijo(x):

    if x==1:

        return 1

    else:

        return x*kaijo(x-1)

dis = 0.0

for i in range(n):

    for j in range(n):

        dis += (((X[i]-X[j])**2+(Y[i]-Y[j])**2)**0.5)*kaijo(n-1)

print((dis/kaijo(n)))

import numpy as np

n = int(eval(input()))

towns = []

for _ in range(n):

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

    towns.append((x,y))

dist = []

for i in range(n-1):

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

        x1,y1 = towns[i]

        x2,y2 = towns[j]

        dist.append(np.sqrt((x1-x2)**2+(y1-y2)**2))

print(((sum(dist)/len(dist)) * (n-1)))

n = int(eval(input()))
X, Y = [0] * n, [0] * n
for i in range(n):
    x, y = list(map(int, input().split()))
    X[i] = x
    Y[i] = y

def kaijo(x):
    if x == 1:
        return 1
    else:
        return x * kaijo(x - 1)

dis = 0.0
for i in range(n):
    for j in range(n):
        dis += (((X[i] - X[j]) ** 2 + (Y[i] - Y[j]) ** 2) ** 0.5) * kaijo(n - 1)
print((dis / kaijo(n)))

import numpy as np

n = int(eval(input()))
towns = []
for _ in range(n):
    x, y = list(map(int, input().split()))
    towns.append((x, y))
dist = []
for i in range(n - 1):
    for j in range(i + 1, n):
        x1, y1 = towns[i]
        x2, y2 = towns[j]
        dist.append(np.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2))
print(((sum(dist) / len(dist)) * (n - 1)))

+print(((sum(dist) / len(dist)) * (n - 1)))


Input:
import math

def manhattan(xs, ys):

    return sum([abs(x-y) for x, y in zip(xs, ys)])

def euclid(xs, ys):

    return math.sqrt(sum([(x-y)**2 for x, y in zip(xs, ys)]))

def l3(xs, ys):

    return sum([abs(x-y)**3 for x, y in zip(xs, ys)])**(1/3)

def chev(xs, ys):

    return max([abs(x-y) for x, y in zip(xs, ys)])

def norm():

    n = int(eval(input()))

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

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

    print((manhattan(xs, ys)))

    print((euclid(xs, ys)))

    print((l3(xs, ys)))

    print((chev(xs, ys)))

norm()

import math

n = int(eval(input()))

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

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

print((sum([math.fabs(v[0] - v[1]) for v in zip(x, y)])))

print((sum([math.fabs((v[0] - v[1]) ** 2) for v in zip(x, y)]) ** (1/2)))

print((sum([math.fabs((v[0] - v[1]) ** 3) for v in zip(x, y)]) ** (1/3)))

print((max([math.fabs(v[0] - v[1]) for v in zip(x, y)])))

import math

def manhattan(xs, ys):
    return sum([abs(x - y) for x, y in zip(xs, ys)])

def euclid(xs, ys):
    return math.sqrt(sum([(x - y) ** 2 for x, y in zip(xs, ys)]))

def l3(xs, ys):
    return sum([abs(x - y) ** 3 for x, y in zip(xs, ys)]) ** (1 / 3)

def chev(xs, ys):
    return max([abs(x - y) for x, y in zip(xs, ys)])

def norm():
    n = int(eval(input()))
    xs = list(map(int, input().split()))
    ys = list(map(int, input().split()))
    print((manhattan(xs, ys)))
    print((euclid(xs, ys)))
    print((l3(xs, ys)))
    print((chev(xs, ys)))

norm()

import math

n = int(eval(input()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))
print((sum([math.fabs(v[0] - v[1]) for v in zip(x, y)])))
print((sum([math.fabs((v[0] - v[1]) ** 2) for v in zip(x, y)]) ** (1 / 2)))
print((sum([math.fabs((v[0] - v[1]) ** 3) for v in zip(x, y)]) ** (1 / 3)))
print((max([math.fabs(v[0] - v[1]) for v in zip(x, y)])))

-    return sum([abs(x - y) for x, y in zip(xs, ys)])

-    return math.sqrt(sum([(x - y) ** 2 for x, y in zip(xs, ys)]))

-    return sum([abs(x - y) ** 3 for x, y in zip(xs, ys)]) ** (1 / 3)

-    return max([abs(x - y) for x, y in zip(xs, ys)])

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

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

+print((sum([math.fabs(v[0] - v[1]) for v in zip(x, y)])))

+print((max([math.fabs(v[0] - v[1]) for v in zip(x, y)])))


Input:
import sys

sys.setrecursionlimit(10 ** 9)

def rec(x, n):

    # print(pos)

    if pos[x] is None:

        pos[x] = n

    else:

        if pos[x] == n:

            return True

        else:

            # print(pos[x], n)

            return False

    for nx, d in g[x]:

        if not rec(nx, n + d):

            return False

    else:

        return True

INF = 1 << 30

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

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

for _ in range(M):

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

    L -= 1

    R -= 1

    g[L].append((R, D))

    g[R].append((L, -D))

pos = [None for _ in range(N)]

for v in range(N):

    # print(pos)

    if pos[v] is None:

        if not rec(v, 0):

            print('No')

            break

else:

    print('Yes')

def main():

    from collections import deque

    import sys

    input = sys.stdin.readline

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

    g = tuple(set() for _ in range(N))

    h = [0] * N  # 入り次数

    for _ in range(M):

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

        L -= 1

        R -= 1

        g[L].add((R, D))

        h[R] += 1

    dist = [-1] * N

    def dfs(s):

        dist[s] = 0

        dq = deque([s])

        while dq:

            v = dq.popleft()

            for u, d in g[v]:

                if ~dist[u]:

                    if dist[u] != dist[v] + d:

                        return False

                else:

                    dist[u] = dist[v] + d

                    dq.append(u)

        return True

    # 始点からのパスを処理

    for s in range(N):

        if h[s]: continue  # sに入ってくるパスがあるので、sを始点にしない

        if ~dist[s]: continue

        if not dfs(s):

            print('No')

            return

    # サイクルを処理（どの点も入るパスがあり、処理できていない）

    for s in range(N):

        if ~dist[s]: continue

        if not dfs(s):

            print('No')

            return

    print('Yes')

if __name__ == '__main__':

    main()

import sys

sys.setrecursionlimit(10**9)

def rec(x, n):
    # print(pos)
    if pos[x] is None:
        pos[x] = n
    else:
        if pos[x] == n:
            return True
        else:
            # print(pos[x], n)
            return False
    for nx, d in g[x]:
        if not rec(nx, n + d):
            return False
    else:
        return True

INF = 1 << 30
N, M = list(map(int, input().split()))
g = [[] for _ in range(N)]
for _ in range(M):
    L, R, D = list(map(int, input().split()))
    L -= 1
    R -= 1
    g[L].append((R, D))
    g[R].append((L, -D))
pos = [None for _ in range(N)]
for v in range(N):
    # print(pos)
    if pos[v] is None:
        if not rec(v, 0):
            print("No")
            break
else:
    print("Yes")

def main():
    from collections import deque
    import sys

    input = sys.stdin.readline
    N, M = list(map(int, input().split()))
    g = tuple(set() for _ in range(N))
    h = [0] * N  # 入り次数
    for _ in range(M):
        L, R, D = list(map(int, input().split()))
        L -= 1
        R -= 1
        g[L].add((R, D))
        h[R] += 1
    dist = [-1] * N

    def dfs(s):
        dist[s] = 0
        dq = deque([s])
        while dq:
            v = dq.popleft()
            for u, d in g[v]:
                if ~dist[u]:
                    if dist[u] != dist[v] + d:
                        return False
                else:
                    dist[u] = dist[v] + d
                    dq.append(u)
        return True

    # 始点からのパスを処理
    for s in range(N):
        if h[s]:
            continue  # sに入ってくるパスがあるので、sを始点にしない
        if ~dist[s]:
            continue
        if not dfs(s):
            print("No")
            return
    # サイクルを処理（どの点も入るパスがあり、処理できていない）
    for s in range(N):
        if ~dist[s]:
            continue
        if not dfs(s):
            print("No")
            return
    print("Yes")

if __name__ == "__main__":
    main()

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

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

+                    if dist[u] != dist[v] + d:

+                    dist[u] = dist[v] + d

+    # 始点からのパスを処理

+            continue  # sに入ってくるパスがあるので、sを始点にしない

+    # サイクルを処理（どの点も入るパスがあり、処理できていない）

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


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

i, x = 1, 0

while x < X:

    x += i

    i += 1

print((i - 1))

import math

X = int(eval(input()))

print((math.ceil((-1 + (1 + 8 * X) ** 0.5) / 2)))


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

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

dp = [[0,0,0] for _ in range(n)]

for i in range(n):

    if i == 0:

        for j in range(3):

            dp[i][j] = li[i][j]

    else:

        for j in range(3):

            for k in range(3):

                if j == k:

                    continue

                else:

                    dp[i][j] = max(dp[i-1][k] + li[i][j], dp[i][j])

print((max(dp[-1])))

n = int(eval(input()))

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

dp = [[0,0,0] for _ in range(n)]

for i in range(n):

    if i == 0:

        for j in range(3):

            dp[i][j] = li[i][j]

    else:

        for j in range(3):

            for k in range(3):

                if j == k:

                    continue

                dp[i][k] = max(dp[i][k], dp[i-1][j] + li[i][k])

print((max(dp[-1])))

n = int(eval(input()))
li = [list(map(int, input().split())) for _ in range(n)]
dp = [[0, 0, 0] for _ in range(n)]
for i in range(n):
    if i == 0:
        for j in range(3):
            dp[i][j] = li[i][j]
    else:
        for j in range(3):
            for k in range(3):
                if j == k:
                    continue
                else:
                    dp[i][j] = max(dp[i - 1][k] + li[i][j], dp[i][j])
print((max(dp[-1])))

n = int(eval(input()))
li = [list(map(int, input().split())) for _ in range(n)]
dp = [[0, 0, 0] for _ in range(n)]
for i in range(n):
    if i == 0:
        for j in range(3):
            dp[i][j] = li[i][j]
    else:
        for j in range(3):
            for k in range(3):
                if j == k:
                    continue
                dp[i][k] = max(dp[i][k], dp[i - 1][j] + li[i][k])
print((max(dp[-1])))


Input:
# B

n = int(eval(input()))

def SumDegit(x):

    ans = 0

    while x > 0:

        ans += x%10

        x = x //10

    return ans

if n%SumDegit(n) == 0:

    print('Yes')

else:

    print('No')

# ABC 080 B - Harshad Number

n = int(eval(input()))

def harshad(x):

    tot = 0

    X = x

    while x > 0:

        tot += x%10

        x = x // 10

    if (X / tot)%1 == 0:

        return 'Yes'

    else:

        return 'No'

print((harshad(n)))

# B
n = int(eval(input()))

def SumDegit(x):
    ans = 0
    while x > 0:
        ans += x % 10
        x = x // 10
    return ans

if n % SumDegit(n) == 0:
    print("Yes")
else:
    print("No")

# ABC 080 B - Harshad Number
n = int(eval(input()))

def harshad(x):
    tot = 0
    X = x
    while x > 0:
        tot += x % 10
        x = x // 10
    if (X / tot) % 1 == 0:
        return "Yes"
    else:
        return "No"

print((harshad(n)))

-# B
+# ABC 080 B - Harshad Number
-def SumDegit(x):
-    ans = 0
+def harshad(x):
+    tot = 0
+    X = x
-        ans += x % 10
+        tot += x % 10
-    return ans
+    if (X / tot) % 1 == 0:
+        return "Yes"
+    else:
+        return "No"
-if n % SumDegit(n) == 0:
-    print("Yes")
-else:
-    print("No")
+print((harshad(n)))


Input:
from sys import exit, stdin

input = stdin.readline

import copy

# from collections import deque,Counter

# import numpy as np

def pow_mod(a, n, d):

    tmp = 1

    for _ in range(n):

        tmp = (tmp * a) % d

    return tmp

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

mod = 10 ** 9 + 7

ans = (pow_mod(10, N, mod) + pow_mod(8, N, mod) - 2 * pow_mod(9, N, mod)) % mod

print(ans)

from sys import exit, stdin

input = stdin.readline

import copy

# from collections import deque,Counter

# import numpy as np

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

mod = 10 ** 9 + 7

ans = (pow(10, N, mod) + pow(8, N, mod) - 2 * pow(9, N, mod)) % mod

print(ans)

from sys import exit, stdin

input = stdin.readline
import copy

# from collections import deque,Counter
# import numpy as np
def pow_mod(a, n, d):
    tmp = 1
    for _ in range(n):
        tmp = (tmp * a) % d
    return tmp

(N,) = list(map(int, input().split()))
mod = 10**9 + 7
ans = (pow_mod(10, N, mod) + pow_mod(8, N, mod) - 2 * pow_mod(9, N, mod)) % mod
print(ans)

from sys import exit, stdin

input = stdin.readline
import copy

# from collections import deque,Counter
# import numpy as np
(N,) = list(map(int, input().split()))
mod = 10**9 + 7
ans = (pow(10, N, mod) + pow(8, N, mod) - 2 * pow(9, N, mod)) % mod
print(ans)

-ans = (pow_mod(10, N, mod) + pow_mod(8, N, mod) - 2 * pow_mod(9, N, mod)) % mod

+ans = (pow(10, N, mod) + pow(8, N, mod) - 2 * pow(9, N, mod)) % mod


Input:
from collections import deque

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

T = [[] for i in range(N)]

E = []

for i in range(N-1):

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

    a, b = a-1, b-1

    T[a].append(b)

    T[b].append(a)

    E.append((a, b))

def bfs(n):

    visited = [False] * N

    dist = [0] * N

    queue = deque([n])

    while queue:

        node = queue.pop()

        if visited[node]:

            continue

        visited[node] = True

        for n in T[node]:

            if not visited[n]:

                dist[n] = dist[node] + 1

                queue.appendleft(n)

    return dist

dist = []

for i in range(N):

    dist.append(bfs(i))

ans = float('inf')

if K % 2 == 0:

    # 全ての頂点について全探索

    for i in range(N):

        ans = min(ans, len(list([x for x in dist[i] if K / 2 < x])))

else:

    # 全ての辺について全探索

    for a, b in E:

        adist = [min(d1, d2) for d1, d2 in zip(dist[a], dist[b])]

        ans = min(ans, len(list([x for x in adist if (K-1) / 2 < x])))

print(ans)

from collections import deque

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

T = [[] for i in range(N)]

E = []

for i in range(N-1):

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

    a, b = a-1, b-1

    T[a].append(b)

    T[b].append(a)

    E.append((a, b))

def bfs(n):

    visited = [False] * N

    dist = [0] * N

    queue = deque([n])

    while queue:

        node = queue.pop()

        if visited[node]:

            continue

        visited[node] = True

        for n in T[node]:

            if not visited[n]:

                dist[n] = dist[node] + 1

                queue.appendleft(n)

    return dist

dist = []

for i in range(N):

    dist.append(bfs(i))

ans = float('inf')

if K % 2 == 0:

    # 全ての頂点について全探索

    for i in range(N):

        ans = min(ans, len([d for d in dist[i] if d > K / 2]))

else:

    # 全ての辺について全探索

    for a, b in E:

        adist = [(1 if min(d1, d2) > (K-1) / 2 else 0) for d1, d2 in zip(dist[a], dist[b])]

        ans = min(ans, sum(adist))

print(ans)

from collections import deque

N, K = list(map(int, input().split()))
T = [[] for i in range(N)]
E = []
for i in range(N - 1):
    a, b = list(map(int, input().split()))
    a, b = a - 1, b - 1
    T[a].append(b)
    T[b].append(a)
    E.append((a, b))

def bfs(n):
    visited = [False] * N
    dist = [0] * N
    queue = deque([n])
    while queue:
        node = queue.pop()
        if visited[node]:
            continue
        visited[node] = True
        for n in T[node]:
            if not visited[n]:
                dist[n] = dist[node] + 1
                queue.appendleft(n)
    return dist

dist = []
for i in range(N):
    dist.append(bfs(i))
ans = float("inf")
if K % 2 == 0:
    # 全ての頂点について全探索
    for i in range(N):
        ans = min(ans, len(list([x for x in dist[i] if K / 2 < x])))
else:
    # 全ての辺について全探索
    for a, b in E:
        adist = [min(d1, d2) for d1, d2 in zip(dist[a], dist[b])]
        ans = min(ans, len(list([x for x in adist if (K - 1) / 2 < x])))
print(ans)

from collections import deque

N, K = list(map(int, input().split()))
T = [[] for i in range(N)]
E = []
for i in range(N - 1):
    a, b = list(map(int, input().split()))
    a, b = a - 1, b - 1
    T[a].append(b)
    T[b].append(a)
    E.append((a, b))

def bfs(n):
    visited = [False] * N
    dist = [0] * N
    queue = deque([n])
    while queue:
        node = queue.pop()
        if visited[node]:
            continue
        visited[node] = True
        for n in T[node]:
            if not visited[n]:
                dist[n] = dist[node] + 1
                queue.appendleft(n)
    return dist

dist = []
for i in range(N):
    dist.append(bfs(i))
ans = float("inf")
if K % 2 == 0:
    # 全ての頂点について全探索
    for i in range(N):
        ans = min(ans, len([d for d in dist[i] if d > K / 2]))
else:
    # 全ての辺について全探索
    for a, b in E:
        adist = [
            (1 if min(d1, d2) > (K - 1) / 2 else 0) for d1, d2 in zip(dist[a], dist[b])
        ]
        ans = min(ans, sum(adist))
print(ans)

-        ans = min(ans, len(list([x for x in dist[i] if K / 2 < x])))

+        ans = min(ans, len([d for d in dist[i] if d > K / 2]))

-        adist = [min(d1, d2) for d1, d2 in zip(dist[a], dist[b])]

-        ans = min(ans, len(list([x for x in adist if (K - 1) / 2 < x])))

+            (1 if min(d1, d2) > (K - 1) / 2 else 0) for d1, d2 in zip(dist[a], dist[b])


Input:
import numpy as np

from itertools import combinations

def main():

    k = int(eval(input()))

    res = 0

    memo = np.zeros((k+1, k+1), int)

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

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

            tmp = np.gcd(i,j)

            memo[i][j] = tmp

            memo[j][i] = tmp

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

        res += i

    for c in combinations(list(range(1,k+1)),2):

        ab = memo[c[0], c[1]]

        res += ab * 6

    for c in combinations(list(range(1,k+1)), 3):

        ab = memo[c[0], c[1]]

        abc = memo[ab, c[2]]

        res += abc * 6

    print(res)

if __name__ == '__main__':

    main()

import math

from itertools import combinations

def main():

    k = int(eval(input()))

    res = 0

    memo = [[0 for _ in range(k+1)] for _ in range(k+1)]

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

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

            tmp = math.gcd(i,j)

            memo[i][j] = tmp

            memo[j][i] = tmp

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

        res += i

    for c in combinations(list(range(1,k+1)),2):

        ab = memo[c[0]][c[1]]

        res += ab * 6

    for c in combinations(list(range(1,k+1)), 3):

        ab = memo[c[0]][c[1]]

        abc = memo[ab][c[2]]

        res += abc * 6

    print(res)

if __name__ == '__main__':

    main()

import numpy as np
from itertools import combinations

def main():
    k = int(eval(input()))
    res = 0
    memo = np.zeros((k + 1, k + 1), int)
    for i in range(1, k + 1):
        for j in range(i, k + 1):
            tmp = np.gcd(i, j)
            memo[i][j] = tmp
            memo[j][i] = tmp
    for i in range(1, k + 1):
        res += i
    for c in combinations(list(range(1, k + 1)), 2):
        ab = memo[c[0], c[1]]
        res += ab * 6
    for c in combinations(list(range(1, k + 1)), 3):
        ab = memo[c[0], c[1]]
        abc = memo[ab, c[2]]
        res += abc * 6
    print(res)

if __name__ == "__main__":
    main()

import math
from itertools import combinations

def main():
    k = int(eval(input()))
    res = 0
    memo = [[0 for _ in range(k + 1)] for _ in range(k + 1)]
    for i in range(1, k + 1):
        for j in range(i, k + 1):
            tmp = math.gcd(i, j)
            memo[i][j] = tmp
            memo[j][i] = tmp
    for i in range(1, k + 1):
        res += i
    for c in combinations(list(range(1, k + 1)), 2):
        ab = memo[c[0]][c[1]]
        res += ab * 6
    for c in combinations(list(range(1, k + 1)), 3):
        ab = memo[c[0]][c[1]]
        abc = memo[ab][c[2]]
        res += abc * 6
    print(res)

if __name__ == "__main__":
    main()

-    memo = np.zeros((k + 1, k + 1), int)

+    memo = [[0 for _ in range(k + 1)] for _ in range(k + 1)]


Input:
# ABC138E - Strings of Impurity

def main():

    S, T = tuple(eval(input()) for _ in range(2))

    if not set(T) <= set(S):  # corner case

        print((-1))

        return

    ans, cur, idx, lim = 1, 0, -1, len(T)

    while cur < lim:

        find = S[idx + 1:].find(T[cur])

        if find == -1:

            ans += 1

            idx = -1

        else:

            idx += find + 1

            cur += 1

    ans = (ans - 1) * len(S) + idx + 1

    print(ans)

if __name__ == "__main__":

    main()

# ABC138E - Strings of Impurity

from bisect import bisect_left as bs

from collections import defaultdict

def main():

    S, T = tuple(eval(input()) for _ in range(2))

    if not set(T) <= set(S):  # corner case

        print((-1))

        return

    idx, ls = defaultdict(list), len(S)

    for i, s in enumerate(S):

        idx[s] += [i]

    cur = -1

    for t in T:

        tgt = idx[t]

        x = (cur + 1) % ls

        i = bs(tgt, x)

        if i < len(tgt):

            cur += 1 + tgt[i] - x

        else:

            cur += 1 + tgt[0] - x + ls

    print((cur + 1))

if __name__ == "__main__":

    main()

# ABC138E - Strings of Impurity
def main():
    S, T = tuple(eval(input()) for _ in range(2))
    if not set(T) <= set(S):  # corner case
        print((-1))
        return
    ans, cur, idx, lim = 1, 0, -1, len(T)
    while cur < lim:
        find = S[idx + 1 :].find(T[cur])
        if find == -1:
            ans += 1
            idx = -1
        else:
            idx += find + 1
            cur += 1
    ans = (ans - 1) * len(S) + idx + 1
    print(ans)

if __name__ == "__main__":
    main()

-    ans, cur, idx, lim = 1, 0, -1, len(T)

-        find = S[idx + 1 :].find(T[cur])

+    idx, ls = defaultdict(list), len(S)


Input:
from sys import stdin

def main():

    #入力

    readline=stdin.readline

    n,t=list(map(int,readline().split()))

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

    li.sort()

    a=[0]*n

    b=[0]*n

    for i in range(n):

        a[i],b[i]=li[i][0],li[i][1]

    #ナップサックDP

    inf=-float("inf")

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

    dp[0][0]=0

    for i in range(n):

        for j in range(t+1):

            #i番目を食べる

            if j!=t:

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

            #i番目を食べない

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

    print((max(dp[n])))

if __name__=="__main__":

    main()

from sys import stdin

def main():

    #入力

    readline=stdin.readline

    n,t=list(map(int,readline().split()))

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

    li.sort()

    a=[0]*n

    b=[0]*n

    for i in range(n):

        a[i],b[i]=li[i][0],li[i][1]

    #ナップサックDP

    inf=-10**9

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

    dp[0][0]=0

    for i in range(n):

        for j in range(t+1):

            #i番目を食べる

            if j!=t:

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

            #i番目を食べない

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

    print((max(dp[n])))

if __name__=="__main__":

    main()

from sys import stdin

def main():
    # 入力
    readline = stdin.readline
    n, t = list(map(int, readline().split()))
    li = [list(map(int, readline().split())) for _ in range(n)]
    li.sort()
    a = [0] * n
    b = [0] * n
    for i in range(n):
        a[i], b[i] = li[i][0], li[i][1]
    # ナップサックDP
    inf = -float("inf")
    dp = [[inf] * (t + 1) for _ in range(n + 1)]
    dp[0][0] = 0
    for i in range(n):
        for j in range(t + 1):
            # i番目を食べる
            if j != t:
                dp[i + 1][min(t, j + a[i])] = max(
                    dp[i + 1][min(t, j + a[i])], dp[i][j] + b[i]
                )
            # i番目を食べない
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
    print((max(dp[n])))

if __name__ == "__main__":
    main()

from sys import stdin

def main():
    # 入力
    readline = stdin.readline
    n, t = list(map(int, readline().split()))
    li = [list(map(int, readline().split())) for _ in range(n)]
    li.sort()
    a = [0] * n
    b = [0] * n
    for i in range(n):
        a[i], b[i] = li[i][0], li[i][1]
    # ナップサックDP
    inf = -(10**9)
    dp = [[inf] * (t + 1) for _ in range(n + 1)]
    dp[0][0] = 0
    for i in range(n):
        for j in range(t + 1):
            # i番目を食べる
            if j != t:
                dp[i + 1][min(t, j + a[i])] = max(
                    dp[i + 1][min(t, j + a[i])], dp[i][j] + b[i]
                )
            # i番目を食べない
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
    print((max(dp[n])))

if __name__ == "__main__":
    main()


Input:
import sys

input = sys.stdin.readline

def gcd(a, b):

  while b:

    a, b = b, a % b

  return a

MOD = 10**9+7

N = int(eval(input()))

F = []

zero_v = 0

inf = 0

zero = 0

for _ in range(N):

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

  if x==0 and y==0:

    zero_v += 1

  elif x==0:

    inf += 1

  elif y==0:

    zero += 1

  else:

    G = gcd(abs(x),abs(y))

    F.append((x//G,y//G))

all_keys = set()

for x,y in F:

  if x*y >0:

    if x>0:

      all_keys.add((x,y))

    else:

      all_keys.add((-x,-y))

  x,y = -y,x

  if x*y >0:

    if x>0:

      all_keys.add((x,y))

    else:

      all_keys.add((-x,-y))

all_dic = {k:[0,0] for k in all_keys}

for x,y in F:

  if x*y > 0:

    if x>0:

      all_dic[(x,y)][0] += 1

    else:

      all_dic[(-x,-y)][0] += 1

  else:

    if x>0:

      all_dic[(-y,x)][1] += 1

    else:

      all_dic[(y,-x)][1] += 1

ans = (pow(2,inf,MOD)) + (pow(2,zero,MOD))-1

ans %= MOD

for k in all_keys:

  P,N = all_dic[k]

  ans *= (pow(2,P,MOD)) + (pow(2,N,MOD))-1

  ans %= MOD

ans += zero_v-1

print((ans%MOD))

import sys

input = sys.stdin.readline

import math

MOD = 10**9+7

N = int(eval(input()))

F = []

zero_v = 0

inf = 0

zero = 0

for _ in range(N):

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

  if x==0 and y==0:

    zero_v += 1

  elif x==0:

    inf += 1

  elif y==0:

    zero += 1

  else:

    G = math.gcd(abs(x),abs(y))

    F.append((x//G,y//G))

all_keys = set()

for x,y in F:

  if x*y >0:

    if x>0:

      all_keys.add((x,y))

    else:

      all_keys.add((-x,-y))

  x,y = -y,x

  if x*y >0:

    if x>0:

      all_keys.add((x,y))

    else:

      all_keys.add((-x,-y))

all_dic = {k:[0,0] for k in all_keys}

for x,y in F:

  if x*y > 0:

    if x>0:

      all_dic[(x,y)][0] += 1

    else:

      all_dic[(-x,-y)][0] += 1

  else:

    if x>0:

      all_dic[(-y,x)][1] += 1

    else:

      all_dic[(y,-x)][1] += 1

ans = (pow(2,inf,MOD)) + (pow(2,zero,MOD))-1

ans %= MOD

for k in all_keys:

  P,N = all_dic[k]

  ans *= (pow(2,P,MOD)) + (pow(2,N,MOD))-1

  ans %= MOD

ans += zero_v-1

print((ans%MOD))

import sys

input = sys.stdin.readline

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

MOD = 10**9 + 7
N = int(eval(input()))
F = []
zero_v = 0
inf = 0
zero = 0
for _ in range(N):
    x, y = list(map(int, input().split()))
    if x == 0 and y == 0:
        zero_v += 1
    elif x == 0:
        inf += 1
    elif y == 0:
        zero += 1
    else:
        G = gcd(abs(x), abs(y))
        F.append((x // G, y // G))
all_keys = set()
for x, y in F:
    if x * y > 0:
        if x > 0:
            all_keys.add((x, y))
        else:
            all_keys.add((-x, -y))
    x, y = -y, x
    if x * y > 0:
        if x > 0:
            all_keys.add((x, y))
        else:
            all_keys.add((-x, -y))
all_dic = {k: [0, 0] for k in all_keys}
for x, y in F:
    if x * y > 0:
        if x > 0:
            all_dic[(x, y)][0] += 1
        else:
            all_dic[(-x, -y)][0] += 1
    else:
        if x > 0:
            all_dic[(-y, x)][1] += 1
        else:
            all_dic[(y, -x)][1] += 1
ans = (pow(2, inf, MOD)) + (pow(2, zero, MOD)) - 1
ans %= MOD
for k in all_keys:
    P, N = all_dic[k]
    ans *= (pow(2, P, MOD)) + (pow(2, N, MOD)) - 1
    ans %= MOD
ans += zero_v - 1
print((ans % MOD))

import sys

input = sys.stdin.readline
import math

MOD = 10**9 + 7
N = int(eval(input()))
F = []
zero_v = 0
inf = 0
zero = 0
for _ in range(N):
    x, y = list(map(int, input().split()))
    if x == 0 and y == 0:
        zero_v += 1
    elif x == 0:
        inf += 1
    elif y == 0:
        zero += 1
    else:
        G = math.gcd(abs(x), abs(y))
        F.append((x // G, y // G))
all_keys = set()
for x, y in F:
    if x * y > 0:
        if x > 0:
            all_keys.add((x, y))
        else:
            all_keys.add((-x, -y))
    x, y = -y, x
    if x * y > 0:
        if x > 0:
            all_keys.add((x, y))
        else:
            all_keys.add((-x, -y))
all_dic = {k: [0, 0] for k in all_keys}
for x, y in F:
    if x * y > 0:
        if x > 0:
            all_dic[(x, y)][0] += 1
        else:
            all_dic[(-x, -y)][0] += 1
    else:
        if x > 0:
            all_dic[(-y, x)][1] += 1
        else:
            all_dic[(y, -x)][1] += 1
ans = (pow(2, inf, MOD)) + (pow(2, zero, MOD)) - 1
ans %= MOD
for k in all_keys:
    P, N = all_dic[k]
    ans *= (pow(2, P, MOD)) + (pow(2, N, MOD)) - 1
    ans %= MOD
ans += zero_v - 1
print((ans % MOD))

-def gcd(a, b):
-    while b:
-        a, b = b, a % b
-    return a
+import math
-        G = gcd(abs(x), abs(y))
+        G = math.gcd(abs(x), abs(y))


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

X=[]

U=[]

ans=0

for i in range(N):

	A,B=input().split()

	X.append(float(A))

	U.append(B)

for i in range(N):

	if U[i]=="JPY":

		ans+=X[i]

	elif U[i]=="BTC":

		ans+=(X[i]*380000.0)

print(ans)

N=int(eval(input()))

ans=0

for i in range (N):

	A,B=input().split()

	if B=="JPY":

		ans+=float(A)

	elif B=="BTC":

		ans+=float(A)*380000.0

print(ans)

N = int(eval(input()))
X = []
U = []
ans = 0
for i in range(N):
    A, B = input().split()
    X.append(float(A))
    U.append(B)
for i in range(N):
    if U[i] == "JPY":
        ans += X[i]
    elif U[i] == "BTC":
        ans += X[i] * 380000.0
print(ans)

N = int(eval(input()))
ans = 0
for i in range(N):
    A, B = input().split()
    if B == "JPY":
        ans += float(A)
    elif B == "BTC":
        ans += float(A) * 380000.0
print(ans)

-X = []
-U = []
-    X.append(float(A))
-    U.append(B)
-for i in range(N):
-    if U[i] == "JPY":
-        ans += X[i]
-    elif U[i] == "BTC":
-        ans += X[i] * 380000.0
+    if B == "JPY":
+        ans += float(A)
+    elif B == "BTC":
+        ans += float(A) * 380000.0


Input:
def Fib(n):

    a=[0,1,1]

    if n<=2:

    	return a[n]

    else:

    	for i in range(n-2):

    		a.append(a[i+1]+a[i+2])

    	return a[n]

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

if m==0:

	print((Fib(n+1)%(10**9+7)))

	exit()

a=[]

for i in range(m):

	a.append(int(eval(input())))

if a[0]!=1:

	a.insert(0,-1)

if a[-1]!=n-1:

	a.append(n+1)

b=[]

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

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

	if a[i+1]-a[i]==1:

		print((0))

		exit()

ans=1

for i in range(len(b)):

	ans*=Fib(b[i])

	ans%=10**9+7

print(ans)

mod=10**9+7

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

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

a.append(n+1)

fib=[1,1]

for i in range(n):

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

	fib.append(r%mod)

ans=1

now=0

for x in a:

	ans*=fib[x-1-now]

	if x-1-now<0:

		print((0))

		exit()

	ans%=mod

	now=x+1

print(ans)

def Fib(n):
    a = [0, 1, 1]
    if n <= 2:
        return a[n]
    else:
        for i in range(n - 2):
            a.append(a[i + 1] + a[i + 2])
        return a[n]

n, m = list(map(int, input().split()))
if m == 0:
    print((Fib(n + 1) % (10**9 + 7)))
    exit()
a = []
for i in range(m):
    a.append(int(eval(input())))
if a[0] != 1:
    a.insert(0, -1)
if a[-1] != n - 1:
    a.append(n + 1)
b = []
for i in range(len(a) - 1):
    b.append(a[i + 1] - a[i] - 1)
    if a[i + 1] - a[i] == 1:
        print((0))
        exit()
ans = 1
for i in range(len(b)):
    ans *= Fib(b[i])
    ans %= 10**9 + 7
print(ans)

mod = 10**9 + 7
n, m = list(map(int, input().split()))
a = [int(eval(input())) for _ in range(m)]
a.append(n + 1)
fib = [1, 1]
for i in range(n):
    r = fib[-1] + fib[-2]
    fib.append(r % mod)
ans = 1
now = 0
for x in a:
    ans *= fib[x - 1 - now]
    if x - 1 - now < 0:
        print((0))
        exit()
    ans %= mod
    now = x + 1
print(ans)

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


Input:
"""

友達でも嫌いでもない人

友達の友達(の友達の...)

-> ok

"""

class UnionFind():

    # コンストラクタ

    def __init__(self, n):

        # 要素数

        self.n = n

        # parents[i]: 要素iの親要素の番号

        # 要素iが根の場合、parents[i] = -(そのグループの要素数)

        self.parents = [-1] * n

    # 要素xが属するグループの根を返す

    # 経路圧縮

    def find(self, x):

        if self.parents[x] < 0:

            return x

        else:

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

            return self.parents[x]

    # 要素xが属するグループと要素yが属するグループとを併合する

    def union(self, x, y):

        x = self.find(x)

        y = self.find(y)

        if x == y:

            return

        if self.parents[x] > self.parents[y]:

            x, y = y, x

        self.parents[x] += self.parents[y]

        self.parents[y] = x

    # 要素xが属するグループの要素数を返す

    def size(self, x):

        return -self.parents[self.find(x)]

    # 要素x,yが同じグループに属するかどうかを返す

    def same(self, x, y):

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

    # 要素xが属するグループに属する要素をリストで返す

    def members(self, x):

        root = self.find(x)

        return [i for i in range(self.n) if self.find(i) == root]

    # 全ての根の要素をリストで返す

    def roots(self):

        return [i for i, x in enumerate(self.parents) if x < 0]

    # グループの数を返す

    def group_count(self):

        return len(self.roots())

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

best = [0] * N

friend = UnionFind(N)

for _ in range(M):

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

    best[A-1] += 1

    best[B-1] += 1

    friend.union(A-1, B-1)

bad = [[] for _ in range(N)]

for _ in range(K):

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

    bad[C-1].append(D-1)

    bad[D-1].append(C-1)

ans = [0] * N

for i in range(N):

    ans[i] = friend.size(i) - best[i] - 1

    for kirai in bad[i]:

        if friend.same(i, kirai):

            ans[i] -= 1

print(*ans, sep=" ")

class UnionFind():

    # コンストラクタ

    def __init__(self, n):

        # 要素数

        self.n = n

        # parents[i]: 要素iの親要素の番号

        # 要素iが根の場合、parents[i] = -(そのグループの要素数)

        self.parents = [-1] * n

    # 要素xが属するグループの根を返す

    # 経路圧縮

    def find(self, x):

        if self.parents[x] < 0:

            return x

        else:

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

            return self.parents[x]

    # 要素xが属するグループと要素yが属するグループとを併合する

    def union(self, x, y):

        x = self.find(x)

        y = self.find(y)

        if x == y:

            return

        if self.parents[x] > self.parents[y]:

            x, y = y, x

        self.parents[x] += self.parents[y]

        self.parents[y] = x

    # 要素xが属するグループの要素数を返す

    def size(self, x):

        return -self.parents[self.find(x)]

    # 要素x,yが同じグループに属するかどうかを返す

    def same(self, x, y):

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

    # 要素xが属するグループに属する要素をリストで返す

    def members(self, x):

        root = self.find(x)

        return [i for i in range(self.n) if self.find(i) == root]

    # 全ての根の要素をリストで返す

    def roots(self):

        return [i for i, x in enumerate(self.parents) if x < 0]

    # グループの数を返す

    def group_count(self):

        return len(self.roots())

def main():

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

    best_friend = [0] * N

    friend = UnionFind(N)

    for _ in range(M):

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

        best_friend[A-1] += 1

        best_friend[B-1] += 1

        friend.union(A-1, B-1)

    blocked = [[] for _ in range(N)]

    for _ in range(K):

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

        blocked[C-1].append(D-1)

        blocked[D-1].append(C-1)

    ans = [0] * N

    for i in range(N):

        # 友達候補 - 友達 - 自分

        ans[i] = friend.size(i) - best_friend[i] - 1

        # 嫌いな人は友達になれない

        for bad in blocked[i]:

            if friend.same(i, bad):

                ans[i] -= 1

    print(*ans, sep=" ")

if __name__ == "__main__":

    main()

"""
友達でも嫌いでもない人
友達の友達(の友達の...)
-> ok
"""

class UnionFind:
    # コンストラクタ
    def __init__(self, n):
        # 要素数
        self.n = n
        # parents[i]: 要素iの親要素の番号
        # 要素iが根の場合、parents[i] = -(そのグループの要素数)
        self.parents = [-1] * n

    # 要素xが属するグループの根を返す
    # 経路圧縮
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    # 要素xが属するグループと要素yが属するグループとを併合する
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    # 要素xが属するグループの要素数を返す
    def size(self, x):
        return -self.parents[self.find(x)]

    # 要素x,yが同じグループに属するかどうかを返す
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # 要素xが属するグループに属する要素をリストで返す
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    # 全ての根の要素をリストで返す
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    # グループの数を返す
    def group_count(self):
        return len(self.roots())

N, M, K = map(int, input().split())
best = [0] * N
friend = UnionFind(N)
for _ in range(M):
    A, B = map(int, input().split())
    best[A - 1] += 1
    best[B - 1] += 1
    friend.union(A - 1, B - 1)
bad = [[] for _ in range(N)]
for _ in range(K):
    C, D = map(int, input().split())
    bad[C - 1].append(D - 1)
    bad[D - 1].append(C - 1)
ans = [0] * N
for i in range(N):
    ans[i] = friend.size(i) - best[i] - 1
    for kirai in bad[i]:
        if friend.same(i, kirai):
            ans[i] -= 1
print(*ans, sep=" ")

class UnionFind:
    # コンストラクタ
    def __init__(self, n):
        # 要素数
        self.n = n
        # parents[i]: 要素iの親要素の番号
        # 要素iが根の場合、parents[i] = -(そのグループの要素数)
        self.parents = [-1] * n

    # 要素xが属するグループの根を返す
    # 経路圧縮
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    # 要素xが属するグループと要素yが属するグループとを併合する
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    # 要素xが属するグループの要素数を返す
    def size(self, x):
        return -self.parents[self.find(x)]

    # 要素x,yが同じグループに属するかどうかを返す
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # 要素xが属するグループに属する要素をリストで返す
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    # 全ての根の要素をリストで返す
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    # グループの数を返す
    def group_count(self):
        return len(self.roots())

def main():
    N, M, K = map(int, input().split())
    best_friend = [0] * N
    friend = UnionFind(N)
    for _ in range(M):
        A, B = map(int, input().split())
        best_friend[A - 1] += 1
        best_friend[B - 1] += 1
        friend.union(A - 1, B - 1)
    blocked = [[] for _ in range(N)]
    for _ in range(K):
        C, D = map(int, input().split())
        blocked[C - 1].append(D - 1)
        blocked[D - 1].append(C - 1)
    ans = [0] * N
    for i in range(N):
        # 友達候補 - 友達 - 自分
        ans[i] = friend.size(i) - best_friend[i] - 1
        # 嫌いな人は友達になれない
        for bad in blocked[i]:
            if friend.same(i, bad):
                ans[i] -= 1
    print(*ans, sep=" ")

if __name__ == "__main__":
    main()

-友達でも嫌いでもない人

-友達の友達(の友達の...)

-    ans[i] = friend.size(i) - best[i] - 1

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

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

+        C, D = map(int, input().split())

+        # 友達候補 - 友達 - 自分

+        ans[i] = friend.size(i) - best_friend[i] - 1

+        # 嫌いな人は友達になれない


Input:
A, P = list(map(int, input().split()))

print(((A * 3 + P) // 2))

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

ans = (a * 3 + p) // 2

print(ans)

-A, P = list(map(int, input().split()))
-print(((A * 3 + P) // 2))
+a, p = list(map(int, input().split()))
+ans = (a * 3 + p) // 2
+print(ans)


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

Dset = set(input().split())

while True:

    if Dset & set(str(N)) == set():

        print(N)

        break

    else:

        N += 1

def check(num, ng):

    for c in str(num):

        if int(c) in ng:

            return False

    return True

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

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

while True:

    if check(N, D):

        print(N)

        break

    else:

        N += 1

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


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

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

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

transit = []

transit2 = []

for i in range(M):

    if abM[i][0] == 1:

        transit.append(abM[i][1])

    if abM[i][1] == N:

        transit2.append(abM[i][0])

# setで共通要素の集合を取ってみる

if len(set(transit) & set(transit2)) != 0:

    print("POSSIBLE")

else:

    print("IMPOSSIBLE")

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

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

# 1からある島への便があるかを保持

transit = [False] * N

# ある島からNへの便があるかを保持

transit2 = [False] * N

for i in range(M):

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

    if a == 1:

        transit[b] = True

    if b == N:

        transit2[a] = True

for i in range(N):

    if transit[i] and transit2[i]:

        print("POSSIBLE")

        exit()

print("IMPOSSIBLE")

-abM = [list(map(int, input().split())) for i in range(M)]

+# 1からある島への便があるかを保持

+# ある島からNへの便があるかを保持

-# setで共通要素の集合を取ってみる

-if len(set(transit) & set(transit2)) != 0:

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


Input:
# coding: utf-8

from heapq import heappop, heappush

from itertools import permutations

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

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

INF=10**9

G=[[INF for i in range(N+1)] for j in range(N+1)]

for i in range(M):

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

    G[A][B]=C

    G[B][A]=C

d=[[INF*10 for i in range(N+1)] for j in range(R)]

for k in range(R):

    r=town[k]

    d[k][r]=0

    used=[False for i in range(N+1)]

    heap=[]

    heappush(heap,(d[k][r],r))

    while heap:

        d_u, u = heappop(heap)

        used[u] = True

        if d[k][u] < d_u:

            continue

        for v in range(N+1):

            if not(used[v]) and d_u + G[u][v] < d[k][v]:

                d[k][v] = d_u + G[u][v]

                heappush(heap,(d[k][v],v))

ans=INF

L=[i for i in range(R)]

for v in permutations(L,R):

    D=0

    for i in range(R-1):

        D+=d[v[i]][town[v[i+1]]]

    ans=min(ans,D)

print(ans)

# coding: utf-8

from heapq import heappop, heappush

from itertools import permutations

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

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

INF=10**11

G=[[INF for j in range(N+1)] for i in range(N+1)]

conection=[[] for i in range(N+1)]

RG=[[INF for j in range(N+1)] for i in range(N+1)]

for i in range(M):

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

    G[A][B]=C

    G[B][A]=C

    conection[A].append(B)

    conection[B].append(A)

for k in range(R):

    start=r_list[k]

    d=[INF for i in range(N+1)]

    d[start]=0

    used=[False for i in range(N+1)]

    heap=[]

    heappush(heap,(d[start],start))

    while heap:

        d_u, u = heappop(heap)

        used[u] = True

        if d[u] < d_u:

            continue

        for v in conection[u]:

            if not(used[v]) and d_u + G[u][v] < d[v]:

                d[v] = d_u + G[u][v]

                heappush(heap,(d[v],v))

    for i in range(R):

        r=r_list[i]

        RG[start][r]=d[r]

        RG[r][start]=d[r]

P=permutations(r_list,R)

ans=INF

for p in P:

    tmp=0

    for j in range(R-1):

        tmp+=RG[p[j]][p[j+1]]

    ans=min(ans,tmp)

print(ans)

# coding: utf-8
from heapq import heappop, heappush
from itertools import permutations

N, M, R = list(map(int, input().split()))
town = list(map(int, input().split()))
INF = 10**9
G = [[INF for i in range(N + 1)] for j in range(N + 1)]
for i in range(M):
    A, B, C = list(map(int, input().split()))
    G[A][B] = C
    G[B][A] = C
d = [[INF * 10 for i in range(N + 1)] for j in range(R)]
for k in range(R):
    r = town[k]
    d[k][r] = 0
    used = [False for i in range(N + 1)]
    heap = []
    heappush(heap, (d[k][r], r))
    while heap:
        d_u, u = heappop(heap)
        used[u] = True
        if d[k][u] < d_u:
            continue
        for v in range(N + 1):
            if not (used[v]) and d_u + G[u][v] < d[k][v]:
                d[k][v] = d_u + G[u][v]
                heappush(heap, (d[k][v], v))
ans = INF
L = [i for i in range(R)]
for v in permutations(L, R):
    D = 0
    for i in range(R - 1):
        D += d[v[i]][town[v[i + 1]]]
    ans = min(ans, D)
print(ans)

# coding: utf-8
from heapq import heappop, heappush
from itertools import permutations

N, M, R = list(map(int, input().split()))
r_list = list(map(int, input().split()))
INF = 10**11
G = [[INF for j in range(N + 1)] for i in range(N + 1)]
conection = [[] for i in range(N + 1)]
RG = [[INF for j in range(N + 1)] for i in range(N + 1)]
for i in range(M):
    A, B, C = list(map(int, input().split()))
    G[A][B] = C
    G[B][A] = C
    conection[A].append(B)
    conection[B].append(A)
for k in range(R):
    start = r_list[k]
    d = [INF for i in range(N + 1)]
    d[start] = 0
    used = [False for i in range(N + 1)]
    heap = []
    heappush(heap, (d[start], start))
    while heap:
        d_u, u = heappop(heap)
        used[u] = True
        if d[u] < d_u:
            continue
        for v in conection[u]:
            if not (used[v]) and d_u + G[u][v] < d[v]:
                d[v] = d_u + G[u][v]
                heappush(heap, (d[v], v))
    for i in range(R):
        r = r_list[i]
        RG[start][r] = d[r]
        RG[r][start] = d[r]
P = permutations(r_list, R)
ans = INF
for p in P:
    tmp = 0
    for j in range(R - 1):
        tmp += RG[p[j]][p[j + 1]]
    ans = min(ans, tmp)
print(ans)

-G = [[INF for i in range(N + 1)] for j in range(N + 1)]

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

+G = [[INF for j in range(N + 1)] for i in range(N + 1)]

+RG = [[INF for j in range(N + 1)] for i in range(N + 1)]

-d = [[INF * 10 for i in range(N + 1)] for j in range(R)]

-            if not (used[v]) and d_u + G[u][v] < d[k][v]:

-                heappush(heap, (d[k][v], v))

+            if not (used[v]) and d_u + G[u][v] < d[v]:

+                heappush(heap, (d[v], v))


Input:
icase=0

if icase==0:

    n=int(eval(input()))

    f=[]

    for i in range(n):

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

        f.append(fi)

    p=[]

    for i in range(n):

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

        p.append(pi)

elif icase==1:

    n=1

    f=[[1, 1, 0, 1, 0, 0, 0, 1, 0, 1]]

    p=[[3, 4, 5, 6, 7, 8, 9, -2, -3, 4, -2]]

elif icase==2:

    n=2

    f=[[1, 1, 1, 1, 1, 0, 0, 0, 0, 0],

       [0, 0, 0, 0, 0, 1, 1, 1, 1, 1]]

    p=[[0, -2, -2, -2, -2, -2, -1, -1, -1, -1, -1],

       [0, -2, -2, -2, -2, -2, -1, -1, -1, -1, -1]]

elif icase==3:

    n=3

    f=[[1, 1, 1, 1, 1, 1, 0, 0, 1, 1],

       [0, 1, 0, 1, 1, 1, 1, 0, 1, 0],

       [1, 0, 1, 1, 0, 1, 0, 1, 0, 1]]

    p=[[-8, 6, -2, -8, -8, 4, 8, 7, -6, 2, 2],

       [-9, 2, 0, 1, 7, -5, 0, -2, -6, 5, 5],

       [6, -6, 7, -9, 6, -5, 8, 0, -9, -7, -7]]

import itertools

sumpmax=-10**11

for i in itertools.product([0,1], repeat=10):

    r=list(i)

    sump=0

    if sum(r)!=0:

        for jj in range(n):

            ci=0

            for j in range(10):

                ci=ci+r[j]*f[jj][j]

            sump=sump+p[jj][ci]

#            print(sump,r)

        sumpmax=max(sump,sumpmax)

print(sumpmax)

import itertools

n=int(eval(input()))

f=[[]]*n

for i in range(n):

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

#    f[i].append(fij)

    f[i]=fij

p=[[]]*n

for i in range(n):

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

    p[i]=pij

pmax=-10**11

for a in itertools.product([0,1], repeat=10):

    if sum(a)==0:

        continue

    psum=0

    for ni in range(n):

        k=0

        for i in range(10):

            if f[ni][i]==1 and a[i]==1:

                k+=1

        psum=psum+p[ni][k]

    pmax=max(pmax,psum)

print(pmax)

import itertools

n = int(eval(input()))
f = [[]] * n
for i in range(n):
    fij = list(map(int, input().split()))
    #    f[i].append(fij)
    f[i] = fij
p = [[]] * n
for i in range(n):
    pij = list(map(int, input().split()))
    p[i] = pij
pmax = -(10**11)
for a in itertools.product([0, 1], repeat=10):
    if sum(a) == 0:
        continue
    psum = 0
    for ni in range(n):
        k = 0
        for i in range(10):
            if f[ni][i] == 1 and a[i] == 1:
                k += 1
        psum = psum + p[ni][k]
    pmax = max(pmax, psum)
print(pmax)

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

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

-for i in itertools.product([0, 1], repeat=10):

-                ci = ci + r[j] * f[jj][j]

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

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

+for a in itertools.product([0, 1], repeat=10):


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

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

INF = float('inf')

dp = [INF] * (1 + 10 ** 5)

dp[0] = 0

for i in range(n):

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

    if i < 2:

        continue

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

print((dp[n-1]))

N = int(eval(input()))

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

INF = float('inf')

dp = [INF] * N

dp[0] = 0

for i in range(1, N):

    if i == 1:

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

    else:

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

# print(dp)

print((dp[N - 1]))

n = int(eval(input()))
h = list(map(int, input().split()))
INF = float("inf")
dp = [INF] * (1 + 10**5)
dp[0] = 0
for i in range(n):
    dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]))
    if i < 2:
        continue
    dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]))
print((dp[n - 1]))

N = int(eval(input()))
h = list(map(int, input().split()))
INF = float("inf")
dp = [INF] * N
dp[0] = 0
for i in range(1, N):
    if i == 1:
        dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]))
    else:
        dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]))
# print(dp)
print((dp[N - 1]))


Input:
#!/usr/bin/python3

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

def main():

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

  Xn = []

  for _ in range(N):

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

  ans = 0

  ansset = [i**2 for i in range(1001)]

  for i in range(N):

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

      sm = 0

      for k in range(D):

        sm += (Xn[i][k]-Xn[j][k])**2

      if sm in ansset:

        ans += 1

  print(ans)

if __name__ == "__main__":

  main()

#!/usr/bin/python3

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

def main():

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

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

  sqrtset = [i**2 for i in range(1000)]

  ans = 0

  for i in range(N):

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

      sm = 0

      for d in range(D):

        sm += (Xn[i][d]-Xn[j][d])**2

      if sm in sqrtset:

        ans += 1

  print(ans)

if __name__ == "__main__":

  main()

#!/usr/bin/python3
# -*- coding: utf-8 -*-
def main():
    N, D = list(map(int, input().split()))
    Xn = []
    for _ in range(N):
        Xn.append(list(map(int, input().split())))
    ans = 0
    ansset = [i**2 for i in range(1001)]
    for i in range(N):
        for j in range(i + 1, N):
            sm = 0
            for k in range(D):
                sm += (Xn[i][k] - Xn[j][k]) ** 2
            if sm in ansset:
                ans += 1
    print(ans)

if __name__ == "__main__":
    main()

#!/usr/bin/python3
# -*- coding: utf-8 -*-
def main():
    N, D = list(map(int, input().split()))
    Xn = [list(map(int, input().split())) for _ in range(N)]
    sqrtset = [i**2 for i in range(1000)]
    ans = 0
    for i in range(N):
        for j in range(i + 1, N):
            sm = 0
            for d in range(D):
                sm += (Xn[i][d] - Xn[j][d]) ** 2
            if sm in sqrtset:
                ans += 1
    print(ans)

if __name__ == "__main__":
    main()

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

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

+    sqrtset = [i**2 for i in range(1000)]

-    ansset = [i**2 for i in range(1001)]


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

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

flg = False

for i in range(n):

  if list_num[i] % 2 == 1 or (list_num[i] % 2 == 0 and (list_num[i] % 3 == 0 or list_num[i] % 5 == 0)):

    flg = True

  else:

    flg = False

    break

if flg:

  print("APPROVED")

else:

  print("DENIED")

n = int(eval(input()))

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

flg = True

for number in numbers:

    if number % 2 == 0 and number % 3 != 0 and number % 5 != 0:

        flg = False

        break

if flg:

    print("APPROVED")

else:

    print("DENIED")

n = int(eval(input()))
list_num = list(map(int, input().split()))
flg = False
for i in range(n):
    if list_num[i] % 2 == 1 or (
        list_num[i] % 2 == 0 and (list_num[i] % 3 == 0 or list_num[i] % 5 == 0)
    ):
        flg = True
    else:
        flg = False
        break
if flg:
    print("APPROVED")
else:
    print("DENIED")

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

-        list_num[i] % 2 == 0 and (list_num[i] % 3 == 0 or list_num[i] % 5 == 0)

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

+    if number % 2 == 0 and number % 3 != 0 and number % 5 != 0:


Input:
while True:

    a=eval(input())

    if a=='-':

        break

    else:

        n=int(eval(input()))

        for i in range(n):

             h=int(eval(input()))

             a=a[h:]+a[:h]

    print(a)

while True:

    a=input()

    if a=='-':

        break

    else:

        n=int(input())

        for i in range(n):

             h=int(input())

             a=a[h:]+a[:h]

    print(a)

while True:
    a = eval(input())
    if a == "-":
        break
    else:
        n = int(eval(input()))
        for i in range(n):
            h = int(eval(input()))
            a = a[h:] + a[:h]
    print(a)

while True:
    a = input()
    if a == "-":
        break
    else:
        n = int(input())
        for i in range(n):
            h = int(input())
            a = a[h:] + a[:h]
    print(a)

-    a = eval(input())
+    a = input()
-        n = int(eval(input()))
+        n = int(input())
-            h = int(eval(input()))
+            h = int(input())


Input:
import sys

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

from collections import defaultdict

N = int(eval(input()))

def prime_factorize(n):

  ret = []

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

    if i > n:break

    while n % i == 0:

      n //= i

      ret.append(i)

  if n != 1:

    ret.append(n)

  return ret

dic = defaultdict(int)

lis = prime_factorize(N)

for num in lis:

    dic[num] += 1

ans = 0

for v in list(dic.values()):

    i = 1

    while v >= i:

        v -= i

        i += 1

    ans += i - 1

print(ans)

import sys

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

N = int(eval(input()))

def prime_factorize(n):

  ret = []

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

    if i > n:break

    cnt = 0

    while n % i == 0:

      n //= i

      cnt += 1

    if cnt > 0:

      ret.append((i, cnt))

  if n != 1:

    ret.append((n, 1))

  return ret

lis = prime_factorize(N)

ans = 0

for v, cnt in lis:

    i = 1

    while cnt >= i:

        cnt -= i

        i += 1

    ans += i - 1

print(ans)

import sys

input = lambda: sys.stdin.readline().rstrip()
from collections import defaultdict

N = int(eval(input()))

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

dic = defaultdict(int)
lis = prime_factorize(N)
for num in lis:
    dic[num] += 1
ans = 0
for v in list(dic.values()):
    i = 1
    while v >= i:
        v -= i
        i += 1
    ans += i - 1
print(ans)

import sys

input = lambda: sys.stdin.readline().rstrip()
N = int(eval(input()))

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

lis = prime_factorize(N)
ans = 0
for v, cnt in lis:
    i = 1
    while cnt >= i:
        cnt -= i
        i += 1
    ans += i - 1
print(ans)

-from collections import defaultdict
+        cnt = 0
-            ret.append(i)
+            cnt += 1
+        if cnt > 0:
+            ret.append((i, cnt))
-        ret.append(n)
+        ret.append((n, 1))
-dic = defaultdict(int)
-for num in lis:
-    dic[num] += 1
-for v in list(dic.values()):
+for v, cnt in lis:
-    while v >= i:
-        v -= i
+    while cnt >= i:
+        cnt -= i


Input:
import sys

input = sys.stdin.readline

from itertools import combinations

def readlines(n):

    for _ in range(n):

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

def bene(me, f, p):

    a = sum(1 if f[m] == 1 else 0 for m in me)

    return p[a]

def main():

    n = int(eval(input()))

    F = list(readlines(n))

    P = list(readlines(n))

    for i in range(1, 11):

        for comb in combinations(list(range(10)), i):

            yield sum(bene(comb, f, p) for f, p in zip(F,P))

print((max(main())))

import sys

input = sys.stdin.readline

from itertools import combinations

def readlines(n):

    for _ in range(n):

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

def bene(me, f, p):

    a = len([0 for m in me if f[m] == 1])

    return p[a]

def main():

    n = int(eval(input()))

    F = list(readlines(n))

    P = list(readlines(n))

    for i in range(1, 11):

        for comb in combinations(list(range(10)), i):

            yield sum(bene(comb, f, p) for f, p in zip(F,P))

print((max(main())))

import sys

input = sys.stdin.readline
from itertools import combinations

def readlines(n):
    for _ in range(n):
        yield list(map(int, input().split()))

def bene(me, f, p):
    a = sum(1 if f[m] == 1 else 0 for m in me)
    return p[a]

def main():
    n = int(eval(input()))
    F = list(readlines(n))
    P = list(readlines(n))
    for i in range(1, 11):
        for comb in combinations(list(range(10)), i):
            yield sum(bene(comb, f, p) for f, p in zip(F, P))

print((max(main())))

import sys

input = sys.stdin.readline
from itertools import combinations

def readlines(n):
    for _ in range(n):
        yield list(map(int, input().split()))

def bene(me, f, p):
    a = len([0 for m in me if f[m] == 1])
    return p[a]

def main():
    n = int(eval(input()))
    F = list(readlines(n))
    P = list(readlines(n))
    for i in range(1, 11):
        for comb in combinations(list(range(10)), i):
            yield sum(bene(comb, f, p) for f, p in zip(F, P))

print((max(main())))

-    a = sum(1 if f[m] == 1 else 0 for m in me)

+    a = len([0 for m in me if f[m] == 1])


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

x = [0]*n

for i in range(q):

  a = int(eval(input()))

  a -= 1

  x[a] += 1

y = [k]*n

for i in range(n):

  y[i] -= (q-x[i])

  if y[i] <= 0:

    print('No')

  else:

    print('Yes')

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

A = [int(eval(input())) for _ in range(q)]

B = [k-q]*n

for i in range(q):

    B[A[i]-1] += 1

for i in range(n):

    if B[i] <= 0:

        print('No')

    else:

        print('Yes')

n, k, q = list(map(int, input().split()))
x = [0] * n
for i in range(q):
    a = int(eval(input()))
    a -= 1
    x[a] += 1
y = [k] * n
for i in range(n):
    y[i] -= q - x[i]
    if y[i] <= 0:
        print("No")
    else:
        print("Yes")

n, k, q = list(map(int, input().split()))
A = [int(eval(input())) for _ in range(q)]
B = [k - q] * n
for i in range(q):
    B[A[i] - 1] += 1
for i in range(n):
    if B[i] <= 0:
        print("No")
    else:
        print("Yes")

+A = [int(eval(input())) for _ in range(q)]


Input:
from collections import deque

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

maze = [list(eval(input())) for i in range(h)]

dx = [1, 0, -1, 0]

dy = [0, 1, 0, -1]

sx, sy, gx, gy = 0, 0, h - 1, w - 1

d = [[float("inf")] * w for _ in range(h)]

que = deque([])

que.append((sx, sy))

d[sx][sy] = 0

def bfs():

    while que:

        p = que.popleft()

        if p[0] == gx and p[1] == gy:

            break

        for i in range(4):

            nx = p[0] + dx[i]

            ny = p[1] + dy[i]

            if 0 <= nx < h and 0 <= ny < w and maze[nx][ny] != "#" and d[nx][ny] == float("inf"):

                que.append((nx, ny))

                d[nx][ny] = d[p[0]][p[1]] + 1

    return d[gx][gy]

##最短距離を格納

bfs = bfs()

cnt = 0

for i in range(h):

    for j in range(w):

        if maze[i][j] == ".":

            cnt += 1

if bfs == float("inf"):

    print((-1))

else:

    print((cnt - (bfs + 1)))

from collections import deque

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

maze = [list(eval(input())) for i in range(h)]

dh = [1, 0, -1, 0]

dw = [0, 1, 0, -1]

sh, sw, gh, gw = 0, 0, h - 1, w - 1

d = [[float("inf")] * w for _ in range(h)]

que = deque([])

que.append((sh, sw))

d[sh][sw] = 0

def bfs():

    while que:

        p = que.popleft()

        if p[0] == gh and p[1] == gw:

            break

        for i in range(4):

            nh = p[0] + dh[i]

            nw = p[1] + dw[i]

            if 0 <= nh < h and 0 <= nw < w and maze[nh][nw] != "#" and d[nh][nw] == float("inf"):

                que.append((nh, nw))

                d[nh][nw] = d[p[0]][p[1]] + 1

    return d[gh][gw]

##最短距離を格納

bfs = bfs()

cnt = 0

for i in range(h):

    for j in range(w):

        if maze[i][j] == ".":

            cnt += 1

if bfs == float("inf"):

    print((-1))

else:

    print((cnt - (bfs + 1)))

from collections import deque

h, w = list(map(int, input().split()))
maze = [list(eval(input())) for i in range(h)]
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
sx, sy, gx, gy = 0, 0, h - 1, w - 1
d = [[float("inf")] * w for _ in range(h)]
que = deque([])
que.append((sx, sy))
d[sx][sy] = 0

def bfs():
    while que:
        p = que.popleft()
        if p[0] == gx and p[1] == gy:
            break
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            if (
                0 <= nx < h
                and 0 <= ny < w
                and maze[nx][ny] != "#"
                and d[nx][ny] == float("inf")
            ):
                que.append((nx, ny))
                d[nx][ny] = d[p[0]][p[1]] + 1
    return d[gx][gy]

##最短距離を格納
bfs = bfs()
cnt = 0
for i in range(h):
    for j in range(w):
        if maze[i][j] == ".":
            cnt += 1
if bfs == float("inf"):
    print((-1))
else:
    print((cnt - (bfs + 1)))

from collections import deque

h, w = list(map(int, input().split()))
maze = [list(eval(input())) for i in range(h)]
dh = [1, 0, -1, 0]
dw = [0, 1, 0, -1]
sh, sw, gh, gw = 0, 0, h - 1, w - 1
d = [[float("inf")] * w for _ in range(h)]
que = deque([])
que.append((sh, sw))
d[sh][sw] = 0

def bfs():
    while que:
        p = que.popleft()
        if p[0] == gh and p[1] == gw:
            break
        for i in range(4):
            nh = p[0] + dh[i]
            nw = p[1] + dw[i]
            if (
                0 <= nh < h
                and 0 <= nw < w
                and maze[nh][nw] != "#"
                and d[nh][nw] == float("inf")
            ):
                que.append((nh, nw))
                d[nh][nw] = d[p[0]][p[1]] + 1
    return d[gh][gw]

##最短距離を格納
bfs = bfs()
cnt = 0
for i in range(h):
    for j in range(w):
        if maze[i][j] == ".":
            cnt += 1
if bfs == float("inf"):
    print((-1))
else:
    print((cnt - (bfs + 1)))

-                and maze[nx][ny] != "#"

-                and d[nx][ny] == float("inf")

+                and maze[nh][nw] != "#"

+                and d[nh][nw] == float("inf")


Input:
import sys

sys.setrecursionlimit(1 << 25)

readline = sys.stdin.buffer.readline

read = sys.stdin.readline  # 文字列読み込む時はこっち

import numpy as np

from functools import partial

array = partial(np.array, dtype=np.int64)

zeros = partial(np.zeros, dtype=np.int64)

full = partial(np.full, dtype=np.int64)

def ints(): return np.fromstring(readline(), sep=' ', dtype=np.int64)

def read_matrix(H, W)->np.ndarray:

    '''return np.ndarray shape=(H,W) matrix'''

    lines = []

    for _ in range(H):

        lines.append(read())

    lines = ' '.join(lines)  # byte同士の結合ができないのでreadlineでなくreadで

    return np.fromstring(lines, sep=' ', dtype=np.int64).reshape(H, W)

MOD = 10**9 + 7

INF = 2**31  # 2147483648 > 10**9

# default import

N, K = ints()

A = read_matrix(N, N)

# from numba import njit

# @njit('i8[:,:](i8[:,:],i8[:,:])', cache=True)

def matmul_mod(X: np.ndarray, Y: np.ndarray)->np.ndarray:

    MOD = 10**9 + 7

    # return X @ Y

    ret = np.empty((X.shape[0], Y.shape[1]), dtype=np.int64)

    for i in range(X.shape[0]):  # Xの行

        for j in range(Y.shape[1]):  # Yの列

            tmp = (X[i, :] * Y[:, j]) % MOD

            ret[i, j] = tmp.sum() % MOD

    return ret

A_double = np.asanyarray(A, dtype=np.int64)

ans = np.eye(N, dtype=np.int64)

for j in range(int(K).bit_length()):

    if (K >> j) & 1:

        ans = matmul_mod(ans, A_double)

    A_double = matmul_mod(A_double, A_double)

print((ans.sum() % MOD))

import sys

sys.setrecursionlimit(1 << 25)

readline = sys.stdin.buffer.readline

read = sys.stdin.readline  # 文字列読み込む時はこっち

import numpy as np

from functools import partial

array = partial(np.array, dtype=np.int64)

zeros = partial(np.zeros, dtype=np.int64)

full = partial(np.full, dtype=np.int64)

def ints(): return np.fromstring(readline(), sep=' ', dtype=np.int64)

def read_matrix(H, W)->np.ndarray:

    '''return np.ndarray shape=(H,W) matrix'''

    lines = []

    for _ in range(H):

        lines.append(read())

    lines = ' '.join(lines)  # byte同士の結合ができないのでreadlineでなくreadで

    return np.fromstring(lines, sep=' ', dtype=np.int64).reshape(H, W)

MOD = 10**9 + 7

INF = 2**31  # 2147483648 > 10**9

# default import

N, K = ints()

A = read_matrix(N, N)

# from numba import njit

# @njit('i8[:,:](i8[:,:],i8[:,:])', cache=True)

def matmul_mod(X: np.ndarray, Y: np.ndarray)->np.ndarray:

    MOD = 10**9 + 7

    # return X @ Y

    ret = np.empty((X.shape[0], Y.shape[1]), dtype=np.int64)

    for i in range(X.shape[0]):  # Xの行

        for j in range(Y.shape[1]):  # Yの列

            tmp = (X[i, :] * Y[:, j]) % MOD

            ret[i, j] = tmp.sum() % MOD

    return ret

def matmul_mod_try(X: np.ndarray, Y: np.ndarray)->np.ndarray:

    MOD = 10**9 + 7

    # return X @ Y

    ret = np.empty((X.shape[0], Y.shape[1]), dtype=np.int64)

    YT = Y.T

    for i in range(X.shape[0]):  # Xの行

        Xi = X[i, :]

        tmp = (YT * Xi) % MOD

        ret[i, :] = tmp.sum(1) % MOD

    return ret

A_double = np.asanyarray(A, dtype=np.int64)

ans = np.eye(N, dtype=np.int64)

for j in range(int(K).bit_length()):

    if (K >> j) & 1:

        # t1, t2 = matmul_mod(ans, A_double), matmul_mod_try(ans, A_double)

        # assert np.array_equal(t1, t2), (t1, t2)

        ans = matmul_mod_try(ans, A_double)

    A_double = matmul_mod_try(A_double, A_double)

print((ans.sum() % MOD))

import sys

sys.setrecursionlimit(1 << 25)
readline = sys.stdin.buffer.readline
read = sys.stdin.readline  # 文字列読み込む時はこっち
import numpy as np
from functools import partial

array = partial(np.array, dtype=np.int64)
zeros = partial(np.zeros, dtype=np.int64)
full = partial(np.full, dtype=np.int64)

def ints():
    return np.fromstring(readline(), sep=" ", dtype=np.int64)

def read_matrix(H, W) -> np.ndarray:
    """return np.ndarray shape=(H,W) matrix"""
    lines = []
    for _ in range(H):
        lines.append(read())
    lines = " ".join(lines)  # byte同士の結合ができないのでreadlineでなくreadで
    return np.fromstring(lines, sep=" ", dtype=np.int64).reshape(H, W)

MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
N, K = ints()
A = read_matrix(N, N)
# from numba import njit
# @njit('i8[:,:](i8[:,:],i8[:,:])', cache=True)
def matmul_mod(X: np.ndarray, Y: np.ndarray) -> np.ndarray:
    MOD = 10**9 + 7
    # return X @ Y
    ret = np.empty((X.shape[0], Y.shape[1]), dtype=np.int64)
    for i in range(X.shape[0]):  # Xの行
        for j in range(Y.shape[1]):  # Yの列
            tmp = (X[i, :] * Y[:, j]) % MOD
            ret[i, j] = tmp.sum() % MOD
    return ret

A_double = np.asanyarray(A, dtype=np.int64)
ans = np.eye(N, dtype=np.int64)
for j in range(int(K).bit_length()):
    if (K >> j) & 1:
        ans = matmul_mod(ans, A_double)
    A_double = matmul_mod(A_double, A_double)
print((ans.sum() % MOD))

import sys

sys.setrecursionlimit(1 << 25)
readline = sys.stdin.buffer.readline
read = sys.stdin.readline  # 文字列読み込む時はこっち
import numpy as np
from functools import partial

array = partial(np.array, dtype=np.int64)
zeros = partial(np.zeros, dtype=np.int64)
full = partial(np.full, dtype=np.int64)

def ints():
    return np.fromstring(readline(), sep=" ", dtype=np.int64)

def read_matrix(H, W) -> np.ndarray:
    """return np.ndarray shape=(H,W) matrix"""
    lines = []
    for _ in range(H):
        lines.append(read())
    lines = " ".join(lines)  # byte同士の結合ができないのでreadlineでなくreadで
    return np.fromstring(lines, sep=" ", dtype=np.int64).reshape(H, W)

MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
N, K = ints()
A = read_matrix(N, N)
# from numba import njit
# @njit('i8[:,:](i8[:,:],i8[:,:])', cache=True)
def matmul_mod(X: np.ndarray, Y: np.ndarray) -> np.ndarray:
    MOD = 10**9 + 7
    # return X @ Y
    ret = np.empty((X.shape[0], Y.shape[1]), dtype=np.int64)
    for i in range(X.shape[0]):  # Xの行
        for j in range(Y.shape[1]):  # Yの列
            tmp = (X[i, :] * Y[:, j]) % MOD
            ret[i, j] = tmp.sum() % MOD
    return ret

def matmul_mod_try(X: np.ndarray, Y: np.ndarray) -> np.ndarray:
    MOD = 10**9 + 7
    # return X @ Y
    ret = np.empty((X.shape[0], Y.shape[1]), dtype=np.int64)
    YT = Y.T
    for i in range(X.shape[0]):  # Xの行
        Xi = X[i, :]
        tmp = (YT * Xi) % MOD
        ret[i, :] = tmp.sum(1) % MOD
    return ret

A_double = np.asanyarray(A, dtype=np.int64)
ans = np.eye(N, dtype=np.int64)
for j in range(int(K).bit_length()):
    if (K >> j) & 1:
        # t1, t2 = matmul_mod(ans, A_double), matmul_mod_try(ans, A_double)
        # assert np.array_equal(t1, t2), (t1, t2)
        ans = matmul_mod_try(ans, A_double)
    A_double = matmul_mod_try(A_double, A_double)
print((ans.sum() % MOD))

+def matmul_mod_try(X: np.ndarray, Y: np.ndarray) -> np.ndarray:

+    ret = np.empty((X.shape[0], Y.shape[1]), dtype=np.int64)

-        ans = matmul_mod(ans, A_double)

-    A_double = matmul_mod(A_double, A_double)

+        # t1, t2 = matmul_mod(ans, A_double), matmul_mod_try(ans, A_double)

+        # assert np.array_equal(t1, t2), (t1, t2)

+        ans = matmul_mod_try(ans, A_double)

+    A_double = matmul_mod_try(A_double, A_double)


Input:
# https://atcoder.jp/contests/abc106/tasks/abc106_d

# どうやったら高速に区間[p,q]に完全に入っている区間の数を取得できるか？

# p,qを二次元座標として捉えると電車1本の線は二次元平面上の1点として表せる

# このときp,qの区間に完全に入っている電車の本数というのは、x軸、y軸の両方において[p,q]となる四角形内にある電車の本数

# queryに高速に答えるために二次元累積和を構築する

import sys

read = sys.stdin.readline

def read_ints():

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

def read_tuple(H):

    '''

    H is number of rows

    '''

    ret = []

    for _ in range(H):

        ret.append(tuple(map(int, read().split())))

    return ret

import numpy as np

N, M, Q = read_ints()

LR = read_tuple(M)

pq = read_tuple(Q)

# numpy使わずに再実装 #入れるときはpythonのほうが速いので

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

for L, R in LR:

    LR2d[L][R] += 1

LR2d = np.array(LR2d, np.int64)

LR2d_accum = np.zeros((N + 2, N + 2), np.int64)

LR2d_accum[1:, 1:] = LR2d.cumsum(axis=0).cumsum(axis=1)  # 1次元累積和同様半開区間で考える

# つまりインデックスi,jとはもとの配列においてi,jを含まない四角形の領域の合計を出す

# queryに答えていく

ans = []

for p, q in pq:

    ans.append(LR2d_accum[q + 1, q + 1] - LR2d_accum[q + 1, p] -

               LR2d_accum[p, q + 1] + LR2d_accum[p, p])

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

# https://atcoder.jp/contests/abc106/tasks/abc106_d

# どうやったら高速に区間[p,q]に完全に入っている区間の数を取得できるか？

# p,qを二次元座標として捉えると電車1本の線は二次元平面上の1点として表せる

# このときp,qの区間に完全に入っている電車の本数というのは、x軸、y軸の両方において[p,q]となる四角形内にある電車の本数

# queryに高速に答えるために二次元累積和を構築する

import sys

read = sys.stdin.readline

def read_ints():

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

def read_tuple(H):

    '''

    H is number of rows

    '''

    ret = []

    for _ in range(H):

        ret.append(tuple(map(int, read().split())))

    return ret

# クラスで実装してみる

class cumsum2d:

    def __init__(self, ls: list):

        '''

        2次元のリストを受け取る

        '''

        import numpy as np

        self.ls = np.array(ls)

        H, W = self.ls.shape

        self.ls_accum = np.zeros((H + 1, W + 1))

        self.ls_accum[1:, 1:] = self.ls.cumsum(axis=0).cumsum(axis=1)

    def total(self, i1, j1, i2, j2):

        '''

        点(i1,j1),(i1,j2),(i2,j1),(i2,j2)の4点が成す四角の中の合計を取り出す

        ただし i1<=i2, j1<=j2

        ただし、i軸に関しては[i1,i2),j軸に関しては[j1,j2)の半開区間である

        '''

        return self.ls_accum[i2, j2] - self.ls_accum[i1, j2] \

            - self.ls_accum[i2, j1] + self.ls_accum[i1, j1]

N, M, Q = read_ints()

LR = read_tuple(M)

pq = read_tuple(Q)

# numpy使わずに再実装 #入れるときはpythonのほうが速いので

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

for L, R in LR:

    LR2d[L][R] += 1

LR2d_accum = cumsum2d(LR2d)

# queryに答えていく

ans = []

for p, q in pq:

    ans.append(int(LR2d_accum.total(p, p, q + 1, q + 1)))

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

# https://atcoder.jp/contests/abc106/tasks/abc106_d
# どうやったら高速に区間[p,q]に完全に入っている区間の数を取得できるか？
# p,qを二次元座標として捉えると電車1本の線は二次元平面上の1点として表せる
# このときp,qの区間に完全に入っている電車の本数というのは、x軸、y軸の両方において[p,q]となる四角形内にある電車の本数
# queryに高速に答えるために二次元累積和を構築する
import sys

read = sys.stdin.readline

def read_ints():
    return list(map(int, read().split()))

def read_tuple(H):
    """
    H is number of rows
    """
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret

import numpy as np

N, M, Q = read_ints()
LR = read_tuple(M)
pq = read_tuple(Q)
# numpy使わずに再実装 #入れるときはpythonのほうが速いので
LR2d = [[0] * (N + 1) for _ in range(N + 1)]
for L, R in LR:
    LR2d[L][R] += 1
LR2d = np.array(LR2d, np.int64)
LR2d_accum = np.zeros((N + 2, N + 2), np.int64)
LR2d_accum[1:, 1:] = LR2d.cumsum(axis=0).cumsum(axis=1)  # 1次元累積和同様半開区間で考える
# つまりインデックスi,jとはもとの配列においてi,jを含まない四角形の領域の合計を出す
# queryに答えていく
ans = []
for p, q in pq:
    ans.append(
        LR2d_accum[q + 1, q + 1]
        - LR2d_accum[q + 1, p]
        - LR2d_accum[p, q + 1]
        + LR2d_accum[p, p]
    )
print(*ans, sep="\n")

# https://atcoder.jp/contests/abc106/tasks/abc106_d
# どうやったら高速に区間[p,q]に完全に入っている区間の数を取得できるか？
# p,qを二次元座標として捉えると電車1本の線は二次元平面上の1点として表せる
# このときp,qの区間に完全に入っている電車の本数というのは、x軸、y軸の両方において[p,q]となる四角形内にある電車の本数
# queryに高速に答えるために二次元累積和を構築する
import sys

read = sys.stdin.readline

def read_ints():
    return list(map(int, read().split()))

def read_tuple(H):
    """
    H is number of rows
    """
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret

# クラスで実装してみる
class cumsum2d:
    def __init__(self, ls: list):
        """
        2次元のリストを受け取る
        """
        import numpy as np

        self.ls = np.array(ls)
        H, W = self.ls.shape
        self.ls_accum = np.zeros((H + 1, W + 1))
        self.ls_accum[1:, 1:] = self.ls.cumsum(axis=0).cumsum(axis=1)

    def total(self, i1, j1, i2, j2):
        """
        点(i1,j1),(i1,j2),(i2,j1),(i2,j2)の4点が成す四角の中の合計を取り出す
        ただし i1<=i2, j1<=j2
        ただし、i軸に関しては[i1,i2),j軸に関しては[j1,j2)の半開区間である
        """
        return (
            self.ls_accum[i2, j2]
            - self.ls_accum[i1, j2]
            - self.ls_accum[i2, j1]
            + self.ls_accum[i1, j1]
        )

N, M, Q = read_ints()
LR = read_tuple(M)
pq = read_tuple(Q)
# numpy使わずに再実装 #入れるときはpythonのほうが速いので
LR2d = [[0] * (N + 1) for _ in range(N + 1)]
for L, R in LR:
    LR2d[L][R] += 1
LR2d_accum = cumsum2d(LR2d)
# queryに答えていく
ans = []
for p, q in pq:
    ans.append(int(LR2d_accum.total(p, p, q + 1, q + 1)))
print(*ans, sep="\n")

+# クラスで実装してみる

+        2次元のリストを受け取る

+        self.ls_accum = np.zeros((H + 1, W + 1))

+        self.ls_accum[1:, 1:] = self.ls.cumsum(axis=0).cumsum(axis=1)

+        点(i1,j1),(i1,j2),(i2,j1),(i2,j2)の4点が成す四角の中の合計を取り出す

+        ただし、i軸に関しては[i1,i2),j軸に関しては[j1,j2)の半開区間である

-LR2d_accum = np.zeros((N + 2, N + 2), np.int64)

-LR2d_accum[1:, 1:] = LR2d.cumsum(axis=0).cumsum(axis=1)  # 1次元累積和同様半開区間で考える

-# つまりインデックスi,jとはもとの配列においてi,jを含まない四角形の領域の合計を出す

+    ans.append(int(LR2d_accum.total(p, p, q + 1, q + 1)))


Input:
import collections

N=int(eval(input()))

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

c = collections.Counter(A)

ans=0

n=len(set(A))

c_=c.most_common()

for i in range(n):

    a=int(c_[i][0])

    b=c_[i][1]

    if a <= b:

        ans+=b-a

    else:

        ans+=b

print(ans)

# coding: utf-8

import collections

N = int(eval(input()))

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

A.sort()

c = collections.Counter(A)

A_ = list(set(A))

ans = 0

for a in A_:

    #print(c[a],a)

    if a > c[a]:

        ans += c[a]

    else:

        ans += c[a]-a

print(ans)

import collections

N = int(eval(input()))
A = list(map(int, input().split()))
c = collections.Counter(A)
ans = 0
n = len(set(A))
c_ = c.most_common()
for i in range(n):
    a = int(c_[i][0])
    b = c_[i][1]
    if a <= b:
        ans += b - a
    else:
        ans += b
print(ans)

# coding: utf-8
import collections

N = int(eval(input()))
A = list(map(int, input().split()))
A.sort()
c = collections.Counter(A)
A_ = list(set(A))
ans = 0
for a in A_:
    # print(c[a],a)
    if a > c[a]:
        ans += c[a]
    else:
        ans += c[a] - a
print(ans)

+# coding: utf-8
+A.sort()
+A_ = list(set(A))
-n = len(set(A))
-c_ = c.most_common()
-for i in range(n):
-    a = int(c_[i][0])
-    b = c_[i][1]
-    if a <= b:
-        ans += b - a
+for a in A_:
+    # print(c[a],a)
+    if a > c[a]:
+        ans += c[a]
-        ans += b
+        ans += c[a] - a


Input:
import sys

input = sys.stdin.readline

sys.setrecursionlimit(10 ** 7)

N = int(eval(input()))

x,y,z = 0,0,0 # 最後に特定アクションを行った場合の最大幸福度

for _ in range(N):

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

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

answer = max(x,y,z)

print(answer)

import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

N = int(readline())

m = list(map(int,read().split()))

ABC = list(zip(m,m,m))

x,y,z = 0,0,0 # 最後の活動 -> 幸福度のmax

for a,b,c in ABC:

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

answer = max(x,y,z)

print(answer)

import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**7)
N = int(eval(input()))
x, y, z = 0, 0, 0  # 最後に特定アクションを行った場合の最大幸福度
for _ in range(N):
    a, b, c = list(map(int, input().split()))
    x, y, z = max(y, z) + a, max(x, z) + b, max(x, y) + c
answer = max(x, y, z)
print(answer)

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
m = list(map(int, read().split()))
ABC = list(zip(m, m, m))
x, y, z = 0, 0, 0  # 最後の活動 -> 幸福度のmax
for a, b, c in ABC:
    x, y, z = max(y, z) + a, max(x, z) + b, max(x, y) + c
answer = max(x, y, z)
print(answer)

-x, y, z = 0, 0, 0  # 最後に特定アクションを行った場合の最大幸福度

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


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

def check(p):

  _N = N

  while _N%p == 0:

    _N //= p

  return (_N-1)%p == 0

n = int(N**0.5) + 1

P0 = set([N])

P1 = set([N-1])

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

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

    P1.add(i)

    P1.add((N-1)//i)

  if N%i == 0:

    P0.add(i)

    P0.add(N//i)

P0.discard(1)

P1.discard(1)

ans = len(P1)

for p in P0:

  ans += check(p)

print(ans)

def check(p):

  _N = N

  while _N%p == 0:

    _N //= p

  return (_N-1)%p == 0

def calc_divisors(n):

    m = int(n**0.5)

    left = []

    right = []

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

        if n%i == 0:

            left.append(i)

            right.append(n//i)

    if left[-1] == right[-1]:

        right.pop()

    return left + right[::-1]

N = int(eval(input()))

P0 = calc_divisors(N)[1:] # [:1]で1を除外

P1 = calc_divisors(N-1)[1:] # 同上

ans = len(P1)

for p in P0:

  ans += check(p)

print(ans)

N = int(eval(input()))

def check(p):
    _N = N
    while _N % p == 0:
        _N //= p
    return (_N - 1) % p == 0

n = int(N**0.5) + 1
P0 = set([N])
P1 = set([N - 1])
for i in range(2, n + 1):
    if (N - 1) % i == 0:
        P1.add(i)
        P1.add((N - 1) // i)
    if N % i == 0:
        P0.add(i)
        P0.add(N // i)
P0.discard(1)
P1.discard(1)
ans = len(P1)
for p in P0:
    ans += check(p)
print(ans)

def check(p):
    _N = N
    while _N % p == 0:
        _N //= p
    return (_N - 1) % p == 0

def calc_divisors(n):
    m = int(n**0.5)
    left = []
    right = []
    for i in range(1, m + 1):
        if n % i == 0:
            left.append(i)
            right.append(n // i)
    if left[-1] == right[-1]:
        right.pop()
    return left + right[::-1]

N = int(eval(input()))
P0 = calc_divisors(N)[1:]  # [:1]で1を除外
P1 = calc_divisors(N - 1)[1:]  # 同上
ans = len(P1)
for p in P0:
    ans += check(p)
print(ans)

-N = int(eval(input()))
-n = int(N**0.5) + 1
-P0 = set([N])
-P1 = set([N - 1])
-for i in range(2, n + 1):
-    if (N - 1) % i == 0:
-        P1.add(i)
-        P1.add((N - 1) // i)
-    if N % i == 0:
-        P0.add(i)
-        P0.add(N // i)
-P0.discard(1)
-P1.discard(1)
+def calc_divisors(n):
+    m = int(n**0.5)
+    left = []
+    right = []
+    for i in range(1, m + 1):
+        if n % i == 0:
+            left.append(i)
+            right.append(n // i)
+    if left[-1] == right[-1]:
+        right.pop()
+    return left + right[::-1]
+
+
+N = int(eval(input()))
+P0 = calc_divisors(N)[1:]  # [:1]で1を除外
+P1 = calc_divisors(N - 1)[1:]  # 同上