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

if M % N == 0:

    print((M // N))

else:

    ans = 1

    for n in range(1, M // N + 1):

        res = M - n * N

        if res % n == 0:

            ans = n

    print(ans)

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

divisor = []

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

    if M % i == 0:

        divisor.append(i)

        if i != M // i:

            divisor.append(M // i)

print((max([x for x in divisor if x <= M // N])))

N, M = list(map(int, input().split()))
divisor = []
for i in range(1, int(M**0.5) + 1):
    if M % i == 0:
        divisor.append(i)
        if i != M // i:
            divisor.append(M // i)
print((max([x for x in divisor if x <= M // N])))

+print((max([x for x in divisor if x <= M // N])))


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

d = [[0]*9 for _ in range(9)]

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

    if i % 10 == 0:

        continue

    s = str(i)

    x = int(s[-1])

    y = int(s[0])

    d[x-1][y-1] += 1

ans = 0

for i in range(9):

    for j in range(9):

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

print(ans)

from collections import defaultdict

N = int(eval(input()))

d = defaultdict(int)

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

    s = str(i)

    f = int(s[0])

    b = int(s[-1])

    d[(f, b)] += 1

ans = 0

for a in range(1, 10):

    for b in range(1, 10):

        ans += d[(a, b)] * d[(b, a)]

print(ans)

N = int(eval(input()))
d = [[0] * 9 for _ in range(9)]
for i in range(1, N + 1):
    if i % 10 == 0:
        continue
    s = str(i)
    x = int(s[-1])
    y = int(s[0])
    d[x - 1][y - 1] += 1
ans = 0
for i in range(9):
    for j in range(9):
        ans += d[i][j] * d[j][i]
print(ans)

+from collections import defaultdict
+
-d = [[0] * 9 for _ in range(9)]
+d = defaultdict(int)
-    if i % 10 == 0:
-        continue
-    x = int(s[-1])
-    y = int(s[0])
-    d[x - 1][y - 1] += 1
+    f = int(s[0])
+    b = int(s[-1])
+    d[(f, b)] += 1
-for i in range(9):
-    for j in range(9):
-        ans += d[i][j] * d[j][i]
+for a in range(1, 10):
+    for b in range(1, 10):
+        ans += d[(a, b)] * d[(b, a)]


Input:
import sys

input = sys.stdin.readline

N = int(eval(input()))

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

cnt = 0

for Ai in A:

    if Ai<0:

        cnt += 1

if cnt%2==0:

    print((sum(abs(Ai) for Ai in A)))

else:

    A.sort(key=lambda x: abs(x))

    print((-abs(A[0])+sum(abs(Ai) for Ai in A[1:])))

import sys

input = sys.stdin.readline

N = int(eval(input()))

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

dp = [[0]*2 for _ in range(N)]

dp[0][1] = -10**18

for i in range(N-1):

    dp[i+1][0] = max(dp[i][0]+A[i], dp[i][1]-A[i])

    dp[i+1][1] = max(dp[i][0]-A[i], dp[i][1]+A[i])

print((max(dp[-1][0]+A[-1], dp[-1][1]-A[-1])))

import sys

input = sys.stdin.readline
N = int(eval(input()))
A = list(map(int, input().split()))
cnt = 0
for Ai in A:
    if Ai < 0:
        cnt += 1
if cnt % 2 == 0:
    print((sum(abs(Ai) for Ai in A)))
else:
    A.sort(key=lambda x: abs(x))
    print((-abs(A[0]) + sum(abs(Ai) for Ai in A[1:])))

-    print((-abs(A[0]) + sum(abs(Ai) for Ai in A[1:])))


Input:
import math

r = float(eval(input()))

a = math.pi * r**2

b = math.pi * r * 2

print((str(a) + " " + str(b)))

Input = float(eval(input()))

Area = Input**2*3.141592653589

Circumference = Input*2*3.141592653589

print(('{0:.6f} {1:.6f}'.format(Area,Circumference)))

Input = float(eval(input()))
Area = Input**2 * 3.141592653589
Circumference = Input * 2 * 3.141592653589
print(("{0:.6f} {1:.6f}".format(Area, Circumference)))


Input:
from bisect import bisect_left, bisect_right

n = int(eval(input()))

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

l.sort()

ans = 0

for i in range(n):

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

        if l[i] == l[j]:

            continue

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

            if l[i] == l[k] or l[j] == l[k]:

                continue

            if l[i] + l[j] > l[k]:

                ans += 1

print(ans)

from bisect import bisect_left, bisect_right

n = int(eval(input()))

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

l.sort()

ans = 0

for j in range(n):

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

        if l[j] == l[k]:

            continue

        ans += max(bisect_left(l, l[j]) - bisect_right(l, l[k] - l[j]), 0)

print(ans)

+        ans += max(bisect_left(l, l[j]) - bisect_right(l, l[k] - l[j]), 0)


Input:
#!/usr/bin/python3

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

import numpy as np

def func(ans, b_list, a_list, c_list, k, x):

    if k == 0:

        b_list = np.asarray(b_list)

        x_list = np.dot(b_list, a_list)

        if np.all(x_list >= x):

            return np.inner(c_list, b_list)

        else:

            return ans

    ans = min(ans, func(ans, b_list + [1], a_list, c_list, k - 1, x))

    ans = min(ans, func(ans, b_list + [0], a_list, c_list, k - 1, x))

    return ans

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

c_list = []

a_list = []

for i in range(0, n):

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

    c_list.append(c)

    a_list.append(a)

ans = float("inf")

c_list = np.asarray(c_list)

a_list = np.asarray(a_list)

ans = min(ans, func(ans, [1], a_list, c_list, n - 1, x))

ans = min(ans, func(ans, [0], a_list, c_list, n - 1, x))

if ans == float("inf"):

    print((-1))

else:

    print(ans)

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

c_list = []

a_list = []

for i in range(0, n):

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

  c_list.append(c)

  a_list.append(a)

ans = float("inf")

for x1 in [0, 1]:

  for x2 in [0, 1]:

    for x3 in [0, 1]:

      for x4 in [0, 1]:

        for x5 in [0, 1]:

          for x6 in [0, 1]:

            for x7 in [0, 1]:

              for x8 in [0, 1]:

                for x9 in [0, 1]:

                  for x10 in [0, 1]:

                    for x11 in [0, 1]:

                      for x12 in [0, 1]:

                        if n == 1:

                          x_list = [x1]

                        elif n == 2:

                          x_list = [x1, x2]

                        elif n == 3:

                          x_list = [x1, x2, x3]

                        elif n == 4:

                          x_list = [x1, x2, x3, x4]

                        elif n == 5:

                          x_list = [x1, x2, x3, x4 ,x5]

                        elif n == 6:

                          x_list = [x1, x2, x3, x4 ,x5, x6]

                        elif n == 7:

                          x_list = [x1, x2, x3, x4 ,x5, x6, x7]

                        elif n == 8:

                          x_list = [x1, x2, x3, x4 ,x5, x6, x7, x8]

                        elif n == 9:

                          x_list = [x1, x2, x3, x4 ,x5, x6, x7, x8, x9]

                        elif n == 10:

                          x_list = [x1, x2, x3, x4 ,x5, x6, x7, x8, x9, x10]

                        elif n == 11:

                          x_list = [x1, x2, x3, x4 ,x5, x6, x7, x8, x9, x10, x11]

                        elif n == 12:

                          x_list = [x1, x2, x3, x4 ,x5, x6, x7, x8, x9, x10, x11, x12]

                        cost = 0

                        gaku_list = [0] * m

                        for i in range(0, n):

                          if x_list[i] == 1:

                            for j in range(0, m):

                              gaku_list[j] += a_list[i][j]

                            cost += c_list[i]

                        flag = 1

                        for gaku in gaku_list:

                          if gaku < x:

                            flag = 0

                            break

                        if flag == 1 and cost < ans:

                          ans = cost

if ans == float("inf"):

  print((-1))

else:

  print(ans)

n, m, x = list(map(int, input().split()))
c_list = []
a_list = []
for i in range(0, n):
    c, *a = list(map(int, input().split()))
    c_list.append(c)
    a_list.append(a)
ans = float("inf")
for x1 in [0, 1]:
    for x2 in [0, 1]:
        for x3 in [0, 1]:
            for x4 in [0, 1]:
                for x5 in [0, 1]:
                    for x6 in [0, 1]:
                        for x7 in [0, 1]:
                            for x8 in [0, 1]:
                                for x9 in [0, 1]:
                                    for x10 in [0, 1]:
                                        for x11 in [0, 1]:
                                            for x12 in [0, 1]:
                                                if n == 1:
                                                    x_list = [x1]
                                                elif n == 2:
                                                    x_list = [x1, x2]
                                                elif n == 3:
                                                    x_list = [x1, x2, x3]
                                                elif n == 4:
                                                    x_list = [x1, x2, x3, x4]
                                                elif n == 5:
                                                    x_list = [x1, x2, x3, x4, x5]
                                                elif n == 6:
                                                    x_list = [x1, x2, x3, x4, x5, x6]
                                                elif n == 7:
                                                    x_list = [
                                                        x1,
                                                        x2,
                                                        x3,
                                                        x4,
                                                        x5,
                                                        x6,
                                                        x7,
                                                    ]
                                                elif n == 8:
                                                    x_list = [
                                                        x1,
                                                        x2,
                                                        x3,
                                                        x4,
                                                        x5,
                                                        x6,
                                                        x7,
                                                        x8,
                                                    ]
                                                elif n == 9:
                                                    x_list = [
                                                        x1,
                                                        x2,
                                                        x3,
                                                        x4,
                                                        x5,
                                                        x6,
                                                        x7,
                                                        x8,
                                                        x9,
                                                    ]
                                                elif n == 10:
                                                    x_list = [
                                                        x1,
                                                        x2,
                                                        x3,
                                                        x4,
                                                        x5,
                                                        x6,
                                                        x7,
                                                        x8,
                                                        x9,
                                                        x10,
                                                    ]
                                                elif n == 11:
                                                    x_list = [
                                                        x1,
                                                        x2,
                                                        x3,
                                                        x4,
                                                        x5,
                                                        x6,
                                                        x7,
                                                        x8,
                                                        x9,
                                                        x10,
                                                        x11,
                                                    ]
                                                elif n == 12:
                                                    x_list = [
                                                        x1,
                                                        x2,
                                                        x3,
                                                        x4,
                                                        x5,
                                                        x6,
                                                        x7,
                                                        x8,
                                                        x9,
                                                        x10,
                                                        x11,
                                                        x12,
                                                    ]
                                                cost = 0
                                                gaku_list = [0] * m
                                                for i in range(0, n):
                                                    if x_list[i] == 1:
                                                        for j in range(0, m):
                                                            gaku_list[j] += a_list[i][j]
                                                        cost += c_list[i]
                                                flag = 1
                                                for gaku in gaku_list:
                                                    if gaku < x:
                                                        flag = 0
                                                        break
                                                if flag == 1 and cost < ans:
                                                    ans = cost
if ans == float("inf"):
    print((-1))
else:
    print(ans)

-def func(ans, b_list, a_list, c_list, k, x):

-        x_list = np.dot(b_list, a_list)

-            return np.inner(c_list, b_list)

-    ans = min(ans, func(ans, b_list + [1], a_list, c_list, k - 1, x))

-    ans = min(ans, func(ans, b_list + [0], a_list, c_list, k - 1, x))

-ans = min(ans, func(ans, [1], a_list, c_list, n - 1, x))

-ans = min(ans, func(ans, [0], a_list, c_list, n - 1, x))

+                                                    x_list = [x1]

+                                                elif n == 2:

+                                                elif n == 3:

+                                                elif n == 4:

+                                                elif n == 5:

+                                                elif n == 6:

+                                                elif n == 7:

+                                                    x_list = [

+                                                elif n == 8:

+                                                    x_list = [

+                                                elif n == 9:

+                                                    x_list = [

+                                                    x_list = [

+                                                    x_list = [

+                                                    x_list = [

+                                                cost = 0

+                                                gaku_list = [0] * m

+                                                for i in range(0, n):

+                                                    if x_list[i] == 1:

+                                                        for j in range(0, m):

+                                                            gaku_list[j] += a_list[i][j]

+                                                        cost += c_list[i]

+                                                flag = 1

+                                                for gaku in gaku_list:

+                                                    if gaku < x:

+                                                        flag = 0

+                                                        break

+                                                if flag == 1 and cost < ans:

+                                                    ans = cost


Input:
import sys

S = sys.stdin.readline().strip()

T = sys.stdin.readline().strip()

ls = len(S)

lt = len(T)

match = 0

for i in range(ls - lt + 1):

    tmp = 0

    for j in range(lt):

        if S[i+j] == T[j]:

            tmp += 1

    match = max(match, tmp)

print((lt - match))

import sys

input = sys.stdin.readline

S = input().strip()

T = input().strip()

ans = float("inf")

ls = len(S)

lt = len(T)

for i in range(ls - lt + 1):

    tmp = 0

    for j in range(lt):

        if S[i+j] != T[j]:

            tmp += 1

    ans = min(ans, tmp)

print(ans)

import sys

S = sys.stdin.readline().strip()
T = sys.stdin.readline().strip()
ls = len(S)
lt = len(T)
match = 0
for i in range(ls - lt + 1):
    tmp = 0
    for j in range(lt):
        if S[i + j] == T[j]:
            tmp += 1
    match = max(match, tmp)
print((lt - match))

import sys

input = sys.stdin.readline
S = input().strip()
T = input().strip()
ans = float("inf")
ls = len(S)
lt = len(T)
for i in range(ls - lt + 1):
    tmp = 0
    for j in range(lt):
        if S[i + j] != T[j]:
            tmp += 1
    ans = min(ans, tmp)
print(ans)

-S = sys.stdin.readline().strip()
-T = sys.stdin.readline().strip()
+input = sys.stdin.readline
+S = input().strip()
+T = input().strip()
+ans = float("inf")
-match = 0
-        if S[i + j] == T[j]:
+        if S[i + j] != T[j]:
-    match = max(match, tmp)
-print((lt - match))
+    ans = min(ans, tmp)
+print(ans)


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

A=["M","A","R","C","H"]

B=[0,0,0,0,0]

s=[]

for i in range(n):

    S=eval(input())

    if S[0] in A:

        s.append(S)

#print(s)

for i in s:

    for j in range(5):

        if A[j]==i[0]:

            B[j]+=1

            break

c=B.count(0)

if c>2:

    print((0))

else:

    c=0

    for i in range(3):

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

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

                c+=(B[i]*B[j]*B[k])

    print(c)

#print(B)

import itertools

n=int(eval(input()))

s=dict()

for i in ["M","A","R","C","H"]:

    s[i]=0

for i in range(n):

    _s=eval(input())

    if _s[0] in ["M","A","R","C","H"]:

        s[_s[0]]+=1

s=list(s.items())

ans=0

for i in range(5):

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

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

            ans+=(s[i][1]*s[j][1]*s[k][1])

print(ans)

n = int(eval(input()))
A = ["M", "A", "R", "C", "H"]
B = [0, 0, 0, 0, 0]
s = []
for i in range(n):
    S = eval(input())
    if S[0] in A:
        s.append(S)
# print(s)
for i in s:
    for j in range(5):
        if A[j] == i[0]:
            B[j] += 1
            break
c = B.count(0)
if c > 2:
    print((0))
else:
    c = 0
    for i in range(3):
        for j in range(i + 1, 4):
            for k in range(j + 1, 5):
                c += B[i] * B[j] * B[k]
    print(c)
# print(B)

import itertools

n = int(eval(input()))
s = dict()
for i in ["M", "A", "R", "C", "H"]:
    s[i] = 0
for i in range(n):
    _s = eval(input())
    if _s[0] in ["M", "A", "R", "C", "H"]:
        s[_s[0]] += 1
s = list(s.items())
ans = 0
for i in range(5):
    for j in range(i + 1, 5):
        for k in range(j + 1, 5):
            ans += s[i][1] * s[j][1] * s[k][1]
print(ans)


Input:
import sys, math

from collections import defaultdict, deque, Counter

#from bisect import bisect_left, bisect_right

#from itertools import combinations, permutations, product

from heapq import heappush, heappop

#from functools import lru_cache

input = sys.stdin.readline

rs = lambda: input().strip()

ri = lambda: int(eval(input()))

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

mod = 1000000007

sys.setrecursionlimit(1000000)

H, W = rl()

C = rl()

D = rl()

M = []

for i in range(H):

	s = rs()

	M.append(s)

start = tuple([C[0]-1, C[1]-1])

end = tuple([D[0]-1, D[1]-1])

queue = deque()

queue.append((start, 0))

visited = defaultdict(lambda: float('inf'))

visited[start] = 0

ds = [(1,0),(-1,0),(0,1),(0,-1)]

while queue:

	n, d = queue.popleft()

	if n == end:

		print(d)

		exit()

	if visited[n] != d:

		continue

	i, j = n

	nd = d

	for di, dj in ds:

		ni, nj = i+di, j+dj

		if not (0 <= ni < H and 0 <= nj < W): continue

		if M[ni][nj] == '#': continue

		if nd < visited[(ni,nj)]:

			queue.appendleft(((ni,nj), nd))

			visited[(ni,nj)] = nd

	nd = d+1

	for di in range(-2, 3):

		for dj in range(-2, 3):

			if (di, dj) == (0,0): continue

			ni, nj = i+di, j+dj

			if not (0 <= ni < H and 0 <= nj < W): continue

			if M[ni][nj] == '#': continue

			if nd < visited[(ni,nj)]:

				queue.append(((ni,nj), nd))

				visited[(ni,nj)] = nd

print((-1))

import sys, math

from collections import defaultdict, deque, Counter

#from bisect import bisect_left, bisect_right

#from itertools import combinations, permutations, product

from heapq import heappush, heappop

#from functools import lru_cache

input = sys.stdin.readline

rs = lambda: input().strip()

ri = lambda: int(eval(input()))

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

mod = 1000000007

sys.setrecursionlimit(1000000)

H, W = rl()

C = rl()

D = rl()

M = []

for i in range(H):

	s = rs()

	M.append(s)

start = tuple([C[0]-1, C[1]-1])

end = tuple([D[0]-1, D[1]-1])

queue = deque()

queue.append((start, 0))

visited = [[float('inf')]*W for _ in range(H)]

visited[start[0]][start[1]] = 0

ds = [(1,0),(-1,0),(0,1),(0,-1)]

while queue:

	n, d = queue.popleft()

	if n == end:

		print(d)

		exit()

	i, j = n

	if visited[i][j] != d:

		continue

	nd = d

	for di, dj in ds:

		ni, nj = i+di, j+dj

		if not (0 <= ni < H and 0 <= nj < W): continue

		if M[ni][nj] == '#': continue

		if nd < visited[ni][nj]:

			queue.appendleft(((ni,nj), nd))

			visited[ni][nj] = nd

	nd = d+1

	for di in range(-2, 3):

		for dj in range(-2, 3):

			if (di, dj) == (0,0): continue

			ni, nj = i+di, j+dj

			if not (0 <= ni < H and 0 <= nj < W): continue

			if M[ni][nj] == '#': continue

			if nd < visited[ni][nj]:

				queue.append(((ni,nj), nd))

				visited[ni][nj] = nd

print((-1))

import sys, math
from collections import defaultdict, deque, Counter

# from bisect import bisect_left, bisect_right
# from itertools import combinations, permutations, product
from heapq import heappush, heappop

# from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(eval(input()))
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)
H, W = rl()
C = rl()
D = rl()
M = []
for i in range(H):
    s = rs()
    M.append(s)
start = tuple([C[0] - 1, C[1] - 1])
end = tuple([D[0] - 1, D[1] - 1])
queue = deque()
queue.append((start, 0))
visited = defaultdict(lambda: float("inf"))
visited[start] = 0
ds = [(1, 0), (-1, 0), (0, 1), (0, -1)]
while queue:
    n, d = queue.popleft()
    if n == end:
        print(d)
        exit()
    if visited[n] != d:
        continue
    i, j = n
    nd = d
    for di, dj in ds:
        ni, nj = i + di, j + dj
        if not (0 <= ni < H and 0 <= nj < W):
            continue
        if M[ni][nj] == "#":
            continue
        if nd < visited[(ni, nj)]:
            queue.appendleft(((ni, nj), nd))
            visited[(ni, nj)] = nd
    nd = d + 1
    for di in range(-2, 3):
        for dj in range(-2, 3):
            if (di, dj) == (0, 0):
                continue
            ni, nj = i + di, j + dj
            if not (0 <= ni < H and 0 <= nj < W):
                continue
            if M[ni][nj] == "#":
                continue
            if nd < visited[(ni, nj)]:
                queue.append(((ni, nj), nd))
                visited[(ni, nj)] = nd
print((-1))

import sys, math
from collections import defaultdict, deque, Counter

# from bisect import bisect_left, bisect_right
# from itertools import combinations, permutations, product
from heapq import heappush, heappop

# from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(eval(input()))
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)
H, W = rl()
C = rl()
D = rl()
M = []
for i in range(H):
    s = rs()
    M.append(s)
start = tuple([C[0] - 1, C[1] - 1])
end = tuple([D[0] - 1, D[1] - 1])
queue = deque()
queue.append((start, 0))
visited = [[float("inf")] * W for _ in range(H)]
visited[start[0]][start[1]] = 0
ds = [(1, 0), (-1, 0), (0, 1), (0, -1)]
while queue:
    n, d = queue.popleft()
    if n == end:
        print(d)
        exit()
    i, j = n
    if visited[i][j] != d:
        continue
    nd = d
    for di, dj in ds:
        ni, nj = i + di, j + dj
        if not (0 <= ni < H and 0 <= nj < W):
            continue
        if M[ni][nj] == "#":
            continue
        if nd < visited[ni][nj]:
            queue.appendleft(((ni, nj), nd))
            visited[ni][nj] = nd
    nd = d + 1
    for di in range(-2, 3):
        for dj in range(-2, 3):
            if (di, dj) == (0, 0):
                continue
            ni, nj = i + di, j + dj
            if not (0 <= ni < H and 0 <= nj < W):
                continue
            if M[ni][nj] == "#":
                continue
            if nd < visited[ni][nj]:
                queue.append(((ni, nj), nd))
                visited[ni][nj] = nd
print((-1))

-visited = defaultdict(lambda: float("inf"))

+visited = [[float("inf")] * W for _ in range(H)]


Input:
from sys import stdin

input = stdin.readline

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

pricelist = [0] * N

matrix = [[0] * M for _ in range(N)]

for i in range(N):

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

    pricelist[i] = row.pop(0)

    matrix[i] = row

mintotalprice = 10**5 * 12 + 1

for bit in range(2**N):

    flag = True

    for j in range(M):

        totalscore = 0

        for i in range(N):

            if (bit>>i & 1) == 1:

                totalscore += matrix[i][j]

        if totalscore < X:

            flag = False

            break

    if flag:

        totalprice = 0

        for i in range(N):

            if (bit>>i & 1) == 1:

                totalprice += pricelist[i]

        mintotalprice = totalprice if mintotalprice > totalprice else mintotalprice

print((mintotalprice if mintotalprice != 10**5 * 12 + 1 else -1))

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

C = [0]*N

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

for i in range(N):

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

MAX = 10**5 * 12 + 1

minprice = MAX

for b in range(2**N):

    abilityList = [0]*M

    price = 0

    for i in range(N):

        if b >> i & 1 == 1:

            abilityList = [x+y for (x,y) in zip(abilityList, A[i])]

            price += C[i]

    judge = True

    for ability in abilityList:

        if ability < X:

            judge = False

    if judge:

        minprice = min(minprice, price)

ans = minprice if minprice != MAX else -1

print(ans)

from sys import stdin

input = stdin.readline
N, M, X = list(map(int, input().split()))
pricelist = [0] * N
matrix = [[0] * M for _ in range(N)]
for i in range(N):
    row = list(map(int, input().split()))
    pricelist[i] = row.pop(0)
    matrix[i] = row
mintotalprice = 10**5 * 12 + 1
for bit in range(2**N):
    flag = True
    for j in range(M):
        totalscore = 0
        for i in range(N):
            if (bit >> i & 1) == 1:
                totalscore += matrix[i][j]
        if totalscore < X:
            flag = False
            break
    if flag:
        totalprice = 0
        for i in range(N):
            if (bit >> i & 1) == 1:
                totalprice += pricelist[i]
        mintotalprice = totalprice if mintotalprice > totalprice else mintotalprice
print((mintotalprice if mintotalprice != 10**5 * 12 + 1 else -1))

N, M, X = list(map(int, input().split()))
C = [0] * N
A = [[[0] * M] for i in range(N)]
for i in range(N):
    C[i], *A[i] = list(map(int, input().split()))
MAX = 10**5 * 12 + 1
minprice = MAX
for b in range(2**N):
    abilityList = [0] * M
    price = 0
    for i in range(N):
        if b >> i & 1 == 1:
            abilityList = [x + y for (x, y) in zip(abilityList, A[i])]
            price += C[i]
    judge = True
    for ability in abilityList:
        if ability < X:
            judge = False
    if judge:
        minprice = min(minprice, price)
ans = minprice if minprice != MAX else -1
print(ans)

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

-                totalscore += matrix[i][j]

-                totalprice += pricelist[i]

-        mintotalprice = totalprice if mintotalprice > totalprice else mintotalprice

-print((mintotalprice if mintotalprice != 10**5 * 12 + 1 else -1))

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

+            abilityList = [x + y for (x, y) in zip(abilityList, A[i])]

+        minprice = min(minprice, price)

+ans = minprice if minprice != MAX else -1


Input:
def main():

    s = eval(input())

    res = ''

    for i in s:

        if i == 'B':

            res = res[:-1]

        else:

            res += i

    print(res)

if __name__ == '__main__':

    main()

def main():

    s = eval(input())

    from collections import deque

    c = deque()

    for i in s:

        if i == 'B':

            if c:

                c.pop()

        else:

            c.append(i)

    print((''.join(list(c))))

if __name__ == '__main__':

    main()

def main():
    s = eval(input())
    res = ""
    for i in s:
        if i == "B":
            res = res[:-1]
        else:
            res += i
    print(res)

if __name__ == "__main__":
    main()

def main():
    s = eval(input())
    from collections import deque

    c = deque()
    for i in s:
        if i == "B":
            if c:
                c.pop()
        else:
            c.append(i)
    print(("".join(list(c))))

if __name__ == "__main__":
    main()

-    res = ""
+    from collections import deque
+
+    c = deque()
-            res = res[:-1]
+            if c:
+                c.pop()
-            res += i
-    print(res)
+            c.append(i)
+    print(("".join(list(c))))


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

count = {0: 0, 1: 0}

for a in input().split():

    count[int(a) % 2] += 1

if count[1] == 0:

    if p == 0:

        print((pow(2, n)))

    else:

        print((0))

else:

    print((pow(2, n - 1)))

import math

def comb(n, r):

    return math.factorial(n) / math.factorial(r) / math.factorial(n - r)

def main():

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

    a = tuple([int(x) % 2 for x in input().split()])

    if n == 1 and a[0] % 2 != p:

        print((0))

        return 0

    t = len(tuple([x for x in a if x == 1]))

    f = n - t

    f_comb = 0

    for j in range(f + 1):

        f_comb += comb(f, j)

    t_comb = 0

    if p == 0:

        for i in range(t + 1):

            if i % 2 == 0:

                t_comb += comb(t, i)

    else:

        for i in range(t + 1):

            if i % 2 == 1:

                t_comb += comb(t, i)

    print((int(t_comb * f_comb)))

    return 0

if __name__ == '__main__':

    main()

import math

def comb(n, r):
    return math.factorial(n) / math.factorial(r) / math.factorial(n - r)

def main():
    n, p = list(map(int, input().split()))
    a = tuple([int(x) % 2 for x in input().split()])
    if n == 1 and a[0] % 2 != p:
        print((0))
        return 0
    t = len(tuple([x for x in a if x == 1]))
    f = n - t
    f_comb = 0
    for j in range(f + 1):
        f_comb += comb(f, j)
    t_comb = 0
    if p == 0:
        for i in range(t + 1):
            if i % 2 == 0:
                t_comb += comb(t, i)
    else:
        for i in range(t + 1):
            if i % 2 == 1:
                t_comb += comb(t, i)
    print((int(t_comb * f_comb)))
    return 0

if __name__ == "__main__":
    main()

+    return math.factorial(n) / math.factorial(r) / math.factorial(n - r)

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

+    a = tuple([int(x) % 2 for x in input().split()])

+    t = len(tuple([x for x in a if x == 1]))


Input:
import numpy as np

h,w=input().split()

h,w=int(h),int(w)

t1=[]

for i in range(h):

    s1=list(input())

    t1.append(s1)

t2=[[0 for i in range(w)] for i in range(h)]

for i in range(h):

    for j in range(w):

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

            for k in range(3):

                for l in range(3):

                    if k==1 and l==1:

                        continue

                    if i+k-1>=0 and j+l-1>=0 and i+k-1<h and j+l-1<w and t1[i+k-1][j+l-1]!="#":

                        t2[i+k-1][j+l-1]+=1

            t2[i][j]="#"

for i in range(h):

    for j in range(w):

        print(t2[i][j],end="")

    print("")

import numpy as np

h, w = input().split()
h, w = int(h), int(w)
t1 = []
for i in range(h):
    s1 = list(input())
    t1.append(s1)
t2 = [[0 for i in range(w)] for i in range(h)]
for i in range(h):
    for j in range(w):
        if t1[i][j] == "#":
            for k in range(3):
                for l in range(3):
                    if k == 1 and l == 1:
                        continue
                    if (
                        i + k - 1 >= 0
                        and j + l - 1 >= 0
                        and i + k - 1 < h
                        and j + l - 1 < w
                        and t1[i + k - 1][j + l - 1] != "#"
                    ):
                        t2[i + k - 1][j + l - 1] += 1
            t2[i][j] = "#"
for i in range(h):
    for j in range(w):
        print(t2[i][j], end="")
    print("")

-t2 = [[0 for i in range(w)] for i in range(h)]

-                        and i + k - 1 < h

-                        and j + l - 1 < w

+            print(count_8(i, j), end="")


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

t = sorted(eval(input()))

t.reverse()

st = [s, t]

if st == sorted(st) and s != t:

    print("Yes")

else:

    print("No")

s = sorted(eval(input()))

t = sorted(eval(input()))

t.reverse()

ts = [t, s]

if ts != sorted(ts):

    print("Yes")

else:

    print("No")

-st = [s, t]
-if st == sorted(st) and s != t:
+ts = [t, s]
+if ts != sorted(ts):


Input:
import random

N = int(eval(input()))

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

random.seed(42)

count = 0

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

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

        count += 1

    while a[i] == a[i+1]:

        a[i+1] = random.randint(1, N)

        if i < N - 2:

            while a[i+1] == a[i+2]:

                a[i+1] = random.randint(1, N)

print(count)

N = int(eval(input()))

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

count = 0

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

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

        count += 1

        a[i+1] = float('inf')

print(count)

import random

N = int(eval(input()))
a = [int(ai) for ai in input().split()]
random.seed(42)
count = 0
for i in range(0, N - 1):
    if a[i] == a[i + 1]:
        count += 1
    while a[i] == a[i + 1]:
        a[i + 1] = random.randint(1, N)
        if i < N - 2:
            while a[i + 1] == a[i + 2]:
                a[i + 1] = random.randint(1, N)
print(count)

N = int(eval(input()))
a = [int(ai) for ai in input().split()]
count = 0
for i in range(0, N - 1):
    if a[i] == a[i + 1]:
        count += 1
        a[i + 1] = float("inf")
print(count)

-        a[i + 1] = random.randint(1, N)

-                a[i + 1] = random.randint(1, N)


Input:
from itertools import product

s=eval(input())

for operators in product(["+","-"],repeat=3):

  formula=""

  for i in range(3):

    formula+=s[i]+operators[i]

  formula+=s[-1]

  if eval(formula)==7:

    print((formula+"=7"))

    exit()

from itertools import product

s=eval(input())

for op in product(["+","-"],repeat=3):

  formula =""

  for i in range(3):

    formula+=s[i]+op[i]

  formula+=s[-1]

  if eval(formula)==7:

    print((formula+"=7"))

    exit()

from itertools import product

s = eval(input())
for operators in product(["+", "-"], repeat=3):
    formula = ""
    for i in range(3):
        formula += s[i] + operators[i]
    formula += s[-1]
    if eval(formula) == 7:
        print((formula + "=7"))
        exit()

from itertools import product

s = eval(input())
for op in product(["+", "-"], repeat=3):
    formula = ""
    for i in range(3):
        formula += s[i] + op[i]
    formula += s[-1]
    if eval(formula) == 7:
        print((formula + "=7"))
        exit()

-for operators in product(["+", "-"], repeat=3):

+for op in product(["+", "-"], repeat=3):


Input:
import sys

sys.setrecursionlimit(10**9)

read=sys.stdin.read

class Unionfind():

    def __init__(self,n):

        self.parents=[-1]*n

        self.dist=[0]*n

    def find(self,x):

        if self.parents[x]<0:

            return x,self.dist[x]

        else:

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

            self.parents[x]=tmp[0]

            self.dist[x]+=tmp[1]

            return self.parents[x],self.dist[x]

    def union(self,x,y,d):

        rx=self.find(x)[0]

        ry=self.find(y)[0]

        diff=self.dist[y]-self.dist[x]-d

        if rx==ry:

            if diff!=0:

                return True

            return False

        if diff<0:

            rx,ry=ry,rx

            diff=-diff

        self.parents[ry]=min(self.parents[ry],self.parents[rx]-diff)

        self.parents[rx]=ry

        self.dist[rx]=diff

        return False

def main():

    n,m,*lrd=list(map(int,read().split()))

    v=Unionfind(n)

    for l,r,d in zip(*[iter(lrd)]*3):

        if v.union(l-1,r-1,d):

            print('No')

            break

    else:

        print('Yes')

if __name__=='__main__':

    main()

import sys

sys.setrecursionlimit(10**9)

read=sys.stdin.read

class Unionfind():

    def __init__(self,n):

        self.parents=[-1]*n

        self.dist=[0]*n

    def find(self,x):

        if self.parents[x]<0:

            return self.dist[x],x

        else:

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

            self.dist[x]+=tmp[0]

            self.parents[x]=tmp[1]

        return self.dist[x], self.parents[x]

    def union(self,x,y,d):

        _,rx=self.find(x)

        _,ry=self.find(y)

        diff=self.dist[y]-self.dist[x]-d

        if rx==ry:

            if diff!=0:

                return True

            return False

        if diff<0:

            rx,ry=ry,rx

            diff=-diff

        self.parents[ry]=min(self.parents[ry],self.parents[rx]-diff)

        self.parents[rx]=ry

        self.dist[rx]=diff

        return False

def main():

    n,m,*lrd=list(map(int,read().split()))

    v=Unionfind(n)

    for l,r,d in zip(*[iter(lrd)]*3):

        if v.union(l-1,r-1,d):

            print('No')

            break

    else:

        if max(-d-1 for d in v.parents if d<0) >10**9:

            print('No')

        else:

            print('Yes')

if __name__=='__main__':

    main()

import sys

sys.setrecursionlimit(10**9)
read = sys.stdin.read

class Unionfind:
    def __init__(self, n):
        self.parents = [-1] * n
        self.dist = [0] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x, self.dist[x]
        else:
            tmp = self.find(self.parents[x])
            self.parents[x] = tmp[0]
            self.dist[x] += tmp[1]
            return self.parents[x], self.dist[x]

    def union(self, x, y, d):
        rx = self.find(x)[0]
        ry = self.find(y)[0]
        diff = self.dist[y] - self.dist[x] - d
        if rx == ry:
            if diff != 0:
                return True
            return False
        if diff < 0:
            rx, ry = ry, rx
            diff = -diff
        self.parents[ry] = min(self.parents[ry], self.parents[rx] - diff)
        self.parents[rx] = ry
        self.dist[rx] = diff
        return False

def main():
    n, m, *lrd = list(map(int, read().split()))
    v = Unionfind(n)
    for l, r, d in zip(*[iter(lrd)] * 3):
        if v.union(l - 1, r - 1, d):
            print("No")
            break
    else:
        print("Yes")

if __name__ == "__main__":
    main()

import sys

sys.setrecursionlimit(10**9)
read = sys.stdin.read

class Unionfind:
    def __init__(self, n):
        self.parents = [-1] * n
        self.dist = [0] * n

    def find(self, x):
        if self.parents[x] < 0:
            return self.dist[x], x
        else:
            tmp = self.find(self.parents[x])
            self.dist[x] += tmp[0]
            self.parents[x] = tmp[1]
        return self.dist[x], self.parents[x]

    def union(self, x, y, d):
        _, rx = self.find(x)
        _, ry = self.find(y)
        diff = self.dist[y] - self.dist[x] - d
        if rx == ry:
            if diff != 0:
                return True
            return False
        if diff < 0:
            rx, ry = ry, rx
            diff = -diff
        self.parents[ry] = min(self.parents[ry], self.parents[rx] - diff)
        self.parents[rx] = ry
        self.dist[rx] = diff
        return False

def main():
    n, m, *lrd = list(map(int, read().split()))
    v = Unionfind(n)
    for l, r, d in zip(*[iter(lrd)] * 3):
        if v.union(l - 1, r - 1, d):
            print("No")
            break
    else:
        if max(-d - 1 for d in v.parents if d < 0) > 10**9:
            print("No")
        else:
            print("Yes")

if __name__ == "__main__":
    main()

-            return self.parents[x], self.dist[x]

+        return self.dist[x], self.parents[x]

+        if max(-d - 1 for d in v.parents if d < 0) > 10**9:


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

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

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

if max(scores) <= 0:

  print((max(scores)))

else:

  positions = [0] + positions

  scores = [0] + scores

  max_point = -pow(10, 9)

  #print(max_point)

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

    s = []

    f_pos = positions[i]

    score = scores[f_pos]

    s.append(score)

    while f_pos != i:

      f_pos = positions[f_pos]

      score += scores[f_pos]

      s.append(score)

    loop = len(s)

    if loop >= k:

      point = max(s[:k])

    elif s[-1] <= 0:

      point = max(s)

    else:

      loop_c = k // loop

      r = k % loop

      point1 = s[-1] * loop_c

      if r != 0:

        point1 += max(s[:r])

      point2 = s[-1] * (loop_c - 1)

      point2 += max(0, max(s))

      point = max(point1, point2)

    max_point = max(max_point, point)

  print(max_point)

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

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

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

if max(scores) <= 0:

  print((max(scores)))

else:

  positions = [0] + positions

  scores = [0] + scores

  max_point = -pow(10, 9)

  #print(max_point)

  dic = {}

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

    f_pos = i

    #print('f_pos',f_pos)

    if f_pos not in dic:

      point_loop = 0

      loop = 0

      pos_set = set([f_pos])

      while True:

        f_pos = positions[f_pos]

        point_loop += scores[f_pos]

        #print('pos', f_pos)

        #print(point)

        loop += 1

        if f_pos in pos_set:

          for j in pos_set:

            dic[j] = [loop, point_loop]

          break

        pos_set.add(f_pos)

    else:

      loop, point_loop = dic[f_pos]

    #print(loop, point)

    loop_c = k // loop

    r = k % loop

    if loop_c == 0 or point_loop <= 0:

      if point_loop <= 0:

        if loop_c > 0:

          r = loop

      point = 0

      for _ in range(r):

        f_pos = positions[f_pos]

        point += scores[f_pos]

        max_point = max(max_point, point)

    else:

      point1, point2 = 0, 0

      point1 = loop_c * point_loop

      max_point1 = point1

      for _ in range(r):

        f_pos = positions[f_pos]

        point1 += scores[f_pos]

        max_point1 = max(point1, max_point1)

      f_pos = i

      point2 = (loop_c - 1) * point_loop

      max_point2 = point2

      for _ in range(loop):

        f_pos = positions[f_pos]

        point2 += scores[f_pos]

        max_point2 = max(point2, max_point2)

      max_point = max(max_point, max(max_point1, max_point2))

  print(max_point)

n, k = list(map(int, input().split()))
positions = [int(i) for i in input().split()]
scores = [int(i) for i in input().split()]
if max(scores) <= 0:
    print((max(scores)))
else:
    positions = [0] + positions
    scores = [0] + scores
    max_point = -pow(10, 9)
    # print(max_point)
    for i in range(1, n + 1):
        s = []
        f_pos = positions[i]
        score = scores[f_pos]
        s.append(score)
        while f_pos != i:
            f_pos = positions[f_pos]
            score += scores[f_pos]
            s.append(score)
        loop = len(s)
        if loop >= k:
            point = max(s[:k])
        elif s[-1] <= 0:
            point = max(s)
        else:
            loop_c = k // loop
            r = k % loop
            point1 = s[-1] * loop_c
            if r != 0:
                point1 += max(s[:r])
            point2 = s[-1] * (loop_c - 1)
            point2 += max(0, max(s))
            point = max(point1, point2)
        max_point = max(max_point, point)
    print(max_point)

n, k = list(map(int, input().split()))
positions = [int(i) for i in input().split()]
scores = [int(i) for i in input().split()]
if max(scores) <= 0:
    print((max(scores)))
else:
    positions = [0] + positions
    scores = [0] + scores
    max_point = -pow(10, 9)
    # print(max_point)
    dic = {}
    for i in range(1, n + 1):
        f_pos = i
        # print('f_pos',f_pos)
        if f_pos not in dic:
            point_loop = 0
            loop = 0
            pos_set = set([f_pos])
            while True:
                f_pos = positions[f_pos]
                point_loop += scores[f_pos]
                # print('pos', f_pos)
                # print(point)
                loop += 1
                if f_pos in pos_set:
                    for j in pos_set:
                        dic[j] = [loop, point_loop]
                    break
                pos_set.add(f_pos)
        else:
            loop, point_loop = dic[f_pos]
        # print(loop, point)
        loop_c = k // loop
        r = k % loop
        if loop_c == 0 or point_loop <= 0:
            if point_loop <= 0:
                if loop_c > 0:
                    r = loop
            point = 0
            for _ in range(r):
                f_pos = positions[f_pos]
                point += scores[f_pos]
                max_point = max(max_point, point)
        else:
            point1, point2 = 0, 0
            point1 = loop_c * point_loop
            max_point1 = point1
            for _ in range(r):
                f_pos = positions[f_pos]
                point1 += scores[f_pos]
                max_point1 = max(point1, max_point1)
            f_pos = i
            point2 = (loop_c - 1) * point_loop
            max_point2 = point2
            for _ in range(loop):
                f_pos = positions[f_pos]
                point2 += scores[f_pos]
                max_point2 = max(point2, max_point2)
            max_point = max(max_point, max(max_point1, max_point2))
    print(max_point)

+                f_pos = positions[f_pos]

+                point_loop += scores[f_pos]

+                        dic[j] = [loop, point_loop]

-            point = max(point1, point2)

-        max_point = max(max_point, point)

+            loop, point_loop = dic[f_pos]

+        if loop_c == 0 or point_loop <= 0:

+                f_pos = positions[f_pos]

+                max_point = max(max_point, point)

+            point1 = loop_c * point_loop

+                f_pos = positions[f_pos]

+                point1 += scores[f_pos]

+                max_point1 = max(point1, max_point1)

+            point2 = (loop_c - 1) * point_loop

+                f_pos = positions[f_pos]

+                point2 += scores[f_pos]

+                max_point2 = max(point2, max_point2)

+            max_point = max(max_point, max(max_point1, max_point2))


Input:
from itertools import accumulate

from bisect import bisect_left

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

memo = [0] * 100010

for _ in range(N):

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

    memo[a] += b

print((bisect_left(list(accumulate(memo)), K)))

from sys import stdin

input = stdin.readline

from itertools import accumulate

from bisect import bisect_left

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

memo = [0] * 100010

for _ in range(N):

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

    memo[a] += b

print((bisect_left(list(accumulate(memo)), K)))

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


Input:
import math

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

sum=0

for i in range(N):

  a=max([math.log(K/(i+1), 2),0])

  a=math.ceil(a)

  sum=sum+0.5**a

print((sum/N))

import math

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

a=0

for i in range(N):

  a+=2**(-max([0,math.ceil(math.log2(K/(i+1)))]))

print((a/N))

import math

N, K = [int(s) for s in input().split()]
sum = 0
for i in range(N):
    a = max([math.log(K / (i + 1), 2), 0])
    a = math.ceil(a)
    sum = sum + 0.5**a
print((sum / N))

import math

N, K = [int(s) for s in input().split()]
a = 0
for i in range(N):
    a += 2 ** (-max([0, math.ceil(math.log2(K / (i + 1)))]))
print((a / N))


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

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

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

R.sort()

B.sort()

count = 0

tmp = []

for bx, by in B:

    for rx, ry in R:

        if bx > rx and by > ry:

            tmp.append([rx, ry])

    if tmp != []:

        max_red = max(tmp, key=lambda r: r[1])

        count += 1

        R.remove(max_red)

        tmp = []

print(count)

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

AB = list(zip(*[iter(I[:2 * N])] * 2))

CD = sorted(zip(*[iter(I[2 * N:])] * 2))

for c, d in CD:

    ma = max(((a, b) for a, b in AB if a < c and b < d), key=lambda x: x[1], default=None)

    if ma:

        AB.remove(ma)

print((N - len(AB)))

N, *I = list(map(int, open(0).read().split()))
AB = list(zip(*[iter(I[: 2 * N])] * 2))
CD = sorted(zip(*[iter(I[2 * N :])] * 2))
for c, d in CD:
    ma = max(
        ((a, b) for a, b in AB if a < c and b < d), key=lambda x: x[1], default=None
    )
    if ma:
        AB.remove(ma)
print((N - len(AB)))

-R = [[int(i) for i in input().split()] for _ in range(N)]

-B = [[int(i) for i in input().split()] for _ in range(N)]

-        max_red = max(tmp, key=lambda r: r[1])

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

+        ((a, b) for a, b in AB if a < c and b < d), key=lambda x: x[1], default=None


Input:
import numpy as np

N = int(eval(input()))

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

X_sort = sorted(X)

small, big = X_sort[N//2-1], X_sort[N//2]

for x in X:

    if x >= big:

        print(small)

    else:

        print(big)

import numpy as np

N = int(eval(input()))
X = list(map(int, input().split()))
X_sort = sorted(X)
small, big = X_sort[N // 2 - 1], X_sort[N // 2]
for x in X:
    if x >= big:
        print(small)
    else:
        print(big)


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

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

for _ in range(m):

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

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

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

checked = [False] * n

count = 0

import queue

q = queue.Queue()

for i in range(n):

    if checked[i]:

        continue

    count += 1

    q.put(i)

    while not q.empty():

        j = q.get()

        checked[j] = True

        for k in card[j]:

            if not checked[k]:

                q.put(k)

print (count)

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

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

for _ in range(m):

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

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

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

checked = [False] * n

count = 0

from collections import deque

for i in range(n):

    if checked[i]:

        continue

    count += 1

    q = deque([i])

    while q:

        j = q.popleft()

        checked[j] = True

        for k in card[j]:

            if not checked[k]:

                q.append(k)

print (count)

n, m = list(map(int, input().split()))
card = [[] for _ in range(n)]
for _ in range(m):
    x, y, _ = list(map(int, input().split()))
    card[x - 1].append(y - 1)
    card[y - 1].append(x - 1)
checked = [False] * n
count = 0
import queue

q = queue.Queue()
for i in range(n):
    if checked[i]:
        continue
    count += 1
    q.put(i)
    while not q.empty():
        j = q.get()
        checked[j] = True
        for k in card[j]:
            if not checked[k]:
                q.put(k)
print(count)

n, m = list(map(int, input().split()))
card = [[] for _ in range(n)]
for _ in range(m):
    x, y, _ = list(map(int, input().split()))
    card[x - 1].append(y - 1)
    card[y - 1].append(x - 1)
checked = [False] * n
count = 0
from collections import deque

for i in range(n):
    if checked[i]:
        continue
    count += 1
    q = deque([i])
    while q:
        j = q.popleft()
        checked[j] = True
        for k in card[j]:
            if not checked[k]:
                q.append(k)
print(count)

-import queue
+from collections import deque
-q = queue.Queue()
-    q.put(i)
-    while not q.empty():
-        j = q.get()
+    q = deque([i])
+    while q:
+        j = q.popleft()
-                q.put(k)
+                q.append(k)


Input:
import itertools

def solve():

    N = int(eval(input()))

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

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

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

    l = list(itertools.permutations(l))

    a = 0

    for k, v in enumerate(l):

        if A == list(v):

            a = k+1

    b = 0

    for k, v in enumerate(l):

        if B == list(v):

            b = k+1

    return abs(a-b)

print((solve()))

import itertools

def solve():

    N = int(eval(input()))

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

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

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

    l = list(itertools.permutations(l))

    a = 0

    b = 0

    for k, v in enumerate(l):

        v = list(v)

        if v == A:

            a = k+1

        if v == B:

            b = k+1

    return abs(a-b)

print((solve()))

import itertools

def solve():
    N = int(eval(input()))
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    l = [i for i in range(1, N + 1)]
    l = list(itertools.permutations(l))
    a = 0
    for k, v in enumerate(l):
        if A == list(v):
            a = k + 1
    b = 0
    for k, v in enumerate(l):
        if B == list(v):
            b = k + 1
    return abs(a - b)

print((solve()))

import itertools

def solve():
    N = int(eval(input()))
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    l = [i for i in range(1, N + 1)]
    l = list(itertools.permutations(l))
    a = 0
    b = 0
    for k, v in enumerate(l):
        v = list(v)
        if v == A:
            a = k + 1
        if v == B:
            b = k + 1
    return abs(a - b)

print((solve()))

-    for k, v in enumerate(l):
-        if A == list(v):
-            a = k + 1
-        if B == list(v):
+        v = list(v)
+        if v == A:
+            a = k + 1
+        if v == B:


Input:
from bisect import bisect_left as b

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

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

a.sort()

while m>0:

  i=a.pop(-1)//2

  a.insert(b(a,i),i)

  m-=1

print((sum(a)))

import heapq

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

A = list([int(x) * (-1) for x in input().split()])

heapq.heapify(A)

for _ in range(M):

  tmp_min = heapq.heappop(A)

  heapq.heappush(A, (-1) * (-tmp_min // 2))

print((-sum(A)))

from bisect import bisect_left as b

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
while m > 0:
    i = a.pop(-1) // 2
    a.insert(b(a, i), i)
    m -= 1
print((sum(a)))

import heapq

N, M = list(map(int, input().split()))
A = list([int(x) * (-1) for x in input().split()])
heapq.heapify(A)
for _ in range(M):
    tmp_min = heapq.heappop(A)
    heapq.heappush(A, (-1) * (-tmp_min // 2))
print((-sum(A)))

+A = list([int(x) * (-1) for x in input().split()])

+    heapq.heappush(A, (-1) * (-tmp_min // 2))


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

if x - r < 0 or x + r > W or y - r < 0 or y + r > H:

  print ("No")

else:

  print ("Yes")

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

if x - r < 0 :

    print("No")

elif x + r > W:

    print("No")

elif  y - r < 0:

    print("No")

elif y + r > H:

  print ("No")

else:

  print ("Yes")

W, H, x, y, r = list(map(int, input().split()))
if x - r < 0 or x + r > W or y - r < 0 or y + r > H:
    print("No")
else:
    print("Yes")

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

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

-if x - r < 0 or x + r > W or y - r < 0 or y + r > H:

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


Input:
import sys

input = sys.stdin.readline

c = 0

num = 0

def check(n):

	strn = str(n)

	l = [0, 0, 0]

	for c in strn:

		if c == '3':

			l[0] = 1

		elif c == '5':

			l[1] = 1

		elif c == '7':

			l[2] = 1

	return all(l) or False

def gen(n):

	global c

	# print(n)

	if n > num:

		return

	if check(n):

		# print(n)

		c += 1

	for i in [3, 5, 7]:

		k = 10 * n + i

		gen(k)

def main():

	global num

	num = int(input().strip())

	gen(0)

	print(c)

if __name__ == '__main__':

	main()

import sys

input = sys.stdin.readline

from operator import itemgetter

sys.setrecursionlimit(10000000)

INF = 10**30

ans = 0

c = ['3', '5', '7']

N = 0

def check(l):

    return len(set(l)) == 3

def nummaker(k, n):

    global ans

    if k == 0:

        q = int(''.join(n))

        if q > N:

            print(ans)

            sys.exit(0)

        if check(n):

            ans += 1

        return

    for i in c:

        m = n[:]

        m.append(i)

        nummaker(k-1, m)

def main():

    global N

    N = int(input().strip())

    for i in range(1, 11):

        nummaker(i, [])

if __name__ == '__main__':

    main()

import sys

input = sys.stdin.readline
c = 0
num = 0

def check(n):
    strn = str(n)
    l = [0, 0, 0]
    for c in strn:
        if c == "3":
            l[0] = 1
        elif c == "5":
            l[1] = 1
        elif c == "7":
            l[2] = 1
    return all(l) or False

def gen(n):
    global c
    # print(n)
    if n > num:
        return
    if check(n):
        # print(n)
        c += 1
    for i in [3, 5, 7]:
        k = 10 * n + i
        gen(k)

def main():
    global num
    num = int(input().strip())
    gen(0)
    print(c)

if __name__ == "__main__":
    main()

import sys

input = sys.stdin.readline
from operator import itemgetter

sys.setrecursionlimit(10000000)
INF = 10**30
ans = 0
c = ["3", "5", "7"]
N = 0

def check(l):
    return len(set(l)) == 3

def nummaker(k, n):
    global ans
    if k == 0:
        q = int("".join(n))
        if q > N:
            print(ans)
            sys.exit(0)
        if check(n):
            ans += 1
        return
    for i in c:
        m = n[:]
        m.append(i)
        nummaker(k - 1, m)

def main():
    global N
    N = int(input().strip())
    for i in range(1, 11):
        nummaker(i, [])

if __name__ == "__main__":
    main()

-c = 0
-num = 0
+from operator import itemgetter
+
+sys.setrecursionlimit(10000000)
+INF = 10**30
+ans = 0
+c = ["3", "5", "7"]
+N = 0
-def check(n):
-    strn = str(n)
-    l = [0, 0, 0]
-    for c in strn:
-        if c == "3":
-            l[0] = 1
-        elif c == "5":
-            l[1] = 1
-        elif c == "7":
-            l[2] = 1
-    return all(l) or False
+def check(l):
+    return len(set(l)) == 3
-def gen(n):
-    global c
-    # print(n)
-    if n > num:
+def nummaker(k, n):
+    global ans
+    if k == 0:
+        q = int("".join(n))
+        if q > N:
+            print(ans)
+            sys.exit(0)
+        if check(n):
+            ans += 1
-    if check(n):
-        # print(n)
-        c += 1
-    for i in [3, 5, 7]:
-        k = 10 * n + i
-        gen(k)
+    for i in c:
+        m = n[:]
+        m.append(i)
+        nummaker(k - 1, m)
-    global num
-    num = int(input().strip())
-    gen(0)
-    print(c)
+    global N
+    N = int(input().strip())
+    for i in range(1, 11):
+        nummaker(i, [])


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

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

L.sort()

ans=0

for i in range(N-2):

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

        ng=N

        ok=j

        while abs(ok-ng)!=1:

            med =(ok+ng)//2

            if L[med]<L[i]+L[j]:

                ok=med

            else:

                ng=med

        ans+=ok-j

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():

    import bisect

    mod=10**9+7

    N=I()

    L=LI()

    L.sort()

    ans=0

    for i in range(N):

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

            a=L[i]

            b=L[j]

            ab=a+b

            num=bisect.bisect_left(L,ab)

            # print(i,j,num-j)

            ans+=num-j-1

    print(ans)

main()

N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N - 2):
    for j in range(i + 1, N):
        ng = N
        ok = j
        while abs(ok - ng) != 1:
            med = (ok + ng) // 2
            if L[med] < L[i] + L[j]:
                ok = med
            else:
                ng = med
        ans += ok - j
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():
    import bisect

    mod = 10**9 + 7
    N = I()
    L = LI()
    L.sort()
    ans = 0
    for i in range(N):
        for j in range(i + 1, N):
            a = L[i]
            b = L[j]
            ab = a + b
            num = bisect.bisect_left(L, ab)
            # print(i,j,num-j)
            ans += num - j - 1
    print(ans)

main()

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

+            num = bisect.bisect_left(L, ab)


Input:
from itertools import combinations_with_replacement

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

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

ans = 0

for A in combinations_with_replacement(list(range(M)), N):

    temp = 0

    for abcd in ABCD:

        if A[abcd[1]-1]+1 == A[abcd[0]-1]+1 + abcd[2]:

            temp += abcd[3]

    if temp > ans:

        ans = temp

print(ans)

from itertools import combinations_with_replacement

def main():

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

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

    ans = 0

    for A in combinations_with_replacement(list(range(M)), N):

        temp = 0

        for abcd in ABCD:

            if A[abcd[1]-1]+1 == A[abcd[0]-1]+1 + abcd[2]:

                temp += abcd[3]

        if temp > ans:

            ans = temp

    print(ans)

if __name__ == '__main__':

    main()

from itertools import combinations_with_replacement

N, M, Q = list(map(int, input().split()))
ABCD = [list(map(int, input().split())) for i in range(Q)]
ans = 0
for A in combinations_with_replacement(list(range(M)), N):
    temp = 0
    for abcd in ABCD:
        if A[abcd[1] - 1] + 1 == A[abcd[0] - 1] + 1 + abcd[2]:
            temp += abcd[3]
    if temp > ans:
        ans = temp
print(ans)

from itertools import combinations_with_replacement

def main():
    N, M, Q = list(map(int, input().split()))
    ABCD = [list(map(int, input().split())) for i in range(Q)]
    ans = 0
    for A in combinations_with_replacement(list(range(M)), N):
        temp = 0
        for abcd in ABCD:
            if A[abcd[1] - 1] + 1 == A[abcd[0] - 1] + 1 + abcd[2]:
                temp += abcd[3]
        if temp > ans:
            ans = temp
    print(ans)

if __name__ == "__main__":
    main()

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

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

-for A in combinations_with_replacement(list(range(M)), N):

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

+    ABCD = [list(map(int, input().split())) for i in range(Q)]

+    for A in combinations_with_replacement(list(range(M)), N):


Input:
from functools import lru_cache

import sys

sys.setrecursionlimit(10 ** 7)

@lru_cache(maxsize=None)

def dfs(h):

    if h == 1:

        return 1

    return 1 + dfs(h // 2) * 2

def main():

    h = int(eval(input()))

    print((dfs(h)))

if __name__ == '__main__':

    main()

#

# input = sys.stdin.readline

# rstrip()

# int(input())

# map(int, input().split())

H = int(eval(input()))

ret = 0

mon = 1

while H:

    H //= 2

    ret += mon

    mon <<= 1

print(ret)

from functools import lru_cache
import sys

sys.setrecursionlimit(10**7)

@lru_cache(maxsize=None)
def dfs(h):
    if h == 1:
        return 1
    return 1 + dfs(h // 2) * 2

def main():
    h = int(eval(input()))
    print((dfs(h)))

if __name__ == "__main__":
    main()
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())

-from functools import lru_cache
-import sys
-sys.setrecursionlimit(10**7)
-@lru_cache(maxsize=None)
-def dfs(h):
-    if h == 1:
-        return 1
-    return 1 + dfs(h // 2) * 2
-def main():
-    h = int(eval(input()))
-    print((dfs(h)))
-if __name__ == "__main__":
-    main()
-#
-# input = sys.stdin.readline
-# rstrip()
-# int(input())
-# map(int, input().split())
+H = int(eval(input()))
+ret = 0
+mon = 1
+while H:
+    H //= 2
+    ret += mon
+    mon <<= 1
+print(ret)


Input:
#!usr/bin/env python3

from collections import defaultdict

def main():

    fl = input().split(" ")

    V = int(fl[0])

    E = int(fl[1])

    R = int(fl[2])

    #Adjacency list

    G = defaultdict(dict)

    for i in range(int(E)):

        s, t, w = [int(x) for x in input().split(" ")]

        G[s][t] = w

    #initialized

    d = {}

    INF = float('inf')

    #INF = 10001

    for i in range(V):

        d[i] = INF

    d[R] = 0

    q = [R]

    while q:

        u = q.pop(0)

        for v in list(G[u].keys()):

            if d[v] > d[u] + G[u][v]:

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

                q.append(v)

    for k in range(V):

        if d[k] == float('inf'):

            print("INF")

        else:

            print((d[k]))

if __name__ == '__main__':

    main()

#!usr/bin/env python3

from collections import defaultdict

def main():

    #Read stdin

    fl = input().split(" ")

    V = int(fl[0])

    E = int(fl[1])

    R = int(fl[2])

    #Adjacency list

    G = defaultdict(list)

    for i in range(int(E)):

        s, t, w = [int(x) for x in input().split(" ")]

        G[s].append((t,w))

    #initialized

    d = {}

    INF = float('inf')

    #INF = 10001

    for i in range(V):

        d[i] = INF

    d[R] = 0

    q = [R]

    while q:

        u = q.pop(0)

        for v in G[u]:

            if d[v[0]] > d[u] + v[1]:

                d[v[0]] = d[u] + v[1]

                q.append(v[0])

    for k in range(V):

        if d[k] == float('inf'):

            print("INF")

        else:

            print((d[k]))

if __name__ == '__main__':

    main()

#!usr/bin/env python3
from collections import defaultdict

def main():
    fl = input().split(" ")
    V = int(fl[0])
    E = int(fl[1])
    R = int(fl[2])
    # Adjacency list
    G = defaultdict(dict)
    for i in range(int(E)):
        s, t, w = [int(x) for x in input().split(" ")]
        G[s][t] = w
    # initialized
    d = {}
    INF = float("inf")
    # INF = 10001
    for i in range(V):
        d[i] = INF
    d[R] = 0
    q = [R]
    while q:
        u = q.pop(0)
        for v in list(G[u].keys()):
            if d[v] > d[u] + G[u][v]:
                d[v] = d[u] + G[u][v]
                q.append(v)
    for k in range(V):
        if d[k] == float("inf"):
            print("INF")
        else:
            print((d[k]))

if __name__ == "__main__":
    main()

#!usr/bin/env python3
from collections import defaultdict

def main():
    # Read stdin
    fl = input().split(" ")
    V = int(fl[0])
    E = int(fl[1])
    R = int(fl[2])
    # Adjacency list
    G = defaultdict(list)
    for i in range(int(E)):
        s, t, w = [int(x) for x in input().split(" ")]
        G[s].append((t, w))
    # initialized
    d = {}
    INF = float("inf")
    # INF = 10001
    for i in range(V):
        d[i] = INF
    d[R] = 0
    q = [R]
    while q:
        u = q.pop(0)
        for v in G[u]:
            if d[v[0]] > d[u] + v[1]:
                d[v[0]] = d[u] + v[1]
                q.append(v[0])
    for k in range(V):
        if d[k] == float("inf"):
            print("INF")
        else:
            print((d[k]))

if __name__ == "__main__":
    main()

+    # Read stdin
-    G = defaultdict(dict)
+    G = defaultdict(list)
-        G[s][t] = w
+        G[s].append((t, w))
-        for v in list(G[u].keys()):
-            if d[v] > d[u] + G[u][v]:
-                d[v] = d[u] + G[u][v]
-                q.append(v)
+        for v in G[u]:
+            if d[v[0]] > d[u] + v[1]:
+                d[v[0]] = d[u] + v[1]
+                q.append(v[0])


Input:
# cs: c nnected switches

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

# cs: connected switches

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

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

# bit全探索(0: すべてoffは不要)

ans = 0

# on: 0:消えてる、1:点いてる

# 10: 1 2  3   4

# 0b: 1 10 11, 100..

for on in range(2**n):

    # bin: バイナリ文字列に変換

    # 3 -> '0b11'

    # rust で右0埋め

    patern = bin(on)[2:].rjust(n, '0')

    ok = True

    for i in range(m):

        ct = 0

        for j in range(cs[i][0]):

            if patern[cs[i][j+1] - 1] == '1':

                ct += 1

        if ct%2 != ps[i]:

            ok = False

    if ok:

        ans += 1

print(ans)

# cs: c nnected switches

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

def get_connected_switches():

    # k s1 s2 .. sn

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

    lst.pop(0) # k is not use

    return list([1<<(d-1) for d in lst])

# cs: connected switches

cs = [get_connected_switches() for _ in range(m)]

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

# bit全探索(0: すべてoffは不要)

ans = 0

# on: 0:消えてる、1:点いてる

# 10: 1 2  3   4

# 0b: 1 10 11, 100..

for on in range(2**n):

    ok = True

    for i in range(m):

        ct = 0

        for s in cs[i]:

            if s&on: ct += 1

        if ct%2 != ps[i]:

            ok = False

    if ok:

        ans += 1

print(ans)

# cs: c nnected switches
n, m = list(map(int, input().split()))
# cs: connected switches
cs = [list(map(int, input().split())) for _ in range(m)]
ps = list(map(int, input().split()))
# bit全探索(0: すべてoffは不要)
ans = 0
# on: 0:消えてる、1:点いてる
# 10: 1 2  3   4
# 0b: 1 10 11, 100..
for on in range(2**n):
    # bin: バイナリ文字列に変換
    # 3 -> '0b11'
    # rust で右0埋め
    patern = bin(on)[2:].rjust(n, "0")
    ok = True
    for i in range(m):
        ct = 0
        for j in range(cs[i][0]):
            if patern[cs[i][j + 1] - 1] == "1":
                ct += 1
        if ct % 2 != ps[i]:
            ok = False
    if ok:
        ans += 1
print(ans)

# cs: c nnected switches
n, m = list(map(int, input().split()))

def get_connected_switches():
    # k s1 s2 .. sn
    lst = list(map(int, input().split()))
    lst.pop(0)  # k is not use
    return list([1 << (d - 1) for d in lst])

# cs: connected switches
cs = [get_connected_switches() for _ in range(m)]
ps = list(map(int, input().split()))
# bit全探索(0: すべてoffは不要)
ans = 0
# on: 0:消えてる、1:点いてる
# 10: 1 2  3   4
# 0b: 1 10 11, 100..
for on in range(2**n):
    ok = True
    for i in range(m):
        ct = 0
        for s in cs[i]:
            if s & on:
                ct += 1
        if ct % 2 != ps[i]:
            ok = False
    if ok:
        ans += 1
print(ans)

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

+    return list([1 << (d - 1) for d in lst])

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

+cs = [get_connected_switches() for _ in range(m)]

-    # bin: バイナリ文字列に変換


Input:
from collections import Counter

def main():

    n = int(eval(input()))

    anas = Counter(''.join(sorted(eval(input()))) for _ in range(n))

    result = sum(sum(range(anas[a])) for a in anas)

    print(result)

main()

from collections import Counter

from sys import stdin

def main():

    n = int(eval(input()))

    anas = Counter(''.join(sorted(stdin.readline())) for _ in range(n))

    result = sum(sum(range(anas[a])) for a in anas)

    print(result)

main()

from collections import Counter

def main():
    n = int(eval(input()))
    anas = Counter("".join(sorted(eval(input()))) for _ in range(n))
    result = sum(sum(range(anas[a])) for a in anas)
    print(result)

main()

from collections import Counter
from sys import stdin

def main():
    n = int(eval(input()))
    anas = Counter("".join(sorted(stdin.readline())) for _ in range(n))
    result = sum(sum(range(anas[a])) for a in anas)
    print(result)

main()

-    anas = Counter("".join(sorted(eval(input()))) for _ in range(n))

+    anas = Counter("".join(sorted(stdin.readline())) for _ in range(n))


Input:
import sys

from bisect import bisect_left, bisect_right, insort

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

ir = lambda: int(sr())

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

N = ir()

S = list('-' + sr())

d = [[] for _ in range(26)]

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

    s = S[i]

    o = ord(s) - ord('a')

    d[o].append(i)

Q = ir()

for _ in range(Q):

    q, a, b = sr().split()

    if q == '1':

        a = int(a)

        if S[a] == b:

            continue

        prev = ord(S[a]) - ord('a')

        d[prev].remove(a)

        next = ord(b) - ord('a')

        insort(d[next], a)

        S[a] = b

    else:

        a = int(a); b = int(b)

        ans = 0

        for alpha in range(26):

            if bisect_right(d[alpha], b) - bisect_left(d[alpha], a) >= 1:

                ans += 1

        print(ans)

import sys

from bisect import bisect_left, bisect_right, insort

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

ir = lambda: int(sr())

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

N = ir()

S = list('-' + sr())

d = [[] for _ in range(26)]

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

    s = S[i]

    o = ord(s) - ord('a')

    d[o].append(i)

Q = ir()

for _ in range(Q):

    q, a, b = sr().split()

    if q == '1':

        a = int(a)

        if S[a] == b:

            continue

        prev = ord(S[a]) - ord('a')

        d[prev].pop(bisect_left(d[prev], a))

        next = ord(b) - ord('a')

        insort(d[next], a)

        S[a] = b

    else:

        a = int(a); b = int(b)

        ans = 0

        for alpha in range(26):

            if bisect_right(d[alpha], b) - bisect_left(d[alpha], a) >= 1:

                ans += 1

        print(ans)

import sys
from bisect import bisect_left, bisect_right, insort

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N = ir()
S = list("-" + sr())
d = [[] for _ in range(26)]
for i in range(1, N + 1):
    s = S[i]
    o = ord(s) - ord("a")
    d[o].append(i)
Q = ir()
for _ in range(Q):
    q, a, b = sr().split()
    if q == "1":
        a = int(a)
        if S[a] == b:
            continue
        prev = ord(S[a]) - ord("a")
        d[prev].remove(a)
        next = ord(b) - ord("a")
        insort(d[next], a)
        S[a] = b
    else:
        a = int(a)
        b = int(b)
        ans = 0
        for alpha in range(26):
            if bisect_right(d[alpha], b) - bisect_left(d[alpha], a) >= 1:
                ans += 1
        print(ans)

import sys
from bisect import bisect_left, bisect_right, insort

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N = ir()
S = list("-" + sr())
d = [[] for _ in range(26)]
for i in range(1, N + 1):
    s = S[i]
    o = ord(s) - ord("a")
    d[o].append(i)
Q = ir()
for _ in range(Q):
    q, a, b = sr().split()
    if q == "1":
        a = int(a)
        if S[a] == b:
            continue
        prev = ord(S[a]) - ord("a")
        d[prev].pop(bisect_left(d[prev], a))
        next = ord(b) - ord("a")
        insort(d[next], a)
        S[a] = b
    else:
        a = int(a)
        b = int(b)
        ans = 0
        for alpha in range(26):
            if bisect_right(d[alpha], b) - bisect_left(d[alpha], a) >= 1:
                ans += 1
        print(ans)

+        d[prev].pop(bisect_left(d[prev], a))


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

stones = list(eval(input()))

l = 0

r = N-1

count = 0

while(True):

  while(stones[l] == "R" and l < N-1):

    l += 1

  while(stones[r] == "W" and r > 0):

    r -= 1

  if (l >= r):

    print(count)

    exit()

  else:

    count += 1

    l += 1

    r -= 1

N= int(eval(input()))

stone_str = eval(input())

r_cnt = stone_str.count('R')

print((stone_str.count('W', 0, r_cnt)))

N = int(eval(input()))
stones = list(eval(input()))
l = 0
r = N - 1
count = 0
while True:
    while stones[l] == "R" and l < N - 1:
        l += 1
    while stones[r] == "W" and r > 0:
        r -= 1
    if l >= r:
        print(count)
        exit()
    else:
        count += 1
        l += 1
        r -= 1

N = int(eval(input()))
stone_str = eval(input())
r_cnt = stone_str.count("R")
print((stone_str.count("W", 0, r_cnt)))

-    while stones[l] == "R" and l < N - 1:


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

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

dp = [float("inf")] * n

dp[0] = 0

for i in range(n-1):

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

        if i+j <= n-1:

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

print((dp[n-1]))

def main():

    import sys

    input = sys.stdin.buffer.readline

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

    h = [0] + [int(i) for i in input().split()]

    memo = [float('inf')] * (N+1)

    memo[1] = 0

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

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

            if i < 0:

                continue

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

    print((memo[N]))

if __name__ == '__main__':

    main()

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

def main():
    import sys

    input = sys.stdin.buffer.readline
    N, K = (int(i) for i in input().split())
    h = [0] + [int(i) for i in input().split()]
    memo = [float("inf")] * (N + 1)
    memo[1] = 0
    for j in range(2, N + 1):
        for i in range(j - K, j):
            if i < 0:
                continue
            memo[j] = min(memo[j], memo[i] + abs(h[j] - h[i]))
    print((memo[N]))

if __name__ == "__main__":
    main()

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

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

+    h = [0] + [int(i) for i in input().split()]

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


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

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

now_max = max(datas[1:])

max_index = (N-1) - datas[::-1].index(now_max)

_min = min(datas)

min_index = datas.index(_min)

if max_index > min_index:

    diff = now_max - _min

else:

    diff = now_max - datas[0]

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

        if i == max_index:

            now_max = max(datas[i+1:])

            max_index = datas.index(now_max,i+1)

        new_diff = now_max - datas[i]

        if diff < new_diff:

            diff = new_diff

print(diff)

from sys import stdin

N,*datas = [int(i) for i in stdin.readlines()]

now_max = max(datas[1:])

max_index = (N-1) - datas[::-1].index(now_max)

_min = min(datas)

min_index = datas.index(_min)

if max_index > min_index:

    diff = now_max - _min

else:

    diff = now_max - datas[0]

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

        if i == max_index:

            now_max = max(datas[i+1:])

            max_index = datas.index(now_max,i+1)

        new_diff = now_max - datas[i]

        if diff < new_diff:

            diff = new_diff

print(diff)

N = int(eval(input()))
datas = [int(eval(input())) for _ in range(N)]
now_max = max(datas[1:])
max_index = (N - 1) - datas[::-1].index(now_max)
_min = min(datas)
min_index = datas.index(_min)
if max_index > min_index:
    diff = now_max - _min
else:
    diff = now_max - datas[0]
    for i in range(1, N - 1):
        if i == max_index:
            now_max = max(datas[i + 1 :])
            max_index = datas.index(now_max, i + 1)
        new_diff = now_max - datas[i]
        if diff < new_diff:
            diff = new_diff
print(diff)

from sys import stdin

N, *datas = [int(i) for i in stdin.readlines()]
now_max = max(datas[1:])
max_index = (N - 1) - datas[::-1].index(now_max)
_min = min(datas)
min_index = datas.index(_min)
if max_index > min_index:
    diff = now_max - _min
else:
    diff = now_max - datas[0]
    for i in range(1, N - 1):
        if i == max_index:
            now_max = max(datas[i + 1 :])
            max_index = datas.index(now_max, i + 1)
        new_diff = now_max - datas[i]
        if diff < new_diff:
            diff = new_diff
print(diff)

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

+N, *datas = [int(i) for i in stdin.readlines()]


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

print(((10**n-2*9**n+8**n)%(10**9+7)))

m = 10**9 + 7

def powmod(x,y):

  a=1

  for i in range(y):

    a=(a*x)%m

  return a

n=int(eval(input()))

s=powmod(10,n)-2*powmod(9,n)+powmod(8,n)

print(((s+m)%m))

m = 10**9 + 7

def powmod(x, y):
    a = 1
    for i in range(y):
        a = (a * x) % m
    return a

n = int(eval(input()))
s = powmod(10, n) - 2 * powmod(9, n) + powmod(8, n)
print(((s + m) % m))

+s = powmod(10, n) - 2 * powmod(9, n) + powmod(8, n)


Input:
import itertools

ans_li = []

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

li = []

for _ in range(n):

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

for i in range(n):

    if i == 0:

        tmp = [kkk for kkk in range(n)]

        #print(tmp)

        #score_li = [0]*m

        #okane = 0

        #print([k for k in range(n)],i+1,tmp)

        for t in tmp:

            score_li = [0]*m

            okane = 0

            #print(li,t,'ttttt')

            for ii,ll in enumerate(list(li[t])):

                if ii==0:

                    okane += li[t][ii]

                else:

                    #print(score_li,ii,ll)

                    score_li[ii-1]+=ll

            flag = True

            #print(score_li,okane)

            for ss in score_li:

                if ss<x:

                    flag = False

            if flag:

                ans_li.append(okane)

    else:

        tmp = list(itertools.combinations(list(range(n)), i+1))

        #print(tmp)

        #score_li = [0]*m

        #okane = 0

        #print([k for k in range(n)],i+1,tmp)

        for t in tmp:

            score_li = [0]*m

            okane = 0

            #print(li,t,'ttttt')

            for aaa in t:

                for ii,ll in enumerate(list(li[aaa])):

                    if ii==0:

                        okane += li[aaa][ii]

                    else:

                        #print(score_li,ii,ll)

                        score_li[ii-1]+=ll

            flag = True

            for ss in score_li:

                if ss<x:

                    flag = False

            if flag:

                ans_li.append(okane)

#print(ans_li)

if len(ans_li)>0:

    print((min(ans_li)))

else:

    print((-1))

import itertools

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

c_li = []

a_li = []

for _ in range(n):

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

    c_li.append(tmp[0])

    a_li.append(tmp[1:])

kumi = list(itertools.product([0,1], repeat=n))

ans_li = []

for each_kumi in kumi:

    each_li = [0]*m

    score = 0

    for i,k in enumerate(each_kumi):

        if k == 1:

            score += c_li[i]

            for j,kk in enumerate(a_li[i]):

                each_li[j] += kk

    flag = True

    for ea in each_li:

        if ea<x:

            flag = False

    if flag:

        ans_li.append(score)

if len(ans_li)==0:

    print((-1))

else:

    print((min(ans_li)))

import itertools

ans_li = []
n, m, x = list(map(int, input().split()))
li = []
for _ in range(n):
    li.append(list(map(int, input().split())))
for i in range(n):
    if i == 0:
        tmp = [kkk for kkk in range(n)]
        # print(tmp)
        # score_li = [0]*m
        # okane = 0
        # print([k for k in range(n)],i+1,tmp)
        for t in tmp:
            score_li = [0] * m
            okane = 0
            # print(li,t,'ttttt')
            for ii, ll in enumerate(list(li[t])):
                if ii == 0:
                    okane += li[t][ii]
                else:
                    # print(score_li,ii,ll)
                    score_li[ii - 1] += ll
            flag = True
            # print(score_li,okane)
            for ss in score_li:
                if ss < x:
                    flag = False
            if flag:
                ans_li.append(okane)
    else:
        tmp = list(itertools.combinations(list(range(n)), i + 1))
        # print(tmp)
        # score_li = [0]*m
        # okane = 0
        # print([k for k in range(n)],i+1,tmp)
        for t in tmp:
            score_li = [0] * m
            okane = 0
            # print(li,t,'ttttt')
            for aaa in t:
                for ii, ll in enumerate(list(li[aaa])):
                    if ii == 0:
                        okane += li[aaa][ii]
                    else:
                        # print(score_li,ii,ll)
                        score_li[ii - 1] += ll
            flag = True
            for ss in score_li:
                if ss < x:
                    flag = False
            if flag:
                ans_li.append(okane)
# print(ans_li)
if len(ans_li) > 0:
    print((min(ans_li)))
else:
    print((-1))

import itertools

n, m, x = list(map(int, input().split()))
c_li = []
a_li = []
for _ in range(n):
    tmp = list(map(int, input().split()))
    c_li.append(tmp[0])
    a_li.append(tmp[1:])
kumi = list(itertools.product([0, 1], repeat=n))
ans_li = []
for each_kumi in kumi:
    each_li = [0] * m
    score = 0
    for i, k in enumerate(each_kumi):
        if k == 1:
            score += c_li[i]
            for j, kk in enumerate(a_li[i]):
                each_li[j] += kk
    flag = True
    for ea in each_li:
        if ea < x:
            flag = False
    if flag:
        ans_li.append(score)
if len(ans_li) == 0:
    print((-1))
else:
    print((min(ans_li)))

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

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

+kumi = list(itertools.product([0, 1], repeat=n))

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

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

-        tmp = [kkk for kkk in range(n)]

-        # print([k for k in range(n)],i+1,tmp)

-            for ii, ll in enumerate(list(li[t])):

-                    # print(score_li,ii,ll)

-                    score_li[ii - 1] += ll

-        tmp = list(itertools.combinations(list(range(n)), i + 1))

-                for ii, ll in enumerate(list(li[aaa])):

-                        okane += li[aaa][ii]

-                        # print(score_li,ii,ll)

-                        score_li[ii - 1] += ll

+            for j, kk in enumerate(a_li[i]):


Input:
import sys

sys.setrecursionlimit(10**9)

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

n,st,sa=f()

g=[set() for _ in range(n)]

for _ in range(n-1):

  a,b=f()

  g[a-1].add(b-1)

  g[b-1].add(a-1)

def dfs(l,v,p=-1,d=0):

  l[v]=d

  for c in g[v]:

    if c!=p: dfs(l,c,v,d+1)

lt=[0]*n

dfs(lt,st-1)

la=[0]*n

dfs(la,sa-1)

print((max(la[i] for i in range(n) if lt[i]<la[i])-1))

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

n,st,sa=f()

g=[set() for _ in range(n)]

for _ in range(n-1):

  a,b=f()

  g[a-1].add(b-1)

  g[b-1].add(a-1)

def bfs(s):

  l=[-1]*n; l[s]=0; q=[s]

  while q:

    v=q.pop(); d=l[v]+1

    for c in g[v]:

      if l[c]<0: l[c]=d; q+=[c]

  return l

lt=bfs(st-1)

la=bfs(sa-1)

print((max(la[i] for i in range(n) if lt[i]<la[i])-1))

import sys

sys.setrecursionlimit(10**9)
f = lambda: list(map(int, sys.stdin.readline().split()))
n, st, sa = f()
g = [set() for _ in range(n)]
for _ in range(n - 1):
    a, b = f()
    g[a - 1].add(b - 1)
    g[b - 1].add(a - 1)

def dfs(l, v, p=-1, d=0):
    l[v] = d
    for c in g[v]:
        if c != p:
            dfs(l, c, v, d + 1)

lt = [0] * n
dfs(lt, st - 1)
la = [0] * n
dfs(la, sa - 1)
print((max(la[i] for i in range(n) if lt[i] < la[i]) - 1))

f = lambda: list(map(int, input().split()))
n, st, sa = f()
g = [set() for _ in range(n)]
for _ in range(n - 1):
    a, b = f()
    g[a - 1].add(b - 1)
    g[b - 1].add(a - 1)

def bfs(s):
    l = [-1] * n
    l[s] = 0
    q = [s]
    while q:
        v = q.pop()
        d = l[v] + 1
        for c in g[v]:
            if l[c] < 0:
                l[c] = d
                q += [c]
    return l

lt = bfs(st - 1)
la = bfs(sa - 1)
print((max(la[i] for i in range(n) if lt[i] < la[i]) - 1))

-f = lambda: list(map(int, sys.stdin.readline().split()))

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


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

# 木だったらなんでもOK?

# いもす法

edge = [0] * (N + 1)

for _ in range(M):

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

    edge[a] += 1

    edge[b] -= 1

ans = "YES"

for i in range(N):

    edge[i + 1] += edge[i]

    if edge[i + 1] % 2 == 1:

        ans = "NO"

        break

print(ans)

import sys

input = sys.stdin.buffer.readline

sys.setrecursionlimit(10 ** 7)

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

cnt = [0] * (N + 1)

for _ in range(M):

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

    cnt[a] ^= 1

    cnt[b] ^= 1

if all(x == 0 for x in cnt):

    print("YES")

else:

    print("NO")

import sys

input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
N, M = list(map(int, input().split()))
cnt = [0] * (N + 1)
for _ in range(M):
    a, b = list(map(int, input().split()))
    cnt[a] ^= 1
    cnt[b] ^= 1
if all(x == 0 for x in cnt):
    print("YES")
else:
    print("NO")

+import sys
+
+input = sys.stdin.buffer.readline
+sys.setrecursionlimit(10**7)
-# 木だったらなんでもOK?
-# いもす法
-edge = [0] * (N + 1)
+cnt = [0] * (N + 1)
-    edge[a] += 1
-    edge[b] -= 1
-ans = "YES"
-for i in range(N):
-    edge[i + 1] += edge[i]
-    if edge[i + 1] % 2 == 1:
-        ans = "NO"
-        break
-print(ans)
+    cnt[a] ^= 1
+    cnt[b] ^= 1
+if all(x == 0 for x in cnt):
+    print("YES")
+else:
+    print("NO")


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

ans = 10**9+7

for i in range(N+1):

  j = N-i

  cnt = 0

  while i > 0:

    cnt += i%6

    i //= 6

  while j > 0:

    cnt += j%9

    j //= 9

  ans = min(ans, cnt)

print(ans)

N = int(eval(input()))

sixs = [6**i for i in range(1,7)]

nines = [9**i for i in range(1,6)]

tmp = {}

def dfs(n):

  if(n < 6):

    return n

  if(n in tmp):

    return tmp[n]

  m = 10**9+7

  if(n >= 9):

    max_nine = max(nine for nine in nines if nine <= n)

    if(n%max_nine == 0):

      m = min(m, n // max_nine)

    else:

      m = min(m, dfs(n - max_nine) + 1)

  max_six = max(six for six in sixs if six <= n)

  if(n%max_six == 0):

    m = min(m, n // max_six)

  tmp[n] = min(m, dfs(n - max_six) + 1)

  return tmp[n]

print((dfs(N)))

N = int(eval(input()))
ans = 10**9 + 7
for i in range(N + 1):
    j = N - i
    cnt = 0
    while i > 0:
        cnt += i % 6
        i //= 6
    while j > 0:
        cnt += j % 9
        j //= 9
    ans = min(ans, cnt)
print(ans)

N = int(eval(input()))
sixs = [6**i for i in range(1, 7)]
nines = [9**i for i in range(1, 6)]
tmp = {}

def dfs(n):
    if n < 6:
        return n
    if n in tmp:
        return tmp[n]
    m = 10**9 + 7
    if n >= 9:
        max_nine = max(nine for nine in nines if nine <= n)
        if n % max_nine == 0:
            m = min(m, n // max_nine)
        else:
            m = min(m, dfs(n - max_nine) + 1)
    max_six = max(six for six in sixs if six <= n)
    if n % max_six == 0:
        m = min(m, n // max_six)
    tmp[n] = min(m, dfs(n - max_six) + 1)
    return tmp[n]

print((dfs(N)))

+        max_nine = max(nine for nine in nines if nine <= n)

+            m = min(m, dfs(n - max_nine) + 1)

+    max_six = max(six for six in sixs if six <= n)

+    tmp[n] = min(m, dfs(n - max_six) + 1)


Input:
import numpy as np

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

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

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

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

p = np.sort(p)[::-1][:x]

q = np.sort(q)[::-1][:y]

mix = np.hstack((p, q, r))

mix = np.sort(mix)[::-1]

eat = x+y

print((sum(mix[:eat])))

import numpy as np

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

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

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

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

p = np.sort(p)[::-1][:x]

q = np.sort(q)[::-1][:y]

a = np.hstack((p, q, r))

a = np.sort(a)[::-1][:(x+y)]

print((np.sum(a)))

import numpy as np

x, y, a, b, c = list(map(int, input().split()))
p = np.array(list(map(int, input().split())))
q = np.array(list(map(int, input().split())))
r = np.array(list(map(int, input().split())))
p = np.sort(p)[::-1][:x]
q = np.sort(q)[::-1][:y]
mix = np.hstack((p, q, r))
mix = np.sort(mix)[::-1]
eat = x + y
print((sum(mix[:eat])))

import numpy as np

x, y, a, b, c = list(map(int, input().split()))
p = np.array(list(map(int, input().split())))
q = np.array(list(map(int, input().split())))
r = np.array(list(map(int, input().split())))
p = np.sort(p)[::-1][:x]
q = np.sort(q)[::-1][:y]
a = np.hstack((p, q, r))
a = np.sort(a)[::-1][: (x + y)]
print((np.sum(a)))

-mix = np.hstack((p, q, r))
-mix = np.sort(mix)[::-1]
-eat = x + y
-print((sum(mix[:eat])))
+a = np.hstack((p, q, r))
+a = np.sort(a)[::-1][: (x + y)]
+print((np.sum(a)))


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

s=eval(input())

if len(s)>k:

  print((s[:k]+'...'))

else:

  print(s)

k=int(eval(input()))

s=eval(input())

l=len(s)

ans=''

for i in range(k):

  ans+=s[i]

  if i==l-1:

    break

else:

  ans+='...'

print(ans)

k = int(eval(input()))
s = eval(input())
if len(s) > k:
    print((s[:k] + "..."))
else:
    print(s)

k = int(eval(input()))
s = eval(input())
l = len(s)
ans = ""
for i in range(k):
    ans += s[i]
    if i == l - 1:
        break
else:
    ans += "..."
print(ans)

-if len(s) > k:
-    print((s[:k] + "..."))
+l = len(s)
+ans = ""
+for i in range(k):
+    ans += s[i]
+    if i == l - 1:
+        break
-    print(s)
+    ans += "..."
+print(ans)


Input:
from itertools import permutations

from math import sqrt, pow, factorial

n = int(eval(input()))

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

def calc(a,b):

    [x1, y1] = a

    [x2, y2] = b

    return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2))

sum = 0

for i in permutations(list(range(n))):

    distance = 0

    for j in range(1, n):

        distance = calc(xy[i[j]], xy[i[j-1]])

        sum += distance

print((sum/factorial(n)))

import numpy as np

from itertools import combinations

from itertools import permutations

from math import factorial

N = int(eval(input()))

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

cnt = 0

for i in xy:

    for j in xy:

        cnt += np.linalg.norm(i - j)

print((cnt / N))

from itertools import permutations
from math import sqrt, pow, factorial

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

def calc(a, b):
    [x1, y1] = a
    [x2, y2] = b
    return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2))

sum = 0
for i in permutations(list(range(n))):
    distance = 0
    for j in range(1, n):
        distance = calc(xy[i[j]], xy[i[j - 1]])
        sum += distance
print((sum / factorial(n)))

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

-    return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2))

-        distance = calc(xy[i[j]], xy[i[j - 1]])

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


Input:
import numpy as np

n=int(eval(input()))

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

lista=0

for i in range(n):

    lista=lista+1/a[i]

print((1/lista))

import numpy as np

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


Input:
import sys

input = sys.stdin.readline

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

print((x+y//2))

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

print((x+y//2))

import sys

input = sys.stdin.readline
x, y = list(map(int, input().split()))
print((x + y // 2))


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

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

ans = 10**9*N

front = 0

back = sum(a)

for i in range(N-1):

    front += a[i]

    back -= a[i]

    ans = min(ans, abs(front-back))

print(ans)

with open(0) as f:

    N, *a = list(map(int, f.read().split()))

score = -sum(a[1:]) + a[0]

ans = abs(score)

for x in a[1:N-1]:

    score += 2*x

    ans = min(ans, abs(score))

print(ans)

N = int(eval(input()))
a = [int(x) for x in input().split()]
ans = 10**9 * N
front = 0
back = sum(a)
for i in range(N - 1):
    front += a[i]
    back -= a[i]
    ans = min(ans, abs(front - back))
print(ans)

with open(0) as f:
    N, *a = list(map(int, f.read().split()))
score = -sum(a[1:]) + a[0]
ans = abs(score)
for x in a[1 : N - 1]:
    score += 2 * x
    ans = min(ans, abs(score))
print(ans)

+    N, *a = list(map(int, f.read().split()))


Input:
import collections

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

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

B = collections.Counter(A)[min(A)]

print((-(-(N-B)//(K-1))))

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

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

print((-(-(N-1)//(K-1))))

import collections

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = collections.Counter(A)[min(A)]
print((-(-(N - B) // (K - 1))))

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
print((-(-(N - 1) // (K - 1))))

-import collections
-B = collections.Counter(A)[min(A)]
-print((-(-(N - B) // (K - 1))))
+print((-(-(N - 1) // (K - 1))))