Input:
def main():

    from itertools import accumulate

    def Eratosthenes(x: int) -> set:

        from math import sqrt

        sup = int(x)

        primes = {i for i in range(2, sup+1)}

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

            if i in primes:

                mul = 2

                while i*mul <= sup:

                    primes.discard(i*mul)

                    mul += 1

        return primes

    P = Eratosthenes(10**5+5)

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

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

        if i in P and (i+1)//2 in P:

            A[i] += 1

    S = list(accumulate(A))

    Q = int(eval(input()))

    LR = [[int(i) for i in input().split()] for j in range(Q)]

    for le, ri in LR:

        print((S[ri] - S[le-1]))

if __name__ == '__main__':

    main()

def Eratosthenes(x: int) -> set:

    from math import sqrt

    sup = int(x)

    primes = {i for i in range(2, sup+1)}

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

        if i in primes:

            mul = 2

            while i*mul <= sup:

                primes.discard(i*mul)

                mul += 1

    return primes

def main():

    import sys

    input = sys.stdin.buffer.readline

    P = Eratosthenes(10**5+5)

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

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

        if i in P and (i+1)//2 in P:

            A[i] = 1

    from itertools import accumulate

    S = list(accumulate(A))

    Q = int(eval(input()))

    LR = [[int(i) for i in input().split()] for j in range(Q)]

    for le, ri in LR:

        print((S[ri] - S[le-1]))

if __name__ == '__main__':

    main()

def main():
    from itertools import accumulate

    def Eratosthenes(x: int) -> set:
        from math import sqrt

        sup = int(x)
        primes = {i for i in range(2, sup + 1)}
        for i in range(2, int(sqrt(sup + 1)) + 1):
            if i in primes:
                mul = 2
                while i * mul <= sup:
                    primes.discard(i * mul)
                    mul += 1
        return primes

    P = Eratosthenes(10**5 + 5)
    A = [0] * (10**5 + 5)
    for i in range(3, 10**5 + 5):
        if i in P and (i + 1) // 2 in P:
            A[i] += 1
    S = list(accumulate(A))
    Q = int(eval(input()))
    LR = [[int(i) for i in input().split()] for j in range(Q)]
    for le, ri in LR:
        print((S[ri] - S[le - 1]))

if __name__ == "__main__":
    main()

def Eratosthenes(x: int) -> set:
    from math import sqrt

    sup = int(x)
    primes = {i for i in range(2, sup + 1)}
    for i in range(2, int(sqrt(sup + 1)) + 1):
        if i in primes:
            mul = 2
            while i * mul <= sup:
                primes.discard(i * mul)
                mul += 1
    return primes

def main():
    import sys

    input = sys.stdin.buffer.readline
    P = Eratosthenes(10**5 + 5)
    A = [0] * (10**5 + 5)
    for i in range(3, 10**5 + 5):
        if i in P and (i + 1) // 2 in P:
            A[i] = 1
    from itertools import accumulate

    S = list(accumulate(A))
    Q = int(eval(input()))
    LR = [[int(i) for i in input().split()] for j in range(Q)]
    for le, ri in LR:
        print((S[ri] - S[le - 1]))

if __name__ == "__main__":
    main()

+    primes = {i for i in range(2, sup + 1)}

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

+                primes.discard(i * mul)

-        primes = {i for i in range(2, sup + 1)}

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

-                    primes.discard(i * mul)


Input:
import sys

sys.setrecursionlimit(1000000)

def dfs(l,d,k):

  for i in l[k]:

    if d[i[0]]==-1:

      d[i[0]]=d[k]+i[1]

      dfs(l,d,i[0])

n=int(eval(input()))

l=[list(map(int,input().split())) for i in range(n-1)]

connection=[[] for i in range(n)]

for i in range(n-1):

  connection[l[i][0]-1].append([l[i][1]-1,l[i][2]])

  connection[l[i][1]-1].append([l[i][0]-1,l[i][2]])

distance=[-1 for i in range(n)]

x=-1

for i in range(n-1):

  if len(connection[i])==1:

    x=i

    break

distance[x]=0

dfs(connection,distance,x)

for i in range(n):

  print((distance[i]%2))

n=int(eval(input()))

l=[list(map(int,input().split())) for i in range(n-1)]

connection=[[] for i in range(n)]

for i in range(n-1):

  connection[l[i][0]-1].append(l[i][1]-1)

  connection[l[i][1]-1].append(l[i][0]-1)

d={}

for i in range(n-1):

  d[(l[i][0]-1,l[i][1]-1)]=l[i][2]

  d[(l[i][1]-1,l[i][0]-1)]=l[i][2]

def bfs(v):

  distance=[-1]*n

  distance[v]=0

  next=[v]

  next2=set()

  visited=[-1]*n

  visitct=0

  while len(next)!=0 and visitct!=n:

    for i in range(len(next)):

      if visited[next[i]]==-1:

        visited[next[i]]=1

        visitct+=1

        for j in range(len(connection[next[i]])):

          if visited[connection[next[i]][j]]==-1:

            distance[connection[next[i]][j]]=distance[next[i]]+d[(next[i],connection[next[i]][j])]

            next2.add(connection[next[i]][j])

    next=list(next2)

    next2=set()

  return distance

ans=bfs(0)

for i in range(n):

  print((ans[i]%2))

import sys

sys.setrecursionlimit(1000000)

def dfs(l, d, k):
    for i in l[k]:
        if d[i[0]] == -1:
            d[i[0]] = d[k] + i[1]
            dfs(l, d, i[0])

n = int(eval(input()))
l = [list(map(int, input().split())) for i in range(n - 1)]
connection = [[] for i in range(n)]
for i in range(n - 1):
    connection[l[i][0] - 1].append([l[i][1] - 1, l[i][2]])
    connection[l[i][1] - 1].append([l[i][0] - 1, l[i][2]])
distance = [-1 for i in range(n)]
x = -1
for i in range(n - 1):
    if len(connection[i]) == 1:
        x = i
        break
distance[x] = 0
dfs(connection, distance, x)
for i in range(n):
    print((distance[i] % 2))

n = int(eval(input()))
l = [list(map(int, input().split())) for i in range(n - 1)]
connection = [[] for i in range(n)]
for i in range(n - 1):
    connection[l[i][0] - 1].append(l[i][1] - 1)
    connection[l[i][1] - 1].append(l[i][0] - 1)
d = {}
for i in range(n - 1):
    d[(l[i][0] - 1, l[i][1] - 1)] = l[i][2]
    d[(l[i][1] - 1, l[i][0] - 1)] = l[i][2]

def bfs(v):
    distance = [-1] * n
    distance[v] = 0
    next = [v]
    next2 = set()
    visited = [-1] * n
    visitct = 0
    while len(next) != 0 and visitct != n:
        for i in range(len(next)):
            if visited[next[i]] == -1:
                visited[next[i]] = 1
                visitct += 1
                for j in range(len(connection[next[i]])):
                    if visited[connection[next[i]][j]] == -1:
                        distance[connection[next[i]][j]] = (
                            distance[next[i]] + d[(next[i], connection[next[i]][j])]
                        )
                        next2.add(connection[next[i]][j])
        next = list(next2)
        next2 = set()
    return distance

ans = bfs(0)
for i in range(n):
    print((ans[i] % 2))

+    connection[l[i][0] - 1].append(l[i][1] - 1)

+    connection[l[i][1] - 1].append(l[i][0] - 1)

+    while len(next) != 0 and visitct != n:

+                for j in range(len(connection[next[i]])):

+                    if visited[connection[next[i]][j]] == -1:

