Input:
from collections import deque

def bfs(maze, visited, queue, H, W):

    count = 0

    while queue:

        y, x = queue.popleft()

        for i, j in ([1, 0], [-1, 0], [0, 1], [0, -1]):

            new_y, new_x = y + i, x + j

            if -1 < new_y < H and -1 < new_x < W:

                if maze[new_y][new_x] == "." and visited[new_y][new_x] == -1:

                    visited[new_y][new_x] = visited[y][x] + 1

                    queue.append([new_y, new_x])

    ans = -1

    for i in range(H):

        for j in range(W):

            ans = max(ans,visited[i][j])

    return ans

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

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

visited = [[-1] * W for i in range(H)]

queue = deque([])

for i in range(H):

    for j in range(W):

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

            visited[i][j] = 0

            queue.append([i, j])

print((bfs(maze, visited, queue, H, W)))

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

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

seen = [[-1] * W for _ in range(H)]

from collections import deque

queue = deque()

for i in range(H):

    for j in range(W):

        if maze[i][j] == '#':

            queue.append([i, j, 0])

            seen[i][j] = 0

def bfs(maze, seen):

    while queue:

        y, x, c = queue.popleft()

        for i, j in [1, 0], [-1, 0], [0, 1], [0, -1]:

            dy = y + i

            dx = x + j

            if dy < 0 or H <= dy or dx < 0 or W <= dx:

                continue

            if seen[dy][dx] > -1:

                continue

            if maze[dy][dx] == '#':

                continue

            seen[dy][dx] = c + 1

            queue.append([dy, dx, c+1])

def check_max(seen):

    ans = 0

    for i in range(H):

        for j in range(W):

            ans = max(ans, seen[i][j])

    return ans

bfs(maze, seen)

print((check_max(seen)))

from collections import deque

def bfs(maze, visited, queue, H, W):
    count = 0
    while queue:
        y, x = queue.popleft()
        for i, j in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_y, new_x = y + i, x + j
            if -1 < new_y < H and -1 < new_x < W:
                if maze[new_y][new_x] == "." and visited[new_y][new_x] == -1:
                    visited[new_y][new_x] = visited[y][x] + 1
                    queue.append([new_y, new_x])
    ans = -1
    for i in range(H):
        for j in range(W):
            ans = max(ans, visited[i][j])
    return ans

H, W = list(map(int, input().split()))
maze = [eval(input()) for i in range(H)]
visited = [[-1] * W for i in range(H)]
queue = deque([])
for i in range(H):
    for j in range(W):
        if maze[i][j] == "#":
            visited[i][j] = 0
            queue.append([i, j])
print((bfs(maze, visited, queue, H, W)))

H, W = list(map(int, input().split()))
maze = [eval(input()) for _ in range(H)]
seen = [[-1] * W for _ in range(H)]
from collections import deque

queue = deque()
for i in range(H):
    for j in range(W):
        if maze[i][j] == "#":
            queue.append([i, j, 0])
            seen[i][j] = 0

def bfs(maze, seen):
    while queue:
        y, x, c = queue.popleft()
        for i, j in [1, 0], [-1, 0], [0, 1], [0, -1]:
            dy = y + i
            dx = x + j
            if dy < 0 or H <= dy or dx < 0 or W <= dx:
                continue
            if seen[dy][dx] > -1:
                continue
            if maze[dy][dx] == "#":
                continue
            seen[dy][dx] = c + 1
            queue.append([dy, dx, c + 1])

def check_max(seen):
    ans = 0
    for i in range(H):
        for j in range(W):
            ans = max(ans, seen[i][j])
    return ans

bfs(maze, seen)
print((check_max(seen)))

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

-            new_y, new_x = y + i, x + j

-            if -1 < new_y < H and -1 < new_x < W:

-                if maze[new_y][new_x] == "." and visited[new_y][new_x] == -1:

-                    visited[new_y][new_x] = visited[y][x] + 1

-                    queue.append([new_y, new_x])

+            if dy < 0 or H <= dy or dx < 0 or W <= dx:

+            queue.append([dy, dx, c + 1])

-            ans = max(ans, visited[i][j])

-maze = [eval(input()) for i in range(H)]

-print((bfs(maze, visited, queue, H, W)))


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

for i in range(-1000,1000):

    for j in range(-1000,1000):

        if i**5-j**5==X:

            print((i,j))

            exit()

X=int(eval(input()))

for i in range(-118,120):

    for j in range(-119,119):

        if i**5-j**5==X:

            print((i,j))

            exit()

X = int(eval(input()))
for i in range(-1000, 1000):
    for j in range(-1000, 1000):
        if i**5 - j**5 == X:
            print((i, j))
            exit()

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


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

c = a*b

print(c)

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

A = int(a)

B = 100*b

