Input:
import numpy as np

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

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

Amax=max(A)

n0 = 2**int(np.ceil(np.log2(2*Amax+1)))#Amax+1以上となる最小の2のべき乗数

Afre=np.zeros(n0).astype(int)#パワーの頻度(1~Amax+1)

for i in range(N):

    Afre[A[i]]+=1

#astype(int)は切り捨てなので，rintで四捨五入してから．

S = np.rint(np.fft.irfft(np.fft.rfft(Afre)*np.fft.rfft(Afre))).astype(int)

Scum =S.cumsum()#累積和

bd = N*N-M#上からM個を取り出したい

i=np.searchsorted(Scum,bd)#価値iを生み出せる組みがM個以上ある

#価値iが生み出せる選び方の余分なものを引きたい

remove=((Scum[-1]-Scum[i])-M)*i

ans=0

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

    ans+=S[j]*j

print((ans-remove))

import sys

input = sys.stdin.readline

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

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

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

"""

「1回の握手でX以上幸福度が上がるならば採用」としたときに，何個採用することになるか？

此の値が初めてM以上になったところのXを利用すれば答えが出る．

例えばM+2開催消してしまったら，2*X引けば良い

「X以上なら採用」は左手ごとに，右手を二分探索

"""

def main():

    import bisect

    mod=10**9+7

    N,M=MI()

    A=LI()

    A.sort()

    def ch(X):

        temp=0

        for i in range(N):#左手

            l=A[i]

            t=X-l

            num=bisect.bisect_left(A,t)

            temp+=N-num

        return temp>=M

    ok=0

    ng=2*(10**5) + 1

    while ng - ok > 1:

        med=(ok+ng)//2

        if ch(med):

            ok=med

        else:

            ng=med

    # 総和の計算パート，累積和で

    S=[0]*(N+1)

    for i in range(N):

        S[i+1]=S[i]+A[i]

    ans=0

    temp=0

    X=ok

    for i in range(N):#左手

        l=A[i]

        t=X-l

        num=bisect.bisect_left(A,t)

        temp+=N-num

        ans+=S[-1] - S[num] + (N-num)*l

        # print(i,num,S[-1]-S[num],(N-num)*l)

    if temp>M:

        ans-=X*(temp-M)

    print(ans)

main()

import numpy as np

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
Amax = max(A)
n0 = 2 ** int(np.ceil(np.log2(2 * Amax + 1)))  # Amax+1以上となる最小の2のべき乗数
Afre = np.zeros(n0).astype(int)  # パワーの頻度(1~Amax+1)
for i in range(N):
    Afre[A[i]] += 1
# astype(int)は切り捨てなので，rintで四捨五入してから．
S = np.rint(np.fft.irfft(np.fft.rfft(Afre) * np.fft.rfft(Afre))).astype(int)
Scum = S.cumsum()  # 累積和
bd = N * N - M  # 上からM個を取り出したい
i = np.searchsorted(Scum, bd)  # 価値iを生み出せる組みがM個以上ある
# 価値iが生み出せる選び方の余分なものを引きたい
remove = ((Scum[-1] - Scum[i]) - M) * i
ans = 0
for j in range(i + 1, n0):
    ans += S[j] * j
print((ans - remove))

import sys

input = sys.stdin.readline

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

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

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

"""
「1回の握手でX以上幸福度が上がるならば採用」としたときに，何個採用することになるか？
此の値が初めてM以上になったところのXを利用すれば答えが出る．
例えばM+2開催消してしまったら，2*X引けば良い
「X以上なら採用」は左手ごとに，右手を二分探索
"""

def main():
    import bisect

    mod = 10**9 + 7
    N, M = MI()
    A = LI()
    A.sort()

    def ch(X):
        temp = 0
        for i in range(N):  # 左手
            l = A[i]
            t = X - l
            num = bisect.bisect_left(A, t)
            temp += N - num
        return temp >= M

    ok = 0
    ng = 2 * (10**5) + 1
    while ng - ok > 1:
        med = (ok + ng) // 2
        if ch(med):
            ok = med
        else:
            ng = med
    # 総和の計算パート，累積和で
    S = [0] * (N + 1)
    for i in range(N):
        S[i + 1] = S[i] + A[i]
    ans = 0
    temp = 0
    X = ok
    for i in range(N):  # 左手
        l = A[i]
        t = X - l
        num = bisect.bisect_left(A, t)
        temp += N - num
        ans += S[-1] - S[num] + (N - num) * l
        # print(i,num,S[-1]-S[num],(N-num)*l)
    if temp > M:
        ans -= X * (temp - M)
    print(ans)

main()

-n0 = 2 ** int(np.ceil(np.log2(2 * Amax + 1)))  # Amax+1以上となる最小の2のべき乗数

-Afre = np.zeros(n0).astype(int)  # パワーの頻度(1~Amax+1)

-# astype(int)は切り捨てなので，rintで四捨五入してから．

-S = np.rint(np.fft.irfft(np.fft.rfft(Afre) * np.fft.rfft(Afre))).astype(int)

-bd = N * N - M  # 上からM個を取り出したい

-i = np.searchsorted(Scum, bd)  # 価値iを生み出せる組みがM個以上ある

-# 価値iが生み出せる選び方の余分なものを引きたい

-remove = ((Scum[-1] - Scum[i]) - M) * i

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

+「1回の握手でX以上幸福度が上がるならば採用」としたときに，何個採用することになるか？

+此の値が初めてM以上になったところのXを利用すれば答えが出る．

+例えばM+2開催消してしまったら，2*X引けば良い

+「X以上なら採用」は左手ごとに，右手を二分探索

+            num = bisect.bisect_left(A, t)

+    # 総和の計算パート，累積和で

+        # print(i,num,S[-1]-S[num],(N-num)*l)


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

s= list(eval(input()))

ans = []

tmp = s[0]

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

    print((1))

    exit()

for i in range(1, n):

    if s[i] == tmp:

        continue

    else:

        ans.append(tmp)

        tmp = s[i]

if ans[-1] == s[-1]:

    print((len(ans)))

else:

    ans.append(s[-1])

    print((len(ans)))

n = int(eval(input()))

s = eval(input())

ans = 1

for i in range(n-1):

  ans += (s[i] != s[i+1])

print(ans)

n = int(eval(input()))
s = list(eval(input()))
ans = []
tmp = s[0]
if len(set(s)) == 1:
    print((1))
    exit()
for i in range(1, n):
    if s[i] == tmp:
        continue
    else:
        ans.append(tmp)
        tmp = s[i]
if ans[-1] == s[-1]:
    print((len(ans)))
else:
    ans.append(s[-1])
    print((len(ans)))

n = int(eval(input()))
s = eval(input())
ans = 1
for i in range(n - 1):
    ans += s[i] != s[i + 1]
print(ans)

-s = list(eval(input()))
-ans = []
-tmp = s[0]
-if len(set(s)) == 1:
-    print((1))
-    exit()
-for i in range(1, n):
-    if s[i] == tmp:
-        continue
-    else:
-        ans.append(tmp)
-        tmp = s[i]
-if ans[-1] == s[-1]:
-    print((len(ans)))
-else:
-    ans.append(s[-1])
-    print((len(ans)))
+s = eval(input())
+ans = 1
+for i in range(n - 1):
+    ans += s[i] != s[i + 1]
+print(ans)


Input:
while True:

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

    if n == x == 0:

        break

    count = 0

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

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

            for c in range(b+1, n+1):

                if (a + b + c) == x:

                    count += 1

    print(count)

while True:

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

    if n == x == 0:

        break

    count = 0

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

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

            for c in range(b+1, n+1):

                if (a + b + c) == x:

                    count += 1

                elif (a + b + c) > x:

                    break

    print(count)

while True:
    (n, x) = [int(i) for i in input().split()]
    if n == x == 0:
        break
    count = 0
    for a in range(1, n + 1):
        for b in range(a + 1, n + 1):
            for c in range(b + 1, n + 1):
                if (a + b + c) == x:
                    count += 1
    print(count)

while True:
    (n, x) = [int(i) for i in input().split()]
    if n == x == 0:
        break
    count = 0
    for a in range(1, n + 1):
        for b in range(a + 1, n + 1):
            for c in range(b + 1, n + 1):
                if (a + b + c) == x:
                    count += 1
                elif (a + b + c) > x:
                    break
    print(count)

+                elif (a + b + c) > x:
+                    break


Input:
def main():

    from string import ascii_lowercase

    dic = {i: s for i, s in enumerate(ascii_lowercase)}

    N = int(input())

    ans = []

    def dfs(s, mx):

        if len(s) == N:

            ans.append(s)

            return

        else:

            for i in range(mx+2):

                mx = max(mx, i)

                dfs(s + dic[i], mx)

    dfs("a", 0)

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

if __name__ == '__main__':

    main()

def main():

    from string import ascii_lowercase

    N = int(eval(input()))

    ascii_dic = {i: a for i, a in enumerate(ascii_lowercase)}

    ascii_rdic = {a: i for i, a in enumerate(ascii_lowercase)}

    # ans = []

    def dfs(A):

        if len(A) == N:

            # ans.append("".join(A))

            print(("".join(A)))

            return

        if not A:

            dfs(["a"])

        else:

            s = max(ascii_rdic[a] for a in A)

            for i in range(s+2):

                dfs(A + [ascii_dic[i]])

    dfs([])

    # for i in range(len(ans)):

    #     for j in range(i+1, len(ans)):

    #         S = ans[i]

    #         T = ans[j]

    #         same = True  # 同型である

    #         for k in range(N):

    #             for m in range(k, N):

    #                 if not ((S[k] == S[m] and T[k] == T[m]) or

    #                         (S[k] != S[m] and T[k] != T[m])):

    #                     same = False

    #         if same:  # 同型である

    #             print(S, T)

if __name__ == '__main__':

    main()

def main():
    from string import ascii_lowercase

    dic = {i: s for i, s in enumerate(ascii_lowercase)}
    N = int(input())
    ans = []

    def dfs(s, mx):
        if len(s) == N:
            ans.append(s)
            return
        else:
            for i in range(mx + 2):
                mx = max(mx, i)
                dfs(s + dic[i], mx)

    dfs("a", 0)
    print(*ans, sep="\n")

if __name__ == "__main__":
    main()

def main():
    from string import ascii_lowercase

    N = int(eval(input()))
    ascii_dic = {i: a for i, a in enumerate(ascii_lowercase)}
    ascii_rdic = {a: i for i, a in enumerate(ascii_lowercase)}
    # ans = []
    def dfs(A):
        if len(A) == N:
            # ans.append("".join(A))
            print(("".join(A)))
            return
        if not A:
            dfs(["a"])
        else:
            s = max(ascii_rdic[a] for a in A)
            for i in range(s + 2):
                dfs(A + [ascii_dic[i]])

    dfs([])
    # for i in range(len(ans)):
    #     for j in range(i+1, len(ans)):
    #         S = ans[i]
    #         T = ans[j]
    #         same = True  # 同型である
    #         for k in range(N):
    #             for m in range(k, N):
    #                 if not ((S[k] == S[m] and T[k] == T[m]) or
    #                         (S[k] != S[m] and T[k] != T[m])):
    #                     same = False
    #         if same:  # 同型である
    #             print(S, T)

if __name__ == "__main__":
    main()

-    dic = {i: s for i, s in enumerate(ascii_lowercase)}

+    ascii_dic = {i: a for i, a in enumerate(ascii_lowercase)}

+    ascii_rdic = {a: i for i, a in enumerate(ascii_lowercase)}

+            s = max(ascii_rdic[a] for a in A)

+                dfs(A + [ascii_dic[i]])