+                        distance[connection[next[i]][j]] = (

+                            distance[next[i]] + d[(next[i], connection[next[i]][j])]

+                        next2.add(connection[next[i]][j])


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

r=0

for i in range(n+1):

    if a<=sum([int(j) for j in str(i)])<=b:

        r+=i

print(r)

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

s=0

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

    k=0

    m=i

    while m>0:

        k+=m%10

        m=m//10

    if a<=k<=b:

        s+=i

print(s)

n, a, b = list(map(int, input().split()))
r = 0
for i in range(n + 1):
    if a <= sum([int(j) for j in str(i)]) <= b:
        r += i
print(r)

n, a, b = list(map(int, input().split()))
s = 0
for i in range(1, n + 1):
    k = 0
    m = i
    while m > 0:
        k += m % 10
        m = m // 10
    if a <= k <= b:
        s += i
print(s)

-    if a <= sum([int(j) for j in str(i)]) <= b:


Input:
eval(input())

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

lst.sort()

print((lst[-1]-lst[0]))

eval(input())

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

print((lst[-1]-lst[0]))

eval(input())
lst = list(map(int, input().split()))
lst.sort()
print((lst[-1] - lst[0]))

eval(input())
lst = sorted(list(map(int, input().split())))
print((lst[-1] - lst[0]))

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


Input:
from fractions import Fraction

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

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

cnt=0

for i in a:

	if (sum(a))*(Fraction(1,4*m))<=i:

		cnt+=1

		if cnt==m:

			print("Yes")

if cnt<m:

	print("No")

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

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

cnt=0

for i in a:

	if (sum(a)/(4*m))<=i:

		cnt+=1

		if cnt==m:

			print("Yes")

if cnt<m:

	print("No")

from fractions import Fraction

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
cnt = 0
for i in a:
    if (sum(a)) * (Fraction(1, 4 * m)) <= i:
        cnt += 1
        if cnt == m:
            print("Yes")
if cnt < m:
    print("No")

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
cnt = 0
for i in a:
    if (sum(a) / (4 * m)) <= i:
        cnt += 1
        if cnt == m:
            print("Yes")
if cnt < m:
    print("No")


-print(int(input()) ** 2)
+r = int(input())
+print(r * r)


Input:
from sys import stdin

import sys

import numpy as np

import collections

from functools import cmp_to_key

import heapq

##  input functions for me

def rsa(sep = ''):

    if sep == '' :

        return input().split()

    else: return input().split(sep)

def rip(sep = ''):

    if sep == '' :

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

    else: return list(map(int, input().split(sep)))

def ria(sep = ''):

    return list(rip(sep))

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

def rd(): return float(eval(input()))

def rs(): return eval(input())

##

def inv(v, mod):

    return pow(v, mod-2, mod)

def main():

    r1, c1, r2, c2 = rip()

    MM = int(2e6+10)

    fact = [0] * MM

    finv = [0] * MM

    fact[0] = 1

    finv[0] = 1

    mod = int(1e9) + 7

    for i in range(1,MM): fact[i] = (fact[i-1] * i % mod)

    finv[MM-1] = inv(fact[MM-1], mod)

    for i in reversed(list(range(1,MM-1))):

        finv[i] = finv[i + 1] * (i + 1) % mod

    def sum_naive(r, c):

        #[0, r) * [0, c)

        ret = 0

        for i in range(r):

            ret += fact[i + 1 + c - 1] * finv[i + 1] * finv[c - 1] % mod

        return ret

    def sum(r, c):

        #[0, r) * [0, c)

        ret = fact[r + c] * finv[r] * finv[c] % mod

        ret += -1 + mod

        ret %= mod

        return ret

    ans = 0

    ans += sum(r2 + 1, c2 + 1)

    ans -= sum(r2 + 1, c1)

    ans -= sum(r1, c2 + 1)

    ans += sum(r1, c1)

    ans %= mod

    print(ans)

if __name__ == "__main__":

    main()

from sys import stdin

import sys

import numpy as np

import collections

from functools import cmp_to_key

import heapq

##  input functions for me

def rsa(sep = ''):

    if sep == '' :

        return input().split()

    else: return input().split(sep)

def rip(sep = ''):

    if sep == '' :

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

    else: return list(map(int, input().split(sep)))

def ria(sep = ''):

    return list(rip(sep))

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

def rd(): return float(eval(input()))

def rs(): return eval(input())

##

def inv(v, mod):

    return pow(v, mod-2, mod)

def main():

    r1, c1, r2, c2 = rip()

    MM = int(2e6+10)

    fact = [0] * MM

    finv = [0] * MM

    fact[0] = 1

    finv[0] = 1

    mod = int(1e9) + 7

    for i in range(1,MM): fact[i] = (fact[i-1] * i % mod)

    '''

    finv[MM-1] = inv(fact[MM-1], mod)

    for i in reversed(range(1,MM-1)):

        finv[i] = finv[i + 1] * (i + 1) % mod

    def sum_naive(r, c):

        #[0, r) * [0, c)

        ret = 0

        for i in range(r):

            ret += fact[i + 1 + c - 1] * finv[i + 1] * finv[c - 1] % mod

        return ret

    def sum(r, c):

        #[0, r) * [0, c)

        ret = fact[r + c] * finv[r] * finv[c] % mod

        ret += -1 + mod

        ret %= mod

        return ret

    '''

    def sum(r, c):

        #[0, r) * [0, c)

        ret = fact[r + c] * inv(fact[r], mod) * inv(fact[c], mod) % mod

        ret += -1 + mod

        ret %= mod

        return ret

    ans = 0

    ans += sum(r2 + 1, c2 + 1)

    ans -= sum(r2 + 1, c1)

    ans -= sum(r1, c2 + 1)

    ans += sum(r1, c1)

    ans %= mod

    print(ans)

if __name__ == "__main__":

    main()

from sys import stdin
import sys
import numpy as np
import collections
from functools import cmp_to_key
import heapq

##  input functions for me
def rsa(sep=""):
    if sep == "":
        return input().split()
    else:
        return input().split(sep)

def rip(sep=""):
    if sep == "":
        return list(map(int, input().split()))
    else:
        return list(map(int, input().split(sep)))

def ria(sep=""):
    return list(rip(sep))

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

def rd():
    return float(eval(input()))

def rs():
    return eval(input())

##
def inv(v, mod):
    return pow(v, mod - 2, mod)

def main():
    r1, c1, r2, c2 = rip()
    MM = int(2e6 + 10)
    fact = [0] * MM
    finv = [0] * MM
    fact[0] = 1
    finv[0] = 1
    mod = int(1e9) + 7
    for i in range(1, MM):
        fact[i] = fact[i - 1] * i % mod
    finv[MM - 1] = inv(fact[MM - 1], mod)
    for i in reversed(list(range(1, MM - 1))):
        finv[i] = finv[i + 1] * (i + 1) % mod

    def sum_naive(r, c):
        # [0, r) * [0, c)
        ret = 0
        for i in range(r):
            ret += fact[i + 1 + c - 1] * finv[i + 1] * finv[c - 1] % mod
        return ret

    def sum(r, c):
        # [0, r) * [0, c)
        ret = fact[r + c] * finv[r] * finv[c] % mod
        ret += -1 + mod
        ret %= mod
        return ret

    ans = 0
    ans += sum(r2 + 1, c2 + 1)
    ans -= sum(r2 + 1, c1)
    ans -= sum(r1, c2 + 1)
    ans += sum(r1, c1)
    ans %= mod
    print(ans)

if __name__ == "__main__":
    main()

from sys import stdin
import sys
import numpy as np
import collections
from functools import cmp_to_key
import heapq

##  input functions for me
def rsa(sep=""):
    if sep == "":
        return input().split()
    else:
        return input().split(sep)

def rip(sep=""):
    if sep == "":
        return list(map(int, input().split()))
    else:
        return list(map(int, input().split(sep)))

def ria(sep=""):
    return list(rip(sep))

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

def rd():
    return float(eval(input()))

def rs():
    return eval(input())

##
def inv(v, mod):
    return pow(v, mod - 2, mod)

def main():
    r1, c1, r2, c2 = rip()
    MM = int(2e6 + 10)
    fact = [0] * MM
    finv = [0] * MM
    fact[0] = 1
    finv[0] = 1
    mod = int(1e9) + 7
    for i in range(1, MM):
        fact[i] = fact[i - 1] * i % mod
    """
    finv[MM-1] = inv(fact[MM-1], mod)
    for i in reversed(range(1,MM-1)):
        finv[i] = finv[i + 1] * (i + 1) % mod
    def sum_naive(r, c):
        #[0, r) * [0, c)
        ret = 0
        for i in range(r):
            ret += fact[i + 1 + c - 1] * finv[i + 1] * finv[c - 1] % mod
        return ret
    def sum(r, c):
        #[0, r) * [0, c)
        ret = fact[r + c] * finv[r] * finv[c] % mod
        ret += -1 + mod
        ret %= mod
        return ret
    """

    def sum(r, c):
        # [0, r) * [0, c)
        ret = fact[r + c] * inv(fact[r], mod) * inv(fact[c], mod) % mod
        ret += -1 + mod
        ret %= mod
        return ret

    ans = 0
    ans += sum(r2 + 1, c2 + 1)
    ans -= sum(r2 + 1, c1)
    ans -= sum(r1, c2 + 1)
    ans += sum(r1, c1)
    ans %= mod
    print(ans)

if __name__ == "__main__":
    main()

-    finv[MM - 1] = inv(fact[MM - 1], mod)

-    for i in reversed(list(range(1, MM - 1))):

+        ret = fact[r + c] * finv[r] * finv[c] % mod

-        ret = fact[r + c] * finv[r] * finv[c] % mod

+        ret = fact[r + c] * inv(fact[r], mod) * inv(fact[c], mod) % mod


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

A = sorted(int(a) - i for i, a in enumerate(input().split(), 1))

if N % 2:

    median = A[N // 2]

    print((sum(abs(a - median) for a in A)))

else:

    median1 = A[N // 2 - 1]

    median2 = A[N // 2]

    print((min(sum(abs(a - median1) for a in A), sum(abs(a - median2) for a in A))))

N = int(eval(input()))

A = sorted(int(a) - i for i, a in enumerate(input().split(), 1))

median = A[N // 2]

print((sum(abs(a - median) for a in A)))

-    print((sum(abs(a - median) for a in A)))

-    print((min(sum(abs(a - median1) for a in A), sum(abs(a - median2) for a in A))))

+print((sum(abs(a - median) for a in A)))


Input:
from operator import mul

from functools import reduce

def cmb(n,r):

    r = min(n-r,r)

    if r == 0: return 1

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

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

    return over // under

N = int(eval(input()))

K = int(eval(input()))

L = len(str(N))

S = str(N)

if K>L:

  print((0))

  import sys

  sys.exit()

if K==1:

  s = ['0']*L

  cnt = 0

  for i in range(L):

    for j in range(1,10):

      s[i] = str(j)

      x = ''.join(s)

      x = int(x)

      if x<=N:

        cnt += 1

      s[i] = '0'

elif K==2:

  s = ['0']*L

  cnt = 0

  for i in range(L-1):

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

      for a in range(1,10):

        for b in range(1,10):

          s[i] = str(a)

          s[j] = str(b)

          x = ''.join(s)

          x = int(x)

          if x<=N:

            cnt += 1

          s[i] = '0'

          s[j] = '0'

else:

  s = ['0']*L

  cnt = 0

  cnt += cmb(L-1,3)*(9**3) if L>3 else 0

  g = int(S[0])

  s[0] = S[0]

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

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

      for a in range(1,10):

        for b in range(1,10):

          s[j] = str(a)

          s[i] = str(b)

          x = ''.join(s)

          x = int(x)

#          print(x)

          if x<=N:

            cnt += g

          else:

            cnt += g-1

          s[i] = '0'

          s[j] = '0'

print(cnt)

from functools import lru_cache

N = int(eval(input()))

K = int(eval(input()))

@lru_cache(None)

def F(N,K):

  assert N>=0

  if N<10:

    if K==0:

      return 1

    if K==1:

      return N

    return 0

  q,r = divmod(N,10)

  ret = 0

  if K>=1:

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

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

  ret += F(q,K)

  return ret

print((F(N,K)))

from operator import mul
from functools import reduce

def cmb(n, r):
    r = min(n - r, r)
    if r == 0:
        return 1
    over = reduce(mul, list(range(n, n - r, -1)))
    under = reduce(mul, list(range(1, r + 1)))
    return over // under

N = int(eval(input()))
K = int(eval(input()))
L = len(str(N))
S = str(N)
if K > L:
    print((0))
    import sys

    sys.exit()
if K == 1:
    s = ["0"] * L
    cnt = 0
    for i in range(L):
        for j in range(1, 10):
            s[i] = str(j)
            x = "".join(s)
            x = int(x)
            if x <= N:
                cnt += 1
            s[i] = "0"
elif K == 2:
    s = ["0"] * L
    cnt = 0
    for i in range(L - 1):
        for j in range(i + 1, L):
            for a in range(1, 10):
                for b in range(1, 10):
                    s[i] = str(a)
                    s[j] = str(b)
                    x = "".join(s)
                    x = int(x)
                    if x <= N:
                        cnt += 1
                    s[i] = "0"
                    s[j] = "0"
else:
    s = ["0"] * L
    cnt = 0
    cnt += cmb(L - 1, 3) * (9**3) if L > 3 else 0
    g = int(S[0])
    s[0] = S[0]
    for i in range(1, L - 1):
        for j in range(i + 1, L):
            for a in range(1, 10):
                for b in range(1, 10):
                    s[j] = str(a)
                    s[i] = str(b)
                    x = "".join(s)
                    x = int(x)
                    #          print(x)
                    if x <= N:
                        cnt += g
                    else:
                        cnt += g - 1
                    s[i] = "0"
                    s[j] = "0"
print(cnt)

from functools import lru_cache

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

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

print((F(N, K)))

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

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

-                    #          print(x)


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

N = int(eval(input()))

A, B, C = [0]*N, [0]*N, [0]*N

for i in range(N):

    A[i], B[i], C[i] = inpl()

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

DP[0] = [A[0], B[0], C[0]]

for i in range(1, N):

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

    DP[i][1] = max(DP[i-1][0] + B[i], DP[i-1][2] + B[i])

    DP[i][2] = max(DP[i-1][0] + C[i], DP[i-1][1] + C[i])

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

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

N = int(eval(input()))

sa, sb, sc = 0, 0, 0

for i in range(N):

    a, b, c = inpl()

    sa, sb, sc = max(sb+a, sc+a), max(sa+b, sc+b), max(sa+c, sb+c)

print((max(sa, sb, sc)))

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

N = int(eval(input()))
sa, sb, sc = 0, 0, 0
for i in range(N):
    a, b, c = inpl()
    sa, sb, sc = max(sb + a, sc + a), max(sa + b, sc + b), max(sa + c, sb + c)
print((max(sa, sb, sc)))

+    sa, sb, sc = max(sb + a, sc + a), max(sa + b, sc + b), max(sa + c, sb + c)


Input:
import sys

def solve():

    input = sys.stdin.readline

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

    P = 0

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

        coins = 0

        k = i

        while k < K:

            coins += 1

            k *= 2

        P += pow(0.5, coins) / N

    print(P)

    return 0

if __name__ == "__main__":

    solve()

import sys

def solve():

    input = sys.stdin.readline

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

    possible = 0

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

        this_poss = 1

        if i < K:

            t = i

            while t < K:

                this_poss *= 0.5

                t *= 2

        possible += this_poss / N

    print(possible)

    return 0

if __name__ == "__main__":

    solve()

-    P = 0
+    possible = 0
-        coins = 0
-        k = i
-        while k < K:
-            coins += 1
-            k *= 2
-        P += pow(0.5, coins) / N
-    print(P)
+        this_poss = 1
+        if i < K:
+            t = i
+            while t < K:
+                this_poss *= 0.5
+                t *= 2
+        possible += this_poss / N
+    print(possible)


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

print(((A+B)//2 if (A+B)&1==0 else 'IMPOSSIBLE'))

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

if A > B: A, B = B, A

if (B - A) & 1:

    print('IMPOSSIBLE')

    exit()

print((A + (B - A) // 2))

A, B = list(map(int, input().split()))
print(((A + B) // 2 if (A + B) & 1 == 0 else "IMPOSSIBLE"))

A, B = list(map(int, input().split()))
if A > B:
    A, B = B, A
if (B - A) & 1:
    print("IMPOSSIBLE")
    exit()
print((A + (B - A) // 2))

-print(((A + B) // 2 if (A + B) & 1 == 0 else "IMPOSSIBLE"))


Input:
from bisect import bisect_left, bisect

def sieve_of_eratosthenes_2017(N):

    numbers = [n & 1 for n in range(N + 1)]

    numbers[1] = 0

    numbers[2] = 1

    like2017 = []

    p = 1

    while True:

        while not numbers[p]:

            p += 2

        if p * p > N:

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

                if numbers[i] & numbers[(i + 1) >> 1]:

                    like2017.append(i)

            return like2017

        if numbers[(p + 1) >> 1]:

            like2017.append(p)

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

            numbers[i] = 0

        p += 2

like2017 = sieve_of_eratosthenes_2017(10 ** 5)

Q = int(eval(input()))

for _ in range(Q):

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

    lindex = bisect_left(like2017, l)

    rindex = bisect(like2017, r)

    print((rindex - lindex))

from itertools import accumulate

def sieve_of_eratosthenes_2017(N):

    numbers = [n & 1 for n in range(N + 1)]

    numbers[1] = 0

    numbers[2] = 1

    like2017 = [0] * (N + 1)

    p = 1

    while True:

        while not numbers[p]:

            p += 2

        if p * p > N:

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

                if numbers[i] & numbers[(i + 1) >> 1]:

                    like2017[i] = 1

            return like2017

        if numbers[(p + 1) >> 1]:

            like2017[p] = 1

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

            numbers[i] = 0

        p += 2

like2017 = sieve_of_eratosthenes_2017(10 ** 5)

like2017_sum = list(accumulate(like2017))

Q = int(eval(input()))

for _ in range(Q):

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

    print((like2017_sum[r] - like2017_sum[l] + like2017[l]))

from bisect import bisect_left, bisect

def sieve_of_eratosthenes_2017(N):
    numbers = [n & 1 for n in range(N + 1)]
    numbers[1] = 0
    numbers[2] = 1
    like2017 = []
    p = 1
    while True:
        while not numbers[p]:
            p += 2
        if p * p > N:
            for i in range(p, N + 1, 2):
                if numbers[i] & numbers[(i + 1) >> 1]:
                    like2017.append(i)
            return like2017
        if numbers[(p + 1) >> 1]:
            like2017.append(p)
        for i in range(p * 2, N + 1, p):
            numbers[i] = 0
        p += 2

like2017 = sieve_of_eratosthenes_2017(10**5)
Q = int(eval(input()))
for _ in range(Q):
    l, r = list(map(int, input().split()))
    lindex = bisect_left(like2017, l)
    rindex = bisect(like2017, r)
    print((rindex - lindex))

from itertools import accumulate

def sieve_of_eratosthenes_2017(N):
    numbers = [n & 1 for n in range(N + 1)]
    numbers[1] = 0
    numbers[2] = 1
    like2017 = [0] * (N + 1)
    p = 1
    while True:
        while not numbers[p]:
            p += 2
        if p * p > N:
            for i in range(p, N + 1, 2):
                if numbers[i] & numbers[(i + 1) >> 1]:
                    like2017[i] = 1
            return like2017
        if numbers[(p + 1) >> 1]:
            like2017[p] = 1
        for i in range(p * 2, N + 1, p):
            numbers[i] = 0
        p += 2

like2017 = sieve_of_eratosthenes_2017(10**5)
like2017_sum = list(accumulate(like2017))
Q = int(eval(input()))
for _ in range(Q):
    l, r = list(map(int, input().split()))
    print((like2017_sum[r] - like2017_sum[l] + like2017[l]))


Input:
#!/usr/bin/env python3

#ABC110 C

s = list(eval(input()))

t = list(eval(input()))

if len(set(s)) != len(set(t)):

    print('No')

    quit()

dif = {}

for x,y in zip(s,t):

    if x not in dif:

        dif[x] = y

    elif dif[x] != y:

        print('No')

        quit()

print('Yes')

#!/usr/bin/env python3

import sys

import math

from bisect import bisect_right as br

from bisect import bisect_left as bl

sys.setrecursionlimit(2147483647)

from heapq import heappush, heappop,heappushpop

from collections import defaultdict

from itertools import accumulate

from collections import Counter

from collections import deque

from operator import itemgetter

from itertools import permutations

mod = 10**9 + 7

inf = float('inf')

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

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

s = eval(input())

t = eval(input())

if len(list(Counter(s).values())) != len(list(Counter(t).values())):

    print('No')

    quit()

n = len(s)

S = [-1]*26

for i in range(n):

    sidx = ord(s[i]) - ord("a")

    tidx = ord(t[i]) - ord("a")

    if S[tidx] < 0:

        S[tidx] = sidx

    else:

        if S[tidx] != sidx:

            print('No')

            quit()

print('Yes')

#!/usr/bin/env python3
# ABC110 C
s = list(eval(input()))
t = list(eval(input()))
if len(set(s)) != len(set(t)):
    print("No")
    quit()
dif = {}
for x, y in zip(s, t):
    if x not in dif:
        dif[x] = y
    elif dif[x] != y:
        print("No")
        quit()
print("Yes")

#!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl

sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop, heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations

mod = 10**9 + 7
inf = float("inf")

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

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

s = eval(input())
t = eval(input())
if len(list(Counter(s).values())) != len(list(Counter(t).values())):
    print("No")
    quit()
n = len(s)
S = [-1] * 26
for i in range(n):
    sidx = ord(s[i]) - ord("a")
    tidx = ord(t[i]) - ord("a")
    if S[tidx] < 0:
        S[tidx] = sidx
    else:
        if S[tidx] != sidx:
            print("No")
            quit()
print("Yes")

+from heapq import heappush, heappop, heappushpop

+    return list(map(int, sys.stdin.readline().split()))

+if len(list(Counter(s).values())) != len(list(Counter(t).values())):


Input:
import queue

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

p=queue.PriorityQueue()

s=[0]*-~n

for _ in[0]*q:

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

 s[a]+=v;p.put((-s[a],a))

 while 1:

  t=p.get()

  if -t[0]==s[t[1]]:print((t[1],-t[0]));p.put(t);break

import sys

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

s=[0]*-~n

w=m=0

for e in sys.stdin:

 a,v=list(map(int,e.split()))

 s[a]+=v

 if v<0 and a==w:m=max(s);w=s.index(m)

 elif s[a]>m:w,m=a,s[a]

 elif s[a]==m:w=min(w,a)

 print((w,m))

import queue

n, q = list(map(int, input().split()))
p = queue.PriorityQueue()
s = [0] * -~n
for _ in [0] * q:
    a, v = list(map(int, input().split()))
    s[a] += v
    p.put((-s[a], a))
    while 1:
        t = p.get()
        if -t[0] == s[t[1]]:
            print((t[1], -t[0]))
            p.put(t)
            break

import sys

n, q = list(map(int, input().split()))
s = [0] * -~n
w = m = 0
for e in sys.stdin:
    a, v = list(map(int, e.split()))
    s[a] += v
    if v < 0 and a == w:
        m = max(s)
        w = s.index(m)
    elif s[a] > m:
        w, m = a, s[a]
    elif s[a] == m:
        w = min(w, a)
    print((w, m))

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


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

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

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

for i in range(1, n):

    a1[i] += a1[i - 1]

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

    a2[i] += a2[i + 1]

res = 0

for i in range(n):

    tmp = a1[i] + a2[i]

    res = max(tmp, res)

print(res)

n = int(eval(input()))

dp = [[0 for i in range(n)] for i in range(2)]

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

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

dp[0][0] = a1[0]

for i in range(1, n):

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

dp[1][0] = dp[0][0] + a2[0]

for i in range(1, n):

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

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

+dp = [[0 for i in range(n)] for i in range(2)]


Input:
from fractions import gcd

from functools import reduce

N = int(eval(input()))

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

my_gcd = reduce(gcd, A)

A = [a // my_gcd for a in A]

flag = False

my_gcd_2 = 0

my_gcd_3 = 0

def make_divisors(n):

    divisors = []

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

        if n % i == 0:

            divisors.append(i)

            if i != n // i:

                divisors.append(n//i)

    return divisors

for i in range(N):

    a = A[i]

    if my_gcd_2 == 0:

        my_gcd_2 = a

    else:

        if gcd(my_gcd_2, a) == 1:

            if flag is False:

                if i == 1:

                    my_gcd_3 = a

                else:

                    divisors = make_divisors(a)

                    for d in divisors[::-1]:

                        if len([j for j in A[:i] if j % d]) == 1:

                            my_gcd_3 = d

                            break

                flag = True

                continue

            else:

                my_gcd_2 = -1

        if my_gcd_3 and gcd(my_gcd_3, a) == 1:

            my_gcd_3 = -1

        if my_gcd_2:

            my_gcd_2 = gcd(my_gcd_2, a)

        if my_gcd_3:

            my_gcd_3 = gcd(my_gcd_3, a)

else:

    ans_1 = my_gcd * my_gcd_2

    ans_2 = my_gcd * my_gcd_3

    print((max(ans_1, ans_2, my_gcd)))

from fractions import gcd

N = int(eval(input()))

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

gcd_from_left = [0] * (N + 1)

gcd_from_right = [0] * (N + 1)

gcd_from_left[1] = A[0]

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

    gcd_from_left[i] = gcd(A[i - 1], gcd_from_left[i - 1])

A = A[::-1]

gcd_from_right[1] = A[0]

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

    gcd_from_right[i] = gcd(A[i - 1], gcd_from_right[i - 1])

ans = 0

for i in range(1, N + 1): # 抜かすやつのindex

    if i == 1:

        ans = max(ans, gcd_from_right[N - i])

    elif i == N:

        ans = max(ans, gcd_from_left[i - 1])

    else:

        ans = max(ans, gcd(gcd_from_left[i - 1], gcd_from_right[N - i]))

print(ans)

from fractions import gcd
from functools import reduce

N = int(eval(input()))
A = list(map(int, input().split()))
my_gcd = reduce(gcd, A)
A = [a // my_gcd for a in A]
flag = False
my_gcd_2 = 0
my_gcd_3 = 0

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    return divisors

for i in range(N):
    a = A[i]
    if my_gcd_2 == 0:
        my_gcd_2 = a
    else:
        if gcd(my_gcd_2, a) == 1:
            if flag is False:
                if i == 1:
                    my_gcd_3 = a
                else:
                    divisors = make_divisors(a)
                    for d in divisors[::-1]:
                        if len([j for j in A[:i] if j % d]) == 1:
                            my_gcd_3 = d
                            break
                flag = True
                continue
            else:
                my_gcd_2 = -1
        if my_gcd_3 and gcd(my_gcd_3, a) == 1:
            my_gcd_3 = -1
        if my_gcd_2:
            my_gcd_2 = gcd(my_gcd_2, a)
        if my_gcd_3:
            my_gcd_3 = gcd(my_gcd_3, a)
else:
    ans_1 = my_gcd * my_gcd_2
    ans_2 = my_gcd * my_gcd_3
    print((max(ans_1, ans_2, my_gcd)))

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

-                divisors.append(n // i)

+    gcd_from_left[i] = gcd(A[i - 1], gcd_from_left[i - 1])

+    gcd_from_right[i] = gcd(A[i - 1], gcd_from_right[i - 1])

+for i in range(1, N + 1):  # 抜かすやつのindex

+        ans = max(ans, gcd_from_right[N - i])

+        ans = max(ans, gcd_from_left[i - 1])

-                    divisors = make_divisors(a)

-                    for d in divisors[::-1]:

-                        if len([j for j in A[:i] if j % d]) == 1:

-                            my_gcd_3 = d

-        if my_gcd_3 and gcd(my_gcd_3, a) == 1:

-            my_gcd_2 = gcd(my_gcd_2, a)

-            my_gcd_3 = gcd(my_gcd_3, a)

+        ans = max(ans, gcd(gcd_from_left[i - 1], gcd_from_right[N - i]))


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

ans=0

aend=0

bstart=0

aendbstart=0

for i in range(n):

  s=eval(input())

  ans+=s.count("AB")

  if s[0]=="B" and s[-1]=="A":

    aendbstart+=1

  elif s[0]=="B":

    bstart+=1

  elif s[-1]=="A":

    aend+=1

anow=False

if aend>0:

  aend-=1

  anow=True

elif aendbstart>0:

  aendbstart-=1

  anow=True

if anow:

  ans+=aendbstart

if anow and bstart>0:

  bstart-=1

  ans+=1

  anow=False

if aend>0 and bstart>0:

  ans+=min(aend,bstart)

print(ans)

# (1)ABが含まれる個数・・・まず単純にカウント

# (2)Aで終わるけどBで始まらないものの個数

# (3)Bで始まるものAで終わらないもののの個数

# (4)Bで始まってAで終わるものの個数 の個数 - 1

# (4)が1以上ある場合、(2),(3)を一つずつ使うことでそれぞれ+1

# それでも(2)(3)のペアが作れればペアごとに+1

import sys

readline = sys.stdin.readline

N = int(readline())

ans = 0

a_end = 0

b_start = 0

a_end_b_start = 0

for i in range(N):

  s = readline().rstrip()

  ans += s.count("AB")

  if s[-1] == "A" and s[0] == "B":

    a_end_b_start += 1

  elif s[-1] == "A":

    a_end += 1

  elif s[0] == "B":

    b_start += 1

if a_end_b_start > 0:

  ans += a_end_b_start - 1

  if a_end > 0:

    a_end -= 1

    ans += 1

  if b_start > 0:

    b_start -= 1

    ans += 1

ans += min(a_end,b_start)

print(ans)

n = int(eval(input()))
ans = 0
aend = 0
bstart = 0
aendbstart = 0
for i in range(n):
    s = eval(input())
    ans += s.count("AB")
    if s[0] == "B" and s[-1] == "A":
        aendbstart += 1
    elif s[0] == "B":
        bstart += 1
    elif s[-1] == "A":
        aend += 1
anow = False
if aend > 0:
    aend -= 1
    anow = True
elif aendbstart > 0:
    aendbstart -= 1
    anow = True
if anow:
    ans += aendbstart
if anow and bstart > 0:
    bstart -= 1
    ans += 1
    anow = False
if aend > 0 and bstart > 0:
    ans += min(aend, bstart)
print(ans)

# (1)ABが含まれる個数・・・まず単純にカウント
# (2)Aで終わるけどBで始まらないものの個数
# (3)Bで始まるものAで終わらないもののの個数
# (4)Bで始まってAで終わるものの個数 の個数 - 1
# (4)が1以上ある場合、(2),(3)を一つずつ使うことでそれぞれ+1
# それでも(2)(3)のペアが作れればペアごとに+1
import sys

readline = sys.stdin.readline
N = int(readline())
ans = 0
a_end = 0
b_start = 0
a_end_b_start = 0
for i in range(N):
    s = readline().rstrip()
    ans += s.count("AB")
    if s[-1] == "A" and s[0] == "B":
        a_end_b_start += 1
    elif s[-1] == "A":
        a_end += 1
    elif s[0] == "B":
        b_start += 1
if a_end_b_start > 0:
    ans += a_end_b_start - 1
    if a_end > 0:
        a_end -= 1
        ans += 1
    if b_start > 0:
        b_start -= 1
        ans += 1
ans += min(a_end, b_start)
print(ans)

-n = int(eval(input()))
+# (1)ABが含まれる個数・・・まず単純にカウント
+# (2)Aで終わるけどBで始まらないものの個数
+# (3)Bで始まるものAで終わらないもののの個数
+# (4)Bで始まってAで終わるものの個数 の個数 - 1
+# (4)が1以上ある場合、(2),(3)を一つずつ使うことでそれぞれ+1
+# それでも(2)(3)のペアが作れればペアごとに+1
+import sys
+
+readline = sys.stdin.readline
+N = int(readline())
-aend = 0
-bstart = 0
-aendbstart = 0
-for i in range(n):
-    s = eval(input())
+a_end = 0
+b_start = 0
+a_end_b_start = 0
+for i in range(N):
+    s = readline().rstrip()
-    if s[0] == "B" and s[-1] == "A":
-        aendbstart += 1
+    if s[-1] == "A" and s[0] == "B":
+        a_end_b_start += 1
+    elif s[-1] == "A":
+        a_end += 1
-        bstart += 1
-    elif s[-1] == "A":
-        aend += 1
-anow = False
-if aend > 0:
-    aend -= 1
-    anow = True
-elif aendbstart > 0:
-    aendbstart -= 1
-    anow = True
-if anow:
-    ans += aendbstart
-if anow and bstart > 0:
-    bstart -= 1
-    ans += 1
-    anow = False
-if aend > 0 and bstart > 0:
-    ans += min(aend, bstart)
+        b_start += 1
+if a_end_b_start > 0:
+    ans += a_end_b_start - 1
+    if a_end > 0:
+        a_end -= 1
+        ans += 1
+    if b_start > 0:
+        b_start -= 1
+        ans += 1
+ans += min(a_end, b_start)


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

D = int(eval(input()))

MOD = 10**9 + 7

dp = [[[0]*(int(len(str(K)))+1) for _ in range(D)] for _ in range(2)]

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

for digit in range(int(len(str(K)))):

    for smaller_flg in [0,1]:

        lim = 9 if smaller_flg else int(str(K)[digit])

        for digit_num in range(lim+1):

            new_smaller_flg = smaller_flg or digit_num < lim

            for mod_d in range(D):

                new_mod_d = (mod_d + digit_num)%D

                dp[new_smaller_flg][new_mod_d][digit+1] += dp[smaller_flg][mod_d][digit]

                dp[new_smaller_flg][new_mod_d][digit+1] %= MOD

print(((dp[1][0][int(len(str(K)))] + dp[0][0][int(len(str(K)))] - 1) % MOD))

K = int(eval(input()))

D = int(eval(input()))

MOD = 10**9 + 7

dp = [[[0]*D for _ in range(2)] for _ in range(int(len(str(K)))+1)]

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

# 外側の要素から外側のループに置くと参照が速くなる

for digit in range(int(len(str(K)))):

    for smaller_flg in [0,1]:

        lim = 9 if smaller_flg else int(str(K)[digit])

        for digit_num in range(lim+1):

            new_smaller_flg = smaller_flg or digit_num < lim

            for mod_d in range(D):

                new_mod_d = (mod_d + digit_num)%D

                dp[digit+1][new_smaller_flg][new_mod_d] += dp[digit][smaller_flg][mod_d]

                dp[digit+1][new_smaller_flg][new_mod_d] %= MOD

print(((dp[int(len(str(K)))][1][0] + dp[int(len(str(K)))][0][0] - 1) % MOD))

K = int(eval(input()))
D = int(eval(input()))
MOD = 10**9 + 7
dp = [[[0] * (int(len(str(K))) + 1) for _ in range(D)] for _ in range(2)]
dp[0][0][0] = 1
for digit in range(int(len(str(K)))):
    for smaller_flg in [0, 1]:
        lim = 9 if smaller_flg else int(str(K)[digit])
        for digit_num in range(lim + 1):
            new_smaller_flg = smaller_flg or digit_num < lim
            for mod_d in range(D):
                new_mod_d = (mod_d + digit_num) % D
                dp[new_smaller_flg][new_mod_d][digit + 1] += dp[smaller_flg][mod_d][
                    digit
                ]
                dp[new_smaller_flg][new_mod_d][digit + 1] %= MOD
print(((dp[1][0][int(len(str(K)))] + dp[0][0][int(len(str(K)))] - 1) % MOD))

K = int(eval(input()))
D = int(eval(input()))
MOD = 10**9 + 7
dp = [[[0] * D for _ in range(2)] for _ in range(int(len(str(K))) + 1)]
dp[0][0][0] = 1
# 外側の要素から外側のループに置くと参照が速くなる
for digit in range(int(len(str(K)))):
    for smaller_flg in [0, 1]:
        lim = 9 if smaller_flg else int(str(K)[digit])
        for digit_num in range(lim + 1):
            new_smaller_flg = smaller_flg or digit_num < lim
            for mod_d in range(D):
                new_mod_d = (mod_d + digit_num) % D
                dp[digit + 1][new_smaller_flg][new_mod_d] += dp[digit][smaller_flg][
                    mod_d
                ]
                dp[digit + 1][new_smaller_flg][new_mod_d] %= MOD
print(((dp[int(len(str(K)))][1][0] + dp[int(len(str(K)))][0][0] - 1) % MOD))

-dp = [[[0] * (int(len(str(K))) + 1) for _ in range(D)] for _ in range(2)]

+dp = [[[0] * D for _ in range(2)] for _ in range(int(len(str(K))) + 1)]

+# 外側の要素から外側のループに置くと参照が速くなる

-                dp[new_smaller_flg][new_mod_d][digit + 1] += dp[smaller_flg][mod_d][

+                dp[digit + 1][new_smaller_flg][new_mod_d] += dp[digit][smaller_flg][

-                dp[new_smaller_flg][new_mod_d][digit + 1] %= MOD

+                dp[digit + 1][new_smaller_flg][new_mod_d] %= MOD


Input:
def main():

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

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

    ab.sort()

    ans = 0

    for i, j in ab:

        if m < j:

            ans += i*m

            break

        m -= j

        ans += i*j

    print(ans)

main()

import sys

input = sys.stdin.readline

def main():

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

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

    ab.sort()

    ans = 0

    for i, j in ab:

        if m < j:

            ans += i*m

            break

        m -= j

        ans += i*j

    print(ans)

main()

import sys

input = sys.stdin.readline

def main():
    n, m = list(map(int, input().split()))
    ab = [tuple(map(int, input().split())) for _ in range(n)]
    ab.sort()
    ans = 0
    for i, j in ab:
        if m < j:
            ans += i * m
            break
        m -= j
        ans += i * j
    print(ans)

main()

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


Input:
def d_CardEater(N, A):

    from collections import Counter, defaultdict

    a = Counter(A)  # a[i]は数列の中にiが何回出たか

    a = sorted(list(a.items()), key=lambda x: x[0])

    d = defaultdict(int)  # aのうち2回以上出た値の一覧

    for k, v in a:

        if v >= 2:

            d[k] = v - 1  # あとの計算の便宜のため、1引いておく

    n = sum(d.values())  # 少なくとも値が重複したn枚分は捨てることになる

    if n % 2 == 0:

        ans = N - n

    else:

        # nが奇数だと、山札dの中のカードのうち1枚を、値の重複がないカードからなる

        # 山の中の1枚を道連れにして捨てる必要があるため、さらに1引く

        ans = N - n - 1

    return ans

N = int(eval(input()))

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

print((d_CardEater(N, A)))

def d_card_eater(N, A):

    # 解説どおり

    from collections import Counter

    kind = len(set(A))  # 数列に現れる値の種類の数

    ans = kind if kind % 2 == 1 else kind - 1

    return ans

N = int(eval(input()))

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

print((d_card_eater(N, A)))

-    from collections import Counter, defaultdict

+    # 解説どおり

-    a = Counter(A)  # a[i]は数列の中にiが何回出たか

-    a = sorted(list(a.items()), key=lambda x: x[0])

-    d = defaultdict(int)  # aのうち2回以上出た値の一覧

-            d[k] = v - 1  # あとの計算の便宜のため、1引いておく

-    n = sum(d.values())  # 少なくとも値が重複したn枚分は捨てることになる

-        # nが奇数だと、山札dの中のカードのうち1枚を、値の重複がないカードからなる

-        # 山の中の1枚を道連れにして捨てる必要があるため、さらに1引く

+    ans = kind if kind % 2 == 1 else kind - 1


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

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

  if str(i ** 0.5)[-1] == "0":

    print(i)

    exit()

import math

n = int(eval(input()))

print((math.floor(n**0.5)**2))

n = int(eval(input()))
for i in range(n, 0, -1):
    if str(i**0.5)[-1] == "0":
        print(i)
        exit()

import math

n = int(eval(input()))
print((math.floor(n**0.5) ** 2))

+import math
+
-for i in range(n, 0, -1):
-    if str(i**0.5)[-1] == "0":
-        print(i)
-        exit()
+print((math.floor(n**0.5) ** 2))


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

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

cnt2 = 0

cnt1 = 1

aa.append(-1)

a = aa.pop(0)

for i in range(1,n):

    if i == a:

        cnt2, cnt1 = cnt1, 0

        a = aa.pop(0)

    else:

        cnt2, cnt1 = cnt1, cnt2+cnt1

else:

    ans = (cnt2+cnt1)%1000000007

print(ans)

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

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

a.append(-1)

idx = 0

mod = 10**9+7

dp = [0]*(n+1)

dp[0] = 1

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

else: dp[1] = 1

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

    if i == a[idx]:

        dp[i] = 0

        idx += 1

    else:

        dp[i] = (dp[i-1] + dp[i-2])%mod

print((dp[n]))

n, m = list(map(int, input().split()))
aa = [int(eval(input())) for i in range(m)]
cnt2 = 0
cnt1 = 1
aa.append(-1)
a = aa.pop(0)
for i in range(1, n):
    if i == a:
        cnt2, cnt1 = cnt1, 0
        a = aa.pop(0)
    else:
        cnt2, cnt1 = cnt1, cnt2 + cnt1
else:
    ans = (cnt2 + cnt1) % 1000000007
print(ans)

n, m = list(map(int, input().split()))
a = [int(eval(input())) for _ in range(m)]
a.append(-1)
idx = 0
mod = 10**9 + 7
dp = [0] * (n + 1)
dp[0] = 1
if a[idx] == 1:
    idx += 1
else:
    dp[1] = 1
for i in range(2, n + 1):
    if i == a[idx]:
        dp[i] = 0
        idx += 1
    else:
        dp[i] = (dp[i - 1] + dp[i - 2]) % mod
print((dp[n]))

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

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


Input:
# AOJ 0084 Search Engine

# Python3 2018.6.15 bal4u

import re

s = re.split('[., ]', eval(input()))

ans = []

for i in s:

	if len(i) >= 3 and len(i) <= 6:

		ans.append(i)

print((*ans))

# AOJ 0084 Search Engine

# Python3 2018.6.15 bal4u

import re

s = re.split('[., ]', eval(input()))

ans = []

for i in s:

	if 3 <= len(i) <= 6:

		ans.append(i)

print((*ans))

# AOJ 0084 Search Engine
# Python3 2018.6.15 bal4u
import re

s = re.split("[., ]", eval(input()))
ans = []
for i in s:
    if len(i) >= 3 and len(i) <= 6:
        ans.append(i)
print((*ans))

# AOJ 0084 Search Engine
# Python3 2018.6.15 bal4u
import re

s = re.split("[., ]", eval(input()))
ans = []
for i in s:
    if 3 <= len(i) <= 6:
        ans.append(i)
print((*ans))


Input:
def main():

    from sys import setrecursionlimit, stdin

    from os import environ

    from collections import defaultdict, deque, Counter

    from math import ceil, floor, gcd

    from itertools import accumulate, combinations, combinations_with_replacement

    setrecursionlimit(10**6)

    dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in environ else lambda *x: 0

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

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

    II = lambda: int(input())

    P = 10**9+7

    INF = 10**9+10

    sa,sb = input().split()

    a = int(sa)

    sb = sb.split('.')

    b100 = int(sb[0])*100

    if len(sb) ==2:

        b100 += int(sb[1])

    print(a*b100//100)

    # print(int(a*(b*10**2))//10**2)

    # print(int(a),int(b*10**2))

    # print(int(a)*int(b*10**2)//10**2)

main()

#999999999999999 9.99

def main():

    from sys import setrecursionlimit, stdin

    from os import environ

    from collections import defaultdict, deque, Counter

    from math import ceil, floor, gcd

    from itertools import accumulate, combinations, combinations_with_replacement

    setrecursionlimit(10**6)

    dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in environ else lambda *x: 0

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

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

    II = lambda: int(input())

    P = 10**9+7

    INF = 10**9+10

    sa,sb = input().split()

    a = int(sa)

    b = int(float(sb)*100+0.5)

    print(a*b//100)

main()

def main():
    from sys import setrecursionlimit, stdin
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor, gcd
    from itertools import accumulate, combinations, combinations_with_replacement

    setrecursionlimit(10**6)
    dbg = (
        (lambda *something: print(*something))
        if "TERM_PROGRAM" in environ
        else lambda *x: 0
    )
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int, input().split()))
    II = lambda: int(input())
    P = 10**9 + 7
    INF = 10**9 + 10
    sa, sb = input().split()
    a = int(sa)
    sb = sb.split(".")
    b100 = int(sb[0]) * 100
    if len(sb) == 2:
        b100 += int(sb[1])
    print(a * b100 // 100)
    # print(int(a*(b*10**2))//10**2)
    # print(int(a),int(b*10**2))
    # print(int(a)*int(b*10**2)//10**2)

main()
# 999999999999999 9.99

def main():
    from sys import setrecursionlimit, stdin
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor, gcd
    from itertools import accumulate, combinations, combinations_with_replacement

    setrecursionlimit(10**6)
    dbg = (
        (lambda *something: print(*something))
        if "TERM_PROGRAM" in environ
        else lambda *x: 0
    )
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int, input().split()))
    II = lambda: int(input())
    P = 10**9 + 7
    INF = 10**9 + 10
    sa, sb = input().split()
    a = int(sa)
    b = int(float(sb) * 100 + 0.5)
    print(a * b // 100)

main()


Input:
from collections import Counter

n = int(eval(input()))

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

a = Counter(lis[::2])

b = Counter(lis[1::2])

aa = sorted(list(a.items()), key=lambda x:x[1], reverse=True)

bb = sorted(list(b.items()), key=lambda x:x[1], reverse=True)

if aa[0][0] == bb[0][0]:

    if len(aa) > 1 and len(bb) > 1:

        res = n - max(aa[0][1]+bb[1][1], aa[1][1]+bb[0][1])

    elif len(aa) == 1 and len(bb) > 1:

        res = n - aa[0][1] - bb[1][1]

    elif len(aa) > 1 and len(bb) == 1:

        res = n - aa[1][1] - bb[0][1]

    else:

        res = n - aa[0][1]

else:

    res = n - aa[0][1] - bb[0][1]

print(res)

from collections import Counter

n = int(eval(input()))

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

a = Counter(lis[::2])

b = Counter(lis[1::2])

aa = sorted(list(a.items()), key=lambda x:x[1], reverse=True)

bb = sorted(list(b.items()), key=lambda x:x[1], reverse=True)

aa.append((0, 0))

bb.append((0, 0))

if aa[0][0] == bb[0][0]:

    res = n - max(aa[0][1]+bb[1][1], aa[1][1]+bb[0][1])

else:

    res = n - aa[0][1] - bb[0][1]

print(res)

from collections import Counter

n = int(eval(input()))
lis = list(map(int, input().split()))
a = Counter(lis[::2])
b = Counter(lis[1::2])
aa = sorted(list(a.items()), key=lambda x: x[1], reverse=True)
bb = sorted(list(b.items()), key=lambda x: x[1], reverse=True)
if aa[0][0] == bb[0][0]:
    if len(aa) > 1 and len(bb) > 1:
        res = n - max(aa[0][1] + bb[1][1], aa[1][1] + bb[0][1])
    elif len(aa) == 1 and len(bb) > 1:
        res = n - aa[0][1] - bb[1][1]
    elif len(aa) > 1 and len(bb) == 1:
        res = n - aa[1][1] - bb[0][1]
    else:
        res = n - aa[0][1]
else:
    res = n - aa[0][1] - bb[0][1]
print(res)

from collections import Counter

n = int(eval(input()))
lis = list(map(int, input().split()))
a = Counter(lis[::2])
b = Counter(lis[1::2])
aa = sorted(list(a.items()), key=lambda x: x[1], reverse=True)
bb = sorted(list(b.items()), key=lambda x: x[1], reverse=True)
aa.append((0, 0))
bb.append((0, 0))
if aa[0][0] == bb[0][0]:
    res = n - max(aa[0][1] + bb[1][1], aa[1][1] + bb[0][1])
else:
    res = n - aa[0][1] - bb[0][1]
print(res)


Input:
import math

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

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

ans = math.ceil((n-1)/(k-1))

print(ans)

import math

n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = math.ceil((n - 1) / (k - 1))
print(ans)


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

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

s=sum(b)

a=[i for i in b if i>=s/(4*m)]

print(("Yes" if len(a)>=m else "No"))

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

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

cnt = 0

for i in b:

    if i >= sum(b)/(4*a[1]):

        cnt +=1

    else:

        pass

if cnt >= a[1]:

    print("Yes")

else:

    print("No")

n, m = list(map(int, input().split()))
b = list(map(int, input().split()))
s = sum(b)
a = [i for i in b if i >= s / (4 * m)]
print(("Yes" if len(a) >= m else "No"))

a = list(map(int, input().split()))
b = list(map(int, input().split()))
cnt = 0
for i in b:
    if i >= sum(b) / (4 * a[1]):
        cnt += 1
    else:
        pass
if cnt >= a[1]:
    print("Yes")
else:
    print("No")

-print(("Yes" if len(a) >= m else "No"))


Input:
import sys

stdin = sys.stdin

def li(): return list(map(int, stdin.readline().split()))

def li_(): return [int(x)-1 for x in stdin.readline().split()]

def lf(): return list(map(float, stdin.readline().split()))

def ls(): return stdin.readline().split()

def ns(): return stdin.readline().rstrip()

def lc(): return list(ns())

def ni(): return int(stdin.readline())

def nf(): return float(stdin.readline())

from collections import Counter

n = ni()

a = list(li())

even = Counter(a[::2])

odd = Counter(a[1::2])

es = [(0,0)]

for ek,ev in list(even.items()):

    es.append((ev,ek))

es.sort()

os = [(0,0)]

for ok,ov in list(odd.items()):

    os.append((ov,ok))

os.sort()

if es[-1][1] != os[-1][1]:

    print(((n//2-es[-1][0]) + (n//2-os[-1][0])))

else:

    print((min((n//2-es[-1][0]) + (n//2-os[-2][0]),

              (n//2-es[-2][0]) + (n//2-os[-1][0]))))

import sys

stdin = sys.stdin

def li(): return list(map(int, stdin.readline().split()))

def li_(): return [int(x)-1 for x in stdin.readline().split()]

def lf(): return list(map(float, stdin.readline().split()))

def ls(): return stdin.readline().split()

def ns(): return stdin.readline().rstrip()

def lc(): return list(ns())

def ni(): return int(stdin.readline())

def nf(): return float(stdin.readline())

from collections import Counter

n = ni()

a = list(li())

even = Counter(a[::2])

odd = Counter(a[1::2])

es = even.most_common(2)

os = odd.most_common(2)

es = es + [(0,0)]

os = os + [(0,0)]

if es[0][0] != os[0][0]:

    print(((n//2-es[0][1]) + (n//2-os[0][1])))

else:

    print((min((n//2-es[1][1]) + (n//2-os[0][1]),

              (n//2-es[0][1]) + (n//2-os[1][1]))))

import sys

stdin = sys.stdin

def li():
    return list(map(int, stdin.readline().split()))

def li_():
    return [int(x) - 1 for x in stdin.readline().split()]

def lf():
    return list(map(float, stdin.readline().split()))

def ls():
    return stdin.readline().split()

def ns():
    return stdin.readline().rstrip()

def lc():
    return list(ns())

def ni():
    return int(stdin.readline())

def nf():
    return float(stdin.readline())

from collections import Counter

n = ni()
a = list(li())
even = Counter(a[::2])
odd = Counter(a[1::2])
es = [(0, 0)]
for ek, ev in list(even.items()):
    es.append((ev, ek))
es.sort()
os = [(0, 0)]
for ok, ov in list(odd.items()):
    os.append((ov, ok))
os.sort()
if es[-1][1] != os[-1][1]:
    print(((n // 2 - es[-1][0]) + (n // 2 - os[-1][0])))
else:
    print(
        (
            min(
                (n // 2 - es[-1][0]) + (n // 2 - os[-2][0]),
                (n // 2 - es[-2][0]) + (n // 2 - os[-1][0]),
            )
        )
    )

import sys

stdin = sys.stdin

def li():
    return list(map(int, stdin.readline().split()))

def li_():
    return [int(x) - 1 for x in stdin.readline().split()]

def lf():
    return list(map(float, stdin.readline().split()))

def ls():
    return stdin.readline().split()

def ns():
    return stdin.readline().rstrip()

def lc():
    return list(ns())

def ni():
    return int(stdin.readline())

def nf():
    return float(stdin.readline())

from collections import Counter

n = ni()
a = list(li())
even = Counter(a[::2])
odd = Counter(a[1::2])
es = even.most_common(2)
os = odd.most_common(2)
es = es + [(0, 0)]
os = os + [(0, 0)]
if es[0][0] != os[0][0]:
    print(((n // 2 - es[0][1]) + (n // 2 - os[0][1])))
else:
    print(
        (
            min(
                (n // 2 - es[1][1]) + (n // 2 - os[0][1]),
                (n // 2 - es[0][1]) + (n // 2 - os[1][1]),
            )
        )
    )


Input:
#!/usr/bin/env python3

def solve(S: str):

    stack = []

    N = len(S)

    for i, s in enumerate(S):

        if i == 0:

            stack.append(s)

        else:

            if len(stack) == 0:

                stack.append(s)

            else:

                if s != stack[-1]:

                    tmp = stack.pop()

                else:

                    stack.append(s)

    print((N - len(stack)))

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)

def main():

    S = str(eval(input()))

    solve(S)

if __name__ == '__main__':

    main()

#!/usr/bin/env python3

def solve_short(S: str):

    print((2*min(S.count('0'), S.count('1'))))

def solve(S: str):

    stack = []

    N = len(S)

    for i, s in enumerate(S):

        if i == 0:

            stack.append(s)

        else:

            if len(stack) == 0:

                stack.append(s)

            else:

                if s != stack[-1]:

                    tmp = stack.pop()

                else:

                    stack.append(s)

    print((N - len(stack)))

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)

def main():

    S = str(eval(input()))

    solve_short(S)

if __name__ == '__main__':

    main()

#!/usr/bin/env python3
def solve(S: str):
    stack = []
    N = len(S)
    for i, s in enumerate(S):
        if i == 0:
            stack.append(s)
        else:
            if len(stack) == 0:
                stack.append(s)
            else:
                if s != stack[-1]:
                    tmp = stack.pop()
                else:
                    stack.append(s)
    print((N - len(stack)))

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    S = str(eval(input()))
    solve(S)

if __name__ == "__main__":
    main()

#!/usr/bin/env python3
def solve_short(S: str):
    print((2 * min(S.count("0"), S.count("1"))))

def solve(S: str):
    stack = []
    N = len(S)
    for i, s in enumerate(S):
        if i == 0:
            stack.append(s)
        else:
            if len(stack) == 0:
                stack.append(s)
            else:
                if s != stack[-1]:
                    tmp = stack.pop()
                else:
                    stack.append(s)
    print((N - len(stack)))

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    S = str(eval(input()))
    solve_short(S)

if __name__ == "__main__":
    main()


Input:
# Reference: https://note.nkmk.me/python-union-find/

class UnionFind:

    # if x is root: self.parents[x] = -(the number of the group nodes)

    # else: self.parents[x] = the parent of x

    def __init__(self, n):

        self.n = n

        self.parents = [-1] * n

    # return the parent of x

    def find(self, x):

        history = []

        while self.parents[x] >= 0:

            history.append(x)

            x = self.parents[x]

        for node in history:

            self.parents[node] = x

        return x

    # merge the group of x and the group of y

    def union(self, x, y):

        x = self.find(x)

        y = self.find(y)

        if x == y:

            return

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

            x, y = y, x

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

        self.parents[y] = x

    # return the size of the group of x

    def size(self, x):

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

    # return whether x and y in a same group

    def same(self, x, y):

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

    # return [all nodes which is in the group of x]

    # O(n)

    def members(self, x):

        root = self.find(x)

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

    # return [all roots]

    # O(n)

    def roots(self):

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

    # return {root: members of the group}

    # O(n * n)

    def all_group_members(self):

        return {r: self.members(r) for r in self.roots()}

from bisect import bisect

from sys import stdin

input = stdin.buffer.readline

def main():

    n = int(eval(input()))

    l = [0] * n

    for i in range(n):

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

        l[x-1] = (y - 1, i)

    # iで管理

    uf = UnionFind(n)

    roots = []

    for y, i in l:

        if len(roots) == 0 or -roots[-1][0] > y:

            roots.append((-y, i))

        else:

            ind = bisect(roots, (-y, i))

            new_y = roots[-1][0]

            for old_y, old_i in roots[ind:]:

                uf.union(i, old_i)

            roots = roots[:ind]

            roots.append((new_y, i))

    for i in range(n):

        print((uf.size(i)))

main()

# Reference: https://note.nkmk.me/python-union-find/

class UnionFind:

    # if x is root: self.parents[x] = -(the number of the group nodes)

    # else: self.parents[x] = the parent of x

    def __init__(self, n):

        self.n = n

        self.parents = [-1] * n

    # return the parent of x

    def find(self, x):

        history = []

        while self.parents[x] >= 0:

            history.append(x)

            x = self.parents[x]

        for node in history:

            self.parents[node] = x

        return x

    # merge the group of x and the group of y

    def union(self, x, y):

        x = self.find(x)

        y = self.find(y)

        if x == y:

            return

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

            x, y = y, x

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

        self.parents[y] = x

    # return the size of the group of x

    def size(self, x):

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

from sys import stdin

input = stdin.buffer.readline

def main():

    n = int(eval(input()))

    l = [0] * n

    for i in range(n):

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

        l[x-1] = (y-1, i)

    uf = UnionFind(n)

    roots = []

    for y, i in l:

        if len(roots) == 0 or roots[-1][0] > y:

            roots.append((y, i))

        else:

            new_y = roots[-1][0]

            while len(roots) > 0 and roots[-1][0] < y:

                old_y, old_i = roots.pop()

                uf.union(i, old_i)

            roots.append((new_y, i))

    # O(uf.size(i)) = 1

    for i in range(n):

        print((uf.size(i)))

main()

# Reference: https://note.nkmk.me/python-union-find/
class UnionFind:
    # if x is root: self.parents[x] = -(the number of the group nodes)
    # else: self.parents[x] = the parent of x
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    # return the parent of x
    def find(self, x):
        history = []
        while self.parents[x] >= 0:
            history.append(x)
            x = self.parents[x]
        for node in history:
            self.parents[node] = x
        return x

    # merge the group of x and the group of y
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    # return the size of the group of x
    def size(self, x):
        return -self.parents[self.find(x)]

    # return whether x and y in a same group
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # return [all nodes which is in the group of x]
    # O(n)
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    # return [all roots]
    # O(n)
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    # return {root: members of the group}
    # O(n * n)
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

from bisect import bisect
from sys import stdin

input = stdin.buffer.readline

def main():
    n = int(eval(input()))
    l = [0] * n
    for i in range(n):
        x, y = list(map(int, input().split()))
        l[x - 1] = (y - 1, i)
    # iで管理
    uf = UnionFind(n)
    roots = []
    for y, i in l:
        if len(roots) == 0 or -roots[-1][0] > y:
            roots.append((-y, i))
        else:
            ind = bisect(roots, (-y, i))
            new_y = roots[-1][0]
            for old_y, old_i in roots[ind:]:
                uf.union(i, old_i)
            roots = roots[:ind]
            roots.append((new_y, i))
    for i in range(n):
        print((uf.size(i)))

main()

# Reference: https://note.nkmk.me/python-union-find/
class UnionFind:
    # if x is root: self.parents[x] = -(the number of the group nodes)
    # else: self.parents[x] = the parent of x
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    # return the parent of x
    def find(self, x):
        history = []
        while self.parents[x] >= 0:
            history.append(x)
            x = self.parents[x]
        for node in history:
            self.parents[node] = x
        return x

    # merge the group of x and the group of y
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    # return the size of the group of x
    def size(self, x):
        return -self.parents[self.find(x)]

from sys import stdin

input = stdin.buffer.readline

def main():
    n = int(eval(input()))
    l = [0] * n
    for i in range(n):
        x, y = list(map(int, input().split()))
        l[x - 1] = (y - 1, i)
    uf = UnionFind(n)
    roots = []
    for y, i in l:
        if len(roots) == 0 or roots[-1][0] > y:
            roots.append((y, i))
        else:
            new_y = roots[-1][0]
            while len(roots) > 0 and roots[-1][0] < y:
                old_y, old_i = roots.pop()
                uf.union(i, old_i)
            roots.append((new_y, i))
    # O(uf.size(i)) = 1
    for i in range(n):
        print((uf.size(i)))

main()

-    # return whether x and y in a same group

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

-    # return [all nodes which is in the group of x]

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

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

-    # return {root: members of the group}

-        return {r: self.members(r) for r in self.roots()}

-        if len(roots) == 0 or -roots[-1][0] > y:

+        if len(roots) == 0 or roots[-1][0] > y:

-            ind = bisect(roots, (-y, i))

-            for old_y, old_i in roots[ind:]:

+            while len(roots) > 0 and roots[-1][0] < y:

+                old_y, old_i = roots.pop()


Input:
s=eval(input())

b=l=r=0

for i in s:

  l+=(int(i)==b)

  r+=(int(i)!=b)

  b^=1

print((min(l,r)))

s=eval(input())

b=c=0

for i in s:

  c+=(int(i)==b)

  b^=1

print((min(c,len(s)-c)))

s = eval(input())
b = l = r = 0
for i in s:
    l += int(i) == b
    r += int(i) != b
    b ^= 1
print((min(l, r)))

s = eval(input())
b = c = 0
for i in s:
    c += int(i) == b
    b ^= 1
print((min(c, len(s) - c)))


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

S=eval(input())

Alp={"A":0,"B":1,"C":2,"D":3,"E":4,"F":5,"G":6,"H":7,"I":8,"J":9,"K":10,"L":11,"M":12,"N":13,"O":14,"P":15,"Q":16,"R":17,"S":18,"T":19,"U":20,"V":21,"W":22,"X":23,"Y":24,"Z":25}

new_Alp=[]

for i in range(len(S)):

  num=Alp[S[i]]

  num+=N

  num%=26

  for key,atai in list(Alp.items()):

    if atai==num:

      new_Alp.append(key)

new_alp="".join(new_Alp)

print(new_alp)

N=int(eval(input()))

S=eval(input())

alp=list(S)

def func(mozi):

  ord_mozi=ord(mozi)

  new_ord_mozi=(ord_mozi-65+N)%26+65

  new_chr_mozi=chr(new_ord_mozi)

  return new_chr_mozi

new_alp=list(map(func,alp))

print(("".join(new_alp)))

N = int(eval(input()))
S = eval(input())
alp = list(S)

def func(mozi):
    ord_mozi = ord(mozi)
    new_ord_mozi = (ord_mozi - 65 + N) % 26 + 65
    new_chr_mozi = chr(new_ord_mozi)
    return new_chr_mozi

new_alp = list(map(func, alp))
print(("".join(new_alp)))

-    for key, atai in list(Alp.items()):

+    new_ord_mozi = (ord_mozi - 65 + N) % 26 + 65


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

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

from collections import Counter

Sc = Counter(S).most_common()

print((len(Sc)))

N = int(eval(input()))

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

print((len(set(S))))

-from collections import Counter
-Sc = Counter(S).most_common()
-print((len(Sc)))
+print((len(set(S))))


Input:
# ABC120 C - String Transformation

si = lambda: eval(input())

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

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

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

S = si()

T = si()

dict_S = {}

dict_T = {}

for i in range(len(S)):

    if S[i] in dict_S:

        if dict_S[S[i]] != T[i]:

            print("No")

            exit()

    else:

        dict_S[S[i]] = T[i]

    if T[i] in dict_T:

        if dict_T[T[i]] != S[i]:

            print("No")

            exit()

    else:

        dict_T[T[i]] = S[i]

print("Yes")

from collections import defaultdict as dd

s=eval(input())

t=eval(input())

ds=dd(int)

dt=dd(int)

for ss in s:

    ds[ss]+=1

for tt in t:

    dt[tt]+=1

# print(ds)

# print(dt)

ls,lt=[],[]

for k,v in list(ds.items()):

    ls.append(v)

for k,v in list(dt.items()):

    lt.append(v)

# print(ls)

# print(lt)

ls.sort()

lt.sort()

for a,b in zip(ls,lt):

    if a!=b:

        print('No')

        exit()

print('Yes')

from collections import defaultdict as dd

s = eval(input())
t = eval(input())
ds = dd(int)
dt = dd(int)
for ss in s:
    ds[ss] += 1
for tt in t:
    dt[tt] += 1
# print(ds)
# print(dt)
ls, lt = [], []
for k, v in list(ds.items()):
    ls.append(v)
for k, v in list(dt.items()):
    lt.append(v)
# print(ls)
# print(lt)
ls.sort()
lt.sort()
for a, b in zip(ls, lt):
    if a != b:
        print("No")
        exit()
print("Yes")

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

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

+from collections import defaultdict as dd


Input:
S = eval(input())

if len(set(S)) == 1:

    print("No")

else:

    print("Yes")

S = eval(input())

ans = "Yes" if len(set(S)) == 2 else "No"

print(ans)

+ans = "Yes" if len(set(S)) == 2 else "No"


Input:
import sys

import math

primes = [2]

for line in sys.stdin:

  try:

    n = int(line)

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

      if i % 2 == 0:

        continue

      elif math.sqrt(i) == 0:

        continue

      elif len([j for j in primes if i % j == 0]) > 0:

        continue

      primes.append(i)

    if n == 3:

      print(2, end=" ")

    else:

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

        if i % 2 == 0:

          continue

        elif math.sqrt(i) == 0:

          continue

        elif len([j for j in primes if i % j == 0 and i != j]) > 0:

          continue

        print(i, end=" ")

        break

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

      if i % 2 == 0:

        continue

      elif math.sqrt(i) == 0:

        continue

      elif len([j for j in primes if i % j == 0 and i != j]) > 0:

        continue

      print(i)

      break

  except:

    break

# 04.77 sec -> Time Limit Exceeded?

import sys

import math

# Sieve of Eratosthenes

N = 50021

searchList = list(range(3, N + 1, 2))

primes = [2]

while True:

  top = searchList.pop(0)

  primes.append(top)

  if top > math.sqrt(N):

    break

  searchList = [s for s in searchList if s % top != 0]

primes.extend(searchList)

# solve

for line in sys.stdin:

  try:

    n = int(line)

    pre = 2

    for p in primes:

      if p < n:

        pre = p

      if p > n:

        print((pre, p))

        break

  except:

    break

+    searchList = [s for s in searchList if s % top != 0]

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

-            elif len([j for j in primes if i % j == 0]) > 0:

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

-                elif math.sqrt(i) == 0:

-                elif len([j for j in primes if i % j == 0 and i != j]) > 0:

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


Input:
dhw = [(1,0),(0,-1),(0,1),(-1,0),

( 2,-2),( 2,-1),( 2, 0),( 2, 1),( 2, 2),

( 1,-2),( 1,-1),        ( 1, 1),( 1, 2),

( 0,-2),                        ( 0, 2),

(-1,-2),(-1,-1),        (-1, 1),(-1, 2),

(-2,-2),(-2,-1),(-2, 0),(-2, 1),(-2, 2)]

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

sh, sw = [int(x)-1 for x in input().split()]

eh, ew = [int(x)-1 for x in input().split()]

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

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

dst[sh][sw] = 0

from collections import deque

dq = deque([[sh, sw]])

while dq:

    h, w = dq.popleft()

    for i in range(4):

        nh = h + dhw[i][0]; nw = w + dhw[i][1]

        if nh < 0 or H <= nh : continue

        if nw < 0 or W <= nw : continue

        if S[nh][nw] == '#': continue

        if dst[nh][nw] == -1 or dst[h][w] < dst[nh][nw]:

            dst[nh][nw] = dst[h][w]

            dq.appendleft([nh, nw])

    for i in range(4, 24):

        nh = h + dhw[i][0]; nw = w + dhw[i][1]

        if nh < 0 or H <= nh : continue

        if nw < 0 or W <= nw : continue

        if S[nh][nw] == '#': continue

        if dst[nh][nw] >= 0: continue

        if dst[nh][nw] == -1 or dst[h][w] + 1 < dst[nh][nw]:

            dst[nh][nw] = dst[h][w] + 1

            dq.append([nh, nw])

print((dst[eh][ew]))

dhw = [(1,0),(0,-1),(0,1),(-1,0),

( 2,-2),( 2,-1),( 2, 0),( 2, 1),( 2, 2),

( 1,-2),( 1,-1),        ( 1, 1),( 1, 2),

( 0,-2),                        ( 0, 2),

(-1,-2),(-1,-1),        (-1, 1),(-1, 2),

(-2,-2),(-2,-1),(-2, 0),(-2, 1),(-2, 2)]

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

sh, sw = [int(x)-1 for x in input().split()]

eh, ew = [int(x)-1 for x in input().split()]

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

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

dst[sh][sw] = 0

from collections import deque

dq = deque([(sh, sw)])

while dq:

    h, w = dq.popleft()

    for i in range(4):

        nh = h + dhw[i][0]; nw = w + dhw[i][1]

        if nh < 0 or H <= nh : continue

        if nw < 0 or W <= nw : continue

        if S[nh][nw] == '#': continue

        if dst[nh][nw] == -1 or dst[h][w] < dst[nh][nw]:

            dst[nh][nw] = dst[h][w]

            dq.appendleft((nh, nw))

    for i in range(4, 24):

        nh = h + dhw[i][0]; nw = w + dhw[i][1]

        if nh < 0 or H <= nh : continue

        if nw < 0 or W <= nw : continue

        if S[nh][nw] == '#': continue

        if dst[nh][nw] >= 0: continue

        if dst[nh][nw] == -1:

            dst[nh][nw] = dst[h][w] + 1

        elif dst[h][w] + 1 < dst[nh][nw]:

            dst[nh][nw] = min(dst[nh][nw], dst[h][w] + 1)

        else: continue

        dq.append((nh, nw))

print((dst[eh][ew]))

dhw = [
    (1, 0),
    (0, -1),
    (0, 1),
    (-1, 0),
    (2, -2),
    (2, -1),
    (2, 0),
    (2, 1),
    (2, 2),
    (1, -2),
    (1, -1),
    (1, 1),
    (1, 2),
    (0, -2),
    (0, 2),
    (-1, -2),
    (-1, -1),
    (-1, 1),
    (-1, 2),
    (-2, -2),
    (-2, -1),
    (-2, 0),
    (-2, 1),
    (-2, 2),
]
H, W = list(map(int, input().split()))
sh, sw = [int(x) - 1 for x in input().split()]
eh, ew = [int(x) - 1 for x in input().split()]
S = [eval(input()) for _ in range(H)]
dst = [[-1] * W for _ in range(H)]
dst[sh][sw] = 0
from collections import deque

dq = deque([[sh, sw]])
while dq:
    h, w = dq.popleft()
    for i in range(4):
        nh = h + dhw[i][0]
        nw = w + dhw[i][1]
        if nh < 0 or H <= nh:
            continue
        if nw < 0 or W <= nw:
            continue
        if S[nh][nw] == "#":
            continue
        if dst[nh][nw] == -1 or dst[h][w] < dst[nh][nw]:
            dst[nh][nw] = dst[h][w]
            dq.appendleft([nh, nw])
    for i in range(4, 24):
        nh = h + dhw[i][0]
        nw = w + dhw[i][1]
        if nh < 0 or H <= nh:
            continue
        if nw < 0 or W <= nw:
            continue
        if S[nh][nw] == "#":
            continue
        if dst[nh][nw] >= 0:
            continue
        if dst[nh][nw] == -1 or dst[h][w] + 1 < dst[nh][nw]:
            dst[nh][nw] = dst[h][w] + 1
            dq.append([nh, nw])
print((dst[eh][ew]))

dhw = [
    (1, 0),
    (0, -1),
    (0, 1),
    (-1, 0),
    (2, -2),
    (2, -1),
    (2, 0),
    (2, 1),
    (2, 2),
    (1, -2),
    (1, -1),
    (1, 1),
    (1, 2),
    (0, -2),
    (0, 2),
    (-1, -2),
    (-1, -1),
    (-1, 1),
    (-1, 2),
    (-2, -2),
    (-2, -1),
    (-2, 0),
    (-2, 1),
    (-2, 2),
]
H, W = list(map(int, input().split()))
sh, sw = [int(x) - 1 for x in input().split()]
eh, ew = [int(x) - 1 for x in input().split()]
S = [eval(input()) for _ in range(H)]
dst = [[-1] * W for _ in range(H)]
dst[sh][sw] = 0
from collections import deque

dq = deque([(sh, sw)])
while dq:
    h, w = dq.popleft()
    for i in range(4):
        nh = h + dhw[i][0]
        nw = w + dhw[i][1]
        if nh < 0 or H <= nh:
            continue
        if nw < 0 or W <= nw:
            continue
        if S[nh][nw] == "#":
            continue
        if dst[nh][nw] == -1 or dst[h][w] < dst[nh][nw]:
            dst[nh][nw] = dst[h][w]
            dq.appendleft((nh, nw))
    for i in range(4, 24):
        nh = h + dhw[i][0]
        nw = w + dhw[i][1]
        if nh < 0 or H <= nh:
            continue
        if nw < 0 or W <= nw:
            continue
        if S[nh][nw] == "#":
            continue
        if dst[nh][nw] >= 0:
            continue
        if dst[nh][nw] == -1:
            dst[nh][nw] = dst[h][w] + 1
        elif dst[h][w] + 1 < dst[nh][nw]:
            dst[nh][nw] = min(dst[nh][nw], dst[h][w] + 1)
        else:
            continue
        dq.append((nh, nw))
print((dst[eh][ew]))

-        if dst[nh][nw] == -1 or dst[h][w] + 1 < dst[nh][nw]:

+        elif dst[h][w] + 1 < dst[nh][nw]:

+            dst[nh][nw] = min(dst[nh][nw], dst[h][w] + 1)


Input:
import sys

ff = sys.stdin

while True :

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

    if (a == 0) & (b == 0) :

        break

    if a < b : print((a, b))

    else : print((b, a))

exit()

import sys

ff = sys.stdin
while True:
    a, b = list(map(int, ff.readline().split()))
    if (a == 0) & (b == 0):
        break
    if a < b:
        print((a, b))
    else:
        print((b, a))
exit()


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

GACHA={}

for n in range(N):

  g=eval(input())

  GACHA[g]=GACHA.get(g,0)

print((len(GACHA)))

N = int(eval(input()))

GACHA=[eval(input()) for n in range(N)]

print((len(set(GACHA))))

N = int(eval(input()))
GACHA = {}
for n in range(N):
    g = eval(input())
    GACHA[g] = GACHA.get(g, 0)
print((len(GACHA)))

N = int(eval(input()))
GACHA = [eval(input()) for n in range(N)]
print((len(set(GACHA))))

+GACHA = [eval(input()) for n in range(N)]


Input:
from itertools import permutations

from math import sqrt

n=int(eval(input()))

permlist = list(permutations(list(range(n))))

#print('permlist: {}'.format(permlist))

x = []

y = []

for i in range(n):

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

    x.append(xi)

    y.append(yi)

lengths = 0.0

for p in permlist:

    length = 0.0

    for _ in range(len(p)-1):

        i = p[_]

        j = p[_+1]

        #print('i: {} j:{}'.format(i,j))

        length += sqrt( (x[i]-x[j])**2 + (y[i]-y[j])**2 )

    #print('length: {}'.format(length))

    lengths += length

print((lengths/len(permlist)))

from itertools import permutations

from math import sqrt

def readinput():

    n=int(eval(input()))

    xyList=[]

    for _ in range(n):

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

        xyList.append((x,y))

    return n,xyList

def main(n,xyList):

    sum=0.0

    factn=0

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

        #print(tup)

        factn+=1

        x0=xyList[tup[0]][0]

        y0=xyList[tup[0]][1]

        for i in tup:

            x=xyList[i][0]

            y=xyList[i][1]

            sum+=sqrt((x-x0)**2+(y-y0)**2)

            x0=x

            y0=y

    ans=sum/factn

    return ans

if __name__=='__main__':

    n,xyList=readinput()

    #print(xyList)

    ans=main(n,xyList)

    print(ans)

from itertools import permutations
from math import sqrt

n = int(eval(input()))
permlist = list(permutations(list(range(n))))
# print('permlist: {}'.format(permlist))
x = []
y = []
for i in range(n):
    xi, yi = list(map(int, input().split()))
    x.append(xi)
    y.append(yi)
lengths = 0.0
for p in permlist:
    length = 0.0
    for _ in range(len(p) - 1):
        i = p[_]
        j = p[_ + 1]
        # print('i: {} j:{}'.format(i,j))
        length += sqrt((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2)
    # print('length: {}'.format(length))
    lengths += length
print((lengths / len(permlist)))

from itertools import permutations
from math import sqrt

def readinput():
    n = int(eval(input()))
    xyList = []
    for _ in range(n):
        x, y = list(map(int, input().split()))
        xyList.append((x, y))
    return n, xyList

def main(n, xyList):
    sum = 0.0
    factn = 0
    for tup in permutations(list(range(n))):
        # print(tup)
        factn += 1
        x0 = xyList[tup[0]][0]
        y0 = xyList[tup[0]][1]
        for i in tup:
            x = xyList[i][0]
            y = xyList[i][1]
            sum += sqrt((x - x0) ** 2 + (y - y0) ** 2)
            x0 = x
            y0 = y
    ans = sum / factn
    return ans

if __name__ == "__main__":
    n, xyList = readinput()
    # print(xyList)
    ans = main(n, xyList)
    print(ans)

-    xi, yi = list(map(int, input().split()))

-    # print('length: {}'.format(length))

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

+    for tup in permutations(list(range(n))):


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

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

s=0

cap=[]

flag=False

ans=2**(n+1)-1

for i,a in enumerate(A):

    s*=2

    s+=a

    cap.append(2**i-s)

    #if i!=n:

    #    ans-=a*(2**(n+1-i)-2)

    if s>2**i:

        flag=True

        break

if flag:

    print((-1))

else:

    remain=2**n-s

    ans=0

    node=0

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

        a=A[i]

        c=cap[i]

        node=min(c,node)+a

        ans+=node

    print(ans)

n=int(eval(input()))

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

s=0

cap=[]

flag=False

for i,a in enumerate(A):

    s*=2

    s+=a

    cap.append(min(2**i-s,(n+1-i)*10**8))

    if s>2**i:

        flag=True

        break

if flag:

    print((-1))

else:

    remain=2**n-s

    ans=0

    node=0

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

        a=A[i]

        c=cap[i]

        node=min(c,node)+a

        ans+=node

    print(ans)

n = int(eval(input()))
A = list(map(int, input().split()))
s = 0
cap = []
flag = False
ans = 2 ** (n + 1) - 1
for i, a in enumerate(A):
    s *= 2
    s += a
    cap.append(2**i - s)
    # if i!=n:
    #    ans-=a*(2**(n+1-i)-2)
    if s > 2**i:
        flag = True
        break
if flag:
    print((-1))
else:
    remain = 2**n - s
    ans = 0
    node = 0
    for i in range(n, -1, -1):
        a = A[i]
        c = cap[i]
        node = min(c, node) + a
        ans += node
    print(ans)

n = int(eval(input()))
A = list(map(int, input().split()))
s = 0
cap = []
flag = False
for i, a in enumerate(A):
    s *= 2
    s += a
    cap.append(min(2**i - s, (n + 1 - i) * 10**8))
    if s > 2**i:
        flag = True
        break
if flag:
    print((-1))
else:
    remain = 2**n - s
    ans = 0
    node = 0
    for i in range(n, -1, -1):
        a = A[i]
        c = cap[i]
        node = min(c, node) + a
        ans += node
    print(ans)


Input:
import decimal

a, b = (decimal.Decimal(x) for x in input().split())

print((int(a*b)))

a, b = input().split()

a = int(a)

b = int(b.replace(".", ""))

print((a*b//100))

import decimal

a, b = (decimal.Decimal(x) for x in input().split())
print((int(a * b)))

a, b = input().split()
a = int(a)
b = int(b.replace(".", ""))
print((a * b // 100))

-a, b = (decimal.Decimal(x) for x in input().split())


Input:
def mk_table(n):

    res = [1] * (n + 1)

    res[:2] = [0, 0]

    for i in range(2, n):

        if i ** 2 > n:

            break

        if res[i] == 1:

            j = 2

            while i * j <= n:

                res[i * j] = 0

                j += 1

    return res

tbl = mk_table(999999)

try:

    while 1:

        print((len([x for x in tbl[:int(eval(input()))+1] if x == 1])))

except Exception:

    pass

def mk_table(n):

    res = [1] * (n + 1)

    res[:2] = 0, 0

    for i in range(2, n):

        if i ** 2 > n:

            break

        if res[i] == 1:

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

                res[j] = 0

    return res

tbl = mk_table(999999)

try:

    while 1:

        print((len([x for x in tbl[:int(eval(input()))+1] if x == 1])))

except Exception:

    pass

def mk_table(n):
    res = [1] * (n + 1)
    res[:2] = [0, 0]
    for i in range(2, n):
        if i**2 > n:
            break
        if res[i] == 1:
            j = 2
            while i * j <= n:
                res[i * j] = 0
                j += 1
    return res

tbl = mk_table(999999)
try:
    while 1:
        print((len([x for x in tbl[: int(eval(input())) + 1] if x == 1])))
except Exception:
    pass

def mk_table(n):
    res = [1] * (n + 1)
    res[:2] = 0, 0
    for i in range(2, n):
        if i**2 > n:
            break
        if res[i] == 1:
            for j in range(i * 2, n + 1, i):
                res[j] = 0
    return res

tbl = mk_table(999999)
try:
    while 1:
        print((len([x for x in tbl[: int(eval(input())) + 1] if x == 1])))
except Exception:
    pass

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


Input:
import sys

# 許容する再帰処理の回数を変更

sys.setrecursionlimit(10**5+10)

# inputを高速化する。

input = sys.stdin.readline

# 入力

vacation = int(eval(input()))

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

# DPテーブル

# 最大化問題なので0で初期化

dp = [[0 for i in range(3)] for j in range(vacation+1)]

# dpの最大値を更新するための関数

def chmax(a, b):

    if a > b:

        return a

    else:

        return b

# メモ化再帰の関数

def rec(i):

    # DPの値が既に更新されている場合はその値を返す

    for j in range(3):

        if dp[i][j] > 0:

            break

        # 再帰の終了条件

        if i == 0:

            dp[i][j] = 0

            break

        # i-1 を再帰

        res = 0

        for k in range(3):

            if j == k:

                continue

            res = chmax(res, rec(i-1)[k] + lst_happiness[i-1][k])

            # 結果をメモする

            dp[i][j] = res

    return dp[i]

ans = rec(vacation)

ans = max(ans)

print(ans)

import sys

import numpy as np

# inputを高速化する。

input = sys.stdin.readline

# 入力

vacation = int(eval(input()))

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

# lst_happinessをndarrayにする。

arr_happiness_a = np.array([lst_happiness[i][0] for i in range(vacation)])

arr_happiness_b = np.array([lst_happiness[i][1] for i in range(vacation)])

arr_happiness_c = np.array([lst_happiness[i][2] for i in range(vacation)])

# DPのndarrayを作る。

dp_a = np.zeros(vacation, dtype=int)

dp_b = np.zeros(vacation, dtype=int)

dp_c = np.zeros(vacation, dtype=int)

# dpに初期値を入れる。

dp_a[0] = arr_happiness_a[0]

dp_b[0] = arr_happiness_b[0]

dp_c[0] = arr_happiness_c[0]

for i in range(1, vacation):

    dp_a[i] += max(dp_b[i-1], dp_c[i-1]) + arr_happiness_a[i]

    dp_b[i] += max(dp_a[i-1], dp_c[i-1]) + arr_happiness_b[i]

    dp_c[i] += max(dp_a[i-1], dp_b[i-1]) + arr_happiness_c[i]

ans = max(dp_a[vacation-1], dp_b[vacation-1], dp_c[vacation-1])

print(ans)

import sys

# 許容する再帰処理の回数を変更
sys.setrecursionlimit(10**5 + 10)
# inputを高速化する。
input = sys.stdin.readline
# 入力
vacation = int(eval(input()))
lst_happiness = [list(map(int, input().split())) for i in range(vacation)]
# DPテーブル
# 最大化問題なので0で初期化
dp = [[0 for i in range(3)] for j in range(vacation + 1)]
# dpの最大値を更新するための関数
def chmax(a, b):
    if a > b:
        return a
    else:
        return b

# メモ化再帰の関数
def rec(i):
    # DPの値が既に更新されている場合はその値を返す
    for j in range(3):
        if dp[i][j] > 0:
            break
        # 再帰の終了条件
        if i == 0:
            dp[i][j] = 0
            break
        # i-1 を再帰
        res = 0
        for k in range(3):
            if j == k:
                continue
            res = chmax(res, rec(i - 1)[k] + lst_happiness[i - 1][k])
            # 結果をメモする
            dp[i][j] = res
    return dp[i]

ans = rec(vacation)
ans = max(ans)
print(ans)

import sys
import numpy as np

# inputを高速化する。
input = sys.stdin.readline
# 入力
vacation = int(eval(input()))
lst_happiness = [list(map(int, input().split())) for i in range(vacation)]
# lst_happinessをndarrayにする。
arr_happiness_a = np.array([lst_happiness[i][0] for i in range(vacation)])
arr_happiness_b = np.array([lst_happiness[i][1] for i in range(vacation)])
arr_happiness_c = np.array([lst_happiness[i][2] for i in range(vacation)])
# DPのndarrayを作る。
dp_a = np.zeros(vacation, dtype=int)
dp_b = np.zeros(vacation, dtype=int)
dp_c = np.zeros(vacation, dtype=int)
# dpに初期値を入れる。
dp_a[0] = arr_happiness_a[0]
dp_b[0] = arr_happiness_b[0]
dp_c[0] = arr_happiness_c[0]
for i in range(1, vacation):
    dp_a[i] += max(dp_b[i - 1], dp_c[i - 1]) + arr_happiness_a[i]
    dp_b[i] += max(dp_a[i - 1], dp_c[i - 1]) + arr_happiness_b[i]
    dp_c[i] += max(dp_a[i - 1], dp_b[i - 1]) + arr_happiness_c[i]
ans = max(dp_a[vacation - 1], dp_b[vacation - 1], dp_c[vacation - 1])
print(ans)

-# 許容する再帰処理の回数を変更

-# 最大化問題なので0で初期化

-dp = [[0 for i in range(3)] for j in range(vacation + 1)]

-# dpの最大値を更新するための関数

-    # DPの値が既に更新されている場合はその値を返す

-        # 再帰の終了条件

-            res = chmax(res, rec(i - 1)[k] + lst_happiness[i - 1][k])

-            # 結果をメモする

+arr_happiness_a = np.array([lst_happiness[i][0] for i in range(vacation)])

+arr_happiness_b = np.array([lst_happiness[i][1] for i in range(vacation)])

+arr_happiness_c = np.array([lst_happiness[i][2] for i in range(vacation)])

+# dpに初期値を入れる。

+    dp_a[i] += max(dp_b[i - 1], dp_c[i - 1]) + arr_happiness_a[i]

+    dp_b[i] += max(dp_a[i - 1], dp_c[i - 1]) + arr_happiness_b[i]

+    dp_c[i] += max(dp_a[i - 1], dp_b[i - 1]) + arr_happiness_c[i]

+ans = max(dp_a[vacation - 1], dp_b[vacation - 1], dp_c[vacation - 1])


Input:
S=eval(input())

judge=True

for i in range(4):

  counter=int(0)

  for j in range(4):

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

      counter+=1

  if counter!=2:

    judge=False

if judge:

  print('Yes')

else:

  print('No')

s=eval(input())

output='Yes'

for i in range(4):

  counter=0

  for j in range(4):

    if s[i]==s[j]:

      counter+=1

  if counter!=2:

    output='No'

print(output)

S = eval(input())
judge = True
for i in range(4):
    counter = int(0)
    for j in range(4):
        if S[i] == S[j]:
            counter += 1
    if counter != 2:
        judge = False
if judge:
    print("Yes")
else:
    print("No")

s = eval(input())
output = "Yes"
for i in range(4):
    counter = 0
    for j in range(4):
        if s[i] == s[j]:
            counter += 1
    if counter != 2:
        output = "No"
print(output)

-S = eval(input())
-judge = True
+s = eval(input())
+output = "Yes"
-    counter = int(0)
+    counter = 0
-        if S[i] == S[j]:
+        if s[i] == s[j]:
-        judge = False
-if judge:
-    print("Yes")
-else:
-    print("No")
+        output = "No"
+print(output)


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

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

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

if k >= n:

    ans = 0

else:

    h.sort()

    tmp = 0

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

        tmp += h[i]

    ans = (sum(h) - tmp)

print(ans)

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

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

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

"""

if k >= n:

    ans = 0

else:

    h.sort()

    tmp = 0

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

        tmp += h[i]

    ans = (sum(h) - tmp)

print(ans)

"""

if k >= n:

    ans = 0

else:

    h.sort()

    ans = 0

    for i in range(n - k):

        ans += h[i]

print(ans)

# -*- coding: utf-8 -*-
n, k = list(map(int, input().split()))
h = [int(i) for i in input().split()]
if k >= n:
    ans = 0
else:
    h.sort()
    tmp = 0
    for i in range(n - k, n):
        tmp += h[i]
    ans = sum(h) - tmp
print(ans)

# -*- coding: utf-8 -*-
n, k = list(map(int, input().split()))
h = [int(i) for i in input().split()]
"""
if k >= n:
    ans = 0
else:
    h.sort()
    tmp = 0
    for i in range(n-k, n):
        tmp += h[i]
    ans = (sum(h) - tmp)
print(ans)
"""
if k >= n:
    ans = 0
else:
    h.sort()
    ans = 0
    for i in range(n - k):
        ans += h[i]
print(ans)

+"""
-    for i in range(n - k, n):
+    for i in range(n-k, n):
-    ans = sum(h) - tmp
+    ans = (sum(h) - tmp)
+"""
+if k >= n:
+    ans = 0
+else:
+    h.sort()
+    ans = 0
+    for i in range(n - k):
+        ans += h[i]
+print(ans)


Input:
import sys

stdin = sys.stdin

ri = lambda: int(rs())

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

rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

R, G, B, N = rl()

answer = 0

for r in range(N//R + 1):

    sum = r * R

    for g in range((N-sum)//G + 1):

        sum2 = sum + g * G

        if (N-sum2)%B == 0:

            answer += 1

print(answer)

#45

import sys

import numpy as np

stdin = sys.stdin

ri = lambda: int(rs())

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

rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

R, G, B, N = rl()

UP = 3000

A = np.zeros(UP+1, dtype=np.int32)

for r in range(UP+1):

    if r * R > UP:

        break

    A[r*R::G] += 1

answer = A[N::-B].sum()

print(answer)

#08

import sys

stdin = sys.stdin
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces
R, G, B, N = rl()
answer = 0
for r in range(N // R + 1):
    sum = r * R
    for g in range((N - sum) // G + 1):
        sum2 = sum + g * G
        if (N - sum2) % B == 0:
            answer += 1
print(answer)
# 45

import sys
import numpy as np

stdin = sys.stdin
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces
R, G, B, N = rl()
UP = 3000
A = np.zeros(UP + 1, dtype=np.int32)
for r in range(UP + 1):
    if r * R > UP:
        break
    A[r * R :: G] += 1
answer = A[N::-B].sum()
print(answer)
# 08

-    for g in range((N - sum) // G + 1):


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

dp=[list(map(int,input().split()))]

for _ in range(1,N):

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

    dp.append([a+max(dp[-1][1:]),b+max(dp[-1][0],dp[-1][2]),c+max(dp[-1][:2])])

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

N=int(eval(input()))

a0,b0,c0=list(map(int,input().split()))

for _ in range(1,N):

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

    a0,b0,c0=a+max(b0,c0),b+max(a0,c0),c+max(a0,b0)

print((max(a0,b0,c0)))

N = int(eval(input()))
dp = [list(map(int, input().split()))]
for _ in range(1, N):
    a, b, c = list(map(int, input().split()))
    dp.append([a + max(dp[-1][1:]), b + max(dp[-1][0], dp[-1][2]), c + max(dp[-1][:2])])
print((max(dp[-1])))

N = int(eval(input()))
a0, b0, c0 = list(map(int, input().split()))
for _ in range(1, N):
    a, b, c = list(map(int, input().split()))
    a0, b0, c0 = a + max(b0, c0), b + max(a0, c0), c + max(a0, b0)
print((max(a0, b0, c0)))

+a0, b0, c0 = list(map(int, input().split()))


Input:
import bisect as bs

def prime(m):

  N = list(range(1,m+1, 2))

  N[0] = 2

  for i in range(1, int(m**.5)+1):

    x = N[i]

    if x: N[i+x::x] = [0] * len(N[i+x::x])

  return [_f for _f in N if _f]

P = prime(10000)

x = [a for a,b in zip(P[1:],P[:-1]) if a-b==2]

while 1:

  n = eval(input())

  if n==0: break

  a = x[bs.bisect_right(x, n)-1]

  print(a-2, a)

import bisect as bs

def prime(m):

  N = list(range(1,m+1, 2))

  N[0] = 2

  n = len(N)

  for i in range(1, n):

    x = N[i]

    if x: N[i+x::x] = [0]*len(N[i+x::x])

  return [_f for _f in N if _f]

P = prime(10000)

x = []

a = P[0]

for b in P[1:]:

  if b-a==2: x.append(b)

  a=b

while 1:

  n = int(input())

  if n==0: break

  a = x[bs.bisect_right(x, n)-1]

  print(a-2, a)

import bisect as bs

def prime(m):
    N = list(range(1, m + 1, 2))
    N[0] = 2
    for i in range(1, int(m**0.5) + 1):
        x = N[i]
        if x:
            N[i + x :: x] = [0] * len(N[i + x :: x])
    return [_f for _f in N if _f]

P = prime(10000)
x = [a for a, b in zip(P[1:], P[:-1]) if a - b == 2]
while 1:
    n = eval(input())
    if n == 0:
        break
    a = x[bs.bisect_right(x, n) - 1]
    print(a - 2, a)

import bisect as bs

def prime(m):
    N = list(range(1, m + 1, 2))
    N[0] = 2
    n = len(N)
    for i in range(1, n):
        x = N[i]
        if x:
            N[i + x :: x] = [0] * len(N[i + x :: x])
    return [_f for _f in N if _f]

P = prime(10000)
x = []
a = P[0]
for b in P[1:]:
    if b - a == 2:
        x.append(b)
    a = b
while 1:
    n = int(input())
    if n == 0:
        break
    a = x[bs.bisect_right(x, n) - 1]
    print(a - 2, a)

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