c = int(A*B//100)

print(c)

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

a, b = list(map(float, input().split()))
A = int(a)
B = 100 * b
c = int(A * B // 100)
print(c)

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


Input:
import sys

INF = sys.maxsize

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

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

memo = [INF] * N

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

  if i == N - 1:

    # ゴールからゴールの距離を0で初期化

    memo[i] = 0

    continue

  cost = INF

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

    # 範囲外

    if i + j >= N:

      continue

    cost = min(cost, memo[i + j] + abs(heights[i] - heights[i + j]))

  memo[i] = cost

print((memo[0]))

import sys

INF = sys.maxsize

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

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

memo = [INF] * N

memo[0] = 0

for i in range(N):

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

    if i + k < N:

      memo[i + k] = min(

        memo[i + k],

        memo[i] + abs(heights[i] - heights[i + k])

      )

print((memo[N - 1]))

import sys

INF = sys.maxsize
N, K = list(map(int, input().split()))
heights = list(map(int, input().split()))
memo = [INF] * N
memo[0] = 0
for i in range(N):
    for k in range(1, K + 1):
        if i + k < N:
            memo[i + k] = min(memo[i + k], memo[i] + abs(heights[i] - heights[i + k]))
print((memo[N - 1]))

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

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

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

-        # ゴールからゴールの距離を0で初期化

-        # 範囲外

-        cost = min(cost, memo[i + j] + abs(heights[i] - heights[i + j]))

+            memo[i + k] = min(memo[i + k], memo[i] + abs(heights[i] - heights[i + k]))


Input:
import sys

from collections import defaultdict

def sieve_of_eratosthenes(n=5 * 10 ** 6):

  sieve = [1] * (n + 1); sieve[0] = sieve[1] = 0

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

    if not sieve[i]: continue

    for j in range(i * 2, n, i): sieve[j] = 0

  prime_numbers = [i for i in range(2, n + 1) if sieve[i]]

  return sieve, prime_numbers

is_prime, prime_numbers = sieve_of_eratosthenes(10 ** 3)

def prime_factorize(n):

  res = defaultdict(int)

  if n < 2: return res

  border = int(n ** 0.5)

  for p in prime_numbers:

    if p > border: break

    while n % p == 0: res[p] += 1; n //= p

    if n == 1: return res

  res[n] = 1

  return res

def prime_factorize_factorial(n):

  res = defaultdict(int)

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

    for p, c in list(prime_factorize(i).items()): res[p] += c

  return res

MOD = 10 ** 9 + 7

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

def main():

  res = 1

  for c in list(prime_factorize_factorial(n).values()):

    res *= c + 1; res %= MOD

  print(res)

if __name__ ==  '__main__':

  main()

import sys

def sieve_of_eratosthenes(n=5 * 10 ** 6):

  sieve = [1] * (n + 1); sieve[0] = sieve[1] = 0

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

    if not sieve[i]: continue

    for j in range(i * 2, n, i): sieve[j] = 0

  prime_numbers = [i for i in range(2, n + 1) if sieve[i]]

  return sieve, prime_numbers

is_prime, prime_numbers = sieve_of_eratosthenes(10 ** 3)

def prime_factorize(n):

  res = dict()

  if n < 2: return res

  border = int(n ** 0.5)

  for p in prime_numbers:

    if p > border: break

    while n % p == 0: res[p] = res.get(p, 0) + 1; n //= p

    if n == 1: return res

  res[n] = 1

  return res

def prime_factorize_factorial(n):

  res = dict()

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

    for p, c in list(prime_factorize(i).items()): res[p] = res.get(p, 0) + c

  return res

MOD = 10 ** 9 + 7

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

def main():

  res = 1

  for c in list(prime_factorize_factorial(n).values()):

    res *= c + 1; res %= MOD

  print(res)

if __name__ ==  '__main__':

  main()

import sys
from collections import defaultdict

def sieve_of_eratosthenes(n=5 * 10**6):
    sieve = [1] * (n + 1)
    sieve[0] = sieve[1] = 0
    for i in range(2, int(n**0.5) + 1):
        if not sieve[i]:
            continue
        for j in range(i * 2, n, i):
            sieve[j] = 0
    prime_numbers = [i for i in range(2, n + 1) if sieve[i]]
    return sieve, prime_numbers

is_prime, prime_numbers = sieve_of_eratosthenes(10**3)

def prime_factorize(n):
    res = defaultdict(int)
    if n < 2:
        return res
    border = int(n**0.5)
    for p in prime_numbers:
        if p > border:
            break
        while n % p == 0:
            res[p] += 1
            n //= p
        if n == 1:
            return res
    res[n] = 1
    return res

def prime_factorize_factorial(n):
    res = defaultdict(int)
    for i in range(2, n + 1):
        for p, c in list(prime_factorize(i).items()):
            res[p] += c
    return res

MOD = 10**9 + 7
n = int(sys.stdin.readline().rstrip())

def main():
    res = 1
    for c in list(prime_factorize_factorial(n).values()):
        res *= c + 1
        res %= MOD
    print(res)

if __name__ == "__main__":
    main()

import sys

def sieve_of_eratosthenes(n=5 * 10**6):
    sieve = [1] * (n + 1)
    sieve[0] = sieve[1] = 0
    for i in range(2, int(n**0.5) + 1):
        if not sieve[i]:
            continue
        for j in range(i * 2, n, i):
            sieve[j] = 0
    prime_numbers = [i for i in range(2, n + 1) if sieve[i]]
    return sieve, prime_numbers

is_prime, prime_numbers = sieve_of_eratosthenes(10**3)

def prime_factorize(n):
    res = dict()
    if n < 2:
        return res
    border = int(n**0.5)
    for p in prime_numbers:
        if p > border:
            break
        while n % p == 0:
            res[p] = res.get(p, 0) + 1
            n //= p
        if n == 1:
            return res
    res[n] = 1
    return res

def prime_factorize_factorial(n):
    res = dict()
    for i in range(2, n + 1):
        for p, c in list(prime_factorize(i).items()):
            res[p] = res.get(p, 0) + c
    return res

MOD = 10**9 + 7
n = int(sys.stdin.readline().rstrip())

def main():
    res = 1
    for c in list(prime_factorize_factorial(n).values()):
        res *= c + 1
        res %= MOD
    print(res)

if __name__ == "__main__":
    main()

-from collections import defaultdict
-    res = defaultdict(int)
+    res = dict()
-            res[p] += 1
+            res[p] = res.get(p, 0) + 1
-    res = defaultdict(int)
+    res = dict()
-            res[p] += c
+            res[p] = res.get(p, 0) + c


Input:
import sys

# import pdb

input = sys.stdin.readline

N = int(eval(input()))

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

dp_list = [-1 for _ in range(N)]

dp_list[0] = 0

dp_list[1] = abs(hs[1] - hs[0])

sys.setrecursionlimit(1000000)

def dp_memo(p):

  if dp_list[p] != -1:

    return dp_list[p]

  result = min(dp_memo(p-1) + abs(hs[p] - hs[p-1]), dp_memo(p-2) + abs(hs[p] - hs[p-2]))

  dp_list[p] = result

  return result

def dp_recur():

  cost1 = 0

  cost2 = abs(hs[1] - hs[0])

  if N == 2:

    print(cost2)

    exit()

  # pdb.set_trace()

  for i in range(2, N):

    cost3 = min(cost2 + abs(hs[i] - hs[i-1]), cost1 + abs(hs[i] - hs[i-2]))

    cost1 = cost2

    cost2 = cost3

  return cost3

# print(dp_recur())

print((dp_memo(N-1)))

N = int(eval(input()))

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

if N == 2:

  print((abs(hs[1] - hs[0])))

  exit()

total_cost = [-1 for _ in range(N)]

total_cost[0] = 0

total_cost[1] = abs(hs[1]-hs[0])

for i in range(2, N):

  total_cost[i] = min(abs(hs[i]-hs[i-1]) + total_cost[i-1], abs(hs[i]-hs[i-2]) + total_cost[i-2])

print((total_cost[N-1]))

import sys

# import pdb
input = sys.stdin.readline
N = int(eval(input()))
hs = list(map(int, input().split()))
dp_list = [-1 for _ in range(N)]
dp_list[0] = 0
dp_list[1] = abs(hs[1] - hs[0])
sys.setrecursionlimit(1000000)

def dp_memo(p):
    if dp_list[p] != -1:
        return dp_list[p]
    result = min(
        dp_memo(p - 1) + abs(hs[p] - hs[p - 1]), dp_memo(p - 2) + abs(hs[p] - hs[p - 2])
    )
    dp_list[p] = result
    return result

def dp_recur():
    cost1 = 0
    cost2 = abs(hs[1] - hs[0])
    if N == 2:
        print(cost2)
        exit()
    # pdb.set_trace()
    for i in range(2, N):
        cost3 = min(cost2 + abs(hs[i] - hs[i - 1]), cost1 + abs(hs[i] - hs[i - 2]))
        cost1 = cost2
        cost2 = cost3
    return cost3

# print(dp_recur())
print((dp_memo(N - 1)))

N = int(eval(input()))
hs = list(map(int, input().split()))
if N == 2:
    print((abs(hs[1] - hs[0])))
    exit()
total_cost = [-1 for _ in range(N)]
total_cost[0] = 0
total_cost[1] = abs(hs[1] - hs[0])
for i in range(2, N):
    total_cost[i] = min(
        abs(hs[i] - hs[i - 1]) + total_cost[i - 1],
        abs(hs[i] - hs[i - 2]) + total_cost[i - 2],
    )
print((total_cost[N - 1]))

-        dp_memo(p - 1) + abs(hs[p] - hs[p - 1]), dp_memo(p - 2) + abs(hs[p] - hs[p - 2])

+        abs(hs[i] - hs[i - 1]) + total_cost[i - 1],

+        abs(hs[i] - hs[i - 2]) + total_cost[i - 2],

-        cost3 = min(cost2 + abs(hs[i] - hs[i - 1]), cost1 + abs(hs[i] - hs[i - 2]))


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

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

ans = float("INF")

for i in range(1<<N):

    cnt = 0

    tmp = a[:]

    m = tmp[0]

    for j in range(1,N):

        if i >> j & 1 and m >= tmp[j]:

            cnt += m - tmp[j] + 1

            tmp[j] = m + 1

        m = max(m,tmp[j])

    color = 1

    m = tmp[0]

    for j in range(1,N):

        if tmp[j] > m:

            color += 1

            m = tmp[j]

    if color >= K: ans = min(ans,cnt)

print(ans)

from itertools import combinations as comb

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

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

ans = float("INF")

for c in comb(list(range(1,N)),K-1):

    cnt = 0

    color = 0

    mh = a[0]

    for i in range(1,N):

        if i == c[color]:

            cnt += max(mh-a[i]+1,0)

            color += 1

            if color == K-1: break

            mh = max(mh+1,a[i])

        else:

            mh = max(mh,a[i])

    ans = min(cnt ,ans)

print(ans)

N, K = list(map(int, input().split()))
a = [int(i) for i in input().split()]
ans = float("INF")
for i in range(1 << N):
    cnt = 0
    tmp = a[:]
    m = tmp[0]
    for j in range(1, N):
        if i >> j & 1 and m >= tmp[j]:
            cnt += m - tmp[j] + 1
            tmp[j] = m + 1
        m = max(m, tmp[j])
    color = 1
    m = tmp[0]
    for j in range(1, N):
        if tmp[j] > m:
            color += 1
            m = tmp[j]
    if color >= K:
        ans = min(ans, cnt)
print(ans)

from itertools import combinations as comb

N, K = list(map(int, input().split()))
a = [int(i) for i in input().split()]
ans = float("INF")
for c in comb(list(range(1, N)), K - 1):
    cnt = 0
    color = 0
    mh = a[0]
    for i in range(1, N):
        if i == c[color]:
            cnt += max(mh - a[i] + 1, 0)
            color += 1
            if color == K - 1:
                break
            mh = max(mh + 1, a[i])
        else:
            mh = max(mh, a[i])
    ans = min(cnt, ans)
print(ans)

+from itertools import combinations as comb

+for c in comb(list(range(1, N)), K - 1):


Input:
import math

def fact(n):

    return math.factorial(n)

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

if abs(N-M) >= 2:

    print((0))

    exit()

mod = int(1e9)+7

if N == M:

    print((2*fact(N)*fact(M)%mod))

else:

    print((fact(N)*fact(M)%mod))

import math

def fact(n):

    mod = int(1e9)+7

    return math.factorial(n)%mod

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

if abs(N-M) >= 2:

    print((0))

    exit()

mod = int(1e9)+7

if N == M:

    print((2*fact(N)*fact(M)%mod))

else:

    print((fact(N)*fact(M)%mod))

import math

def fact(n):
    return math.factorial(n)

N, M = list(map(int, input().split()))
if abs(N - M) >= 2:
    print((0))
    exit()
mod = int(1e9) + 7
if N == M:
    print((2 * fact(N) * fact(M) % mod))
else:
    print((fact(N) * fact(M) % mod))

import math

def fact(n):
    mod = int(1e9) + 7
    return math.factorial(n) % mod

N, M = list(map(int, input().split()))
if abs(N - M) >= 2:
    print((0))
    exit()
mod = int(1e9) + 7
if N == M:
    print((2 * fact(N) * fact(M) % mod))
else:
    print((fact(N) * fact(M) % mod))

-    return math.factorial(n)
+    mod = int(1e9) + 7
+    return math.factorial(n) % mod


Input:
import math

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

if abs(N-M)>1:

    print((0))

    exit()

IF = 10**9+7

ans = math.factorial(N)*math.factorial(M)

if abs(N-M)==0:

    ans*=2

print((ans%IF))

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

mod = pow(10,9)+7

def f(x,mod):

    k = 1

    res = 1

    while k<x:

        k+=1

        res*=k

        res %= mod

    return res

if abs(N-M)>1:print((0))

elif abs(N-M)==1:

    a = f(min(N,M),mod)

    print((pow(a,2,mod)*max(N,M)%mod))

else:

    a = f(N,mod)

    print((2*pow(a,2,mod)%mod))

import math

N, M = list(map(int, input().split()))
if abs(N - M) > 1:
    print((0))
    exit()
IF = 10**9 + 7
ans = math.factorial(N) * math.factorial(M)
if abs(N - M) == 0:
    ans *= 2
print((ans % IF))

N, M = list(map(int, input().split()))
mod = pow(10, 9) + 7

def f(x, mod):
    k = 1
    res = 1
    while k < x:
        k += 1
        res *= k
        res %= mod
    return res

if abs(N - M) > 1:
    print((0))
elif abs(N - M) == 1:
    a = f(min(N, M), mod)
    print((pow(a, 2, mod) * max(N, M) % mod))
else:
    a = f(N, mod)
    print((2 * pow(a, 2, mod) % mod))

-ans = math.factorial(N) * math.factorial(M)

+    print((pow(a, 2, mod) * max(N, M) % mod))


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

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

f = 10**100

for p in range(min(x), max(x) + 1):

    l = [(x[i] - p)**2 for i in range(n)]

    f1 = sum(l)

    f = min(f, f1)

print(f)

n = int(eval(input()))

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

x_mean = sum(x)/n

p1 = int(x_mean)

p2 = p1 + 1

if abs(x_mean - p1) > abs(x_mean - p2):

    p = p2

else:

    p = p1

ans = 0

for i in range(n):

    ans += (x[i]-p)**2

print(ans)

n = int(eval(input()))
x = list(map(int, input().split()))
f = 10**100
for p in range(min(x), max(x) + 1):
    l = [(x[i] - p) ** 2 for i in range(n)]
    f1 = sum(l)
    f = min(f, f1)
print(f)

n = int(eval(input()))
x = list(map(int, input().split()))
x_mean = sum(x) / n
p1 = int(x_mean)
p2 = p1 + 1
if abs(x_mean - p1) > abs(x_mean - p2):
    p = p2
else:
    p = p1
ans = 0
for i in range(n):
    ans += (x[i] - p) ** 2
print(ans)

-    l = [(x[i] - p) ** 2 for i in range(n)]

+if abs(x_mean - p1) > abs(x_mean - p2):


Input:
I=lambda:list(map(int,input().split()));

n,q=I();r=[0]*n;e=[[]for _ in range(n)];y=[0]+[1]*n;s=[0]

for _ in range(n-1):a,b=I();e[a-1]+=b-1,;e[b-1]+=a-1,;

for _ in range(q):p,x=I();r[p-1]+=x;

while s:

  u=s.pop();v=r[u];

  for c in e[u]:

    if y[c]:y[c]=0;r[c]+=v;s+=c,;

print((*r))

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

from collections import deque

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

ans=[0]*n

for i in range(n-1):

  a,b=[int(x)-1 for x in input().split()]

  edge[a].append(b)

  edge[b].append(a)

for i in range(q):

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

  p-=1

  ans[p]+=x

done=[False]*n

q=deque([])

q.append(0)

done[0]=True

while q:

  v=q.popleft()

  done[v]=True

  for c in edge[v]:

    if done[c]==False:

      ans[c]+=ans[v]

      q.append(c)

print((*ans))

I = lambda: list(map(int, input().split()))
n, q = I()
r = [0] * n
e = [[] for _ in range(n)]
y = [0] + [1] * n
s = [0]
for _ in range(n - 1):
    a, b = I()
    e[a - 1] += (b - 1,)
    e[b - 1] += (a - 1,)
for _ in range(q):
    p, x = I()
    r[p - 1] += x
while s:
    u = s.pop()
    v = r[u]
    for c in e[u]:
        if y[c]:
            y[c] = 0
            r[c] += v
            s += (c,)
print((*r))

n, q = list(map(int, input().split()))
from collections import deque

edge = [[] for _ in range(n)]
ans = [0] * n
for i in range(n - 1):
    a, b = [int(x) - 1 for x in input().split()]
    edge[a].append(b)
    edge[b].append(a)
for i in range(q):
    p, x = list(map(int, input().split()))
    p -= 1
    ans[p] += x
done = [False] * n
q = deque([])
q.append(0)
done[0] = True
while q:
    v = q.popleft()
    done[v] = True
    for c in edge[v]:
        if done[c] == False:
            ans[c] += ans[v]
            q.append(c)
print((*ans))

-I = lambda: list(map(int, input().split()))

+    a, b = [int(x) - 1 for x in input().split()]

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


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

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

A.sort()

M=10**6+1

cnt=[0]*M

for i in A:

    if cnt[i]!=0:

        cnt[i]=2

        continue

    for j in range(i,M,i):

        cnt[j]+=1

ans=0

for i in A:

    if cnt[i]==1:

        ans+=1

print(ans)

from collections import Counter

max_=10**6+1

ans=0

n=int(eval(input()))

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

b=[True]*(max_+1)

data.sort()

c=Counter(data)

for d in data:

    if b[d]:

        for j in range(d,max_,d):

            b[j]=False

        if c[d]==1:#複数存在考慮

            ans+=1

print(ans)

n = int(eval(input()))
A = list(map(int, input().split()))
A.sort()
M = 10**6 + 1
cnt = [0] * M
for i in A:
    if cnt[i] != 0:
        cnt[i] = 2
        continue
    for j in range(i, M, i):
        cnt[j] += 1
ans = 0
for i in A:
    if cnt[i] == 1:
        ans += 1
print(ans)

from collections import Counter

max_ = 10**6 + 1
ans = 0
n = int(eval(input()))
data = list(map(int, input().split()))
b = [True] * (max_ + 1)
data.sort()
c = Counter(data)
for d in data:
    if b[d]:
        for j in range(d, max_, d):
            b[j] = False
        if c[d] == 1:  # 複数存在考慮
            ans += 1
print(ans)

+from collections import Counter
+
+max_ = 10**6 + 1
+ans = 0
-A = list(map(int, input().split()))
-A.sort()
-M = 10**6 + 1
-cnt = [0] * M
-for i in A:
-    if cnt[i] != 0:
-        cnt[i] = 2
-        continue
-    for j in range(i, M, i):
-        cnt[j] += 1
-ans = 0
-for i in A:
-    if cnt[i] == 1:
-        ans += 1
+data = list(map(int, input().split()))
+b = [True] * (max_ + 1)
+data.sort()
+c = Counter(data)
+for d in data:
+    if b[d]:
+        for j in range(d, max_, d):
+            b[j] = False
+        if c[d] == 1:  # 複数存在考慮
+            ans += 1


Input:
import sys

import numpy as np

input = sys.stdin.readline

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

tv_guide = np.zeros((c, 10**5+1), dtype=np.int)

for _ in range(n):

    s, t, c = [int(x)-1 for x in input().split()]

    tv_guide[c][s:t+1] = 1

ans = 0

for time in range(10**5+1):

    count = sum(tv_guide[:,time])

    ans = max(count, ans)

print(ans)

import sys

input = sys.stdin.readline

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

tv_guide = []

for _ in range(n):

    start, end, channel = list(map(int, input().split()))

    tv_guide.append([start, 1, channel-1])

    tv_guide.append([end, 0, channel-1])

tv_guide.sort(key=lambda x:(x[0], -x[1]))

channel_count = [0] * c

channel_set = set()

ans = 0

for time, on, channel in tv_guide:

    if on:

        channel_set.add(channel)

        channel_count[channel] += 1

    else:

        channel_count[channel] -= 1

        if channel_count[channel] == 0:

            channel_set.discard(channel)

    candidate = len(channel_set)

    if ans < candidate:

        ans = candidate

print(ans)

import sys
import numpy as np

input = sys.stdin.readline
n, c = list(map(int, input().split()))
tv_guide = np.zeros((c, 10**5 + 1), dtype=np.int)
for _ in range(n):
    s, t, c = [int(x) - 1 for x in input().split()]
    tv_guide[c][s : t + 1] = 1
ans = 0
for time in range(10**5 + 1):
    count = sum(tv_guide[:, time])
    ans = max(count, ans)
print(ans)

import sys

input = sys.stdin.readline
n, c = list(map(int, input().split()))
tv_guide = []
for _ in range(n):
    start, end, channel = list(map(int, input().split()))
    tv_guide.append([start, 1, channel - 1])
    tv_guide.append([end, 0, channel - 1])
tv_guide.sort(key=lambda x: (x[0], -x[1]))
channel_count = [0] * c
channel_set = set()
ans = 0
for time, on, channel in tv_guide:
    if on:
        channel_set.add(channel)
        channel_count[channel] += 1
    else:
        channel_count[channel] -= 1
        if channel_count[channel] == 0:
            channel_set.discard(channel)
    candidate = len(channel_set)
    if ans < candidate:
        ans = candidate
print(ans)

-tv_guide = np.zeros((c, 10**5 + 1), dtype=np.int)

-    s, t, c = [int(x) - 1 for x in input().split()]

+    start, end, channel = list(map(int, input().split()))

+    tv_guide.append([start, 1, channel - 1])

+    tv_guide.append([end, 0, channel - 1])

+tv_guide.sort(key=lambda x: (x[0], -x[1]))

+        if channel_count[channel] == 0:

+            channel_set.discard(channel)


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

print((int((x-z)/(y+z))))

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

print(((x-z)//(y+z)))

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

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


Input:
# https://atcoder.jp/contests/abc095/tasks/arc096_a

# A1枚→A円

# B1枚→B円

# A,B両方一枚→AB円

# もし2AB<=A+Bならmin(X,Y)になるまで買ったほうが安い

# Aだけ必要→A<AB→Aを買う、違うならABを買う

# Bだけ必要→上に同じ

# もし2AB<=A+Bでなかった場合

# A,B<ABの場合→A,Bを個別に買う

# A<2AB の場合→Aは個別で

# この議論は上に統合される

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

# 両方買うほうがお得のときは先に買っておく

ans = 0

if 2 * c <= a + b:

    n = min(x, y)

    ans += 2 * n * c

    x -= n

    y -= n

# print(x, y, ans)

# Aだけ買う

if a <= 2 * c:

    ans += x * a

else:

    ans += x * 2 * c

if b <= 2 * c:

    ans += y * b

else:

    ans += y * 2 * c

print(ans)

import sys

sys.setrecursionlimit(1 << 25)

read = sys.stdin.readline

ra = range

enu = enumerate

def read_ints():

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

def read_a_int():

    return int(read())

def read_tuple(H):

    '''

    H is number of rows

    '''

    ret = []

    for _ in range(H):

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

    return ret

def read_col(H):

    '''

    H is number of rows

    A列、B列が与えられるようなとき

    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合

    '''

    ret = []

    for _ in range(H):

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

    return tuple(map(list, list(zip(*ret))))

def read_matrix(H):

    '''

    H is number of rows

    '''

    ret = []

    for _ in range(H):

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

    return ret

    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため

MOD = 10**9 + 7

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

# default import

from collections import defaultdict, Counter, deque

from operator import itemgetter

from itertools import product, permutations, combinations

from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# https://atcoder.jp/contests/abc095/tasks/arc096_a

A, B, C, X, Y = read_ints()

# もし組み合わせて買ったほうがいいなら限界まで組み合わせて買う

buyed = min(X, Y)

c1 = min(A + B, 2 * C) * buyed

X -= buyed

Y -= buyed

if X:

    c2 = min(A, 2 * C) * X

elif Y:

    c2 = min(B, 2 * C) * Y

else:

    c2 = 0

print((c1 + c2))

import sys

sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate

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

def read_a_int():
    return int(read())

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

def read_col(H):
    """
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    """
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, list(zip(*ret))))

def read_matrix(H):
    """
    H is number of rows
    """
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため

MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# https://atcoder.jp/contests/abc095/tasks/arc096_a
A, B, C, X, Y = read_ints()
# もし組み合わせて買ったほうがいいなら限界まで組み合わせて買う
buyed = min(X, Y)
c1 = min(A + B, 2 * C) * buyed
X -= buyed
Y -= buyed
if X:
    c2 = min(A, 2 * C) * X
elif Y:
    c2 = min(B, 2 * C) * Y
else:
    c2 = 0
print((c1 + c2))

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

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

+    A列、B列が与えられるようなとき

+    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合

+        ret.append(list(map(int, read().split())))

+    return tuple(map(list, list(zip(*ret))))

+    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため

+from collections import defaultdict, Counter, deque

+from itertools import product, permutations, combinations

+from bisect import bisect_left, bisect_right  # , insort_left, insort_right

-# Aだけ必要→A<AB→Aを買う、違うならABを買う

-# Bだけ必要→上に同じ

-# A<2AB の場合→Aは個別で

-# この議論は上に統合される

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

-# 両方買うほうがお得のときは先に買っておく

+# もし組み合わせて買ったほうがいいなら限界まで組み合わせて買う


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

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

sum = n

for i in m:

    x = x - i

while x - min(m) >= 0:

    x = x - min(m)

    sum += 1

print(sum)

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

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

x -= sum(m)

print((n + x//min(m)))

n, x = list(map(int, input().split()))
m = [int(eval(input())) for i in range(n)]
x -= sum(m)
print((n + x // min(m)))

-sum = n
-for i in m:
-    x = x - i
-while x - min(m) >= 0:
-    x = x - min(m)
-    sum += 1
-print(sum)
+x -= sum(m)
+print((n + x // min(m)))


Input:
s,t,a,b,x,y=list(map(int,open(0).read().split()))

if a*s+b*t==x*s+y*t:

  print('infinity')

  exit()

if a<x:a,b,x,y=x,y,a,b

if a*s+b*t>x*s+y*t:

  print((0))

  exit()

n=(a*s-x*s)/(x*s+y*t-(a*s+b*t))

m=int(n)

print((m*2+(n>m)))

s,t,a,b,x,y=list(map(int,open(0).read().split()))

i=(x-a)*s

j=(b-y)*t-i

print((max(0,i//j*2+(i%j!=0))if j else'infinity'))

s, t, a, b, x, y = list(map(int, open(0).read().split()))
if a * s + b * t == x * s + y * t:
    print("infinity")
    exit()
if a < x:
    a, b, x, y = x, y, a, b
if a * s + b * t > x * s + y * t:
    print((0))
    exit()
n = (a * s - x * s) / (x * s + y * t - (a * s + b * t))
m = int(n)
print((m * 2 + (n > m)))

s, t, a, b, x, y = list(map(int, open(0).read().split()))
i = (x - a) * s
j = (b - y) * t - i
print((max(0, i // j * 2 + (i % j != 0)) if j else "infinity"))

+print((max(0, i // j * 2 + (i % j != 0)) if j else "infinity"))


Input:
import sys, re

from collections import deque, defaultdict, Counter

from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd

from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby

from operator import itemgetter, mul

from copy import deepcopy

from string import ascii_lowercase, ascii_uppercase, digits

from bisect import bisect, bisect_left, insort, insort_left

from heapq import heappush, heappop

from functools import reduce

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

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

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

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

def ZIP(n): return list(zip(*(MAP() for _ in range(n))))

sys.setrecursionlimit(10 ** 9)

INF = float('inf')

mod = 10 ** 9 + 7

#mod = 998244353

from decimal import *

#import numpy as np

#decimal.getcontext().prec = 10

N = INT()

AB = [LIST() for _ in range(N)]

for i in range(N):

	AB[i].append(sum(AB[i]))

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

print((sum([AB[i][0] for i in range(0, N, 2)]) - sum([AB[i][1] for i in range(1, N, 2)])))

import sys, re

from collections import deque, defaultdict, Counter

from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, log

from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby

from operator import itemgetter, mul

from copy import deepcopy

from string import ascii_lowercase, ascii_uppercase, digits

from bisect import bisect, bisect_left, insort, insort_left

from fractions import gcd

from heapq import heappush, heappop

from functools import reduce

from decimal import Decimal

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

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

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

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

def ZIP(n): return list(zip(*(MAP() for _ in range(n))))

sys.setrecursionlimit(10 ** 9)

INF = float('inf')

mod = 10**9 + 7

from decimal import *

N = INT()

AB = [LIST() for _ in range(N)]

X = -sum([x[1] for x in AB])

for i, (A, B) in enumerate(sorted(AB, key=lambda x:x[0]+x[1], reverse = True)):

	if i%2 == 0:

		X += A+B

print(X)

import sys, re
from collections import deque, defaultdict, Counter
from math import (
    ceil,
    sqrt,
    hypot,
    factorial,
    pi,
    sin,
    cos,
    tan,
    asin,
    acos,
    atan,
    radians,
    degrees,
    log2,
    gcd,
)
from itertools import (
    accumulate,
    permutations,
    combinations,
    combinations_with_replacement,
    product,
    groupby,
)
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce

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

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

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

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

def ZIP(n):
    return list(zip(*(MAP() for _ in range(n))))

sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
# mod = 998244353
from decimal import *

# import numpy as np
# decimal.getcontext().prec = 10
N = INT()
AB = [LIST() for _ in range(N)]
for i in range(N):
    AB[i].append(sum(AB[i]))
AB.sort(key=lambda x: -x[2])
print(
    (sum([AB[i][0] for i in range(0, N, 2)]) - sum([AB[i][1] for i in range(1, N, 2)]))
)

import sys, re
from collections import deque, defaultdict, Counter
from math import (
    ceil,
    sqrt,
    hypot,
    factorial,
    pi,
    sin,
    cos,
    tan,
    asin,
    acos,
    atan,
    radians,
    degrees,
    log2,
    log,
)
from itertools import (
    accumulate,
    permutations,
    combinations,
    combinations_with_replacement,
    product,
    groupby,
)
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal

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

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

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

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

def ZIP(n):
    return list(zip(*(MAP() for _ in range(n))))

sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
from decimal import *

N = INT()
AB = [LIST() for _ in range(N)]
X = -sum([x[1] for x in AB])
for i, (A, B) in enumerate(sorted(AB, key=lambda x: x[0] + x[1], reverse=True)):
    if i % 2 == 0:
        X += A + B
print(X)

-    (sum([AB[i][0] for i in range(0, N, 2)]) - sum([AB[i][1] for i in range(1, N, 2)]))

+for i, (A, B) in enumerate(sorted(AB, key=lambda x: x[0] + x[1], reverse=True)):


Input:
import itertools

while True:

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

    if N == K == S == 0:

        break

    ans = 0

    for l in itertools.combinations(list(range(1, N+1)), K):

        if sum(l) == S:

            ans += 1

    print(ans)

import itertools

while True:

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

    if N == K == S == 0:

        break

    print((sum(1 for l in itertools.combinations(list(range(1, N+1)), K) if sum(l) == S)))

import itertools

while True:
    N, K, S = list(map(int, input().split()))
    if N == K == S == 0:
        break
    ans = 0
    for l in itertools.combinations(list(range(1, N + 1)), K):
        if sum(l) == S:
            ans += 1
    print(ans)

import itertools

while True:
    N, K, S = list(map(int, input().split()))
    if N == K == S == 0:
        break
    print(
        (
            sum(
                1
                for l in itertools.combinations(list(range(1, N + 1)), K)
                if sum(l) == S
            )
        )
    )

-    for l in itertools.combinations(list(range(1, N + 1)), K):

+                for l in itertools.combinations(list(range(1, N + 1)), K)


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

out = int(li[0] / (li[1] + li[2])) * li[1]

remain = li[0] - int(li[0] / (li[1] + li[2])) *  (li[1] + li[2])

if(remain > li[1]):

    out += li[1]

else:

    out += remain

print(out)

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

n = int(N / (A + B))

m = min(N - n * (A + B), A)

print((n * A + m))

li = list(map(int, input().split()))
out = int(li[0] / (li[1] + li[2])) * li[1]
remain = li[0] - int(li[0] / (li[1] + li[2])) * (li[1] + li[2])
if remain > li[1]:
    out += li[1]
else:
    out += remain
print(out)

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


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

lst = [int(s) for s in input().split()]

def suc(ls):

  val_ls=ls

  i=0

  while(i<N and val_ls[i]==0):

    i+=1

  if i==N:

    return []

  else:

    while(i<N and val_ls[i]!=0):

      val_ls[i]-=1

      i+=1

    return val_ls

ans=0

while(lst!=[]):

  ans+=1

  lst=suc(lst)

print((ans-1))

N=int(eval(input()))

ls=[int(s) for s in input().split()]

ls.append(0)

a=0

for i in range(N):

  a+=max([0,ls[i]-ls[i+1]])

print(a)

N = int(eval(input()))
lst = [int(s) for s in input().split()]

def suc(ls):
    val_ls = ls
    i = 0
    while i < N and val_ls[i] == 0:
        i += 1
    if i == N:
        return []
    else:
        while i < N and val_ls[i] != 0:
            val_ls[i] -= 1
            i += 1
        return val_ls

ans = 0
while lst != []:
    ans += 1
    lst = suc(lst)
print((ans - 1))

N = int(eval(input()))
ls = [int(s) for s in input().split()]
ls.append(0)
a = 0
for i in range(N):
    a += max([0, ls[i] - ls[i + 1]])
print(a)

-lst = [int(s) for s in input().split()]

-        while i < N and val_ls[i] != 0:


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

A = [int(eval(input())) for i in range(N)]

if A[0]:

    print((-1))

    exit()

ans = 0

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

    if b-a > 1:

        print((-1))

        exit()

    if b==0: continue

    if b-a == 1:

        ans += 1

    else:

        ans += b

print(ans)

N = int(eval(input()))

A = [int(eval(input())) for i in range(N)]

if A[0]:

    print((-1))

    exit()

ans = 0

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

    if a+1 < b:

        print((-1))

        exit()

    if a+1 == b:

        ans += 1

    else:

        ans += b

print(ans)

N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
if A[0]:
    print((-1))
    exit()
ans = 0
for a, b in zip(A, A[1:]):
    if b - a > 1:
        print((-1))
        exit()
    if b == 0:
        continue
    if b - a == 1:
        ans += 1
    else:
        ans += b
print(ans)

N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
if A[0]:
    print((-1))
    exit()
ans = 0
for a, b in zip(A, A[1:]):
    if a + 1 < b:
        print((-1))
        exit()
    if a + 1 == b:
        ans += 1
    else:
        ans += b
print(ans)


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

s=eval(input())

a=[int(s[i])-1 for i in range(n)]

div=[0]*(n+1)

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

  div[i]+=div[i-1]

  x=i

  while not x&1:

    x>>=1

    div[i]+=1

XOR=0

for i in range(n):

  if div[n-1]<=div[i]+div[n-1-i]:

    XOR^=a[i]

if XOR&1:

  print((1))

  exit(0)

for i in a:

  if i==1:

    print((0))

    exit(0)

XOR=0

for i in range(n):

  if div[n-1]<=div[i]+div[n-1-i]:

    XOR^=a[i]>>1

if XOR&1:

  print((2))

  exit(0)

print((0))

n=int(eval(input()))

s=eval(input())

a=[int(s[i])-1 for i in range(n)]

div=[0]*(n+1)

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

  div[i]+=div[i-1]

  x=i

  while not x&1:

    x>>=1

    div[i]+=1

XOR=0;one=False

for i in range(n):

  one|=a[i]==1

  if div[n-1]<=div[i]+div[n-1-i]:

    XOR^=a[i]

if XOR&1:print((1))

elif one:print((0))

elif XOR&2:print((2))

else:print((0))

n = int(eval(input()))
s = eval(input())
a = [int(s[i]) - 1 for i in range(n)]
div = [0] * (n + 1)
for i in range(1, n + 1):
    div[i] += div[i - 1]
    x = i
    while not x & 1:
        x >>= 1
        div[i] += 1
XOR = 0
for i in range(n):
    if div[n - 1] <= div[i] + div[n - 1 - i]:
        XOR ^= a[i]
if XOR & 1:
    print((1))
    exit(0)
for i in a:
    if i == 1:
        print((0))
        exit(0)
XOR = 0
for i in range(n):
    if div[n - 1] <= div[i] + div[n - 1 - i]:
        XOR ^= a[i] >> 1
if XOR & 1:
    print((2))
    exit(0)
print((0))

n = int(eval(input()))
s = eval(input())
a = [int(s[i]) - 1 for i in range(n)]
div = [0] * (n + 1)
for i in range(1, n + 1):
    div[i] += div[i - 1]
    x = i
    while not x & 1:
        x >>= 1
        div[i] += 1
XOR = 0
one = False
for i in range(n):
    one |= a[i] == 1
    if div[n - 1] <= div[i] + div[n - 1 - i]:
        XOR ^= a[i]
if XOR & 1:
    print((1))
elif one:
    print((0))
elif XOR & 2:
    print((2))
else:
    print((0))


Input:
import math

import fractions

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

gcd = fractions.gcd(A,B)

N = int(math.ceil(math.sqrt(gcd)))

cd = []

for i in range(1,N):

    if A%i==0 and B%i==0:

        cd.append(i)

        cd.append(gcd//i)

if N==1:

    cd.append(N)

ans=0

cd.sort()

for i in range(len(cd)):

    tr=1

    for j in range(1,i):

        if cd[i]%cd[j]==0:

            tr=0

            break

    if tr==1:

        ans+=1

print(ans)

import sys

input = sys.stdin.readline

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

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

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

def main():

    def factorization(n):

        if n==1:

            return []

        arr = []

        temp = n

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

            if temp%i==0:

                cnt=0

                while temp%i==0:

                    cnt+=1

                    temp //= i

                arr.append([i, cnt])

        if temp!=1:

            arr.append([temp, 1])

        if arr==[]:

            arr.append([n, 1])

        return arr

    mod=10**9+7

    a,b=MI()

    from math import gcd

    g=gcd(a,b)

    arr=factorization(g)

    ans=len(arr)+1

    print(ans)

main()

import math
import fractions

A, B = list(map(int, input().split()))
gcd = fractions.gcd(A, B)
N = int(math.ceil(math.sqrt(gcd)))
cd = []
for i in range(1, N):
    if A % i == 0 and B % i == 0:
        cd.append(i)
        cd.append(gcd // i)
if N == 1:
    cd.append(N)
ans = 0
cd.sort()
for i in range(len(cd)):
    tr = 1
    for j in range(1, i):
        if cd[i] % cd[j] == 0:
            tr = 0
            break
    if tr == 1:
        ans += 1
print(ans)

import sys

input = sys.stdin.readline

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

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

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

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

    mod = 10**9 + 7
    a, b = MI()
    from math import gcd

    g = gcd(a, b)
    arr = factorization(g)
    ans = len(arr) + 1
    print(ans)

main()

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


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

maxn = -1

ans = ()

for at in range(0,31):

    for bt in range(0,31-at):

        water = (at * a + bt * b) * 100

        if water > f:

            continue

        # 溶け残らないように砂糖を選ぶ

        maxsugar = water * e // 100

        for ct in range(0, (maxsugar+1)//c + 1):

            for dt in range(0, (maxsugar-ct*c+1)//d + 1):

                sugar = ct * c + dt * d

                if 0 < sugar + water <= f and sugar <= (at * a + bt * b) * e:

                    # 水１００に対して溶けている砂糖の量

                    n = 100 * sugar / water

                    if n == e:

                        print((water + sugar, sugar))

                        exit()

                    if n > maxn:

                        ans = water + sugar, sugar

                        maxn = n

print((*ans))

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

maxn = -1

ans = ()

for at in range(0,31):

    for bt in range(0,31-at):

        water = (at * a + bt * b) * 100

        if water > f:

            continue

        # 溶け残らないように砂糖を選ぶ

        maxsugar = water * e // 100

        for ct in range(0, (maxsugar)//c + 1):

            for dt in range(0, (maxsugar-ct*c+1)//d + 1):

                sugar = ct * c + dt * d

                if 0 < sugar + water <= f and sugar <= (at * a + bt * b) * e:

                    # 水１００に対して溶けている砂糖の量

                    n = 100 * sugar / water

                    if n == e:

                        print((water + sugar, sugar))

                        exit()

                    if n > maxn:

                        ans = water + sugar, sugar

                        maxn = n

print((*ans))

a, b, c, d, e, f = list(map(int, input().split()))
maxn = -1
ans = ()
for at in range(0, 31):
    for bt in range(0, 31 - at):
        water = (at * a + bt * b) * 100
        if water > f:
            continue
        # 溶け残らないように砂糖を選ぶ
        maxsugar = water * e // 100
        for ct in range(0, (maxsugar + 1) // c + 1):
            for dt in range(0, (maxsugar - ct * c + 1) // d + 1):
                sugar = ct * c + dt * d
                if 0 < sugar + water <= f and sugar <= (at * a + bt * b) * e:
                    # 水１００に対して溶けている砂糖の量
                    n = 100 * sugar / water
                    if n == e:
                        print((water + sugar, sugar))
                        exit()
                    if n > maxn:
                        ans = water + sugar, sugar
                        maxn = n
print((*ans))

a, b, c, d, e, f = list(map(int, input().split()))
maxn = -1
ans = ()
for at in range(0, 31):
    for bt in range(0, 31 - at):
        water = (at * a + bt * b) * 100
        if water > f:
            continue
        # 溶け残らないように砂糖を選ぶ
        maxsugar = water * e // 100
        for ct in range(0, (maxsugar) // c + 1):
            for dt in range(0, (maxsugar - ct * c + 1) // d + 1):
                sugar = ct * c + dt * d
                if 0 < sugar + water <= f and sugar <= (at * a + bt * b) * e:
                    # 水１００に対して溶けている砂糖の量
                    n = 100 * sugar / water
                    if n == e:
                        print((water + sugar, sugar))
                        exit()
                    if n > maxn:
                        ans = water + sugar, sugar
                        maxn = n
print((*ans))

-        for ct in range(0, (maxsugar + 1) // c + 1):

+        for ct in range(0, (maxsugar) // c + 1):


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

print((chr(ord(C)+1)))

C = str(eval(input()))
print((chr(ord(C) + 1)))


Input:
import numpy as np

a = np.zeros(201)

for d in range(1,201,2):

  a[d::2*d]+=1

a=(a==8).cumsum()

N = int(eval(input()))

print((a[N]))

N = int(eval(input()))

a = 0

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

  n = 0

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

    if i%j==0:

      n+=1

    if n==8:

      a+=1

print(a)

import numpy as np

a = np.zeros(201)
for d in range(1, 201, 2):
    a[d :: 2 * d] += 1
a = (a == 8).cumsum()
N = int(eval(input()))
print((a[N]))

N = int(eval(input()))
a = 0
for i in range(1, 1 + N, 2):
    n = 0
    for j in range(1, 1 + i, 2):
        if i % j == 0:
            n += 1
        if n == 8:
            a += 1
print(a)


Input:
p, g, ig = 998244353, 3, 332748118

W = [pow(g, (p - 1) >> i, p) for i in range(24)]

iW = [pow(ig, (p - 1) >> i, p) for i in range(24)]

def fft(k, f):

    for l in range(k, 0, -1):

        d = 1 << l - 1

        for i in range(1 << k - l):

            u = 1

            for j in range(i * 2 * d, (i * 2 + 1) * d):

                f[j], f[j+d] = (f[j] + f[j+d]) % p, u * (f[j] - f[j+d]) % p

                u = u * W[l] % p

def ifft(k, f):

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

        d = 1 << l - 1

        for i in range(1 << k - l):

            u = 1

            for j in range(i * 2 * d, (i * 2 + 1) * d):

                f[j+d] *= u

                f[j], f[j+d] = (f[j] + f[j+d]) % p, (f[j] - f[j+d]) % p

                u = u * iW[l] % p

def convolve(a, b):

    n0 = len(a) + len(b) - 1

    k = (n0).bit_length()

    n = 1 << k

    a = a + [0] * (n - len(a))

    b = b + [0] * (n - len(b))

    fft(k, a), fft(k, b)

    for i in range(n):

        a[i] = a[i] * b[i] % p

    ifft(k, a)

    invn = pow(n, p - 2, p)

    for i in range(n0):

        a[i] = a[i] * invn % p

    del a[n0:]

    return a

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

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

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

print((*convolve(A, B)))

p, g, ig = 998244353, 3, 332748118

W = [pow(g, (p - 1) >> i, p) for i in range(24)]

iW = [pow(ig, (p - 1) >> i, p) for i in range(24)]

def fft(k, f):

    for l in range(k, 0, -1):

        d = 1 << l - 1

        U = [1]

        for i in range(d):

            U.append(U[-1] * W[l] % p)

        for i in range(1 << k - l):

            for j in range(d):

                s = i * 2 * d + j

                f[s], f[s+d] = (f[s] + f[s+d]) % p, U[j] * (f[s] - f[s+d]) % p

def ifft(k, f):

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

        d = 1 << l - 1

        for i in range(1 << k - l):

            u = 1

            for j in range(i * 2 * d, (i * 2 + 1) * d):

                f[j+d] *= u

                f[j], f[j+d] = (f[j] + f[j+d]) % p, (f[j] - f[j+d]) % p

                u = u * iW[l] % p

def convolve(a, b):

    n0 = len(a) + len(b) - 1

    k = (n0).bit_length()

    n = 1 << k

    a = a + [0] * (n - len(a))

    b = b + [0] * (n - len(b))

    fft(k, a), fft(k, b)

    for i in range(n):

        a[i] = a[i] * b[i] % p

    ifft(k, a)

    invn = pow(n, p - 2, p)

    for i in range(n0):

        a[i] = a[i] * invn % p

    del a[n0:]

    return a

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

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

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

print((*convolve(A, B)))

p, g, ig = 998244353, 3, 332748118
W = [pow(g, (p - 1) >> i, p) for i in range(24)]
iW = [pow(ig, (p - 1) >> i, p) for i in range(24)]

def fft(k, f):
    for l in range(k, 0, -1):
        d = 1 << l - 1
        for i in range(1 << k - l):
            u = 1
            for j in range(i * 2 * d, (i * 2 + 1) * d):
                f[j], f[j + d] = (f[j] + f[j + d]) % p, u * (f[j] - f[j + d]) % p
                u = u * W[l] % p

def ifft(k, f):
    for l in range(1, k + 1):
        d = 1 << l - 1
        for i in range(1 << k - l):
            u = 1
            for j in range(i * 2 * d, (i * 2 + 1) * d):
                f[j + d] *= u
                f[j], f[j + d] = (f[j] + f[j + d]) % p, (f[j] - f[j + d]) % p
                u = u * iW[l] % p

def convolve(a, b):
    n0 = len(a) + len(b) - 1
    k = (n0).bit_length()
    n = 1 << k
    a = a + [0] * (n - len(a))
    b = b + [0] * (n - len(b))
    fft(k, a), fft(k, b)
    for i in range(n):
        a[i] = a[i] * b[i] % p
    ifft(k, a)
    invn = pow(n, p - 2, p)
    for i in range(n0):
        a[i] = a[i] * invn % p
    del a[n0:]
    return a

N, M = list(map(int, input().split()))
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
print((*convolve(A, B)))

p, g, ig = 998244353, 3, 332748118
W = [pow(g, (p - 1) >> i, p) for i in range(24)]
iW = [pow(ig, (p - 1) >> i, p) for i in range(24)]

def fft(k, f):
    for l in range(k, 0, -1):
        d = 1 << l - 1
        U = [1]
        for i in range(d):
            U.append(U[-1] * W[l] % p)
        for i in range(1 << k - l):
            for j in range(d):
                s = i * 2 * d + j
                f[s], f[s + d] = (f[s] + f[s + d]) % p, U[j] * (f[s] - f[s + d]) % p

def ifft(k, f):
    for l in range(1, k + 1):
        d = 1 << l - 1
        for i in range(1 << k - l):
            u = 1
            for j in range(i * 2 * d, (i * 2 + 1) * d):
                f[j + d] *= u
                f[j], f[j + d] = (f[j] + f[j + d]) % p, (f[j] - f[j + d]) % p
                u = u * iW[l] % p

def convolve(a, b):
    n0 = len(a) + len(b) - 1
    k = (n0).bit_length()
    n = 1 << k
    a = a + [0] * (n - len(a))
    b = b + [0] * (n - len(b))
    fft(k, a), fft(k, b)
    for i in range(n):
        a[i] = a[i] * b[i] % p
    ifft(k, a)
    invn = pow(n, p - 2, p)
    for i in range(n0):
        a[i] = a[i] * invn % p
    del a[n0:]
    return a

N, M = list(map(int, input().split()))
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
print((*convolve(A, B)))

-            for j in range(i * 2 * d, (i * 2 + 1) * d):


Input:
from bisect import bisect

N = int(eval(input()))

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

INF = 10**10

dp = [-INF]

for a in A:

    if a <= -dp[-1]:

        dp.append(-a)

    else:

        i = bisect(dp, -a)

        dp[i] = -a

ans = len(dp) - 1

print(ans)

from bisect import bisect_left

N = int(eval(input()))

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

# 解は最長非増加部分列の長さ

dp = [-1 for _ in range(N)]

for a in A:

    dp[bisect_left(dp, a) - 1] = a

ans = sum(x >= 0 for x in dp)

print(ans)

-from bisect import bisect
+from bisect import bisect_left
-INF = 10**10
-dp = [-INF]
+# 解は最長非増加部分列の長さ
+dp = [-1 for _ in range(N)]
-    if a <= -dp[-1]:
-        dp.append(-a)
-    else:
-        i = bisect(dp, -a)
-        dp[i] = -a
-ans = len(dp) - 1
+    dp[bisect_left(dp, a) - 1] = a
+ans = sum(x >= 0 for x in dp)


Input:
from sys import exit

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

a={} #{種類:美味しさ}

b=[] #[[種類,美味しさ],...]

for _ in range(N):

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

    b.append([t,d])

    try:

        a[t].append(d)

    except KeyError:

        a[t]=[d]

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

f=[0]*(N+1)

x=0

point=0

pointsum=[]

for [t,d] in b[:K]:

    if f[t]==0: x+=1

    f[t]+=1

    point+=d

maxpoint=point+x*x

h=K-1

for [t,d] in b[K:]:

    if f[t]==0:

        f[t]=1

        x+=1

        point+=d

        for i in range(h,-2,-1):

            if i==-1:

                print(maxpoint)

                exit()

            t=b[i][0]

            d=b[i][1]

            if f[t]>1:

                f[t]-=1

                point-=d

                h=i-1

                break

        maxpoint=max(maxpoint,point+x*x)

print(maxpoint)

from sys import exit

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

b=[] #[[種類,美味しさ],...]

for _ in range(N):

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

    b.append([t,d])

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

f=[0]*(N+1)

x=0

point=0

for [t,d] in b[:K]:

    if f[t]==0: x+=1

    f[t]+=1

    point+=d

maxpoint=point+x*x

h=K-1

for [t,d] in b[K:]:

    if f[t]==0:

        f[t]=1

        x+=1

        point+=d

        for i in range(h,-2,-1):

            if i==-1:

                print(maxpoint)

                exit()

            t=b[i][0]

            d=b[i][1]

            if f[t]>1:

                f[t]-=1

                point-=d

                h=i-1

                break

        maxpoint=max(maxpoint,point+x*x)

print(maxpoint)

from sys import exit

N, K = list(map(int, input().split()))
a = {}  # {種類:美味しさ}
b = []  # [[種類,美味しさ],...]
for _ in range(N):
    t, d = list(map(int, input().split()))
    b.append([t, d])
    try:
        a[t].append(d)
    except KeyError:
        a[t] = [d]
b.sort(key=lambda x: -x[1])
f = [0] * (N + 1)
x = 0
point = 0
pointsum = []
for [t, d] in b[:K]:
    if f[t] == 0:
        x += 1
    f[t] += 1
    point += d
maxpoint = point + x * x
h = K - 1
for [t, d] in b[K:]:
    if f[t] == 0:
        f[t] = 1
        x += 1
        point += d
        for i in range(h, -2, -1):
            if i == -1:
                print(maxpoint)
                exit()
            t = b[i][0]
            d = b[i][1]
            if f[t] > 1:
                f[t] -= 1
                point -= d
                h = i - 1
                break
        maxpoint = max(maxpoint, point + x * x)
print(maxpoint)

from sys import exit

N, K = list(map(int, input().split()))
b = []  # [[種類,美味しさ],...]
for _ in range(N):
    t, d = list(map(int, input().split()))
    b.append([t, d])
b.sort(key=lambda x: -x[1])
f = [0] * (N + 1)
x = 0
point = 0
for [t, d] in b[:K]:
    if f[t] == 0:
        x += 1
    f[t] += 1
    point += d
maxpoint = point + x * x
h = K - 1
for [t, d] in b[K:]:
    if f[t] == 0:
        f[t] = 1
        x += 1
        point += d
        for i in range(h, -2, -1):
            if i == -1:
                print(maxpoint)
                exit()
            t = b[i][0]
            d = b[i][1]
            if f[t] > 1:
                f[t] -= 1
                point -= d
                h = i - 1
                break
        maxpoint = max(maxpoint, point + x * x)
print(maxpoint)

-a = {}  # {種類:美味しさ}
-    try:
-        a[t].append(d)
-    except KeyError:
-        a[t] = [d]
-pointsum = []


Input:
#abc150c

from itertools import *

n=int(eval(input()))

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

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

l=list(permutations(list(range(1,n+1))))

print((abs(l.index(p)-l.index(q))))

#abc150c

from itertools import *

n=int(input())

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

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

l=list(permutations(list(range(1,n+1))))

print(abs(l.index(p)-l.index(q)))

# abc150c
from itertools import *

n = int(eval(input()))
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
l = list(permutations(list(range(1, n + 1))))
print((abs(l.index(p) - l.index(q))))

# abc150c
from itertools import *

n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
l = list(permutations(list(range(1, n + 1))))
print(abs(l.index(p) - l.index(q)))

-n = int(eval(input()))
+n = int(input())
-print((abs(l.index(p) - l.index(q))))
+print(abs(l.index(p) - l.index(q)))


Input:
import sys

def recursion_g(eges, length, f):

    if length[f] != -1:

        return length[f]

    memo = [0]

    for t in eges[f]:

        memo.append(recursion_g(eges, length, t) + 1)

    length[f] = max(memo)

    return length[f]

def p_g():

    sys.setrecursionlimit(10 ** 6)

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

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

    length = [-1] * N

    for _ in range(M):

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

        edges[x - 1].append(y - 1)

    for i in range(N):

        recursion_g(edges, length, i)

    print((max(length)))

if __name__ == '__main__':

    p_g()

from collections import deque

def p_g_dp():

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

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

    ins = [0] * N

    for _ in range(M):

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

        outs[f - 1].append(t - 1)

        ins[t - 1] += 1

    q = deque(t for t in range(N) if ins[t] == 0)

    res = []

    dp = [0] * N

    while q:

        f = q.popleft()

        res.append(f)

        for t in outs[f]:

            ins[t] -= 1

            if ins[t] == 0:

                q.append(t)

                dp[t] = max(dp[t], dp[f] + 1)

    print((max(dp)))

if __name__ == '__main__':

    p_g_dp()

import sys

def recursion_g(eges, length, f):
    if length[f] != -1:
        return length[f]
    memo = [0]
    for t in eges[f]:
        memo.append(recursion_g(eges, length, t) + 1)
    length[f] = max(memo)
    return length[f]

def p_g():
    sys.setrecursionlimit(10**6)
    N, M = list(map(int, input().split()))
    edges = [[] for _ in range(N)]
    length = [-1] * N
    for _ in range(M):
        x, y = list(map(int, input().split()))
        edges[x - 1].append(y - 1)
    for i in range(N):
        recursion_g(edges, length, i)
    print((max(length)))

if __name__ == "__main__":
    p_g()

from collections import deque

def p_g_dp():
    N, M = list(map(int, input().split()))
    outs = [[] for _ in range(N)]
    ins = [0] * N
    for _ in range(M):
        f, t = list(map(int, input().split()))
        outs[f - 1].append(t - 1)
        ins[t - 1] += 1
    q = deque(t for t in range(N) if ins[t] == 0)
    res = []
    dp = [0] * N
    while q:
        f = q.popleft()
        res.append(f)
        for t in outs[f]:
            ins[t] -= 1
            if ins[t] == 0:
                q.append(t)
                dp[t] = max(dp[t], dp[f] + 1)
    print((max(dp)))

if __name__ == "__main__":
    p_g_dp()

-        memo.append(recursion_g(eges, length, t) + 1)

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

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

+    q = deque(t for t in range(N) if ins[t] == 0)


Input:
import sys

while True :

    a,b = list(map(int, sys.stdin.readline().split()))

    if a == 0 and b == 0 :

        break

    elif a > b :

        print((b,a))

    else :

        print((a,b))

import sys

while True :

    a,b = sys.stdin.readline().split()

    a = int(a)

    b = int(b)

    if a == 0 and b == 0 :

        break

    elif a > b :

        print((b,a))

    else :

        print((a,b))

import sys

while True:
    a, b = list(map(int, sys.stdin.readline().split()))
    if a == 0 and b == 0:
        break
    elif a > b:
        print((b, a))
    else:
        print((a, b))

import sys

while True:
    a, b = sys.stdin.readline().split()
    a = int(a)
    b = int(b)
    if a == 0 and b == 0:
        break
    elif a > b:
        print((b, a))
    else:
        print((a, b))

-    a, b = list(map(int, sys.stdin.readline().split()))

+    a, b = sys.stdin.readline().split()


Input:
# 初期入力

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

A = [0]

for i in input().split():

    if i !="0":

        A.append( int(i) )

# 1軒ずつ距離のリスト

x =[A[i+1] - A[i] for i,v in enumerate(A[:-1]) ]

if N == len(A):

    x.append(K -A[-1])

else:

    x.append(K - A[-1] +A[1])

#　求めるのは　K　－　max(隣と離れた家の距離)

kyori_min = K - max(x)

print(kyori_min)

# 初期入力

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

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

A.append(0) # 基準地点を最後に追加、スタートが０でもうまくいく

# 1件となりまでの距離

kyori = [ A[i+1] -A[i] for i,v in enumerate(A[:-1]) ]

kyori[-1] = kyori[-1] + K # n番目から基準までは全体から「引く」

kyori.append(A[0] -A[-1] ) # 基準から1番目までの距離

x_saisyo_saigo = kyori[-2] +kyori[-1]

kyori.append(x_saisyo_saigo) # n番目から1番目の距離

# 最短距離は、全体からmax(隣の家との距離)を引く

kyori_min = K - max(kyori)

print(kyori_min)

# 初期入力
K, N = (int(x) for x in input().split(" "))
A = [0]
for i in input().split():
    if i != "0":
        A.append(int(i))
# 1軒ずつ距離のリスト
x = [A[i + 1] - A[i] for i, v in enumerate(A[:-1])]
if N == len(A):
    x.append(K - A[-1])
else:
    x.append(K - A[-1] + A[1])
# 　求めるのは　K　－　max(隣と離れた家の距離)
kyori_min = K - max(x)
print(kyori_min)

# 初期入力
K, N = (int(x) for x in input().split(" "))
A = list(map(int, input().split()))
A.append(0)  # 基準地点を最後に追加、スタートが０でもうまくいく
# 1件となりまでの距離
kyori = [A[i + 1] - A[i] for i, v in enumerate(A[:-1])]
kyori[-1] = kyori[-1] + K  # n番目から基準までは全体から「引く」
kyori.append(A[0] - A[-1])  # 基準から1番目までの距離
x_saisyo_saigo = kyori[-2] + kyori[-1]
kyori.append(x_saisyo_saigo)  # n番目から1番目の距離
# 最短距離は、全体からmax(隣の家との距離)を引く
kyori_min = K - max(kyori)
print(kyori_min)

-# 1軒ずつ距離のリスト

-x = [A[i + 1] - A[i] for i, v in enumerate(A[:-1])]

-# 　求めるのは　K　－　max(隣と離れた家の距離)

+A.append(0)  # 基準地点を最後に追加、スタートが０でもうまくいく

+# 1件となりまでの距離

+kyori = [A[i + 1] - A[i] for i, v in enumerate(A[:-1])]

+kyori[-1] = kyori[-1] + K  # n番目から基準までは全体から「引く」

+kyori.append(A[0] - A[-1])  # 基準から1番目までの距離

+kyori.append(x_saisyo_saigo)  # n番目から1番目の距離

+# 最短距離は、全体からmax(隣の家との距離)を引く


Input:
N = eval(input())

arr = [eval(input())-1 for i in range(N)]

now = 0

count = 0

while (now != 1):

    count += 1

    now = arr[now]

    if count > 100000:

        count = -1

        break

print(count)

N = int(eval(input()))

src = [int(eval(input())) for i in range(N)]

now = 0

for i in range(N):

    a = src[now] - 1

    if a == 1:

        print((i+1))

        exit()

    now = a

print((-1))

N = eval(input())
arr = [eval(input()) - 1 for i in range(N)]
now = 0
count = 0
while now != 1:
    count += 1
    now = arr[now]
    if count > 100000:
        count = -1
        break
print(count)

N = int(eval(input()))
src = [int(eval(input())) for i in range(N)]
now = 0
for i in range(N):
    a = src[now] - 1
    if a == 1:
        print((i + 1))
        exit()
    now = a
print((-1))

-arr = [eval(input()) - 1 for i in range(N)]

+src = [int(eval(input())) for i in range(N)]


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

import sys

from math import sqrt

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

def list2d(a, b, c): return [[c] * b for i in range(a)]

def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]

def ceil(x, y=1): return int(-(-x // y))

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

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

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

def Yes(): print('Yes')

def No(): print('No')

def YES(): print('YES')

def NO(): print('NO')

sys.setrecursionlimit(10 ** 9)

INF = float('inf')

MOD = 10 ** 9 + 7

def divisor_set(N: int) -> set:

    """ 約数の列挙・個数 """

    # 1とその数はデフォで入れとく

    s = {1, N}

    # 終点はルート切り捨て

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

        # 割り切れるなら、iとN/iを追加

        if N % i == 0:

            s.add(i)

            s.add(N // i)

    return s

N=INT()

A=LIST()

A2=[0]*N

B=[]

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

    if A[i]!=A2[i]:

        B.append(i+1)

        div=divisor_set(i+1)

        for num in div:

            A2[num-1]=1-A2[num-1]

print((len(B)))

print((*B))

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

import sys

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

def list2d(a, b, c): return [[c] * b for i in range(a)]

def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]

def ceil(x, y=1): return int(-(-x // y))

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

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

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

def Yes(): print('Yes')

def No(): print('No')

def YES(): print('YES')

def NO(): print('NO')

sys.setrecursionlimit(10 ** 9)

INF = float('inf')

MOD = 10 ** 9 + 7

N=INT()

A=LIST()

# その位置にボールを入れるかを保持するA2

A2=[0]*N

B=[]

# 後ろから決めていく

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

    cur=i+1

    cnt=0

    # curの倍数を全部見に行く

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

        cnt^=A2[j-1]

    # ボールを入れるべきかどうか

    if A[i]!=cnt:

        B.append(cur)

        A2[i]=1

print((len(B)))

print((*B))

# -*- coding: utf-8 -*-
import sys
from math import sqrt

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

def list2d(a, b, c):
    return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
    return [[[d] * c for j in range(b)] for i in range(a)]

def ceil(x, y=1):
    return int(-(-x // y))

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

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

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

def Yes():
    print("Yes")

def No():
    print("No")

def YES():
    print("YES")

def NO():
    print("NO")

sys.setrecursionlimit(10**9)
INF = float("inf")
MOD = 10**9 + 7

def divisor_set(N: int) -> set:
    """約数の列挙・個数"""
    # 1とその数はデフォで入れとく
    s = {1, N}
    # 終点はルート切り捨て
    for i in range(2, int(sqrt(N)) + 1):
        # 割り切れるなら、iとN/iを追加
        if N % i == 0:
            s.add(i)
            s.add(N // i)
    return s

N = INT()
A = LIST()
A2 = [0] * N
B = []
for i in range(N - 1, -1, -1):
    if A[i] != A2[i]:
        B.append(i + 1)
        div = divisor_set(i + 1)
        for num in div:
            A2[num - 1] = 1 - A2[num - 1]
print((len(B)))
print((*B))

# -*- coding: utf-8 -*-
import sys

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

def list2d(a, b, c):
    return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
    return [[[d] * c for j in range(b)] for i in range(a)]

def ceil(x, y=1):
    return int(-(-x // y))

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

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

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

def Yes():
    print("Yes")

def No():
    print("No")

def YES():
    print("YES")

def NO():
    print("NO")

sys.setrecursionlimit(10**9)
INF = float("inf")
MOD = 10**9 + 7
N = INT()
A = LIST()
# その位置にボールを入れるかを保持するA2
A2 = [0] * N
B = []
# 後ろから決めていく
for i in range(N - 1, -1, -1):
    cur = i + 1
    cnt = 0
    # curの倍数を全部見に行く
    for j in range(cur * 2, N + 1, cur):
        cnt ^= A2[j - 1]
    # ボールを入れるべきかどうか
    if A[i] != cnt:
        B.append(cur)
        A2[i] = 1
print((len(B)))
print((*B))

-    """約数の列挙・個数"""

-    # 1とその数はデフォで入れとく

-    # 終点はルート切り捨て

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

-        # 割り切れるなら、iとN/iを追加

+# その位置にボールを入れるかを保持するA2

+# 後ろから決めていく

+    # curの倍数を全部見に行く

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

+    # ボールを入れるべきかどうか


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

s = str(eval(input()))

slist = []

for i in range(n):

  slist.append(s[i])

slime = slist[0]

count = 1

for i in range(1, n):

  if slime != slist[i]:

    count += 1

    slime = slist[i]

print(count)

n = int(eval(input()))

s = str(eval(input()))

slime = s[0]

count = 1

for i in range(1, n):

  if slime != s[i]:

    count += 1

    slime = s[i]

print(count)

-slist = []
-for i in range(n):
-    slist.append(s[i])
-slime = slist[0]
+slime = s[0]
-    if slime != slist[i]:
+    if slime != s[i]:
-        slime = slist[i]
+        slime = s[i]


Input:
import math

import queue

import bisect

import heapq

import time

import itertools

mod = int(1e9+7)

def swap(a,b):

    return (b,a)

def my_round(a,dig=0):

    p = 10 ** dig

    return (a * p * 2 + 1) // 2 / p

def gcd(a,b): #最大公約数

    if (a<b):

        a,b = swap(a,b)

    if (b==0):

        return a

    else:

        return gcd(b,a%b)

def lcm(a,b): #最小公倍数

    return a/gcd(a,b)*b

def divisors(a): # 約数列挙

    divisors = []

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

        if a%i==0:

            divisors.append(i)

            if i!=a//i:

                divisors.append(a//i)

    return divisors

def is_prime(a): #素数判定

    if a<2:

        return False

    elif a==2:

        return True

    elif a%2==0:

        return False

    sqrt_num = int(a**0.5)

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

        if a%i==0:

            return False

    return True

def prime_num(a): #素数列挙

    pn = [2]

    for i in range(3,int(a**0.5),2):

        prime = True

        for j in pn:

            if i%j==0:

                prime = False

                break

        if prime:

            pn.append(i)

    return pn

def prime_fact(a): #素因数分解

    sqrt = math.sqrt(a)

    res = []

    i = 2

    if is_prime(a):

        res.append(a)

    else:

        while a!=1:

            while a%i==0:

                res.append(i)

                a //= i

            i += 1

    return res

def main():

    s = eval(input())

    ans = 0

    for i in range(4):

        if s[i] == '+':

            ans += 1

        else:

            ans -= 1

    print(ans)

    return

if __name__=='__main__':

    main()

# import sys

# import math #sqrt,gcd,pi

# import decimal

# import queue # queue

# import bisect

# import heapq # priolity-queue

# import time

# from itertools import product,permutations,\

#     combinations,combinations_with_replacement

# 重複あり順列、順列、組み合わせ、重複あり組み合わせ

# import collections # deque

# from operator import itemgetter,mul

# from fractions import Fraction

# from functools import reduce

mod = int(1e9+7)

INF = 1<<29

lINF = 1<<35

def readInt():

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

def main():

    s = eval(input())

    ans = 0

    for i in range(len(s)):

        if s[i]=="+":

            ans += 1

        else:

            ans -= 1

    print(ans)

    return

if __name__=='__main__':

    main()

import math
import queue
import bisect
import heapq
import time
import itertools

mod = int(1e9 + 7)

def swap(a, b):
    return (b, a)

def my_round(a, dig=0):
    p = 10**dig
    return (a * p * 2 + 1) // 2 / p

def gcd(a, b):  # 最大公約数
    if a < b:
        a, b = swap(a, b)
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

def lcm(a, b):  # 最小公倍数
    return a / gcd(a, b) * b

def divisors(a):  # 約数列挙
    divisors = []
    for i in range(1, int(a**0.5) + 1):
        if a % i == 0:
            divisors.append(i)
            if i != a // i:
                divisors.append(a // i)
    return divisors

def is_prime(a):  # 素数判定
    if a < 2:
        return False
    elif a == 2:
        return True
    elif a % 2 == 0:
        return False
    sqrt_num = int(a**0.5)
    for i in range(3, sqrt_num + 1, 2):
        if a % i == 0:
            return False
    return True

def prime_num(a):  # 素数列挙
    pn = [2]
    for i in range(3, int(a**0.5), 2):
        prime = True
        for j in pn:
            if i % j == 0:
                prime = False
                break
        if prime:
            pn.append(i)
    return pn

def prime_fact(a):  # 素因数分解
    sqrt = math.sqrt(a)
    res = []
    i = 2
    if is_prime(a):
        res.append(a)
    else:
        while a != 1:
            while a % i == 0:
                res.append(i)
                a //= i
            i += 1
    return res

def main():
    s = eval(input())
    ans = 0
    for i in range(4):
        if s[i] == "+":
            ans += 1
        else:
            ans -= 1
    print(ans)
    return

if __name__ == "__main__":
    main()

# import sys
# import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,\
#     combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce
mod = int(1e9 + 7)
INF = 1 << 29
lINF = 1 << 35

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

def main():
    s = eval(input())
    ans = 0
    for i in range(len(s)):
        if s[i] == "+":
            ans += 1
        else:
            ans -= 1
    print(ans)
    return

if __name__ == "__main__":
    main()

+# from itertools import product,permutations,\

+#     combinations,combinations_with_replacement

+# 重複あり順列、順列、組み合わせ、重複あり組み合わせ

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

-                divisors.append(a // i)

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

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


Input:
S = eval(input())

a = S[:2]

b = S[2:]

if 1 <= int(a) <= 12 and 1 <= int(b) <= 12:

    print('AMBIGUOUS')

elif 0 <= int(a) <= 99 and 1 <= int(b) <= 12:

    print('YYMM')

elif 1 <= int(a) <= 12 and 0 <= int(b) <= 99:

    print('MMYY')

else:

    print('NA')

n = eval(input())

a = int(n[:2])

b = int(n[2:])

if 0 < a <= 12 and  (b == 0 or b > 12):

    print('MMYY')

elif (a == 0 or a > 12) and 0 < b <= 12:

    print('YYMM')

elif 0 < a <= 12 and 0 < b <= 12:

    print('AMBIGUOUS')

else:

    print('NA')

S = eval(input())
a = S[:2]
b = S[2:]
if 1 <= int(a) <= 12 and 1 <= int(b) <= 12:
    print("AMBIGUOUS")
elif 0 <= int(a) <= 99 and 1 <= int(b) <= 12:
    print("YYMM")
elif 1 <= int(a) <= 12 and 0 <= int(b) <= 99:
    print("MMYY")
else:
    print("NA")

n = eval(input())
a = int(n[:2])
b = int(n[2:])
if 0 < a <= 12 and (b == 0 or b > 12):
    print("MMYY")
elif (a == 0 or a > 12) and 0 < b <= 12:
    print("YYMM")
elif 0 < a <= 12 and 0 < b <= 12:
    print("AMBIGUOUS")
else:
    print("NA")


Input:
n = int(input())

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

p = 1

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

while True:

    if p >= len(arr):

        break

    for j in range(0,p):

        if arr[p] < arr[j]:

            arr[p],arr[j] = arr[j],arr[p]

    p += 1

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

def sort(a):

    n = len(a)

    for i in range(1,n):

        for j in range(i):

            p = i-j

            if a[p] < a[p-1]:

                a[p], a[p-1] = a[p-1], a[p]

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

n = int(input())

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

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

sort(a)

n = int(input())
arr = list(map(int, input().split(" ")))
p = 1
print(" ".join(map(str, arr)))
while True:
    if p >= len(arr):
        break
    for j in range(0, p):
        if arr[p] < arr[j]:
            arr[p], arr[j] = arr[j], arr[p]
    p += 1
    print(" ".join(map(str, arr)))

def sort(a):
    n = len(a)
    for i in range(1, n):
        for j in range(i):
            p = i - j
            if a[p] < a[p - 1]:
                a[p], a[p - 1] = a[p - 1], a[p]
        print(" ".join(map(str, a)))

n = int(input())
a = list(map(int, input().split(" ")))
print(" ".join(map(str, a)))
sort(a)

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

-            arr[p], arr[j] = arr[j], arr[p]


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

a=[]

while n:

    a+=n%26,

    n//=26

a=a[::-1]

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

    if a[i]<1:

        a[i]+=26

        a[i-1]-=1

print((''.join(chr(c+96)for c in a[not a[0]:])))

-print(("".join(chr(c + 96) for c in a[not a[0] :])))


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

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

ans = 0

for i in range(n):

    for j in range(30):

        if a[i]%2 == 0:

            a[i] /= 2

            ans += 1

        else:

            break

print(ans)

import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

sys.setrecursionlimit(10 ** 7)

n = int(readline())

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

cnt = 0

for aa in a:

    for i in range(aa):

        if aa % 2 == 0:

            cnt += 1

            aa //= 2

        else:

            break

print(cnt)

n = int(eval(input()))
a = list(map(int, input().split()))
ans = 0
for i in range(n):
    for j in range(30):
        if a[i] % 2 == 0:
            a[i] /= 2
            ans += 1
        else:
            break
print(ans)

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)
n = int(readline())
a = list(map(int, readline().split()))
cnt = 0
for aa in a:
    for i in range(aa):
        if aa % 2 == 0:
            cnt += 1
            aa //= 2
        else:
            break
print(cnt)

-n = int(eval(input()))
-a = list(map(int, input().split()))
-ans = 0
-for i in range(n):
-    for j in range(30):
-        if a[i] % 2 == 0:
-            a[i] /= 2
-            ans += 1
+import sys
+
+read = sys.stdin.buffer.read
+readline = sys.stdin.buffer.readline
+readlines = sys.stdin.buffer.readlines
+sys.setrecursionlimit(10**7)
+n = int(readline())
+a = list(map(int, readline().split()))
+cnt = 0
+for aa in a:
+    for i in range(aa):
+        if aa % 2 == 0:
+            cnt += 1
+            aa //= 2
-print(ans)
+print(cnt)


Input:
from collections import Counter

class UnionFind:

    def __init__(self, size):

        self.data = [-1] * size

    def find(self, x):

        if self.data[x] < 0:

            return x

        else:

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

            return self.data[x]

    def union(self, x, y):

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

        if x != y:

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

                x, y = y, x

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

            self.data[y] = x

        return (x != y)

    def same(self, x, y):

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

    def size(self, x):

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

MAX = 10 ** 5 + 10

uf = UnionFind(2 * MAX)

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

for x, y in zip(*[iter(XY)] * 2):

    uf.union(x, y + MAX)

X = Counter(uf.find(i) for i in range(MAX))

Y = Counter(uf.find(i) for i in range(MAX, MAX * 2))

res = sum(X[i] * Y[i] for i in range(MAX * 2))

print((res - N))

from collections import Counter

class UnionFind:

    def __init__(self, size):

        self.data = [-1] * size

    def find(self, x):

        if self.data[x] < 0:

            return x

        else:

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

            return self.data[x]

    def union(self, x, y):

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

        if x != y:

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

                x, y = y, x

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

            self.data[y] = x

        return (x != y)

    def same(self, x, y):

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

    def size(self, x):

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

def main():

    MAX = 10 ** 5 + 1

    uf = UnionFind(2 * MAX)

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

    for x, y in zip(*[iter(XY)] * 2):

        uf.union(x, y + MAX)

    X = Counter(uf.find(i) for i in range(MAX))

    Y = Counter(uf.find(i) for i in range(MAX, MAX * 2))

    res = sum(X[i] * Y[i] for i in range(MAX * 2))

    print((res - N))

if __name__ == '__main__':

    main()

from collections import Counter

class UnionFind:
    def __init__(self, size):
        self.data = [-1] * size

    def find(self, x):
        if self.data[x] < 0:
            return x
        else:
            self.data[x] = self.find(self.data[x])
            return self.data[x]

    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x != y:
            if self.data[y] < self.data[x]:
                x, y = y, x
            self.data[x] += self.data[y]
            self.data[y] = x
        return x != y

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

    def size(self, x):
        return -self.data[self.find(x)]

MAX = 10**5 + 10
uf = UnionFind(2 * MAX)
N, *XY = list(map(int, open(0).read().split()))
for x, y in zip(*[iter(XY)] * 2):
    uf.union(x, y + MAX)
X = Counter(uf.find(i) for i in range(MAX))
Y = Counter(uf.find(i) for i in range(MAX, MAX * 2))
res = sum(X[i] * Y[i] for i in range(MAX * 2))
print((res - N))

from collections import Counter

class UnionFind:
    def __init__(self, size):
        self.data = [-1] * size

    def find(self, x):
        if self.data[x] < 0:
            return x
        else:
            self.data[x] = self.find(self.data[x])
            return self.data[x]

    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x != y:
            if self.data[y] < self.data[x]:
                x, y = y, x
            self.data[x] += self.data[y]
            self.data[y] = x
        return x != y

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

    def size(self, x):
        return -self.data[self.find(x)]

def main():
    MAX = 10**5 + 1
    uf = UnionFind(2 * MAX)
    N, *XY = list(map(int, open(0).read().split()))
    for x, y in zip(*[iter(XY)] * 2):
        uf.union(x, y + MAX)
    X = Counter(uf.find(i) for i in range(MAX))
    Y = Counter(uf.find(i) for i in range(MAX, MAX * 2))
    res = sum(X[i] * Y[i] for i in range(MAX * 2))
    print((res - N))

if __name__ == "__main__":
    main()

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

-X = Counter(uf.find(i) for i in range(MAX))

-Y = Counter(uf.find(i) for i in range(MAX, MAX * 2))

-res = sum(X[i] * Y[i] for i in range(MAX * 2))

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

+    X = Counter(uf.find(i) for i in range(MAX))

+    Y = Counter(uf.find(i) for i in range(MAX, MAX * 2))

+    res = sum(X[i] * Y[i] for i in range(MAX * 2))


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

print((0 if X < A else 10))

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

if X < A:

    print((0))

else:

    print((10))

-print((0 if X < A else 10))
+if X < A:
+    print((0))
+else:
+    print((10))


Input:
from time import time

def change(before_tax,after_tax,previous_price):

    #change z from taxrate x to taxrate y

    original_price = 0

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

        if i * (100 + before_tax) // 100 == previous_price:

            original_price = i

            break

        else:

            pass

    return original_price * (100 + after_tax) // 100

#l = []

while True:

    x,y,s = [int(x) for x in input().split()]

    if x == 0:

        break

    else:

        ans = 0

        for i in range(1,s):

            price1, price2 = i, s - i

            afterprice = change(x,y,price1) + change(x,y,price2)

            if afterprice > ans:

                ans = afterprice

            else:

                continue

        #l.append(ans)

        print(ans)

'''

for x in l:

    print(x)

'''

def change(before_tax,after_tax,previous_price):

    original_price = 0

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

        if i * (100 + before_tax) // 100 == previous_price:

            original_price = i

            break

        else:

            pass

    return original_price * (100 + after_tax) // 100

ans_list = []

while True:

    x,y,s = [int(x) for x in input().split()]

    if x == 0:

        break

    else:

        ans = 0

        for i in range(1,s):

            price1, price2 = i, s - i

            afterprice = change(x,y,price1) + change(x,y,price2)

            if afterprice > ans:

                ans = afterprice

            else:

                continue

        ans_list.append(ans)

for x in ans_list:

    print(x)

from time import time

def change(before_tax, after_tax, previous_price):
    # change z from taxrate x to taxrate y
    original_price = 0
    for i in range(1, previous_price + 1):
        if i * (100 + before_tax) // 100 == previous_price:
            original_price = i
            break
        else:
            pass
    return original_price * (100 + after_tax) // 100

# l = []
while True:
    x, y, s = [int(x) for x in input().split()]
    if x == 0:
        break
    else:
        ans = 0
        for i in range(1, s):
            price1, price2 = i, s - i
            afterprice = change(x, y, price1) + change(x, y, price2)
            if afterprice > ans:
                ans = afterprice
            else:
                continue
        # l.append(ans)
        print(ans)
"""
for x in l:
    print(x)
"""

def change(before_tax, after_tax, previous_price):
    original_price = 0
    for i in range(1, previous_price + 1):
        if i * (100 + before_tax) // 100 == previous_price:
            original_price = i
            break
        else:
            pass
    return original_price * (100 + after_tax) // 100

ans_list = []
while True:
    x, y, s = [int(x) for x in input().split()]
    if x == 0:
        break
    else:
        ans = 0
        for i in range(1, s):
            price1, price2 = i, s - i
            afterprice = change(x, y, price1) + change(x, y, price2)
            if afterprice > ans:
                ans = afterprice
            else:
                continue
        ans_list.append(ans)
for x in ans_list:
    print(x)

-    # change z from taxrate x to taxrate y


Input:
N, K = [int(x) for x in input().split()]

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

dict = {}

for i in A_lst:

    if not i in list(dict.keys()):

        dict[i] = 1

    else:

        dict[i] += 1

lst = []

for i in list(dict.keys()):

    lst.append(dict[i])

lst.sort()

k = len(lst)

cnt = 0

for i in lst:

    if k <= K:

        break

    else:

        k -= 1

        cnt += i

print(cnt)

N, K = [int(x) for x in input().split()]

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

dict = {}

for i in A_lst:

    if not i in list(dict.keys()):

        dict[i] = 1

    else:

        dict[i] += 1

val_lst = list(dict.values())

val_lst.sort()

k = len(val_lst)

cnt = 0

for i in val_lst:

    if k <= K:

        break

    else:

        k -= 1

        cnt += i

print(cnt)

-lst = []
-for i in list(dict.keys()):
-    lst.append(dict[i])
-lst.sort()
-k = len(lst)
+val_lst = list(dict.values())
+val_lst.sort()
+k = len(val_lst)
-for i in lst:
+for i in val_lst:


Input: print(' '.join(map(str, sorted(map(int, input().split())))[::-1]))

print(' '.join([str(x) for x in sorted([int(x) for x in input().split()])[::-1]]))

-print(" ".join(map(str, sorted(map(int, input().split())))[::-1]))

+print(" ".join([str(x) for x in sorted([int(x) for x in input().split()])[::-1]]))


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

c = []

for i in range(n):

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

    if t1 <= t:

        c.insert(i,c1)

if len(c) == 0:

    print("TLE")

else:

    c.sort(key=int)

    print((c[0]))

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

c = []

for _ in range(n):

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

    if t1 <= t:

        c.append(c1)

if len(c) == 0:

    print("TLE")

else:

    c.sort(key=int)

    print((c[0]))

n, t = list(map(int, input().split()))
c = []
for i in range(n):
    c1, t1 = list(map(int, input().split()))
    if t1 <= t:
        c.insert(i, c1)
if len(c) == 0:
    print("TLE")
else:
    c.sort(key=int)
    print((c[0]))

n, t = list(map(int, input().split()))
c = []
for _ in range(n):
    c1, t1 = list(map(int, input().split()))
    if t1 <= t:
        c.append(c1)
if len(c) == 0:
    print("TLE")
else:
    c.sort(key=int)
    print((c[0]))

-for i in range(n):
+for _ in range(n):
-        c.insert(i, c1)
+        c.append(c1)


Input:
def S(x1,y1,x2,y2,x3,y3):

    return abs(x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2))/2.0

while True:

    try:

        x1,y1,x2,y2,x3,y3,xp,yp = list(map(float,input().split()))

        flag = S(x1,y1,x2,y2,xp,yp)+S(x1,y1,x3,y3,xp,yp)+S(x3,y3,x2,y2,xp,yp)-S(x1,y1,x2,y2,x3,y3) > 0.0000001

        print("NO" if flag else "YES")

    except:

        break

def S(x1, y1, x2, y2, x3, y3):
    return abs(x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) / 2.0

while True:
    try:
        x1, y1, x2, y2, x3, y3, xp, yp = list(map(float, input().split()))
        flag = (
            S(x1, y1, x2, y2, xp, yp)
            + S(x1, y1, x3, y3, xp, yp)
            + S(x3, y3, x2, y2, xp, yp)
            - S(x1, y1, x2, y2, x3, y3)
            > 0.0000001
        )
        print("NO" if flag else "YES")
    except:
        break

+            lambda x1, y1, x2, y2, x3=xp, y3=yp: abs(


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

ans = 0

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

    if  i % 3 == 0 or i % 5 == 0:

        ans += 0

    else:

        ans += i

print(ans)

N = int(eval(input()))

ans = []

for i in range(N+1):

    if i % 3 != 0 and i % 5 != 0:

        ans.append(i)

print((sum(ans)))

N = int(eval(input()))
ans = 0
for i in range(1, N + 1):
    if i % 3 == 0 or i % 5 == 0:
        ans += 0
    else:
        ans += i
print(ans)

N = int(eval(input()))
ans = []
for i in range(N + 1):
    if i % 3 != 0 and i % 5 != 0:
        ans.append(i)
print((sum(ans)))

-ans = 0
-for i in range(1, N + 1):
-    if i % 3 == 0 or i % 5 == 0:
-        ans += 0
-    else:
-        ans += i
-print(ans)
+ans = []
+for i in range(N + 1):
+    if i % 3 != 0 and i % 5 != 0:
+        ans.append(i)
+print((sum(ans)))


Input: n=int(eval(input()));print((([m for m in range(n+1)if int(m*1.08)==n]+[':('])[0]))

n = int(eval(input()))
print((([m for m in range(n + 1) if int(m * 1.08) == n] + [":("])[0]))


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

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

while len(v) > 1:

    new_v = (v[0]+v[1]) / 2

    del v[0:2]

    v = [new_v]+v

print((v[0]))

n = int(eval(input()))

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

ans = (v[0]+v[1])/2

for i in range(2,n):

    ans = (ans+v[i])/2

print(ans)

n = int(eval(input()))
v = sorted(list(map(int, input().split())))
while len(v) > 1:
    new_v = (v[0] + v[1]) / 2
    del v[0:2]
    v = [new_v] + v
print((v[0]))

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


Input:
def getN():

    return int(eval(input()))

def getNM():

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

def getList():

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

def getArray(intn):

    return [int(eval(input())) for i in range(intn)]

def input():

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

def rand_N(ran1, ran2):

    return random.randint(ran1, ran2)

def rand_List(ran1, ran2, rantime):

    return [random.randint(ran1, ran2) for i in range(rantime)]

def rand_ints_nodup(ran1, ran2, rantime):

  ns = []

  while len(ns) < rantime:

    n = random.randint(ran1, ran2)

    if not n in ns:

      ns.append(n)

  return sorted(ns)

def rand_query(ran1, ran2, rantime):

  r_query = []

  while len(r_query) < rantime:

    n_q = rand_ints_nodup(ran1, ran2, 2)

    if not n_q in r_query:

      r_query.append(n_q)

  return sorted(r_query)

from sys import exit

import sys

sys.setrecursionlimit(1000000000)

mod = 998244353

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

# Main Code #

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

N, K = getNM()

que = [getList() for i in range(K)]

dp = [0] * (N + 1)

dp[1] = 1

dp[2] = -1

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

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

    dp[i] %= mod

    for l, r in que:

        if i + l <= N:

            dp[i + l] += dp[i]

        if i + r + 1 <= N:

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

print((dp[N] % mod))

def getN():

    return int(eval(input()))

def getNM():

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

def getList():

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

def getArray(intn):

    return [int(eval(input())) for i in range(intn)]

def input():

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

def rand_N(ran1, ran2):

    return random.randint(ran1, ran2)

def rand_List(ran1, ran2, rantime):

    return [random.randint(ran1, ran2) for i in range(rantime)]

def rand_ints_nodup(ran1, ran2, rantime):

  ns = []

  while len(ns) < rantime:

    n = random.randint(ran1, ran2)

    if not n in ns:

      ns.append(n)

  return sorted(ns)

def rand_query(ran1, ran2, rantime):

  r_query = []

  while len(r_query) < rantime:

    n_q = rand_ints_nodup(ran1, ran2, 2)

    if not n_q in r_query:

      r_query.append(n_q)

  return sorted(r_query)

from sys import exit

import sys

sys.setrecursionlimit(1000000000)

mod = 998244353

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

# Main Code #

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

N, K = getNM()

que = [getList() for i in range(K)]

dp = [0] * (N + 1) # dp[i] iの時の通りの数

imos = [0] * (N + 1) # imos[i]: dp[1] ~ dp[i]までの累計

dp[1] = 1

imos[1] = 1

# 貰うdp

# dp += dp[l] - dp[r]

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

    for l, r in que:

        if i - l >= 0:

            dp[i] += imos[i - l] - imos[max((i - r - 1), 0)]

            dp[i] %= mod

    imos[i] = dp[i]

    imos[i] += imos[i - 1]

    imos[i] %= mod

print((dp[N] % mod))

"""

# 配るdp

dp = [0] * (N + 1)

dp[1] = 1

dp[2] = -1

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

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

    dp[i] %= mod

    for l, r in que:

        if i + l <= N:

            dp[i + l] += dp[i]

        if i + r + 1 <= N:

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

print(dp[N] % mod)

"""

+imos = [0] * (N + 1)  # imos[i]: dp[1] ~ dp[i]までの累計