+    #     for j in range(i+1, len(ans)):

+    #             for m in range(k, N):

+    #                 if not ((S[k] == S[m] and T[k] == T[m]) or


Input:
import math

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

if(N < B):

  print((math.floor(A * N / B) - A * math.floor(N / B)))

else:

  print((math.floor(A * (B-1) / B) - A * math.floor((B-1) / B)))

import math

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

x = min(N, B-1)

print((math.floor(A * x / B) - A * math.floor(x / B)))

import math

A, B, N = list(map(int, input().split()))
if N < B:
    print((math.floor(A * N / B) - A * math.floor(N / B)))
else:
    print((math.floor(A * (B - 1) / B) - A * math.floor((B - 1) / B)))

import math

A, B, N = list(map(int, input().split()))
x = min(N, B - 1)
print((math.floor(A * x / B) - A * math.floor(x / B)))

-    print((math.floor(A * N / B) - A * math.floor(N / B)))

-    print((math.floor(A * (B - 1) / B) - A * math.floor((B - 1) / B)))

+print((math.floor(A * x / B) - A * math.floor(x / B)))


Input:
def slove():

    import sys

    input = sys.stdin.readline

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

    lr = [list(map(int, input().rstrip('\n').split())) for _ in range(m)]

    a = [0] * (n + 2)

    for l, r in lr:

        a[l] += 1

        a[r + 1] -= 1

    t = 0

    cnt = 0

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

        t += a[i]

        if t == m:

            cnt += 1

    print(cnt)

if __name__ == '__main__':

    slove()

def slove():

    import sys

    input = sys.stdin.readline

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

    x = [0] * (n + 2)

    for i in range(m):

        l, r = list(map(int, input().rstrip('\n').split()))

        x[l] += 1

        x[r+1] -= 1

    t = 0

    cnt = 0

    for i in range(n + 2):

        t += x[i]

        if t == m:

            cnt += 1

    print(cnt)

if __name__ == '__main__':

    slove()

def slove():
    import sys

    input = sys.stdin.readline
    n, m = list(map(int, input().rstrip("\n").split()))
    lr = [list(map(int, input().rstrip("\n").split())) for _ in range(m)]
    a = [0] * (n + 2)
    for l, r in lr:
        a[l] += 1
        a[r + 1] -= 1
    t = 0
    cnt = 0
    for i in range(1, n + 1):
        t += a[i]
        if t == m:
            cnt += 1
    print(cnt)

if __name__ == "__main__":
    slove()

def slove():
    import sys

    input = sys.stdin.readline
    n, m = list(map(int, input().rstrip("\n").split()))
    x = [0] * (n + 2)
    for i in range(m):
        l, r = list(map(int, input().rstrip("\n").split()))
        x[l] += 1
        x[r + 1] -= 1
    t = 0
    cnt = 0
    for i in range(n + 2):
        t += x[i]
        if t == m:
            cnt += 1
    print(cnt)

if __name__ == "__main__":
    slove()

-    lr = [list(map(int, input().rstrip("\n").split())) for _ in range(m)]

+        l, r = list(map(int, input().rstrip("\n").split()))


Input: print((b' 3    '[int(eval(input()))%14]))

print((b" 3    "[int(eval(input())) % 14]))

print(ord(" 3    "[eval(input()) % 14]))

+print(ord(" 3    "[eval(input()) % 14]))


Input:
import sys

input = sys.stdin.readline

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

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

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

def main():

    mod=10**9+7

    N,X,Y=MI()

    X-=1

    Y-=1

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

    import heapq

    class Dijkstra():

        """

        ・有向 / 無向は問わない(無向の場合は，逆向きの辺もたす)

        ・負のコストがない場合のみ

        ・計算量はO(E log|V|)

        ・heapを使うことで頂点を走査する必要がなくなる（代わりに，距離更新したものは確定でなくともqueに入れておく）

        """

        #最短のpathをたす

        class Edge():

            #重み付き有向辺

            def __init__(self, _to, _cost):

                self.to =_to

                self.cost = _cost

        def __init__(self, V):

            #引数Vは頂点数

            self.G = [[] for _ in range(V)] #隣接リストG[u][i]が頂点uのi番目の辺

            self. _E = 0 #辺の数

            self._V = V #頂点数

        #proparty - 辺の数

        def E(self):

            return self._E

        #proparty - 頂点数

        def V(self):

            return self._V

        def add(self, _from, _to, _cost):

            #2頂点と辺のコストを追加

            self.G[_from].append(self.Edge(_to,_cost))

            self._E +=1

        def add2(self, _from, _to, _cost):

            #2頂点と辺のコスト（無向）を追加

            self.G[_from].append(self.Edge(_to, _cost))

            self.G[_to].append(self.Edge(_from, _cost))

            self._E +=1

        def shortest_path(self,s):

            #始点sから頂点iまでの最短経路長のリストを返す

            que = [] #priority queue

            d = [float("inf")] * self.V()

            prev = [None]*self.V() #prev[j]は，sからjへ最短経路で行くときのjの一つ前の場所

            d[s] = 0

            heapq.heappush(que,(0,s)) #始点の距離と頂点番号をヒープに追加

            while len(que)!=0:

                #キューに格納されてある中で一番コストが小さい頂点を取り出す

                cost,v = heapq.heappop(que)

                #キューに格納された最短経路長候補がdの距離よりも大きい場合に処理をスキップ

                if d[v] < cost:

                    continue

                #頂点vに隣接する各頂点iに対して，vを経由した場合の距離を計算して，これがd[i]よりも小さい場合に更新

                for i in range(len(self.G[v])):

                    e = self.G[v][i] #vのi個目の隣接辺

                    if d[e.to] > d[v] + e.cost:

                        d[e.to] = d[v] + e.cost #更新

                        prev[e.to] = v

                        heapq.heappush(que,(d[e.to],e.to)) #queに新たな最短経路長候補を追加

            return d

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

    djk = Dijkstra(N)

    for i in range(N-1):

        djk.add2(i,i+1,1)

    djk.add2(X,Y,1)

    ans=[0]*(N+1)

    for i in range(N):

        d=djk.shortest_path(i)

        for j in range(N):

            ans[d[j]]+=1

    for i in range(N-1):

        print((ans[i+1]//2))

main()

import sys

input = sys.stdin.readline

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

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

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

def main():

    mod=10**9+7

    N,X,Y=MI()

    X-=1

    Y-=1

    ans=[0]*N

    for i in range(N):

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

            d=min(j-i,abs(X-i)+1+abs(Y-j))

            ans[d-1]+=1

    for i in range(N-1):

        print((ans[i]))

main()

import sys

input = sys.stdin.readline

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

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

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

def main():
    mod = 10**9 + 7
    N, X, Y = MI()
    X -= 1
    Y -= 1
    ##########################################
    import heapq

    class Dijkstra:
        """
        ・有向 / 無向は問わない(無向の場合は，逆向きの辺もたす)
        ・負のコストがない場合のみ
        ・計算量はO(E log|V|)
        ・heapを使うことで頂点を走査する必要がなくなる（代わりに，距離更新したものは確定でなくともqueに入れておく）
        """

        # 最短のpathをたす
        class Edge:
            # 重み付き有向辺
            def __init__(self, _to, _cost):
                self.to = _to
                self.cost = _cost

        def __init__(self, V):
            # 引数Vは頂点数
            self.G = [[] for _ in range(V)]  # 隣接リストG[u][i]が頂点uのi番目の辺
            self._E = 0  # 辺の数
            self._V = V  # 頂点数

        # proparty - 辺の数
        def E(self):
            return self._E

        # proparty - 頂点数
        def V(self):
            return self._V

        def add(self, _from, _to, _cost):
            # 2頂点と辺のコストを追加
            self.G[_from].append(self.Edge(_to, _cost))
            self._E += 1

        def add2(self, _from, _to, _cost):
            # 2頂点と辺のコスト（無向）を追加
            self.G[_from].append(self.Edge(_to, _cost))
            self.G[_to].append(self.Edge(_from, _cost))
            self._E += 1

        def shortest_path(self, s):
            # 始点sから頂点iまでの最短経路長のリストを返す
            que = []  # priority queue
            d = [float("inf")] * self.V()
            prev = [None] * self.V()  # prev[j]は，sからjへ最短経路で行くときのjの一つ前の場所
            d[s] = 0
            heapq.heappush(que, (0, s))  # 始点の距離と頂点番号をヒープに追加
            while len(que) != 0:
                # キューに格納されてある中で一番コストが小さい頂点を取り出す
                cost, v = heapq.heappop(que)
                # キューに格納された最短経路長候補がdの距離よりも大きい場合に処理をスキップ
                if d[v] < cost:
                    continue
                # 頂点vに隣接する各頂点iに対して，vを経由した場合の距離を計算して，これがd[i]よりも小さい場合に更新
                for i in range(len(self.G[v])):
                    e = self.G[v][i]  # vのi個目の隣接辺
                    if d[e.to] > d[v] + e.cost:
                        d[e.to] = d[v] + e.cost  # 更新
                        prev[e.to] = v
                        heapq.heappush(que, (d[e.to], e.to))  # queに新たな最短経路長候補を追加
            return d

    ########################
    djk = Dijkstra(N)
    for i in range(N - 1):
        djk.add2(i, i + 1, 1)
    djk.add2(X, Y, 1)
    ans = [0] * (N + 1)
    for i in range(N):
        d = djk.shortest_path(i)
        for j in range(N):
            ans[d[j]] += 1
    for i in range(N - 1):
        print((ans[i + 1] // 2))

main()

import sys

input = sys.stdin.readline

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

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

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

def main():
    mod = 10**9 + 7
    N, X, Y = MI()
    X -= 1
    Y -= 1
    ans = [0] * N
    for i in range(N):
        for j in range(i + 1, N):
            d = min(j - i, abs(X - i) + 1 + abs(Y - j))
            ans[d - 1] += 1
    for i in range(N - 1):
        print((ans[i]))

main()

-        ・有向 / 無向は問わない(無向の場合は，逆向きの辺もたす)

-        ・負のコストがない場合のみ

-        ・heapを使うことで頂点を走査する必要がなくなる（代わりに，距離更新したものは確定でなくともqueに入れておく）

-        # 最短のpathをたす

-            # 重み付き有向辺

-            def __init__(self, _to, _cost):

-            # 引数Vは頂点数

-            self.G = [[] for _ in range(V)]  # 隣接リストG[u][i]が頂点uのi番目の辺

-        def add(self, _from, _to, _cost):

-            # 2頂点と辺のコストを追加

-            self.G[_from].append(self.Edge(_to, _cost))

-        def add2(self, _from, _to, _cost):

-            # 2頂点と辺のコスト（無向）を追加

-            self.G[_to].append(self.Edge(_from, _cost))

-            # 始点sから頂点iまでの最短経路長のリストを返す

-            d = [float("inf")] * self.V()

-            prev = [None] * self.V()  # prev[j]は，sからjへ最短経路で行くときのjの一つ前の場所

-            heapq.heappush(que, (0, s))  # 始点の距離と頂点番号をヒープに追加

-                # キューに格納されてある中で一番コストが小さい頂点を取り出す

-                cost, v = heapq.heappop(que)

-                # キューに格納された最短経路長候補がdの距離よりも大きい場合に処理をスキップ

-                # 頂点vに隣接する各頂点iに対して，vを経由した場合の距離を計算して，これがd[i]よりも小さい場合に更新

-                for i in range(len(self.G[v])):

-                    e = self.G[v][i]  # vのi個目の隣接辺

-                    if d[e.to] > d[v] + e.cost:

-                        d[e.to] = d[v] + e.cost  # 更新

-                        heapq.heappush(que, (d[e.to], e.to))  # queに新たな最短経路長候補を追加

+            d = min(j - i, abs(X - i) + 1 + abs(Y - j))


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

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

ma = max(A)

Er = [0 for _ in range(ma + 5)]

for i in range(N):

    temp = A[i]

    if Er[temp] != 2:

        a = 0

        while(1):

            a += 1

            tt = a * temp

            if tt >= ma + 5:

                break

            Er[tt] += 1

ans = 0

for i in range(N):

    temp = A[i]

    if Er[temp] == 1:  ans += 1

print(ans)

N = int(eval(input()))

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

ma = max(A)

l = [0 for _ in range(ma + 10)]

for i in range(N):

    temp = A[i]

    while(temp <= ma + 5):

        l[temp] += 1

        temp += A[i]

ans = 0

for i in range(N):

    if l[A[i]] == 1:  ans += 1

print(ans)

N = int(eval(input()))
A = list(map(int, input().split()))
ma = max(A)
Er = [0 for _ in range(ma + 5)]
for i in range(N):
    temp = A[i]
    if Er[temp] != 2:
        a = 0
        while 1:
            a += 1
            tt = a * temp
            if tt >= ma + 5:
                break
            Er[tt] += 1
ans = 0
for i in range(N):
    temp = A[i]
    if Er[temp] == 1:
        ans += 1
print(ans)

N = int(eval(input()))
A = list(map(int, input().split()))
ma = max(A)
l = [0 for _ in range(ma + 10)]
for i in range(N):
    temp = A[i]
    while temp <= ma + 5:
        l[temp] += 1
        temp += A[i]
ans = 0
for i in range(N):
    if l[A[i]] == 1:
        ans += 1
print(ans)

-Er = [0 for _ in range(ma + 5)]
+l = [0 for _ in range(ma + 10)]
-    if Er[temp] != 2:
-        a = 0
-        while 1:
-            a += 1
-            tt = a * temp
-            if tt >= ma + 5:
-                break
-            Er[tt] += 1
+    while temp <= ma + 5:
+        l[temp] += 1
+        temp += A[i]
-    temp = A[i]
-    if Er[temp] == 1:
+    if l[A[i]] == 1:


Input: s=eval(input());print((min(abs(int('0'+s[i:i+3])-753)for i in range(9))))

s=eval(input());print((min(abs(eval(s[i:i+3]+'-753'))for i in range(9))))

s = eval(input())
print((min(abs(int("0" + s[i : i + 3]) - 753) for i in range(9))))

s = eval(input())
print((min(abs(eval(s[i : i + 3] + "-753")) for i in range(9))))

-print((min(abs(int("0" + s[i : i + 3]) - 753) for i in range(9))))

+print((min(abs(eval(s[i : i + 3] + "-753")) for i in range(9))))


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

a=0

b=n

for i in range(m):

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

  a = max(a, l)

  b = min(b, r)

if b-a+1 >= 0:

  print((b-a+1))

else:

  print((0))

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

l = 1

r = 10**5

for _ in range(m):

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

  l = max(l, l_)

  r = min(r, r_)

if r>=l:

  print((r-l+1))

else:

  print((0))

n, m = list(map(int, input().split()))
a = 0
b = n
for i in range(m):
    l, r = list(map(int, input().split()))
    a = max(a, l)
    b = min(b, r)
if b - a + 1 >= 0:
    print((b - a + 1))
else:
    print((0))

n, m = list(map(int, input().split()))
l = 1
r = 10**5
for _ in range(m):
    l_, r_ = list(map(int, input().split()))
    l = max(l, l_)
    r = min(r, r_)
if r >= l:
    print((r - l + 1))
else:
    print((0))

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

+    l_, r_ = list(map(int, input().split()))


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

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

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

total = 0

count = 0

flag = n-1

for i in range(n):

    total += a[i]

    if total > k:

        total -= a[i]

        flag = i-1

        break

    count += 1

ans = count

for i in range(m):

    if b[i] > k:

        break

    total += b[i]

    count += 1

    while total > k:

        if flag == -1:

            break

        else:

            total -= a[flag]

            flag -= 1

            count -= 1

    if total > k:

        break

    ans = max(ans, count)

total = 0

count = 0

flag = m-1

for i in range(m):

    total += b[i]

    if total > k:

        total -= b[i]

        flag = i-1

        break

    count += 1

for i in range(n):

    if a[i] > k:

        break

    total += a[i]

    count += 1

    while total > k:

        if flag == -1:

            break

        else:

            total -= b[flag]

            flag -= 1

            count -= 1

    if total > k:

        break

    ans = max(ans, count)

print(ans)

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

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

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

total = 0

count = 0

flag = n-1

for i in range(n):

    total += a[i]

    if total > k:

        total -= a[i]

        flag = i-1

        break

    count += 1

ans = count

for i in range(m):

    if b[i] > k:

        break

    total += b[i]

    count += 1

    while total > k:

        if flag == -1:

            break

        else:

            total -= a[flag]

            flag -= 1

            count -= 1

    if total > k:

        break

    ans = max(ans, count)

print(ans)

n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
total = 0
count = 0
flag = n - 1
for i in range(n):
    total += a[i]
    if total > k:
        total -= a[i]
        flag = i - 1
        break
    count += 1
ans = count
for i in range(m):
    if b[i] > k:
        break
    total += b[i]
    count += 1
    while total > k:
        if flag == -1:
            break
        else:
            total -= a[flag]
            flag -= 1
            count -= 1
    if total > k:
        break
    ans = max(ans, count)
total = 0
count = 0
flag = m - 1
for i in range(m):
    total += b[i]
    if total > k:
        total -= b[i]
        flag = i - 1
        break
    count += 1
for i in range(n):
    if a[i] > k:
        break
    total += a[i]
    count += 1
    while total > k:
        if flag == -1:
            break
        else:
            total -= b[flag]
            flag -= 1
            count -= 1
    if total > k:
        break
    ans = max(ans, count)
print(ans)

n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
total = 0
count = 0
flag = n - 1
for i in range(n):
    total += a[i]
    if total > k:
        total -= a[i]
        flag = i - 1
        break
    count += 1
ans = count
for i in range(m):
    if b[i] > k:
        break
    total += b[i]
    count += 1
    while total > k:
        if flag == -1:
            break
        else:
            total -= a[flag]
            flag -= 1
            count -= 1
    if total > k:
        break
    ans = max(ans, count)
print(ans)

-total = 0
-count = 0
-flag = m - 1
-for i in range(m):
-    total += b[i]
-    if total > k:
-        total -= b[i]
-        flag = i - 1
-        break
-    count += 1
-for i in range(n):
-    if a[i] > k:
-        break
-    total += a[i]
-    count += 1
-    while total > k:
-        if flag == -1:
-            break
-        else:
-            total -= b[flag]
-            flag -= 1
-            count -= 1
-    if total > k:
-        break
-    ans = max(ans, count)


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

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

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

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

arrayP.sort(reverse=True)

arrayQ.sort(reverse=True)

arrayR.sort(reverse=True)

arrayAns = []

for i in range(x):

    arrayAns.append(int(arrayP[i]))

for i in range(y):

    arrayAns.append(int(arrayQ[i]))

arrayAns.sort()

for i in range(min(len(arrayR), len(arrayAns))):

    if arrayAns[i] <= int(arrayR[i]):

        arrayAns[i] = int(arrayR[i])

    else:

        break

print((sum(arrayAns)))

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

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

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

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

p.sort(reverse=True)

q.sort(reverse=True)

hoge=p[:X]+q[:Y]+r

hoge.sort(reverse=True)

print((sum(hoge[:X+Y])))

X, Y, A, B, C = list(map(int, input().split()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
hoge = p[:X] + q[:Y] + r
hoge.sort(reverse=True)
print((sum(hoge[: X + Y])))

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

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

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

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

-for i in range(min(len(arrayR), len(arrayAns))):

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


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

"""

B - Frog 2

https://atcoder.jp/contests/dp/tasks/dp_b

AC

"""

import sys

from sys import stdin

def solve(ashiba, N, K):

    dp = [float('inf')] * N

    dp[0] = 0

    for i in range(1, len(ashiba)):

        paths = [dp[j]+abs(ashiba[j]-ashiba[i]) for j in range(max(0, i-K), i)]

        dp[i] = min(paths)

    return dp[-1]

def main(args):

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

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

    ans = solve(ashiba, N, K)

    print(ans)

if __name__ == '__main__':

    main(sys.argv[1:])

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

"""

"""

def chmin(i, j):

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

    if a > b:

        dp[i+j] = b

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

h = list(input().split())

h = [int(i) for i in h]

dp = [10**10]*n

dp[0] = 0

for i in range(0, n):

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

        if i+j < n:

            chmin(i, j)

print((dp[n-1]))

# -*- coding: utf-8 -*-
"""
B - Frog 2
https://atcoder.jp/contests/dp/tasks/dp_b
AC
"""
import sys
from sys import stdin

def solve(ashiba, N, K):
    dp = [float("inf")] * N
    dp[0] = 0
    for i in range(1, len(ashiba)):
        paths = [dp[j] + abs(ashiba[j] - ashiba[i]) for j in range(max(0, i - K), i)]
        dp[i] = min(paths)
    return dp[-1]

def main(args):
    N, K = list(map(int, input().split()))
    ashiba = [int(i) for i in input().split()]
    ans = solve(ashiba, N, K)
    print(ans)

if __name__ == "__main__":
    main(sys.argv[1:])

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

def chmin(i, j):
    a, b = dp[i + j], dp[i] + abs(h[i] - h[i + j])
    if a > b:
        dp[i + j] = b

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

-        paths = [dp[j] + abs(ashiba[j] - ashiba[i]) for j in range(max(0, i - K), i)]

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

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

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


Input:
# coding: utf-8

import sys

import bisect

"""Template"""

class IP:

    """

    入力を取得するクラス

    """

    def __init__(self):

        self.input = sys.stdin.readline

    def I(self):

        """

        1文字の取得に使います

        :return: 数

        """

        return int(eval(input()))

    def IL(self):

        """

        1行を空白で区切りリストにします(int

        :return: リスト

        """

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

    def SL(self):

        """

        1行の文字列を空白区切りでリストにします

        :return: リスト

        """

        return list(map(str, self.input().split()))

    def ILS(self, n):

        """

        1列丸々取得します(int

        :param n: 行数

        :return: リスト

        """

        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):

        """

        1列丸々取得します（str

        :param n: 行数

        :return: リスト

        """

        return [self.input() for _ in range(n)]

class Idea:

    def __init__(self):

        pass

    def HF(self, p):

        """

        Half enumeration

        半分全列挙です

        pの要素の和の組み合わせを作ります。

        ソート、重複削除行います

        :param p: list : 元となるリスト

        :return: list : 組み合わせられた和のリスト

        """

        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):

        """

        bit_full_search2

        bit全探索の改良版

        全探索させたら2進数のリストと10進数のリストを返す

        :return: list２つ : １個目 2進数(16桁)  2個目 10進数で合計

        """

        # 参考

        # https://blog.rossywhite.com/2018/08/06/bit-search/

        # https://atcoder.jp/contests/abc105/submissions/4088632

        value = []

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

            output = []

            for j in range(len(a)):

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

                    """右からj+1番目のiが1かどうか判定"""

                    # output.append(a[j])

                    output.append(a[j])

            value.append([format(i, 'b').zfill(16), sum(output)])

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

        bin = [value[k][0] for k in range(len(value))]

        val = [value[k][1] for k in range(len(value))]

        return bin, val

"""ここからメインコード"""

def main():

    # 1文字に省略

    r, e = range, enumerate

    ip = IP()

    id = Idea()

    """コピーコードです。https://atcoder.jp/contests/abc105/submissions/4088632

    こちらを参考にテストを行っています。"""

    n = ip.I()

    # それぞれ半分全列挙

    list1 = [(-2) ** i for i in r(16)]

    list2 = [(-2) ** (i + 16) for i in r(16)]

    list1_bin, list1_val = id.Bfs2(list1)

    list2_bin, list2_val = id.Bfs2(list2)

    # 2分探索

    ans = 0

    for i in r(len(list1_val)):

        j = bisect.bisect_left(list2_val, n - list1_val[i])

        if j < len(list2_val) and list1_val[i] + list2_val[j] == n:

            ans = list2_bin[j] + list1_bin[i]

            break

    print((int(ans)))

main()

# coding: utf-8

import sys

import bisect

"""Template"""

class IP:

    """

    入力を取得するクラス

    """

    def __init__(self):

        self.input = sys.stdin.readline

    def I(self):

        """

        1文字の取得に使います

        :return: 数

        """

        return int(eval(input()))

    def IL(self):

        """

        1行を空白で区切りリストにします(int

        :return: リスト

        """

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

    def SL(self):

        """

        1行の文字列を空白区切りでリストにします

        :return: リスト

        """

        return list(map(str, self.input().split()))

    def ILS(self, n):

        """

        1列丸々取得します(int

        :param n: 行数

        :return: リスト

        """

        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):

        """

        1列丸々取得します（str

        :param n: 行数

        :return: リスト

        """

        return [self.input() for _ in range(n)]

class Idea:

    def __init__(self):

        pass

    def HF(self, p):

        """

        Half enumeration

        半分全列挙です

        pの要素の和の組み合わせを作ります。

        ソート、重複削除行います

        :param p: list : 元となるリスト

        :return: list : 組み合わせられた和のリスト

        """

        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):

        """

        bit_full_search2

        bit全探索の改良版

        全探索させたら2進数のリストと10進数のリストを返す

        :return: list２つ : １個目 2進数(16桁)  2個目 10進数で合計

        """

        # 参考

        # https://blog.rossywhite.com/2018/08/06/bit-search/

        # https://atcoder.jp/contests/abc105/submissions/4088632

        value = []

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

            output = []

            for j in range(len(a)):

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

                    """右からj+1番目のiが1かどうか判定"""

                    # output.append(a[j])

                    output.append(a[j])

            value.append([format(i, 'b').zfill(16), sum(output)])

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

        bin = [value[k][0] for k in range(len(value))]

        val = [value[k][1] for k in range(len(value))]

        return bin, val

"""ここからメインコード"""

def main():

    """クラス呼び出し等行うよ"""

    # 1文字に省略

    r, e = range, enumerate

    ip = IP()

    id = Idea()

    """この下から書いてね"""

    """コピーコードです。"""

    n = ip.I()

    s = ''

    while True:

        r = n % (-2)

        n //= -2

        if r < 0:

            r += 2

            n += 1

        s += str(r)

        if n == 0: break

    print((s[::-1]))

main()

# coding: utf-8
import sys
import bisect

"""Template"""

class IP:
    """
    入力を取得するクラス
    """

    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: 数
        """
        return int(eval(input()))

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数で合計
        """
        # 参考
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        # https://atcoder.jp/contests/abc105/submissions/4088632
        value = []
        for i in range(1 << len(a)):
            output = []
            for j in range(len(a)):
                if ((i >> j) & 1) == 1:
                    """右からj+1番目のiが1かどうか判定"""
                    # output.append(a[j])
                    output.append(a[j])
            value.append([format(i, "b").zfill(16), sum(output)])
        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

"""ここからメインコード"""

def main():
    # 1文字に省略
    r, e = range, enumerate
    ip = IP()
    id = Idea()
    """コピーコードです。https://atcoder.jp/contests/abc105/submissions/4088632
    こちらを参考にテストを行っています。"""
    n = ip.I()
    # それぞれ半分全列挙
    list1 = [(-2) ** i for i in r(16)]
    list2 = [(-2) ** (i + 16) for i in r(16)]
    list1_bin, list1_val = id.Bfs2(list1)
    list2_bin, list2_val = id.Bfs2(list2)
    # 2分探索
    ans = 0
    for i in r(len(list1_val)):
        j = bisect.bisect_left(list2_val, n - list1_val[i])
        if j < len(list2_val) and list1_val[i] + list2_val[j] == n:
            ans = list2_bin[j] + list1_bin[i]
            break
    print((int(ans)))

main()

# coding: utf-8
import sys
import bisect

"""Template"""

class IP:
    """
    入力を取得するクラス
    """

    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: 数
        """
        return int(eval(input()))

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数で合計
        """
        # 参考
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        # https://atcoder.jp/contests/abc105/submissions/4088632
        value = []
        for i in range(1 << len(a)):
            output = []
            for j in range(len(a)):
                if ((i >> j) & 1) == 1:
                    """右からj+1番目のiが1かどうか判定"""
                    # output.append(a[j])
                    output.append(a[j])
            value.append([format(i, "b").zfill(16), sum(output)])
        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

"""ここからメインコード"""

def main():
    """クラス呼び出し等行うよ"""
    # 1文字に省略
    r, e = range, enumerate
    ip = IP()
    id = Idea()
    """この下から書いてね"""
    """コピーコードです。"""
    n = ip.I()
    s = ""
    while True:
        r = n % (-2)
        n //= -2
        if r < 0:
            r += 2
            n += 1
        s += str(r)
        if n == 0:
            break
    print((s[::-1]))

main()

+    """クラス呼び出し等行うよ"""

-    """コピーコードです。https://atcoder.jp/contests/abc105/submissions/4088632

-    こちらを参考にテストを行っています。"""

+    """この下から書いてね"""

+    """コピーコードです。"""

-    # それぞれ半分全列挙

-    list1_bin, list1_val = id.Bfs2(list1)

-    list2_bin, list2_val = id.Bfs2(list2)

-        j = bisect.bisect_left(list2_val, n - list1_val[i])

-        if j < len(list2_val) and list1_val[i] + list2_val[j] == n:

-            ans = list2_bin[j] + list1_bin[i]


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

num=[3,5,7]

#a[0]=3,a[1]=5,a[7]=5

ans=[3,5,7]

answ=[]

for i1 in range(3):

  for i2 in range(3):

    for i3 in range(3):

      a=set([i1,i2,i3])

      if len(a)>2:

        answ.append(int(str(num[i1])+str(num[i2])+str(num[i3])))

      for i4 in range(3):

        a=set([i1,i2,i3,i4])

        if len(a)>2:

          answ.append(int(str(num[i1])+str(num[i2])+str(num[i3])+str(num[i4])))

        for i5 in range(3):

          a=set([i1,i2,i3,i4,i5])

          if len(a)>2:

            answ.append(int(str(num[i1])+str(num[i2])+str(num[i3])+str(num[i5])+str(num[i4])))

          for i6 in range(3):

            a=set([i1,i2,i3,i4,i5,i6])

            if len(a)>2:

              answ.append(int(str(num[i1])+str(num[i2])+str(num[i3])+str(num[i6])+str(num[i5])+str(num[i4])))

            for i7 in range(3):

              a=set([i1,i2,i3,i4,i5,i6,i7])

              if len(a)>2:

                answ.append(int(str(num[i1])+str(num[i2])+str(num[i3])+str(num[i7])+str(num[i6])+str(num[i5])+str(num[i4])))

              for i8 in range(3):

                a=set([i1,i2,i3,i4,i5,i6,i7,i8])

                if len(a)>2:

                  answ.append(int(str(num[i1])+str(num[i2])+str(num[i3])+str(num[i8])+str(num[i7])+str(num[i6])+str(num[i5])+str(num[i4])))

                for i9 in range(3):

                  a=set([i1,i2,i3,i4,i5,i6,i7,i8,i9])

                  if len(a)>2:

                    answ.append(int(str(num[i1])+str(num[i2])+str(num[i3])+str(num[i9])+str(num[i8])+str(num[i7])+str(num[i6])+str(num[i5])+str(num[i4])))

answ.sort()

left=0

right=len(answ)

while right-left>1:

  mid=(left+right)//2

  if n<answ[mid]:

    right=mid

  else:

    left=mid

if 357>n:

  print((0))

else:

  print((left+1))

n=int(eval(input()))

def dfs(s):

  if s!="" and int(s)>n:

    return 0

  if len(set(list(s)))<3:

    ret=0

  else:

    ret=1

  for i in "753":

    ret+=dfs(s+i)

  return ret

print((dfs("")))

n = int(eval(input()))
num = [3, 5, 7]
# a[0]=3,a[1]=5,a[7]=5
ans = [3, 5, 7]
answ = []
for i1 in range(3):
    for i2 in range(3):
        for i3 in range(3):
            a = set([i1, i2, i3])
            if len(a) > 2:
                answ.append(int(str(num[i1]) + str(num[i2]) + str(num[i3])))
            for i4 in range(3):
                a = set([i1, i2, i3, i4])
                if len(a) > 2:
                    answ.append(
                        int(str(num[i1]) + str(num[i2]) + str(num[i3]) + str(num[i4]))
                    )
                for i5 in range(3):
                    a = set([i1, i2, i3, i4, i5])
                    if len(a) > 2:
                        answ.append(
                            int(
                                str(num[i1])
                                + str(num[i2])
                                + str(num[i3])
                                + str(num[i5])
                                + str(num[i4])
                            )
                        )
                    for i6 in range(3):
                        a = set([i1, i2, i3, i4, i5, i6])
                        if len(a) > 2:
                            answ.append(
                                int(
                                    str(num[i1])
                                    + str(num[i2])
                                    + str(num[i3])
                                    + str(num[i6])
                                    + str(num[i5])
                                    + str(num[i4])
                                )
                            )
                        for i7 in range(3):
                            a = set([i1, i2, i3, i4, i5, i6, i7])
                            if len(a) > 2:
                                answ.append(
                                    int(
                                        str(num[i1])
                                        + str(num[i2])
                                        + str(num[i3])
                                        + str(num[i7])
                                        + str(num[i6])
                                        + str(num[i5])
                                        + str(num[i4])
                                    )
                                )
                            for i8 in range(3):
                                a = set([i1, i2, i3, i4, i5, i6, i7, i8])
                                if len(a) > 2:
                                    answ.append(
                                        int(
                                            str(num[i1])
                                            + str(num[i2])
                                            + str(num[i3])
                                            + str(num[i8])
                                            + str(num[i7])
                                            + str(num[i6])
                                            + str(num[i5])
                                            + str(num[i4])
                                        )
                                    )
                                for i9 in range(3):
                                    a = set([i1, i2, i3, i4, i5, i6, i7, i8, i9])
                                    if len(a) > 2:
                                        answ.append(
                                            int(
                                                str(num[i1])
                                                + str(num[i2])
                                                + str(num[i3])
                                                + str(num[i9])
                                                + str(num[i8])
                                                + str(num[i7])
                                                + str(num[i6])
                                                + str(num[i5])
                                                + str(num[i4])
                                            )
                                        )
answ.sort()
left = 0
right = len(answ)
while right - left > 1:
    mid = (left + right) // 2
    if n < answ[mid]:
        right = mid
    else:
        left = mid
if 357 > n:
    print((0))
else:
    print((left + 1))

n = int(eval(input()))

def dfs(s):
    if s != "" and int(s) > n:
        return 0
    if len(set(list(s))) < 3:
        ret = 0
    else:
        ret = 1
    for i in "753":
        ret += dfs(s + i)
    return ret

print((dfs("")))

-                answ.append(int(str(num[i1]) + str(num[i2]) + str(num[i3])))

-                        int(str(num[i1]) + str(num[i2]) + str(num[i3]) + str(num[i4]))

-                                str(num[i1])

-                                + str(num[i2])

-                                + str(num[i3])

-                                + str(num[i5])

-                                + str(num[i4])

-                    for i6 in range(3):

-                            answ.append(

-                                    str(num[i1])

-                                    + str(num[i2])

-                                    + str(num[i3])

-                                    + str(num[i6])

-                                    + str(num[i5])

-                                    + str(num[i4])

-                        for i7 in range(3):

-                            if len(a) > 2:

-                                answ.append(

-                                    int(

-                                        str(num[i1])

-                                        + str(num[i2])

-                                        + str(num[i3])

-                                        + str(num[i7])

-                                        + str(num[i6])

-                                        + str(num[i5])

-                                        + str(num[i4])

-                            for i8 in range(3):

-                                if len(a) > 2:

-                                    answ.append(

-                                        int(

-                                            str(num[i1])

-                                            + str(num[i2])

-                                            + str(num[i3])

-                                            + str(num[i8])

-                                            + str(num[i7])

-                                            + str(num[i6])

-                                            + str(num[i5])

-                                            + str(num[i4])

-                                for i9 in range(3):

-                                    if len(a) > 2:

-                                        answ.append(

-                                            int(

-                                                str(num[i1])

-                                                + str(num[i2])

-                                                + str(num[i3])

-                                                + str(num[i9])

-                                                + str(num[i8])

-                                                + str(num[i7])

-                                                + str(num[i6])

-                                                + str(num[i5])

-                                                + str(num[i4])


Input:
from sys import stdin

readline = stdin.readline

def main():

    eval(input())

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

    ans = 0

    prev = int(1e9+7)

    cnt = -1

    for cur in H:

        if prev >= cur:

            cnt += 1

        else:

            if ans < cnt:

                ans = cnt

            cnt = 0

        prev = cur

    if ans < cnt:

        ans = cnt

    print(ans)

    return

main()

def main():

    H = list(map(int, open(0).read().split()[1:]))

    ans = 0

    prev = int(1e9+7)

    cnt = -1

    for cur in H:

        if prev >= cur:

            cnt += 1

        else:

            if ans < cnt:

                ans = cnt

            cnt = 0

        prev = cur

    if ans < cnt:

        ans = cnt

    print(ans)

    return

main()

from sys import stdin

readline = stdin.readline

def main():
    eval(input())
    H = list(map(int, readline().split()))
    ans = 0
    prev = int(1e9 + 7)
    cnt = -1
    for cur in H:
        if prev >= cur:
            cnt += 1
        else:
            if ans < cnt:
                ans = cnt
            cnt = 0
        prev = cur
    if ans < cnt:
        ans = cnt
    print(ans)
    return

main()

def main():
    H = list(map(int, open(0).read().split()[1:]))
    ans = 0
    prev = int(1e9 + 7)
    cnt = -1
    for cur in H:
        if prev >= cur:
            cnt += 1
        else:
            if ans < cnt:
                ans = cnt
            cnt = 0
        prev = cur
    if ans < cnt:
        ans = cnt
    print(ans)
    return

main()

-    H = list(map(int, readline().split()))

+    H = list(map(int, open(0).read().split()[1:]))


Input:
import sys

read = sys.stdin.buffer.read

input = sys.stdin.buffer.readline

inputs = sys.stdin.buffer.readlines

# rstrip().decode('utf-8')

# INF=float("inf")

# MOD=10**9+7

# sys.setrecursionlimit(2147483647)

# import math

import numpy as np

# import operator

# import bisect

# from heapq import heapify,heappop,heappush

# from math import gcd

# from fractions import gcd

# from collections import deque

# from collections import defaultdict

# from collections import Counter

# from itertools import accumulate

# from itertools import groupby

# from itertools import permutations

# from itertools import combinations

# from scipy.sparse import csr_matrix

# from scipy.sparse.csgraph import floyd_warshall

# from scipy.sparse.csgraph import csgraph_from_dense

# from scipy.sparse.csgraph import dijkstra

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

def main():

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

	ans=0

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

		x=max(0,np.ceil(np.log2(K/i)))

		ans+=2**(-x)

	print((ans/N))

if __name__ == '__main__':

	main()

import sys

read = sys.stdin.buffer.read

input = sys.stdin.buffer.readline

inputs = sys.stdin.buffer.readlines

# rstrip().decode('utf-8')

# INF=float("inf")

# MOD=10**9+7

# sys.setrecursionlimit(2147483647)

# import math

#import numpy as np

# import operator

# import bisect

# from heapq import heapify,heappop,heappush

# from math import gcd

# from fractions import gcd

# from collections import deque

# from collections import defaultdict

# from collections import Counter

# from itertools import accumulate

# from itertools import groupby

# from itertools import permutations

# from itertools import combinations

# from scipy.sparse import csr_matrix

# from scipy.sparse.csgraph import floyd_warshall

# from scipy.sparse.csgraph import csgraph_from_dense

# from scipy.sparse.csgraph import dijkstra

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

def main():

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

	ans=0

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

		a=0

		while i*(2**a)<K:

			a+=1

		ans+=(1/2**a)/N

	print(ans)

if __name__ == '__main__':

	main()

import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines
# rstrip().decode('utf-8')
# INF=float("inf")
# MOD=10**9+7
# sys.setrecursionlimit(2147483647)
# import math
import numpy as np

# import operator
# import bisect
# from heapq import heapify,heappop,heappush
# from math import gcd
# from fractions import gcd
# from collections import deque
# from collections import defaultdict
# from collections import Counter
# from itertools import accumulate
# from itertools import groupby
# from itertools import permutations
# from itertools import combinations
# from scipy.sparse import csr_matrix
# from scipy.sparse.csgraph import floyd_warshall
# from scipy.sparse.csgraph import csgraph_from_dense
# from scipy.sparse.csgraph import dijkstra
# map(int,input().split())
def main():
    N, K = list(map(int, input().split()))
    ans = 0
    for i in range(1, N + 1):
        x = max(0, np.ceil(np.log2(K / i)))
        ans += 2 ** (-x)
    print((ans / N))

if __name__ == "__main__":
    main()

import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines
# rstrip().decode('utf-8')
# INF=float("inf")
# MOD=10**9+7
# sys.setrecursionlimit(2147483647)
# import math
# import numpy as np
# import operator
# import bisect
# from heapq import heapify,heappop,heappush
# from math import gcd
# from fractions import gcd
# from collections import deque
# from collections import defaultdict
# from collections import Counter
# from itertools import accumulate
# from itertools import groupby
# from itertools import permutations
# from itertools import combinations
# from scipy.sparse import csr_matrix
# from scipy.sparse.csgraph import floyd_warshall
# from scipy.sparse.csgraph import csgraph_from_dense
# from scipy.sparse.csgraph import dijkstra
# map(int,input().split())
def main():
    N, K = list(map(int, input().split()))
    ans = 0
    for i in range(1, N + 1):
        a = 0
        while i * (2**a) < K:
            a += 1
        ans += (1 / 2**a) / N
    print(ans)

if __name__ == "__main__":
    main()

-        x = max(0, np.ceil(np.log2(K / i)))


Input:
#ABC170 D

import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

n = int(readline())

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

a.sort()

if a[0] == a[-1]: # n=1 やサンプル２のような時

  if n > 1:

    print((0))

  else:

    print((1))

  exit()

if a[0] == 1: #１だけは素因数分解するときにバグるので別で処理

  if a[0] == a[1]:

    print((0))

  else:

    print((1))

  exit()

def divisorize(fct): # 約数のリストつくるやつ

    b, e = fct.pop()

    pre_div = divisorize(fct) if fct else [[]]

    suf_div = [[(b, k)] for k in range(e + 1)]

    return [pre + suf for pre in pre_div for suf in suf_div]

def factorize(n): #素因数分解

    fct = []

    b, e = 2, 0

    while b * b <= n:

        while n % b == 0:

            n = n // b

            e = e + 1

        if e > 0:

            fct.append((b, e))

        b, e = b + 1, 0

    if n > 1:

        fct.append((n, 1))

    return fct

def num(fct):

    a = 1

    for base, exponent in fct:

        a = a * base**exponent

    return a

s = set()

ans = 0

for nm,i in enumerate(a):

  c = set()

  fct = factorize(i)

  for div in divisorize(fct): # 約数の集合を作る

      c.add(num(div))

# 積集合をとり、それが空でかつ同じ数字が並んでない時に答えを加算

  if c&s == set() and ((nm < n-1 and a[nm+1] != i) or nm == n-1):

    ans += 1

  s.add(i) #今まで見た数の集合を更新

print(ans)

import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

n = int(readline())

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

a.sort()

if a[0] == a[-1]:

  if n > 1:

    print((0))

  else:

    print((1))

  exit()

def gcd(a, b):

    while b: a, b = b, a % b

    return a

def isPrimeMR(n):

    d = n - 1

    d = d // (d & -d)

    L = [2, 7, 61] if n < 1<<32 else [2, 3, 5, 7, 11, 13, 17] if n < 1<<48 else [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]

    for a in L:

        t = d

        y = pow(a, t, n)

        if y == 1: continue

        while y != n - 1:

            y = y * y % n

            if y == 1 or t == n - 1: return 0

            t <<= 1

    return 1

def findFactorRho(n):

    m = 1 << n.bit_length() // 8

    for c in range(1, 99):

        f = lambda x: (x * x + c) % n

        y, r, q, g = 2, 1, 1, 1

        while g == 1:

            x = y

            for i in range(r):

                y = f(y)

            k = 0

            while k < r and g == 1:

                ys = y

                for i in range(min(m, r - k)):

                    y = f(y)

                    q = q * abs(x - y) % n

                g = gcd(q, n)

                k += m

            r <<= 1

        if g == n:

            g = 1

            while g == 1:

                ys = f(ys)

                g = gcd(abs(x - ys), n)

        if g < n:

            if isPrimeMR(g): return g

            elif isPrimeMR(n // g): return n // g

            return findFactorRho(g)

def primeFactor(n):

    i = 2

    ret = {}

    rhoFlg = 0

    while i * i <= n:

        k = 0

        while n % i == 0:

            n //= i

            k += 1

        if k: ret[i] = k

        i += i % 2 + (3 if i % 3 == 1 else 1)

        if i == 101 and n >= 2 ** 20:

            while n > 1:

                if isPrimeMR(n):

                    ret[n], n = 1, 1

                else:

                    rhoFlg = 1

                    j = findFactorRho(n)

                    k = 0

                    while n % j == 0:

                        n //= j

                        k += 1

                    ret[j] = k

    if n > 1: ret[n] = 1

    if rhoFlg: ret = {x: ret[x] for x in sorted(ret)}

    return ret

def divisors(N):

    pf = primeFactor(N)

    ret = [1]

    for p in pf:

        ret_prev = ret

        ret = []

        for i in range(pf[p]+1):

            for r in ret_prev:

                ret.append(r * (p ** i))

    return ret

s = set()

ans = 0

for nm,i in enumerate(a):

  c = set(divisors(i))

  if c&s == set() and ((nm < n-1 and a[nm+1] != i) or nm == n-1):

    ans += 1

  s.add(i)

print(ans)

# ABC170 D
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(readline())
a = list(map(int, readline().split()))
a.sort()
if a[0] == a[-1]:  # n=1 やサンプル２のような時
    if n > 1:
        print((0))
    else:
        print((1))
    exit()
if a[0] == 1:  # １だけは素因数分解するときにバグるので別で処理
    if a[0] == a[1]:
        print((0))
    else:
        print((1))
    exit()

def divisorize(fct):  # 約数のリストつくるやつ
    b, e = fct.pop()
    pre_div = divisorize(fct) if fct else [[]]
    suf_div = [[(b, k)] for k in range(e + 1)]
    return [pre + suf for pre in pre_div for suf in suf_div]

def factorize(n):  # 素因数分解
    fct = []
    b, e = 2, 0
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct

def num(fct):
    a = 1
    for base, exponent in fct:
        a = a * base**exponent
    return a

s = set()
ans = 0
for nm, i in enumerate(a):
    c = set()
    fct = factorize(i)
    for div in divisorize(fct):  # 約数の集合を作る
        c.add(num(div))
    # 積集合をとり、それが空でかつ同じ数字が並んでない時に答えを加算
    if c & s == set() and ((nm < n - 1 and a[nm + 1] != i) or nm == n - 1):
        ans += 1
    s.add(i)  # 今まで見た数の集合を更新
print(ans)

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(readline())
a = list(map(int, readline().split()))
a.sort()
if a[0] == a[-1]:
    if n > 1:
        print((0))
    else:
        print((1))
    exit()

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

def isPrimeMR(n):
    d = n - 1
    d = d // (d & -d)
    L = (
        [2, 7, 61]
        if n < 1 << 32
        else [2, 3, 5, 7, 11, 13, 17]
        if n < 1 << 48
        else [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]
    )
    for a in L:
        t = d
        y = pow(a, t, n)
        if y == 1:
            continue
        while y != n - 1:
            y = y * y % n
            if y == 1 or t == n - 1:
                return 0
            t <<= 1
    return 1

def findFactorRho(n):
    m = 1 << n.bit_length() // 8
    for c in range(1, 99):
        f = lambda x: (x * x + c) % n
        y, r, q, g = 2, 1, 1, 1
        while g == 1:
            x = y
            for i in range(r):
                y = f(y)
            k = 0
            while k < r and g == 1:
                ys = y
                for i in range(min(m, r - k)):
                    y = f(y)
                    q = q * abs(x - y) % n
                g = gcd(q, n)
                k += m
            r <<= 1
        if g == n:
            g = 1
            while g == 1:
                ys = f(ys)
                g = gcd(abs(x - ys), n)
        if g < n:
            if isPrimeMR(g):
                return g
            elif isPrimeMR(n // g):
                return n // g
            return findFactorRho(g)

def primeFactor(n):
    i = 2
    ret = {}
    rhoFlg = 0
    while i * i <= n:
        k = 0
        while n % i == 0:
            n //= i
            k += 1
        if k:
            ret[i] = k
        i += i % 2 + (3 if i % 3 == 1 else 1)
        if i == 101 and n >= 2**20:
            while n > 1:
                if isPrimeMR(n):
                    ret[n], n = 1, 1
                else:
                    rhoFlg = 1
                    j = findFactorRho(n)
                    k = 0
                    while n % j == 0:
                        n //= j
                        k += 1
                    ret[j] = k
    if n > 1:
        ret[n] = 1
    if rhoFlg:
        ret = {x: ret[x] for x in sorted(ret)}
    return ret

def divisors(N):
    pf = primeFactor(N)
    ret = [1]
    for p in pf:
        ret_prev = ret
        ret = []
        for i in range(pf[p] + 1):
            for r in ret_prev:
                ret.append(r * (p**i))
    return ret

s = set()
ans = 0
for nm, i in enumerate(a):
    c = set(divisors(i))
    if c & s == set() and ((nm < n - 1 and a[nm + 1] != i) or nm == n - 1):
        ans += 1
    s.add(i)
print(ans)

-if a[0] == 1:  # １だけは素因数分解するときにバグるので別で処理

-    pre_div = divisorize(fct) if fct else [[]]

-    suf_div = [[(b, k)] for k in range(e + 1)]

-    return [pre + suf for pre in pre_div for suf in suf_div]

+                for i in range(min(m, r - k)):

+                    q = q * abs(x - y) % n

+                g = gcd(abs(x - ys), n)

+                    j = findFactorRho(n)

+        ret = {x: ret[x] for x in sorted(ret)}

-    for div in divisorize(fct):  # 約数の集合を作る

-    # 積集合をとり、それが空でかつ同じ数字が並んでない時に答えを加算

-    s.add(i)  # 今まで見た数の集合を更新


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

s = input()

cd = 0

d = None

for l in s:

	if d != l:

		cd +=1

		d = l

score = 0

for u,v in zip(s,s[1:]):

	if u == v:

		score +=1

if cd > 2:

	t = min(k,((cd - 2)+1)/2)

	k -= t

	score += 2 * t

	cd -= 2 * t

if cd == 2 and k:

	score +=1

	cd -= 1

print(score)

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

score,d,cd = 0,None,0

s = input()

for i,l in enumerate(s):

	if d != l:

		cd +=1

		d = l

	if i and s[i-1] == s[i]:  score += 1

if cd > 2:

	t = min(k,((cd - 2)+1)/2)

	k -= t

	score += 2 * t

	cd -= 2 * t

if cd == 2 and k:

	score +=1

	cd -= 1

print(score)

n, k = list(map(int, input().split()))
s = input()
cd = 0
d = None
for l in s:
    if d != l:
        cd += 1
        d = l
score = 0
for u, v in zip(s, s[1:]):
    if u == v:
        score += 1
if cd > 2:
    t = min(k, ((cd - 2) + 1) / 2)
    k -= t
    score += 2 * t
    cd -= 2 * t
if cd == 2 and k:
    score += 1
    cd -= 1
print(score)

n, k = list(map(int, input().split()))
score, d, cd = 0, None, 0
s = input()
for i, l in enumerate(s):
    if d != l:
        cd += 1
        d = l
    if i and s[i - 1] == s[i]:
        score += 1
if cd > 2:
    t = min(k, ((cd - 2) + 1) / 2)
    k -= t
    score += 2 * t
    cd -= 2 * t
if cd == 2 and k:
    score += 1
    cd -= 1
print(score)

+score, d, cd = 0, None, 0
-cd = 0
-d = None
-for l in s:
+for i, l in enumerate(s):
-score = 0
-for u, v in zip(s, s[1:]):
-    if u == v:
+    if i and s[i - 1] == s[i]:


Input:
import numpy as np

import itertools

Q = int(eval(input()))

LR = [[int(x) for x in input().split()] for _ in range(Q)]

## エラトステネスの篩

MAX = 10**5

is_prime = np.full(MAX, True)

is_prime[0] = is_prime[1] = False

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

    if is_prime[i]:

        is_prime[i*i::i] = False

NUM = np.zeros(MAX)

for p in range(MAX):

    if is_prime[p] and is_prime[(p+1)//2]:

        NUM[p] += 1

NUMcum = [0] + list(itertools.accumulate(NUM))

for l, r in LR:

    print((int(NUMcum[r+1] - NUMcum[l])))

import itertools

Q = int(eval(input()))

LR = [[int(x) for x in input().split()] for _ in range(Q)]

MAX = 10**5

is_prime = [True] * MAX

is_prime[0] = is_prime[1] = False

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

    if is_prime[i]:

        for j in range(i*i, MAX, i):

            is_prime[j] = False

NUM = [0] * MAX

for p in range(MAX):

    if is_prime[p] and is_prime[(p+1)//2]:

        NUM[p] += 1

NUMcum = [0] + list(itertools.accumulate(NUM))

for l, r in LR:

    print((int(NUMcum[r+1] - NUMcum[l])))

import numpy as np
import itertools

Q = int(eval(input()))
LR = [[int(x) for x in input().split()] for _ in range(Q)]
## エラトステネスの篩
MAX = 10**5
is_prime = np.full(MAX, True)
is_prime[0] = is_prime[1] = False
for i in range(2, int(MAX**0.5) + 1):
    if is_prime[i]:
        is_prime[i * i :: i] = False
NUM = np.zeros(MAX)
for p in range(MAX):
    if is_prime[p] and is_prime[(p + 1) // 2]:
        NUM[p] += 1
NUMcum = [0] + list(itertools.accumulate(NUM))
for l, r in LR:
    print((int(NUMcum[r + 1] - NUMcum[l])))

import itertools

Q = int(eval(input()))
LR = [[int(x) for x in input().split()] for _ in range(Q)]
MAX = 10**5
is_prime = [True] * MAX
is_prime[0] = is_prime[1] = False
for i in range(2, int(MAX**0.5) + 1):
    if is_prime[i]:
        for j in range(i * i, MAX, i):
            is_prime[j] = False
NUM = [0] * MAX
for p in range(MAX):
    if is_prime[p] and is_prime[(p + 1) // 2]:
        NUM[p] += 1
NUMcum = [0] + list(itertools.accumulate(NUM))
for l, r in LR:
    print((int(NUMcum[r + 1] - NUMcum[l])))

-import numpy as np
-## エラトステネスの篩
-is_prime = np.full(MAX, True)
+is_prime = [True] * MAX
-        is_prime[i * i :: i] = False
-NUM = np.zeros(MAX)
+        for j in range(i * i, MAX, i):
+            is_prime[j] = False
+NUM = [0] * MAX


Input:
a, b = (int(i) for i in input().split())

print((sum(range(b-a))-a))

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

c = b - a

d = c*(c+1)//2

print((d - b))

a, b = (int(i) for i in input().split())
print((sum(range(b - a)) - a))

a, b = (int(i) for i in input().split())
c = b - a
d = c * (c + 1) // 2
print((d - b))


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

A = [0]*N

for i in range(N):

    A[i] = int(eval(input()))

a = sorted(A)

Max = a[len(a)-1]

PreMax = a[len(a)-2]

for i in range(N):

    if A[i] < Max:

        print(Max)

    else:

        print(PreMax)

N  = int(eval(input()))

A=[0] * N

for i in range(N):

    A[i] = int(eval(input()))

right = [0]

left =[0]

for a in A:

    left.append(max(a,left[-1]))

for a in reversed(A):

    right.append(max(a,right[-1]))

for i in range(N):

    ans = max(left[i], right[N-i-1] )

    print(ans)

N = int(eval(input()))
A = [0] * N
for i in range(N):
    A[i] = int(eval(input()))
a = sorted(A)
Max = a[len(a) - 1]
PreMax = a[len(a) - 2]
for i in range(N):
    if A[i] < Max:
        print(Max)
    else:
        print(PreMax)

N = int(eval(input()))
A = [0] * N
for i in range(N):
    A[i] = int(eval(input()))
right = [0]
left = [0]
for a in A:
    left.append(max(a, left[-1]))
for a in reversed(A):
    right.append(max(a, right[-1]))
for i in range(N):
    ans = max(left[i], right[N - i - 1])
    print(ans)

+    ans = max(left[i], right[N - i - 1])


Input:
dp=[[1<<30 for _ in range(1001)] for _ in range(1001)]

dp[0][0]=0

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

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

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

for i in range(m):

    for j in range(n+1):

        if dp[i][j]< dp[i+1][j]:dp[i+1][j]=dp[i][j]

        e=d[j]*c[i]

        if dp[i][j]+e<dp[i+1][j+1]:dp[i+1][j+1]=dp[i][j]+e;

dp=list(zip(*dp[::-1]))

print((min(dp[n])))

dp=[[1<<30 for _ in range(1001)] for _ in range(1001)]

dp[0][0]=0

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

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

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

for i in range(m):

    for j in range(n+1):

        if dp[i][j]< dp[i+1][j]:dp[i+1][j]=dp[i][j]

        e=d[j]*c[i]

        if dp[i][j]+e<dp[i+1][j+1]:dp[i+1][j+1]=dp[i][j]+e;

print((dp[m][n]))

dp = [[1 << 30 for _ in range(1001)] for _ in range(1001)]
dp[0][0] = 0
n, m = list(map(int, input().split()))
d = [int(eval(input())) for _ in range(n)] + [0]
c = [int(eval(input())) for _ in range(m)] + [0]
for i in range(m):
    for j in range(n + 1):
        if dp[i][j] < dp[i + 1][j]:
            dp[i + 1][j] = dp[i][j]
        e = d[j] * c[i]
        if dp[i][j] + e < dp[i + 1][j + 1]:
            dp[i + 1][j + 1] = dp[i][j] + e
dp = list(zip(*dp[::-1]))
print((min(dp[n])))

dp = [[1 << 30 for _ in range(1001)] for _ in range(1001)]
dp[0][0] = 0
n, m = list(map(int, input().split()))
d = [int(eval(input())) for _ in range(n)] + [0]
c = [int(eval(input())) for _ in range(m)] + [0]
for i in range(m):
    for j in range(n + 1):
        if dp[i][j] < dp[i + 1][j]:
            dp[i + 1][j] = dp[i][j]
        e = d[j] * c[i]
        if dp[i][j] + e < dp[i + 1][j + 1]:
            dp[i + 1][j + 1] = dp[i][j] + e
print((dp[m][n]))

-dp = list(zip(*dp[::-1]))
-print((min(dp[n])))
+print((dp[m][n]))


Input:
import sys

if sys.version_info[0]>=3: raw_input=input

def insertionSort(a,g):

    global cnt

    for i in range(g,len(a)):

        v = a[i]

        j = i - g

        while j >= 0 and a[j] > v:

            a[j+g] = a[j]

            j = j - g

            cnt+=1

            a[j+g] = v

def shellSort(a):

    global cnt

    cnt = 0

    g = []

    h = 1

    while h <= len(a):

        g.append(h)

        h = 3*h+1

    g.reverse()

    m = len(g)

    print(m)

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

    for i in range(m):

        insertionSort(a,g[i])

a=[int(input()) for i in range(int(input()))]

shellSort(a)

print(cnt)

for e in a: print(e)

import math

def insertionsort(a, n, g):

    cnt = 0

    for i in range(g, n):

        v = a[i]

        j = i - g

        while j >= 0 and a[j] > v:

            a[j + g] = a[j]

            j = j - g

            cnt += 1

        a[j + g] = v

    return cnt

def shellsort(a, n):

    g = []

    gap = 1

    while gap <= math.ceil(n / 3):

        g.append(gap)

        gap = 3 * gap + 1

    g = g[::-1]

    m = len(g)

    print(m)

    print((*g))

    cnt = 0

    for i in range(m):

        cnt += insertionsort(a, n, g[i])

    print(cnt)

n = int(eval(input()))

a = []

for i in range(n):

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

shellsort(a, n)

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

import sys

if sys.version_info[0] >= 3:
    raw_input = input

def insertionSort(a, g):
    global cnt
    for i in range(g, len(a)):
        v = a[i]
        j = i - g
        while j >= 0 and a[j] > v:
            a[j + g] = a[j]
            j = j - g
            cnt += 1
            a[j + g] = v

def shellSort(a):
    global cnt
    cnt = 0
    g = []
    h = 1
    while h <= len(a):
        g.append(h)
        h = 3 * h + 1
    g.reverse()
    m = len(g)
    print(m)
    print((" ".join(map(str, g))))
    for i in range(m):
        insertionSort(a, g[i])

a = [int(input()) for i in range(int(input()))]
shellSort(a)
print(cnt)
for e in a:
    print(e)

+        cnt += insertionsort(a, n, g[i])

-a = [int(input()) for i in range(int(input()))]


Input:
from itertools import product

n = int(eval(input()))

s = eval(input())

ans = 0

for i in product(list(range(10)), repeat = 3):

    a = s.find(str(i[0]))

    if a != -1 and a != n - 1:

        b = s[a + 1:].find(str(i[1]))

        if b != -1:

            b += a + 1

            if b != n - 1:

                c = s[b + 1:].find(str(i[2]))

                if c != -1:

                    ans += 1

print(ans)

n = int(eval(input()))

s = eval(input())

ans = 0

for i in range(1000):

    i = str(i).zfill(3)

    a = s.find(i[0])

    if a != -1:

        b = s.find(i[1], a + 1)

        if b != -1:

            c = s.find(i[2], b + 1)

            if c != -1:

                ans += 1

print(ans)

from itertools import product

n = int(eval(input()))
s = eval(input())
ans = 0
for i in product(list(range(10)), repeat=3):
    a = s.find(str(i[0]))
    if a != -1 and a != n - 1:
        b = s[a + 1 :].find(str(i[1]))
        if b != -1:
            b += a + 1
            if b != n - 1:
                c = s[b + 1 :].find(str(i[2]))
                if c != -1:
                    ans += 1
print(ans)

-for i in product(list(range(10)), repeat=3):


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

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

loop = min(41,K)

for _ in range(loop):

    B = [0]*N

    for n in range(N):

        l = max(0,n-A[n])

        r = min(N-1,n+A[n])

        B[l]+=1

        if r+1<N:

            B[r+1] -= 1

    for n in range(1,N):

        B[n] += B[n-1]

    A = [b for b in B]

print((*A))

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

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

loop = min(41,K)

for _ in range(loop):

    B = [0]*N

    for n in range(N):

        l = max(0,n-A[n])

        r = min(N-1,n+A[n])

        #print(l,r)

        B[l]+=1

        if r+1<N:

            B[r+1] -= 1

    #print(B)

    for n in range(1,N):

        B[n] += B[n-1]

    A = B

print((*A))

N, K = list(map(int, input().split()))
A = [int(i) for i in input().split()]
loop = min(41, K)
for _ in range(loop):
    B = [0] * N
    for n in range(N):
        l = max(0, n - A[n])
        r = min(N - 1, n + A[n])
        B[l] += 1
        if r + 1 < N:
            B[r + 1] -= 1
    for n in range(1, N):
        B[n] += B[n - 1]
    A = [b for b in B]
print((*A))

N, K = list(map(int, input().split()))
A = [int(i) for i in input().split()]
loop = min(41, K)
for _ in range(loop):
    B = [0] * N
    for n in range(N):
        l = max(0, n - A[n])
        r = min(N - 1, n + A[n])
        # print(l,r)
        B[l] += 1
        if r + 1 < N:
            B[r + 1] -= 1
    # print(B)
    for n in range(1, N):
        B[n] += B[n - 1]
    A = B
print((*A))

+        # print(l,r)
+    # print(B)
-    A = [b for b in B]
+    A = B


Input:
from collections import Counter

N = int(eval(input()))

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

c = Counter(A)

ans = 0

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

    ans += v % 2

print(ans)

import sys

from collections import Counter

input = sys.stdin.readline

N = int(eval(input()))

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

ans = len([v for v in list(Counter(A).values()) if v % 2 == 1])

print(ans)

+ans = len([v for v in list(Counter(A).values()) if v % 2 == 1])


Input:
import sys

from operator import mul

from functools import reduce

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

sys.setrecursionlimit(10 ** 7)

def com(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(readline())

if n < 3:

    print((0))

    sys.exit()

ans = 0

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

    num = n - i * 3

    ans += com(num+i-1,i-1) % 1000000007

    ans %= 1000000007

print(ans)

import sys

from operator import mul

from functools import reduce

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

sys.setrecursionlimit(10 ** 7)

def com(n,r):

    r = min(n-r,r)

    if r == 0: return 1

    return reduce(mul,list(range(n,n-r,-1)))//reduce(mul,list(range(1,r+1)))

n = int(readline())

if n < 3:

    print((0))

    sys.exit()

ans = 0

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

    num = n - i * 3

    ans += com(num+i-1,i-1)

print((ans%1000000007))

import sys
from operator import mul
from functools import reduce

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)

def com(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(readline())
if n < 3:
    print((0))
    sys.exit()
ans = 0
for i in range(1, n // 3 + 1):
    num = n - i * 3
    ans += com(num + i - 1, i - 1) % 1000000007
    ans %= 1000000007
print(ans)

import sys
from operator import mul
from functools import reduce

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)

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

n = int(readline())
if n < 3:
    print((0))
    sys.exit()
ans = 0
for i in range(1, n // 3 + 1):
    num = n - i * 3
    ans += com(num + i - 1, i - 1)
print((ans % 1000000007))

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

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

+    return reduce(mul, list(range(n, n - r, -1))) // reduce(mul, list(range(1, r + 1)))


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

if 1 <= A <= 9 and 1 <= B <= 9:

  print((A * B))

else:

  print((-1))

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

if A < 10 and B < 10:

  print((A * B))

else:

  print((-1))


Input:
from scipy.sparse.csgraph import csgraph_from_dense, dijkstra

def main():

    import heapq

    import sys

    input = sys.stdin.buffer.readline

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

    G = [[-1]*N for i in range(N)]

    for i in range(M):

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

        A -= 1

        B -= 1

        G[A][B] = C

        G[B][A] = C

    g = csgraph_from_dense(G, null_value=-1)

    D = dijkstra(g)

    G2 = [[-1]*N for i in range(N)]

    for i in range(N):

        for j in range(N):

            if D[i][j] >= 0 and D[i][j] <= L:

                G2[i][j] = 1

    g2 = csgraph_from_dense(G2, null_value=-1)

    D = dijkstra(g2)

    Q = int(eval(input()))

    for _ in range(Q):

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

        s -= 1

        t -= 1

        if D[s][t] <= N**2:

            print((int(D[s][t])-1))

        else:

            print((-1))

main()

from scipy.sparse.csgraph import csgraph_from_dense, shortest_path

def main():

    import heapq

    import sys

    input = sys.stdin.buffer.readline

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

    G = [[-1]*N for i in range(N)]

    for i in range(M):

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

        A -= 1

        B -= 1

        G[A][B] = C

        G[B][A] = C

    g = csgraph_from_dense(G, null_value=-1)

    D = shortest_path(g)

    G2 = [[-1]*N for i in range(N)]

    for i in range(N):

        for j in range(N):

            if D[i][j] >= 0 and D[i][j] <= L:

                G2[i][j] = 1

    g2 = csgraph_from_dense(G2, null_value=-1)

    D = shortest_path(g2)

    Q = int(eval(input()))

    for _ in range(Q):

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

        s -= 1

        t -= 1

        if D[s][t] <= N**2:

            print((int(D[s][t])-1))

        else:

            print((-1))

main()

from scipy.sparse.csgraph import csgraph_from_dense, dijkstra

def main():
    import heapq
    import sys

    input = sys.stdin.buffer.readline
    N, M, L = list(map(int, input().split()))
    G = [[-1] * N for i in range(N)]
    for i in range(M):
        A, B, C = list(map(int, input().split()))
        A -= 1
        B -= 1
        G[A][B] = C
        G[B][A] = C
    g = csgraph_from_dense(G, null_value=-1)
    D = dijkstra(g)
    G2 = [[-1] * N for i in range(N)]
    for i in range(N):
        for j in range(N):
            if D[i][j] >= 0 and D[i][j] <= L:
                G2[i][j] = 1
    g2 = csgraph_from_dense(G2, null_value=-1)
    D = dijkstra(g2)
    Q = int(eval(input()))
    for _ in range(Q):
        s, t = list(map(int, input().split()))
        s -= 1
        t -= 1
        if D[s][t] <= N**2:
            print((int(D[s][t]) - 1))
        else:
            print((-1))

main()

from scipy.sparse.csgraph import csgraph_from_dense, shortest_path

def main():
    import heapq
    import sys

    input = sys.stdin.buffer.readline
    N, M, L = list(map(int, input().split()))
    G = [[-1] * N for i in range(N)]
    for i in range(M):
        A, B, C = list(map(int, input().split()))
        A -= 1
        B -= 1
        G[A][B] = C
        G[B][A] = C
    g = csgraph_from_dense(G, null_value=-1)
    D = shortest_path(g)
    G2 = [[-1] * N for i in range(N)]
    for i in range(N):
        for j in range(N):
            if D[i][j] >= 0 and D[i][j] <= L:
                G2[i][j] = 1
    g2 = csgraph_from_dense(G2, null_value=-1)
    D = shortest_path(g2)
    Q = int(eval(input()))
    for _ in range(Q):
        s, t = list(map(int, input().split()))
        s -= 1
        t -= 1
        if D[s][t] <= N**2:
            print((int(D[s][t]) - 1))
        else:
            print((-1))

main()

-from scipy.sparse.csgraph import csgraph_from_dense, dijkstra

+from scipy.sparse.csgraph import csgraph_from_dense, shortest_path


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

"""

Created on Sun Aug 26 11:59:46 2018

@author: maezawa

"""

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

array = [[0]*n for _ in range(n)]

for i in range(m):

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

    array[ai-1][bi-1] = 1

    array[bi-1][ai-1] = 1

#print(array)

#dp = [[-1]*n for _ in range(n)]

done = []

def f(i,done):

    if i in done:

        return 0

    if len(done) == n-1:

        return 1

    if sum(array[i]) == 1 and i != 0:

        return 0

    #if dp[i][j] != -1:

    #    return dp[i][j]

    donecopy = done + [i]

    #print(donecopy)

    ans = sum([f(bi,donecopy) for bi in range(n) if array[i][bi] != 0])

    return ans

print((f(0,done)))

import itertools as it

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

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

for i in range(m):

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

    nodes[ai-1].append(bi-1)

    nodes[bi-1].append(ai-1)

cnt = 0

for perm in it.permutations(list(range(1,n)),n-1):

    i = 0

    ok = True

    for j in perm:

        if j not in nodes[i]:

            ok = False

            break

        i = j

    if ok:

        cnt += 1

print(cnt)

# -*- coding: utf-8 -*-
"""
Created on Sun Aug 26 11:59:46 2018
@author: maezawa
"""
n, m = list(map(int, input().split()))
array = [[0] * n for _ in range(n)]
for i in range(m):
    ai, bi = list(map(int, input().split()))
    array[ai - 1][bi - 1] = 1
    array[bi - 1][ai - 1] = 1
# print(array)
# dp = [[-1]*n for _ in range(n)]
done = []

def f(i, done):
    if i in done:
        return 0
    if len(done) == n - 1:
        return 1
    if sum(array[i]) == 1 and i != 0:
        return 0
    # if dp[i][j] != -1:
    #    return dp[i][j]
    donecopy = done + [i]
    # print(donecopy)
    ans = sum([f(bi, donecopy) for bi in range(n) if array[i][bi] != 0])
    return ans

print((f(0, done)))

import itertools as it

n, m = list(map(int, input().split()))
nodes = [[] for _ in range(n)]
for i in range(m):
    ai, bi = list(map(int, input().split()))
    nodes[ai - 1].append(bi - 1)
    nodes[bi - 1].append(ai - 1)
cnt = 0
for perm in it.permutations(list(range(1, n)), n - 1):
    i = 0
    ok = True
    for j in perm:
        if j not in nodes[i]:
            ok = False
            break
        i = j
    if ok:
        cnt += 1
print(cnt)

-    ans = sum([f(bi, donecopy) for bi in range(n) if array[i][bi] != 0])

+for perm in it.permutations(list(range(1, n)), n - 1):


Input:
import sys

import bisect

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())

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

in_s = lambda: readline().rstrip().decode('utf-8')

INF = 10**12

d = lambda a, b: abs(a - b)

def main():

    A, B, Q = in_nn()

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

    s = tmp[:A]

    t = tmp[A:A + B]

    x = tmp[A + B:]

    a = [0] * Q

    for i in range(Q):

        n = x[i]

        if n <= s[0]:

            a1 = -INF

            a2 = s[0]

        elif n >= s[-1]:

            a1 = s[-1]

            a2 = INF

        else:

            si = bisect.bisect_right(s, n)

            a1 = s[si - 1]

            a2 = s[si]

        if n <= t[0]:

            b1 = -INF

            b2 = t[0]

        elif n >= t[-1]:

            b1 = t[-1]

            b2 = INF

        else:

            ti = bisect.bisect_right(t, n)

            b1 = t[ti - 1]

            b2 = t[ti]

        # print(a1, a2, b1, b2)

        ans = d(n, a1) + min(d(a1, b1), d(a1, b2))

        ans = min(ans, d(n, a2) + min(d(a2, b1), d(a2, b2)))

        ans = min(ans, d(n, b1) + min(d(b1, a1), d(b1, a2)))

        ans = min(ans, d(n, b2) + min(d(b2, a1), d(b2, a2)))

        a[i] = ans

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

if __name__ == '__main__':

    main()

import sys

import bisect

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())

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

in_s = lambda: readline().rstrip().decode('utf-8')

INF = 10**12

def main():

    A, B, Q = in_nn()

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

    s = [-INF] + tmp[:A] + [INF]

    t = [-INF] + tmp[A:A + B] + [INF]

    x = tmp[A + B:]

    a = [0] * Q

    d = lambda a, b: abs(a - b)

    for i in range(Q):

        n = x[i]

        si = bisect.bisect_right(s, n)

        a1 = s[si - 1]

        a2 = s[si]

        ti = bisect.bisect_right(t, n)

        b1 = t[ti - 1]

        b2 = t[ti]

        ans = d(n, a1) + min(d(a1, b1), d(a1, b2))

        ans = min(ans, d(n, a2) + min(d(a2, b1), d(a2, b2)))

        ans = min(ans, d(n, b1) + min(d(b1, a1), d(b1, a2)))

        ans = min(ans, d(n, b2) + min(d(b2, a1), d(b2, a2)))

        a[i] = ans

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

if __name__ == '__main__':

    main()

import sys
import bisect

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
in_n = lambda: int(readline())
in_nn = lambda: list(map(int, readline().split()))
in_s = lambda: readline().rstrip().decode("utf-8")
INF = 10**12
d = lambda a, b: abs(a - b)

def main():
    A, B, Q = in_nn()
    tmp = list(map(int, read().split()))
    s = tmp[:A]
    t = tmp[A : A + B]
    x = tmp[A + B :]
    a = [0] * Q
    for i in range(Q):
        n = x[i]
        if n <= s[0]:
            a1 = -INF
            a2 = s[0]
        elif n >= s[-1]:
            a1 = s[-1]
            a2 = INF
        else:
            si = bisect.bisect_right(s, n)
            a1 = s[si - 1]
            a2 = s[si]
        if n <= t[0]:
            b1 = -INF
            b2 = t[0]
        elif n >= t[-1]:
            b1 = t[-1]
            b2 = INF
        else:
            ti = bisect.bisect_right(t, n)
            b1 = t[ti - 1]
            b2 = t[ti]
        # print(a1, a2, b1, b2)
        ans = d(n, a1) + min(d(a1, b1), d(a1, b2))
        ans = min(ans, d(n, a2) + min(d(a2, b1), d(a2, b2)))
        ans = min(ans, d(n, b1) + min(d(b1, a1), d(b1, a2)))
        ans = min(ans, d(n, b2) + min(d(b2, a1), d(b2, a2)))
        a[i] = ans
    print(("\n".join(map(str, a))))

if __name__ == "__main__":
    main()

import sys
import bisect

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
in_n = lambda: int(readline())
in_nn = lambda: list(map(int, readline().split()))
in_s = lambda: readline().rstrip().decode("utf-8")
INF = 10**12

def main():
    A, B, Q = in_nn()
    tmp = list(map(int, read().split()))
    s = [-INF] + tmp[:A] + [INF]
    t = [-INF] + tmp[A : A + B] + [INF]
    x = tmp[A + B :]
    a = [0] * Q
    d = lambda a, b: abs(a - b)
    for i in range(Q):
        n = x[i]
        si = bisect.bisect_right(s, n)
        a1 = s[si - 1]
        a2 = s[si]
        ti = bisect.bisect_right(t, n)
        b1 = t[ti - 1]
        b2 = t[ti]
        ans = d(n, a1) + min(d(a1, b1), d(a1, b2))
        ans = min(ans, d(n, a2) + min(d(a2, b1), d(a2, b2)))
        ans = min(ans, d(n, b1) + min(d(b1, a1), d(b1, a2)))
        ans = min(ans, d(n, b2) + min(d(b2, a1), d(b2, a2)))
        a[i] = ans
    print(("\n".join(map(str, a))))

if __name__ == "__main__":
    main()

+    t = [-INF] + tmp[A : A + B] + [INF]

-            si = bisect.bisect_right(s, n)

-            ti = bisect.bisect_right(t, n)


Input:
import sys

sys.setrecursionlimit(1 << 25)

read = sys.stdin.readline

ra = range

enu = enumerate

def read_ints():

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

def read_a_int():

    return int(read())

def read_tuple(H):

    '''

    H is number of rows

    '''

    ret = []

    for _ in range(H):

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

    return ret

def read_col(H):

    '''

    H is number of rows

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

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

    '''

    ret = []

    for _ in range(H):

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

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

def read_matrix(H):

    '''

    H is number of rows

    '''

    ret = []

    for _ in range(H):

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

    return ret

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

MOD = 10**9 + 7

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

# default import

from collections import defaultdict, Counter, deque

from operator import itemgetter

from itertools import product, permutations, combinations

from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# https://atcoder.jp/contests/abc103/tasks/abc103_b

S = eval(input())

T = eval(input())

S = S + S

print(('Yes' if S.count(T) else 'No'))

import sys

sys.setrecursionlimit(1 << 25)

read = sys.stdin.readline

ra = range

enu = enumerate

def mina(*argv, sub=1): return list([x - sub for x in argv])

# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと

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

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

def read_col(H):

    '''H is number of rows

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

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

    ret = []

    for _ in range(H):

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

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

def read_tuple(H):

    '''H is number of rows'''

    ret = []

    for _ in range(H):

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

    return ret

def read_matrix(H):

    '''H is number of rows'''

    ret = []

    for _ in range(H):

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

    return ret

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

MOD = 10**9 + 7

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

# default import

from collections import defaultdict, Counter, deque

from operator import itemgetter

from itertools import product, permutations, combinations

from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# https://atcoder.jp/contests/abc103/tasks/abc103_b

S = eval(input())

T = eval(input())

S += S

print(('Yes' if S.count(T) else 'No'))

import sys

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

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

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

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

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

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

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

# https://atcoder.jp/contests/abc103/tasks/abc103_b
S = eval(input())
T = eval(input())
S = S + S
print(("Yes" if S.count(T) else "No"))

import sys

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

def mina(*argv, sub=1):
    return list([x - sub for x in argv])

# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと
def read_a_int():
    return int(read())

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

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

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

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

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

# https://atcoder.jp/contests/abc103/tasks/abc103_b
S = eval(input())
T = eval(input())
S += S
print(("Yes" if S.count(T) else "No"))

+    return list([x - sub for x in argv])

+# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと

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

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

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

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

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

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

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

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