Input:
import sys

input = sys.stdin.readline

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

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

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

def main():

    mod=10**9+7

    N,M=MI()

    A=LI()

    CB=[[0,0]for _ in range(M)]

    A.sort()

    for i in range(M):

        CB[i][1],CB[i][0]=MI()

    CB.sort(reverse=True)

    now=0

    for i in range(N):

        if CB[now][1]<=0:

            now+=1

        if now>=M:

            break

        ch=CB[now][0]

        if A[i]<ch:

            A[i]=ch

            CB[now][1]-=1

        else:

            break

    print((sum(A)))

main()

import sys

input = sys.stdin.readline

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

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

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

def main():

    mod=10**9+7

    N,M=MI()

    A=LI()

    B=[0]*M

    C=[0]*M

    for i in range(M):

        B[i],C[i]=MI()

    C,B=list(zip(*sorted(zip(C,B))))

    B=B[::-1]

    C=C[::-1]

    import heapq

    heapq.heapify(A)

    for i in range(M):

        b=B[i]

        c=C[i]

        for _ in range(b):

            a=heapq.heappop(A)

            if a>=c:

                heapq.heappush(A,a)

                break

            else:

                heapq.heappush(A,c)

    ans=0

    for i in range(N):

        a=heapq.heappop(A)

        ans+=a

    print(ans)

main()

import sys

input = sys.stdin.readline

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

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

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

def main():
    mod = 10**9 + 7
    N, M = MI()
    A = LI()
    CB = [[0, 0] for _ in range(M)]
    A.sort()
    for i in range(M):
        CB[i][1], CB[i][0] = MI()
    CB.sort(reverse=True)
    now = 0
    for i in range(N):
        if CB[now][1] <= 0:
            now += 1
        if now >= M:
            break
        ch = CB[now][0]
        if A[i] < ch:
            A[i] = ch
            CB[now][1] -= 1
        else:
            break
    print((sum(A)))

main()

import sys

input = sys.stdin.readline

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

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

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

def main():
    mod = 10**9 + 7
    N, M = MI()
    A = LI()
    B = [0] * M
    C = [0] * M
    for i in range(M):
        B[i], C[i] = MI()
    C, B = list(zip(*sorted(zip(C, B))))
    B = B[::-1]
    C = C[::-1]
    import heapq

    heapq.heapify(A)
    for i in range(M):
        b = B[i]
        c = C[i]
        for _ in range(b):
            a = heapq.heappop(A)
            if a >= c:
                heapq.heappush(A, a)
                break
            else:
                heapq.heappush(A, c)
    ans = 0
    for i in range(N):
        a = heapq.heappop(A)
        ans += a
    print(ans)

main()

+    C, B = list(zip(*sorted(zip(C, B))))


Input:
from math import factorial

n = int(input())

f = factorial(n)

mod = 10 ** 9 + 7

def primes(n):

    is_prime = [True] * (n + 1)

    is_prime[0] = False

    is_prime[1] = False

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

        if not is_prime[i]:

            continue

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

            is_prime[j] = False

    return [i for i in range(n + 1) if is_prime[i]]

ans = 1

for p in primes(n):

    temp = 1

    while f % p == 0:

        temp += 1

        f //= p

    ans = (ans * temp) % mod

print(ans)

n=int(input())

m=10**9+7

p=[1 for i in range(10000)]

p[0]=0

p[1]=0

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

  if p[i]==1:

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

        p[j]=0

ans=1

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

  if p[i]:

    c=0

    k=i

    while n//k>0:

      c=c+(n//k)%m

      k=k*i

    ans=(ans*((c+1)%m))%m

print((ans%m))

from math import factorial

n = int(input())
f = factorial(n)
mod = 10**9 + 7

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

ans = 1
for p in primes(n):
    temp = 1
    while f % p == 0:
        temp += 1
        f //= p
    ans = (ans * temp) % mod
print(ans)

n = int(input())
m = 10**9 + 7
p = [1 for i in range(10000)]
p[0] = 0
p[1] = 0
for i in range(2, n + 1):
    if p[i] == 1:
        for j in range(i * i, n + 1, i):
            p[j] = 0
ans = 1
for i in range(2, n + 1):
    if p[i]:
        c = 0
        k = i
        while n // k > 0:
            c = c + (n // k) % m
            k = k * i
        ans = (ans * ((c + 1) % m)) % m
print((ans % m))

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

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

-    return [i for i in range(n + 1) if is_prime[i]]

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


Input:
from collections import defaultdict

from bisect import bisect_left

s = input()

n = len(s)

s = s + s

t = input()

if set(t) - set(s):

	print((-1))

	exit()

d = defaultdict(list)

for i in range(2 * n):

	d[s[i]] += [i]

cur = tot = 0

for c in t:

	x = d[c][bisect_left(d[c], cur)]

	if x < n:

		cur = x + 1

	else:

		cur = x - n + 1

		tot += n

tot += cur

print(tot)

from collections import defaultdict

from bisect import bisect_left

def main():

	s = input()

	n = len(s)

	s = s + s

	t = input()

	if set(t) - set(s):

		print((-1))

		exit()

	d = defaultdict(list)

	for i in range(2 * n):

		d[s[i]] += [i]

	cur = ncnt = 0

	for c in t:

		x = d[c][bisect_left(d[c], cur)]

		if x < n:

			cur = x + 1

		else:

			cur = x - n + 1

			ncnt += 1

	print((ncnt*n + cur))

if __name__ == "__main__":

	main()

from collections import defaultdict
from bisect import bisect_left

def main():
    s = input()
    n = len(s)
    s = s + s
    t = input()
    if set(t) - set(s):
        print((-1))
        exit()
    d = defaultdict(list)
    for i in range(2 * n):
        d[s[i]] += [i]
    cur = ncnt = 0
    for c in t:
        x = d[c][bisect_left(d[c], cur)]
        if x < n:
            cur = x + 1
        else:
            cur = x - n + 1
            ncnt += 1
    print((ncnt * n + cur))

if __name__ == "__main__":
    main()

+        x = d[c][bisect_left(d[c], cur)]


Input:
import sys

stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

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

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

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

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

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

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

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

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

n = ni()

ab = [list(li()) for _ in range(n)]

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

cur = 0

ans = True

for ai, bi in ab:

    cur += ai

    if cur > bi:

        ans = False

print(("Yes" if ans else "No"))

import sys

stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

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

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

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

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

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

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

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

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

n = ni()

ab = [tuple(li()) for _ in range(n)]

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

cur = 0

ok = True

for ai, bi in ab:

    cur += ai

    if cur > bi:

        ok = False

        break

print(("Yes" if ok else "No"))

import sys

stdin = sys.stdin
sys.setrecursionlimit(10**7)

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

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

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

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

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

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

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

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

n = ni()
ab = [list(li()) for _ in range(n)]
ab.sort(key=lambda x: x[1])
cur = 0
ans = True
for ai, bi in ab:
    cur += ai
    if cur > bi:
        ans = False
print(("Yes" if ans else "No"))

import sys

stdin = sys.stdin
sys.setrecursionlimit(10**7)

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

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

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

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

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

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

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

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

n = ni()
ab = [tuple(li()) for _ in range(n)]
ab.sort(key=lambda x: x[1])
cur = 0
ok = True
for ai, bi in ab:
    cur += ai
    if cur > bi:
        ok = False
        break
print(("Yes" if ok else "No"))

-ab = [list(li()) for _ in range(n)]
+ab = [tuple(li()) for _ in range(n)]
-ans = True
+ok = True
-        ans = False
-print(("Yes" if ans else "No"))
+        ok = False
+        break
+print(("Yes" if ok else "No"))


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

ans = 0

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

    if str(i)[0]+str(i)[1] == str(i)[-1]+str(i)[-2]: ans += 1

print(ans)

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

ans = 0

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

    if str(n) == str(n)[::-1]: ans += 1

print(ans)

n, m = list(map(int, input().split()))
ans = 0
for i in range(n, m + 1):
    if str(i)[0] + str(i)[1] == str(i)[-1] + str(i)[-2]:
        ans += 1
print(ans)

a, b = list(map(int, input().split()))
ans = 0
for n in range(a, b + 1):
    if str(n) == str(n)[::-1]:
        ans += 1
print(ans)


Input:
ans=[]

for i in range (0,10):

    ans.append(int(input()))

ans.sort(reverse=True)

for i in range (0,3):

    print((ans[i]))

mountain=[]

for s in range(0,10):

    mountain.append(int(input()))

mountain.sort(reverse=True)

for s in range(0,3):

 print((mountain[s]))

ans = []
for i in range(0, 10):
    ans.append(int(input()))
ans.sort(reverse=True)
for i in range(0, 3):
    print((ans[i]))

mountain = []
for s in range(0, 10):
    mountain.append(int(input()))
mountain.sort(reverse=True)
for s in range(0, 3):
    print((mountain[s]))

-ans = []
-for i in range(0, 10):
-    ans.append(int(input()))
-ans.sort(reverse=True)
-for i in range(0, 3):
-    print((ans[i]))
+mountain = []
+for s in range(0, 10):
+    mountain.append(int(input()))
+mountain.sort(reverse=True)
+for s in range(0, 3):
+    print((mountain[s]))


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

import sys

def main():

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

    dp = [0]*(S+1)

    dp[0] = 1

    mod = 10**9 + 7

    for i in range(3, S+1):

        cnt = 0

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

            cnt += dp[i-j]

            cnt %= mod

        dp[i] = cnt

    print((dp[-1]))

if __name__ == "__main__":

    main()

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

import sys

def main():

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

    dp = [0]*(S+1)

    dp[0] = 1

    mod = 10**9 + 7

    for i in range(3, S+1):

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

        dp[i] %= mod

    print((dp[-1]))

if __name__ == "__main__":

    main()

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

def main():
    S = int(sys.stdin.readline())
    dp = [0] * (S + 1)
    dp[0] = 1
    mod = 10**9 + 7
    for i in range(3, S + 1):
        cnt = 0
        for j in range(3, i + 1):
            cnt += dp[i - j]
            cnt %= mod
        dp[i] = cnt
    print((dp[-1]))

if __name__ == "__main__":
    main()

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

def main():
    S = int(sys.stdin.readline())
    dp = [0] * (S + 1)
    dp[0] = 1
    mod = 10**9 + 7
    for i in range(3, S + 1):
        dp[i] = dp[i - 3] + dp[i - 1]
        dp[i] %= mod
    print((dp[-1]))

if __name__ == "__main__":
    main()

-        cnt = 0
-        for j in range(3, i + 1):
-            cnt += dp[i - j]
-            cnt %= mod
-        dp[i] = cnt
+        dp[i] = dp[i - 3] + dp[i - 1]
+        dp[i] %= mod


Input:
def solve():

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

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

  if K>=N:

    return 0

  H.sort()

  ans = sum(H[:N-K])

  return ans

print((solve()))

def solve():

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

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

  H.sort()

  ans = sum(H[:max(N-K,0)])

  return ans

print((solve()))

def solve():
    N, K = list(map(int, input().split()))
    H = list(map(int, input().split()))
    if K >= N:
        return 0
    H.sort()
    ans = sum(H[: N - K])
    return ans

print((solve()))

def solve():
    N, K = list(map(int, input().split()))
    H = list(map(int, input().split()))
    H.sort()
    ans = sum(H[: max(N - K, 0)])
    return ans

print((solve()))

-    if K >= N:
-        return 0
-    ans = sum(H[: N - K])
+    ans = sum(H[: max(N - K, 0)])


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

ans = 0

for x in range(k+1):

  for y in range(k+1):

    if 0<=s-x-y<=k:

      ans += 1

print(ans)

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

ans=0

for i in range(k+1):

  num=s-i

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

    if 0<=num-j<=k:

      ans+=1

print(ans)

k, s = list(map(int, input().split()))
ans = 0
for x in range(k + 1):
    for y in range(k + 1):
        if 0 <= s - x - y <= k:
            ans += 1
print(ans)

k, s = list(map(int, input().split()))
ans = 0
for i in range(k + 1):
    num = s - i
    for j in range(min(num + 1, k + 1)):
        if 0 <= num - j <= k:
            ans += 1
print(ans)

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


Input:
import sys

N = int(input())

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

l = 1

p = a[0] - 1

if a[0] == 2:

    print(l)

    sys.exit()

while l < int(1e6):

    l += 1

    if a[p] == 2:

        print(l)

        break

    else:

        p = a[p] - 1

else:

    print((-1))

import sys

N = int(input())

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

l = 1

p = a[0] - 1

if a[0] == 2:

    print(l)

    sys.exit()

while l < int(2e5):

    l += 1

    if a[p] == 2:

        print(l)

        break

    else:

        p = a[p] - 1

else:

    print((-1))

-while l < int(1e6):
+while l < int(2e5):


Input:
import math

def main():

    N = int(input())

    power = math.factorial(N)

    print((power % (10 ** 9 + 7)))

if __name__ == "__main__":

    main()

def main():

    N = int(input())

    power = 1

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

        power *= i

        power %= 10 ** 9 + 7

    print(power)

if __name__ == "__main__":

    main()

import math

def main():
    N = int(input())
    power = math.factorial(N)
    print((power % (10**9 + 7)))

if __name__ == "__main__":
    main()

def main():
    N = int(input())
    power = 1
    for i in range(1, N + 1):
        power *= i
        power %= 10**9 + 7
    print(power)

if __name__ == "__main__":
    main()

-import math
-    power = math.factorial(N)
-    print((power % (10**9 + 7)))
+    power = 1
+    for i in range(1, N + 1):
+        power *= i
+        power %= 10**9 + 7
+    print(power)


Input:
def main():

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

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

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

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

	d = [0]*x*y

	for i in range(x):

		for j in range(y):

			d[i*y+j] = a[i]+b[j]

	d.sort(reverse=True)

	c.sort(reverse=True)

	c_len = min(k, z)

	d_len = min(k, x*y)

	e = [0]*d_len*c_len

	for i in range(d_len):

		for j in range(c_len):

			e[i*c_len+j] = d[i] + c[j]

	e.sort(reverse=True)

	for i in range(k):

		print((e[i]))

if __name__ == '__main__':

    main()

def main():

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

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

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

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

	solve(a, b, c, x, y, z, k)

def solve(a, b, c, x, y, z, k):

	a.sort(reverse=True)

	b.sort(reverse=True)

	c.sort(reverse=True)

	stack = list()

	for p in range(x):

		for q in range(y):

			if (p+1)*(q+1) > k:

				break

			for r in range(z):

				if (p+1)*(q+1)*(r+1) > k:

					break

				stack.append(a[p]+b[q]+c[r])

	stack.sort(reverse=True)

	for i in range(k):

		print((stack[i]))

if __name__ == '__main__':

    main()

def main():
    x, y, z, k = list(map(int, input().split()))
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))
    d = [0] * x * y
    for i in range(x):
        for j in range(y):
            d[i * y + j] = a[i] + b[j]
    d.sort(reverse=True)
    c.sort(reverse=True)
    c_len = min(k, z)
    d_len = min(k, x * y)
    e = [0] * d_len * c_len
    for i in range(d_len):
        for j in range(c_len):
            e[i * c_len + j] = d[i] + c[j]
    e.sort(reverse=True)
    for i in range(k):
        print((e[i]))

if __name__ == "__main__":
    main()

def main():
    x, y, z, k = list(map(int, input().split()))
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))
    solve(a, b, c, x, y, z, k)

def solve(a, b, c, x, y, z, k):
    a.sort(reverse=True)
    b.sort(reverse=True)
    c.sort(reverse=True)
    stack = list()
    for p in range(x):
        for q in range(y):
            if (p + 1) * (q + 1) > k:
                break
            for r in range(z):
                if (p + 1) * (q + 1) * (r + 1) > k:
                    break
                stack.append(a[p] + b[q] + c[r])
    stack.sort(reverse=True)
    for i in range(k):
        print((stack[i]))

if __name__ == "__main__":
    main()

+                stack.append(a[p] + b[q] + c[r])


Input:
from math import sqrt

from bisect import bisect_left

def circle_center(x1, y1, x2, y2):

    xd = x2 - x1; yd = y2 - y1

    d = xd**2 + yd**2

    k = sqrt((4.0 - d) / d) / 2.0

    xc = (x1 + x2) / 2.0

    yc = (y1 + y2) / 2.0

    return [[xc - k*yd, yc + k*xd], [xc + k*yd, yc - k*xd]]

while 1:

    n = int(input())

    if n==0: break

    p = [list(map(float, input().split())) for i in range(n)]

    p.sort()

    prev = 0

    ans = 1

    for i in range(n):

        bx, by = p[i]

        while bx - p[prev][0] >= 2.0: prev += 1

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

            cx, cy = p[j]

            if cx - bx >= 2.0: break

            if (bx - cx)**2 + (by - cy)**2 <= 4.0:

                for ex, ey in circle_center(bx, by, cx, cy):

                    count = 2

                    for k in range(prev, n):

                        if k==i or k==j: continue

                        dx, dy = p[k]

                        if dx - bx >= 2.0: break

                        if (ex - dx)**2 + (ey - dy)**2 <= 1.0:

                            count += 1

                    ans = max(ans, count)

    print(ans)

from math import sqrt

from bisect import bisect_left

def circle_center(x1, y1, x2, y2):

    xd = x2 - x1; yd = y2 - y1

    d = xd**2 + yd**2

    k = sqrt((4.0 - d) / d) / 2.0

    xc = (x1 + x2) / 2.0; yc = (y1 + y2) / 2.0

    xd *= k; yd *= k

    return [[xc - yd, yc + xd], [xc + yd, yc - xd]]

while 1:

    n = int(input())

    if n==0: break

    p = sorted(list(map(float, input().split())) for i in range(n))

    prev = 0

    ans = 1

    for i in range(n):

        bx, by = p[i]

        while bx - p[prev][0] >= 2.0: prev += 1

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

            cx, cy = p[j]

            if cx - bx >= 2.0: break

            if (bx - cx)**2 + (by - cy)**2 <= 4.0:

                for ex, ey in circle_center(bx, by, cx, cy):

                    count = 2

                    for k in range(prev, n):

                        if k==i or k==j: continue

                        dx, dy = p[k]

                        if dx - ex >= 1.0: break

                        if (ex - dx)**2 + (ey - dy)**2 <= 1.0:

                            count += 1

                    ans = max(ans, count)

    print(ans)

from math import sqrt
from bisect import bisect_left

def circle_center(x1, y1, x2, y2):
    xd = x2 - x1
    yd = y2 - y1
    d = xd**2 + yd**2
    k = sqrt((4.0 - d) / d) / 2.0
    xc = (x1 + x2) / 2.0
    yc = (y1 + y2) / 2.0
    return [[xc - k * yd, yc + k * xd], [xc + k * yd, yc - k * xd]]

while 1:
    n = int(input())
    if n == 0:
        break
    p = [list(map(float, input().split())) for i in range(n)]
    p.sort()
    prev = 0
    ans = 1
    for i in range(n):
        bx, by = p[i]
        while bx - p[prev][0] >= 2.0:
            prev += 1
        for j in range(i + 1, n):
            cx, cy = p[j]
            if cx - bx >= 2.0:
                break
            if (bx - cx) ** 2 + (by - cy) ** 2 <= 4.0:
                for ex, ey in circle_center(bx, by, cx, cy):
                    count = 2
                    for k in range(prev, n):
                        if k == i or k == j:
                            continue
                        dx, dy = p[k]
                        if dx - bx >= 2.0:
                            break
                        if (ex - dx) ** 2 + (ey - dy) ** 2 <= 1.0:
                            count += 1
                    ans = max(ans, count)
    print(ans)

from math import sqrt
from bisect import bisect_left

def circle_center(x1, y1, x2, y2):
    xd = x2 - x1
    yd = y2 - y1
    d = xd**2 + yd**2
    k = sqrt((4.0 - d) / d) / 2.0
    xc = (x1 + x2) / 2.0
    yc = (y1 + y2) / 2.0
    xd *= k
    yd *= k
    return [[xc - yd, yc + xd], [xc + yd, yc - xd]]

while 1:
    n = int(input())
    if n == 0:
        break
    p = sorted(list(map(float, input().split())) for i in range(n))
    prev = 0
    ans = 1
    for i in range(n):
        bx, by = p[i]
        while bx - p[prev][0] >= 2.0:
            prev += 1
        for j in range(i + 1, n):
            cx, cy = p[j]
            if cx - bx >= 2.0:
                break
            if (bx - cx) ** 2 + (by - cy) ** 2 <= 4.0:
                for ex, ey in circle_center(bx, by, cx, cy):
                    count = 2
                    for k in range(prev, n):
                        if k == i or k == j:
                            continue
                        dx, dy = p[k]
                        if dx - ex >= 1.0:
                            break
                        if (ex - dx) ** 2 + (ey - dy) ** 2 <= 1.0:
                            count += 1
                    ans = max(ans, count)
    print(ans)

-    return [[xc - k * yd, yc + k * xd], [xc + k * yd, yc - k * xd]]

+    return [[xc - yd, yc + xd], [xc + yd, yc - xd]]

-    p = [list(map(float, input().split())) for i in range(n)]

+    p = sorted(list(map(float, input().split())) for i in range(n))


Input:
def solve():

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

  _S = input()

  S = []

  b = _S[0]

  s = 0

  if b == '0': S.append(0)

  for _s in _S:

    if b == _s:

      s = s + 1

    else:

      b = _s

      S.append(s)

      s = 1

  S.append(s)

  if b == '0': S.append(0)

  num = min(len(S), 2 * K + 1)

  # n = sum(S[0:num if _S[0] == '1' else (num - 1)])

  n = sum(S[0:num])

  m = n

  # for i in range(0 if _S[0] == '1' else -1, len(S) - num, 2):

  for i in range(0, len(S) - num, 2):

    n = n - sum(S[i:i+2])

    n = n + sum(S[i + num:i + num + 2])

    m = max(m, n)

  return m

print((solve()))

def solve():

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

  s = input()

  S = []

  b = s[0]

  cnt = 0

  if s[0] == '0': S.append(0)

  for c in s:

    if b == c: cnt = cnt + 1

    else:

      b = c

      S.append(cnt)

      cnt = 1

  S.append(cnt)

  if s[-1] == '0': S.append(0)

  num = min(len(S), 2 * K + 1)

  part = sum(S[0:num])

  ans = part

  for i in range(0, len(S) - num, 2):

    part = part - sum(S[i:i+2]) + sum(S[i + num:i + num + 2])

    ans = max(ans, part)

  return ans

print((solve()))

def solve():
    N, K = list(map(int, input().split()))
    _S = input()
    S = []
    b = _S[0]
    s = 0
    if b == "0":
        S.append(0)
    for _s in _S:
        if b == _s:
            s = s + 1
        else:
            b = _s
            S.append(s)
            s = 1
    S.append(s)
    if b == "0":
        S.append(0)
    num = min(len(S), 2 * K + 1)
    # n = sum(S[0:num if _S[0] == '1' else (num - 1)])
    n = sum(S[0:num])
    m = n
    # for i in range(0 if _S[0] == '1' else -1, len(S) - num, 2):
    for i in range(0, len(S) - num, 2):
        n = n - sum(S[i : i + 2])
        n = n + sum(S[i + num : i + num + 2])
        m = max(m, n)
    return m

print((solve()))

def solve():
    N, K = list(map(int, input().split()))
    s = input()
    S = []
    b = s[0]
    cnt = 0
    if s[0] == "0":
        S.append(0)
    for c in s:
        if b == c:
            cnt = cnt + 1
        else:
            b = c
            S.append(cnt)
            cnt = 1
    S.append(cnt)
    if s[-1] == "0":
        S.append(0)
    num = min(len(S), 2 * K + 1)
    part = sum(S[0:num])
    ans = part
    for i in range(0, len(S) - num, 2):
        part = part - sum(S[i : i + 2]) + sum(S[i + num : i + num + 2])
        ans = max(ans, part)
    return ans

print((solve()))

-    # for i in range(0 if _S[0] == '1' else -1, len(S) - num, 2):

-        n = n + sum(S[i + num : i + num + 2])

+        part = part - sum(S[i : i + 2]) + sum(S[i + num : i + num + 2])


Input:
import math

N = int(input())

ans = math.factorial(N) % (10 ** 9 + 7)

print(ans)

n = int(input())

from functools import reduce

print((reduce(lambda x,y:x*y%1000000007,list(range(1,n+1)))))

import math

N = int(input())
ans = math.factorial(N) % (10**9 + 7)
print(ans)

n = int(input())
from functools import reduce

print((reduce(lambda x, y: x * y % 1000000007, list(range(1, n + 1)))))

+print((reduce(lambda x, y: x * y % 1000000007, list(range(1, n + 1)))))


Input:
#python3

INF = int(1e9)

def main():

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

    ans = INF

    for i in range(2*10**5+100):

        t = 2*c*i + max(x-i, 0) * a + max(y-i, 0) * b

        ans = min(ans, t)

    print(ans)

main()

INF = int(1e5)+5

def main():

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

    ans = INF*INF

    for i in range(INF):

        tmp = 2*i*c + a*max(x-i, 0) + b*max(y-i, 0)

        ans = min(tmp, ans)

    print(ans)

main()

# python3
INF = int(1e9)

def main():
    a, b, c, x, y = list(map(int, input().split()))
    ans = INF
    for i in range(2 * 10**5 + 100):
        t = 2 * c * i + max(x - i, 0) * a + max(y - i, 0) * b
        ans = min(ans, t)
    print(ans)

main()

INF = int(1e5) + 5

def main():
    a, b, c, x, y = list(map(int, input().split()))
    ans = INF * INF
    for i in range(INF):
        tmp = 2 * i * c + a * max(x - i, 0) + b * max(y - i, 0)
        ans = min(tmp, ans)
    print(ans)

main()


Input:
from functools import reduce

N = int(input())

prime_table = [1] * (N+1)

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

    for t in range(2, x+1):

        while x % t == 0:

            prime_table[t] += 1

            x //= t

print((reduce(lambda x, y: x * y % (int(1e9) + 7), prime_table)))

def prime_factorize(n):

    while n % 2 == 0:

        a[2] += 1

        n //= 2

    f = 3

    while f * f <= n:

        if n % f == 0:

            a[f] += 1

            n //= f

        else:

            f += 2

    if n != 1:

        a[n] += 1

N = int(input())

a = [0]*(N+1)

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

    prime_factorize(i)

ans = 1

for i in a:

    if i > 0:

        ans *= (i+1)

big = 10**9 + 7

print((ans % big))

from functools import reduce

N = int(input())
prime_table = [1] * (N + 1)
for x in range(2, N + 1):
    for t in range(2, x + 1):
        while x % t == 0:
            prime_table[t] += 1
            x //= t
print((reduce(lambda x, y: x * y % (int(1e9) + 7), prime_table)))

def prime_factorize(n):
    while n % 2 == 0:
        a[2] += 1
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a[f] += 1
            n //= f
        else:
            f += 2
    if n != 1:
        a[n] += 1

N = int(input())
a = [0] * (N + 1)
for i in range(2, N + 1):
    prime_factorize(i)
ans = 1
for i in a:
    if i > 0:
        ans *= i + 1
big = 10**9 + 7
print((ans % big))

-print((reduce(lambda x, y: x * y % (int(1e9) + 7), prime_table)))


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

ans = 0

for i in range(K+1):

	for j in range(K+1):

		if (S - i - j) <= K and (S-i-j) >= 0:

			ans += 1

print(ans)

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

ans = 0

for X in range(K+1):

    for Y in range(K+1):

        if 0 <= (S - X - Y) <= K:

            ans += 1

print(ans)

K, S = list(map(int, input().split(" ")))
ans = 0
for i in range(K + 1):
    for j in range(K + 1):
        if (S - i - j) <= K and (S - i - j) >= 0:
            ans += 1
print(ans)

K, S = list(map(int, input().split(" ")))
ans = 0
for X in range(K + 1):
    for Y in range(K + 1):
        if 0 <= (S - X - Y) <= K:
            ans += 1
print(ans)


Input:
while 1:

    ans=0

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

    if n:

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

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

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

                    if i+j+k==x:ans+=1

    else:break

    print(ans)

while 1:

    a=0

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

    if n==0:break

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

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

            c=x-i-j

            if c>j and c<=n:a+=1

    print(a)

while 1:
    ans = 0
    n, x = list(map(int, input().split()))
    if n:
        for i in range(1, n - 1):
            for j in range(i + 1, n):
                for k in range(j + 1, n + 1):
                    if i + j + k == x:
                        ans += 1
    else:
        break
    print(ans)

while 1:
    a = 0
    n, x = list(map(int, input().split()))
    if n == 0:
        break
    for i in range(1, n - 1):
        for j in range(i + 1, n):
            c = x - i - j
            if c > j and c <= n:
                a += 1
    print(a)

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


Input:
def main():

  from statistics import mean

  from math import floor,ceil

  n = int(input())

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

  x_mean = mean(x)

  if x_mean == 0.5:

      greater_than_x = len([i for i in x if i > x_mean])

      if greater_than_x * 2 >= n:

          x_mean = ceil(x_mean)

      else:

          x_mean = floor(x_mean)

  elif x_mean % 1 > 0.5:

      x_mean = ceil(x_mean)

  else:

      x_mean = floor(x_mean)

  x2 = [(num - x_mean)**2 for num in x]

  print((sum(x2)))

main()

import sys

read = sys.stdin.read

def main():

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

    r = float('inf')

    for i1 in range(1, 101):

        rt = 0

        for xe in x:

            rt += (xe - i1)**2

        r = min(r, rt)

    print(r)

if __name__ == '__main__':

    main()

def main():
    from statistics import mean
    from math import floor, ceil

    n = int(input())
    x = list(map(int, input().split()))
    x_mean = mean(x)
    if x_mean == 0.5:
        greater_than_x = len([i for i in x if i > x_mean])
        if greater_than_x * 2 >= n:
            x_mean = ceil(x_mean)
        else:
            x_mean = floor(x_mean)
    elif x_mean % 1 > 0.5:
        x_mean = ceil(x_mean)
    else:
        x_mean = floor(x_mean)
    x2 = [(num - x_mean) ** 2 for num in x]
    print((sum(x2)))

main()

import sys

read = sys.stdin.read

def main():
    n, *x = list(map(int, read().split()))
    r = float("inf")
    for i1 in range(1, 101):
        rt = 0
        for xe in x:
            rt += (xe - i1) ** 2
        r = min(r, rt)
    print(r)

if __name__ == "__main__":
    main()

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

-        greater_than_x = len([i for i in x if i > x_mean])

-    x2 = [(num - x_mean) ** 2 for num in x]

+    n, *x = list(map(int, read().split()))


Input:
import sys

sys.setrecursionlimit(10 ** 6)

def solve():

    S = input()

    # print(S, len(S))

    words = {0: "dream", 1: "dreamer", 2: "erase", 3: "eraser"}

    TABLE = [[-1 for x in range(len(S) + 1)] for y in range(len(words) + 1)]

    def recur(i, w):

        if not TABLE[w][i] == -1:

            return TABLE[w][i]

        if i >= len(S):

            # print("jey", log)

            return True

        r1, r2, r3, r4 = False, False, False, False

        if S[i:i + 5] == words[0]:

            r1 = recur(i + 5, 0)

        if S[i:i + 7] == words[1]:

            r2 = recur(i + 7, 1)

        if S[i:i + 5] == words[2]:

            r3 = recur(i + 5, 2)

        if S[i:i + 6] == words[3]:

            r4 = recur(i + 6, 3)

        TABLE[w][i] = r1 or r2 or r3 or r4 or False

        return TABLE[w][i]

    ans = recur(0, 0)

    return ans

if __name__ == '__main__':

    res = solve()

    if res:

        print("YES")

    else:

        print("NO")

import sys

sys.setrecursionlimit(10 ** 6)

def solve():

    S = input()

    # print(S, len(S))

    S = S[::-1]

    words = ("dream"[::-1], "dreamer"[::-1], "erase"[::-1], "eraser"[::-1])

    def recur(i):

        if i >= len(S):

            return True

        for word in words:

            if S[i:i + len(word)] == word:

                if recur(i + len(word)):

                    return True

        return False

    ans = recur(0)

    return ans

if __name__ == '__main__':

    res = solve()

    if res:

        print("YES")

    else:

        print("NO")

import sys

sys.setrecursionlimit(10**6)

def solve():
    S = input()
    # print(S, len(S))
    words = {0: "dream", 1: "dreamer", 2: "erase", 3: "eraser"}
    TABLE = [[-1 for x in range(len(S) + 1)] for y in range(len(words) + 1)]

    def recur(i, w):
        if not TABLE[w][i] == -1:
            return TABLE[w][i]
        if i >= len(S):
            # print("jey", log)
            return True
        r1, r2, r3, r4 = False, False, False, False
        if S[i : i + 5] == words[0]:
            r1 = recur(i + 5, 0)
        if S[i : i + 7] == words[1]:
            r2 = recur(i + 7, 1)
        if S[i : i + 5] == words[2]:
            r3 = recur(i + 5, 2)
        if S[i : i + 6] == words[3]:
            r4 = recur(i + 6, 3)
        TABLE[w][i] = r1 or r2 or r3 or r4 or False
        return TABLE[w][i]

    ans = recur(0, 0)
    return ans

if __name__ == "__main__":
    res = solve()
    if res:
        print("YES")
    else:
        print("NO")

import sys

sys.setrecursionlimit(10**6)

def solve():
    S = input()
    # print(S, len(S))
    S = S[::-1]
    words = ("dream"[::-1], "dreamer"[::-1], "erase"[::-1], "eraser"[::-1])

    def recur(i):
        if i >= len(S):
            return True
        for word in words:
            if S[i : i + len(word)] == word:
                if recur(i + len(word)):
                    return True
        return False

    ans = recur(0)
    return ans

if __name__ == "__main__":
    res = solve()
    if res:
        print("YES")
    else:
        print("NO")

-    words = {0: "dream", 1: "dreamer", 2: "erase", 3: "eraser"}

-    TABLE = [[-1 for x in range(len(S) + 1)] for y in range(len(words) + 1)]

-        r1, r2, r3, r4 = False, False, False, False

-        TABLE[w][i] = r1 or r2 or r3 or r4 or False

+            if S[i : i + len(word)] == word:

+                if recur(i + len(word)):


Input:
from collections import defaultdict

N = int(input())

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

A.sort()

d = defaultdict(int)

for a in A:

    d[a] += 1

l = sorted(d.items())

max_v = 0

for _, v in l:

    if v > max_v:

        max_v = v

for k, v in l:

    if v == max_v:

        print(k)

    else:

        continue

from collections import defaultdict

def solve():

    N = int(input())

    d = defaultdict(int)

    for _ in range(N):

        a = input()

        d[a] += 1

    m = 0

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

        m = max(m, v)

    l = []

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

        if m == v:

            l.append(k)

    l.sort()

    for ans in l:

        print(ans)

solve()

-N = int(input())
-A = [input() for _ in range(N)]
-A.sort()
-d = defaultdict(int)
-for a in A:
-    d[a] += 1
-l = sorted(d.items())
-max_v = 0
-for _, v in l:
-    if v > max_v:
-        max_v = v
-for k, v in l:
-    if v == max_v:
-        print(k)
-    else:
-        continue
+
+def solve():
+    N = int(input())
+    d = defaultdict(int)
+    for _ in range(N):
+        a = input()
+        d[a] += 1
+    m = 0
+    for k, v in list(d.items()):
+        m = max(m, v)
+    l = []
+    for k, v in list(d.items()):
+        if m == v:
+            l.append(k)
+    l.sort()
+    for ans in l:
+        print(ans)
+
+
+solve()


Input:
n = int(input())

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

a_index = []

for i in range(n):

    a_index.append((i, a[i]))

dic1 = {}

dic2 = {}

for i in range(n):

    one = a_index[i][0] + a_index[i][1]

    two = a_index[i][0] - a_index[i][1]

    if one not in dic1:

        dic1[one] = 1

    else:

        dic1[one] += 1

    if two not in dic2:

        dic2[two] = 1

    else:

        dic2[two] += 1

ans = 0

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

    if i in dic2:

        ans += dic2[i] * dic1[i]

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

    if i in dic1:

        ans += dic1[i] * dic2[i]

        #print(i)

print((ans // 2))

n = int(input())

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

import collections

ans = 0

dic = collections.defaultdict(int)

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

    ans += dic[i - a[i - 1]]

    dic[i + a[i - 1]] += 1

print(ans)

n = int(input())
a = list(map(int, input().split()))
a_index = []
for i in range(n):
    a_index.append((i, a[i]))
dic1 = {}
dic2 = {}
for i in range(n):
    one = a_index[i][0] + a_index[i][1]
    two = a_index[i][0] - a_index[i][1]
    if one not in dic1:
        dic1[one] = 1
    else:
        dic1[one] += 1
    if two not in dic2:
        dic2[two] = 1
    else:
        dic2[two] += 1
ans = 0
for i in list(dic1.keys()):
    if i in dic2:
        ans += dic2[i] * dic1[i]
for i in list(dic2.keys()):
    if i in dic1:
        ans += dic1[i] * dic2[i]
        # print(i)
print((ans // 2))

-    one = a_index[i][0] + a_index[i][1]

-    two = a_index[i][0] - a_index[i][1]


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

ans=chk=0

for i in range(k+1):

    for j in range(k+1):

        if (0<=s-i-j<=k): ans+=1

print(ans)

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

ans=0

x=min(k+1,s+1)

y=max(0,s-k-k)

for i in range(y,x):

    for j in range(y,x):

        if i+j>s: break

        if 0<=s-i-j<=k:

            ans+=1

print(ans)

k, s = list(map(int, input().split()))
ans = chk = 0
for i in range(k + 1):
    for j in range(k + 1):
        if 0 <= s - i - j <= k:
            ans += 1
print(ans)

k, s = list(map(int, input().split()))
ans = 0
x = min(k + 1, s + 1)
y = max(0, s - k - k)
for i in range(y, x):
    for j in range(y, x):
        if i + j > s:
            break
        if 0 <= s - i - j <= k:
            ans += 1
print(ans)

-ans = chk = 0
-for i in range(k + 1):
-    for j in range(k + 1):
+ans = 0
+x = min(k + 1, s + 1)
+y = max(0, s - k - k)
+for i in range(y, x):
+    for j in range(y, x):
+        if i + j > s:
+            break


Input:
N,K = int(input()), int(input())

now = 1

for i in range(N):

    if now*2 < now + K:

        now *= 2

    else:

        now += K

print(now)

N = int(input())

K = int(input())

ans = 1

for i in range(N):

    if ans < K:

        ans *= 2

    else:

        ans += K

print(ans)

N, K = int(input()), int(input())
now = 1
for i in range(N):
    if now * 2 < now + K:
        now *= 2
    else:
        now += K
print(now)

-N, K = int(input()), int(input())
-now = 1
+N = int(input())
+K = int(input())
+ans = 1
-    if now * 2 < now + K:
-        now *= 2
+    if ans < K:
+        ans *= 2
-        now += K
-print(now)
+        ans += K
+print(ans)


Input:
import math

n=int(input())

ans=n

i=1

while(i<=math.sqrt(n)):

    if n%i==0:

        d=i+n/i-2

        ans=min(ans,d)

    i+=1

print((int(ans)))

from math import floor

from math import sqrt

n=int(input())

nn=floor(sqrt(n))

rest=n%nn

while rest!=0:

    nn-=1

    rest=n%nn

nnn=n/nn

print((int(nn+nnn-2)))

import math

n = int(input())
ans = n
i = 1
while i <= math.sqrt(n):
    if n % i == 0:
        d = i + n / i - 2
        ans = min(ans, d)
    i += 1
print((int(ans)))

from math import floor
from math import sqrt

n = int(input())
nn = floor(sqrt(n))
rest = n % nn
while rest != 0:
    nn -= 1
    rest = n % nn
nnn = n / nn
print((int(nn + nnn - 2)))

-import math
+from math import floor
+from math import sqrt
-ans = n
-i = 1
-while i <= math.sqrt(n):
-    if n % i == 0:
-        d = i + n / i - 2
-        ans = min(ans, d)
-    i += 1
-print((int(ans)))
+nn = floor(sqrt(n))
+rest = n % nn
+while rest != 0:
+    nn -= 1
+    rest = n % nn
+nnn = n / nn
+print((int(nn + nnn - 2)))


Input:
import math

N = int(input())

power = math.factorial(N)

print((power % 1000000007))

n=int(input())

ans=1

for i in range(n):

    ans=(ans*(i+1))%(10**9+7)

print(ans)

n = int(input())
ans = 1
for i in range(n):
    ans = (ans * (i + 1)) % (10**9 + 7)
print(ans)


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

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

dp = ["Second"] * (k + 1)

for i in range(k + 1):

    if dp[i] == "Second":

        for a in a_s:

            ii = i + a

            if ii <= k:

                dp[ii] = "First"

print((dp[-1]))

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

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

dp = ["Second"] * (k + 1)

for i in range(k + 1):

    if dp[i] == "Second":

        for a in a_s:

            ii = i + a

            if ii > k:break

            dp[ii] = "First"

print((dp[-1]))

n, k = list(map(int, input().split()))
a_s = list(map(int, input().split()))
dp = ["Second"] * (k + 1)
for i in range(k + 1):
    if dp[i] == "Second":
        for a in a_s:
            ii = i + a
            if ii > k:
                break
            dp[ii] = "First"
print((dp[-1]))

-            if ii <= k:
-                dp[ii] = "First"
+            if ii > k:
+                break
+            dp[ii] = "First"


Input:
S, T = [list(input()) for _ in range(2)]

cnt = 0

for i in range(len(S)):

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

        cnt += 1

print(cnt)

s, t = [input() for i in range(2)]

ans = 0

for i in range(len(s)):

  if s[i] != t[i]:

    ans += 1

print(ans)

-S, T = [list(input()) for _ in range(2)]


Input:
N = int(input())

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

cnt = 0

for i in range(N-1):

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

        cnt += D[i]*D[j]

print(cnt)

N = int(input())

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

cnt = 0

for i in range(N):

    cnt += D[i]**2

tot = 0

for i in range(N):

    tot += D[i]

tot = tot**2

tot -= cnt

print((tot//2))

N = int(input())
D = list(map(int, input().split()))
cnt = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        cnt += D[i] * D[j]
print(cnt)

N = int(input())
D = list(map(int, input().split()))
cnt = 0
for i in range(N):
    cnt += D[i] ** 2
tot = 0
for i in range(N):
    tot += D[i]
tot = tot**2
tot -= cnt
print((tot // 2))

-for i in range(N - 1):
-    for j in range(i + 1, N):
-        cnt += D[i] * D[j]
-print(cnt)
+for i in range(N):
+    cnt += D[i] ** 2
+tot = 0
+for i in range(N):
+    tot += D[i]
+tot = tot**2
+tot -= cnt
+print((tot // 2))


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

mn = [0]*N

for i in range(N):

  mn[i] = int(input())

ans = N

x = X - sum(mn)

while(x >= min(mn)):

  if x // min(mn) == 0:

    mn[mn.index(min(mn))] = 1000000

  else:

    if x >= min(mn):

      x -= min(mn)

      ans += 1

print(ans)

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

mn = [0]*N

for i in range(N):

  mn[i] = int(input())

ans = N

x = X - sum(mn)

while(x >= min(mn)):

  if x // min(mn) == 0:

    mn[mn.index(min(mn))] = 1000000

  else:

    x -= min(mn)

    ans += 1

print(ans)

N, X = list(map(int, input().split()))
mn = [0] * N
for i in range(N):
    mn[i] = int(input())
ans = N
x = X - sum(mn)
while x >= min(mn):
    if x // min(mn) == 0:
        mn[mn.index(min(mn))] = 1000000
    else:
        if x >= min(mn):
            x -= min(mn)
            ans += 1
print(ans)

N, X = list(map(int, input().split()))
mn = [0] * N
for i in range(N):
    mn[i] = int(input())
ans = N
x = X - sum(mn)
while x >= min(mn):
    if x // min(mn) == 0:
        mn[mn.index(min(mn))] = 1000000
    else:
        x -= min(mn)
        ans += 1
print(ans)

-        if x >= min(mn):
-            x -= min(mn)
-            ans += 1
+        x -= min(mn)
+        ans += 1


Input:
#! /usr/bin/env python3

import sys

int1 = lambda x: int(x) - 1

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

sys.setrecursionlimit(500000)

def isMultiple(s, m):

    tmp = 0

    for i in range(len(s)):

        tmp = (tmp * 10 + int(s[i])) % m

        if tmp == 0:

            return i

    return -1

k = int(readline())

acc = "7" * 50000000

if k % 2 == 0:

    ans = -1

else:

    ans = isMultiple(acc, k)

    if ans != -1:

        ans += 1

print(ans)

#! /usr/bin/env python3

import sys

int1 = lambda x: int(x) - 1

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

sys.setrecursionlimit(500000)

k = int(readline())

ans = -1

acc = 7 % k

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

    if acc == 0:

        ans = n

        break

    acc = (10 * acc + 7) % k

print(ans)


Input: n,*l=list(map(int,open(0).read().split()));print((sum(sorted(l*2)[-2:~n:-1])))

n,*l=list(map(int,open(0).read().split()))

l.sort(reverse=1)

print((sum(l[i//2] for i in range(1,n))))

n, *l = list(map(int, open(0).read().split()))
print((sum(sorted(l * 2)[-2:~n:-1])))

n, *l = list(map(int, open(0).read().split()))
l.sort(reverse=1)
print((sum(l[i // 2] for i in range(1, n))))

+print((sum(l[i // 2] for i in range(1, n))))


Input:
import math

N = int(input())

for i in range(int(math.sqrt(N))):

    if N % (int(math.sqrt(N))-i) == 0:

        print((int(N/(int(math.sqrt(N))-i)+int(math.sqrt(N))-i-2)))

        break

import math

N = int(input())

M = int(math.sqrt(N))

for i in range(M):

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

        print((int(N/(M-i)+M-i-2)))

        break

import math

N = int(input())
for i in range(int(math.sqrt(N))):
    if N % (int(math.sqrt(N)) - i) == 0:
        print((int(N / (int(math.sqrt(N)) - i) + int(math.sqrt(N)) - i - 2)))
        break

import math

N = int(input())
M = int(math.sqrt(N))
for i in range(M):
    if N % (M - i) == 0:
        print((int(N / (M - i) + M - i - 2)))
        break

-    if N % (int(math.sqrt(N)) - i) == 0:

-        print((int(N / (int(math.sqrt(N)) - i) + int(math.sqrt(N)) - i - 2)))


Input:
N, L = [int(i) for i in input().split()]

min_ = L

max_ = L + N -1

def eat_apple():

    if max_<0:

        return max_

    if L < 0:

        return 0

    return L

print(((min_+max_)*(max_-min_+1)//2 - eat_apple()))

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

min_ = L

max_ = L + N -1

def eat_apple(N, L, max_):

    if max_<0:

        return max_

    if L < 0:

        return 0

    return L

print(((min_+max_)*(max_-min_+1)//2 - eat_apple(N, L, max_)))

N, L = [int(i) for i in input().split()]
min_ = L
max_ = L + N - 1

def eat_apple():
    if max_ < 0:
        return max_
    if L < 0:
        return 0
    return L

print(((min_ + max_) * (max_ - min_ + 1) // 2 - eat_apple()))

N, L = [int(i) for i in input().split()]
min_ = L
max_ = L + N - 1

def eat_apple(N, L, max_):
    if max_ < 0:
        return max_
    if L < 0:
        return 0
    return L

print(((min_ + max_) * (max_ - min_ + 1) // 2 - eat_apple(N, L, max_)))

-print(((min_ + max_) * (max_ - min_ + 1) // 2 - eat_apple()))

+print(((min_ + max_) * (max_ - min_ + 1) // 2 - eat_apple(N, L, max_)))


Input:
from collections import Counter

N = int(input())

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

ans = 0

ruisekiwa = [0] * (N+1)

for i in range(N):

    ruisekiwa[i+1] = ruisekiwa[i] + inputs[i]

ruisekiwa = ruisekiwa[1:]

ruisekiwa.sort()

counter_ruiseki = Counter(ruisekiwa)

for key, value in list(counter_ruiseki.items()):

    if key == 0 and value == 1:

        ans += value

        continue

    elif key == 0 and value > 1:

        ans += value

    if value > 1:

        ans += sum(list(range(value)))

print(ans)

from collections import Counter

from itertools import accumulate

N = int(input())

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

ans = 0

ruisekiwa = list(accumulate(inputs))

ruisekiwa.sort()

counter_ruiseki = Counter(ruisekiwa)

for key, value in list(counter_ruiseki.items()):

    if key == 0 and value == 1:

        ans += value

        continue

    elif key == 0 and value > 1:

        ans += value

    if value > 1:

        ans += sum(list(range(value)))

print(ans)

from collections import Counter

N = int(input())
inputs = [int(i) for i in input().split()]
ans = 0
ruisekiwa = [0] * (N + 1)
for i in range(N):
    ruisekiwa[i + 1] = ruisekiwa[i] + inputs[i]
ruisekiwa = ruisekiwa[1:]
ruisekiwa.sort()
counter_ruiseki = Counter(ruisekiwa)
for key, value in list(counter_ruiseki.items()):
    if key == 0 and value == 1:
        ans += value
        continue
    elif key == 0 and value > 1:
        ans += value
    if value > 1:
        ans += sum(list(range(value)))
print(ans)

-    ruisekiwa[i + 1] = ruisekiwa[i] + inputs[i]


Input:
import sys

_input = sys.stdin.readline

def resolve():

    N = int(_input())

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

    t, x, y = 0, 0, 0

    for next_t, next_x, next_y in T:

        diff_xy = abs(x - next_x) + abs(y - next_y)

        diff_t = next_t - t

        if diff_xy > diff_t or (diff_xy % 2 != diff_t % 2):

            print('No')

            exit(0)

    print('Yes')

if __name__ == '__main__':

    resolve()

import sys

_input = sys.stdin.readline

def resolve():

    N = int(_input())

    t, x, y = 0, 0, 0

    for _ in range(N):

        next_t, next_x, next_y = list(map(int, _input().split()))

        diff_xy = abs(x - next_x) + abs(y - next_y)

        diff_t = next_t - t

        if diff_xy > diff_t or (diff_xy % 2 != diff_t % 2):

            print('No')

            exit(0)

    print('Yes')

if __name__ == '__main__':

    resolve()

import sys

_input = sys.stdin.readline

def resolve():
    N = int(_input())
    T = [list(map(int, _input().split())) for _ in range(N)]
    t, x, y = 0, 0, 0
    for next_t, next_x, next_y in T:
        diff_xy = abs(x - next_x) + abs(y - next_y)
        diff_t = next_t - t
        if diff_xy > diff_t or (diff_xy % 2 != diff_t % 2):
            print("No")
            exit(0)
    print("Yes")

if __name__ == "__main__":
    resolve()

import sys

_input = sys.stdin.readline

def resolve():
    N = int(_input())
    t, x, y = 0, 0, 0
    for _ in range(N):
        next_t, next_x, next_y = list(map(int, _input().split()))
        diff_xy = abs(x - next_x) + abs(y - next_y)
        diff_t = next_t - t
        if diff_xy > diff_t or (diff_xy % 2 != diff_t % 2):
            print("No")
            exit(0)
    print("Yes")

if __name__ == "__main__":
    resolve()

-    T = [list(map(int, _input().split())) for _ in range(N)]

+        next_t, next_x, next_y = list(map(int, _input().split()))


Input:
S = [int(_) for _ in input()]

length = len(S)

temp = [S[0]]

for x in S[1:]:

    if(len(temp) == 0):

        temp.append(x)

    elif( temp[-1] == x):

        temp.append(x)

    else:

        temp.pop(-1)

print((length-len(temp)))

def main():

    A = input()

    print((2*min(A.count("0"),A.count("1"))))

if __name__ == "__main__":

    main()

S = [int(_) for _ in input()]
length = len(S)
temp = [S[0]]
for x in S[1:]:
    if len(temp) == 0:
        temp.append(x)
    elif temp[-1] == x:
        temp.append(x)
    else:
        temp.pop(-1)
print((length - len(temp)))

def main():
    A = input()
    print((2 * min(A.count("0"), A.count("1"))))

if __name__ == "__main__":
    main()


Input:
K = int(input())

flg = [False]*K

tmp = 7 % K

cnt = 1

if tmp == 0:

    print(cnt)

    exit()

while True:

    tmp = (tmp*10+7)%K

    if flg[tmp]:

        print((-1))

        break

    else:

        cnt += 1

        if tmp == 0:

            print(cnt)

            break

        flg[tmp] = True

K = int(input())

t = 7

t %= K

for i in range(K+1):

    if t == 0:

        print((i+1))

        exit()

    t = (t*10+7)%K

print((-1))

K = int(input())
flg = [False] * K
tmp = 7 % K
cnt = 1
if tmp == 0:
    print(cnt)
    exit()
while True:
    tmp = (tmp * 10 + 7) % K
    if flg[tmp]:
        print((-1))
        break
    else:
        cnt += 1
        if tmp == 0:
            print(cnt)
            break
        flg[tmp] = True

K = int(input())
t = 7
t %= K
for i in range(K + 1):
    if t == 0:
        print((i + 1))
        exit()
    t = (t * 10 + 7) % K
print((-1))

-flg = [False] * K
-tmp = 7 % K
-cnt = 1
-if tmp == 0:
-    print(cnt)
-    exit()
-while True:
-    tmp = (tmp * 10 + 7) % K
-    if flg[tmp]:
-        print((-1))
-        break
-    else:
-        cnt += 1
-        if tmp == 0:
-            print(cnt)
-            break
-        flg[tmp] = True
+t = 7
+t %= K
+for i in range(K + 1):
+    if t == 0:
+        print((i + 1))
+        exit()
+    t = (t * 10 + 7) % K
+print((-1))


Input:
from math import factorial

print((factorial(int(input())) % (10**9+7)))

ans = 1

for k in range(1, int(input())+1):

    ans = ans*k % (10**9+7)

print(ans)

from math import factorial

print((factorial(int(input())) % (10**9 + 7)))

ans = 1
for k in range(1, int(input()) + 1):
    ans = ans * k % (10**9 + 7)
print(ans)

-print((factorial(int(input())) % (10**9 + 7)))


Input:
import sys

sys.setrecursionlimit(202020)

N = int(input())

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

for i in range(1,N):

    a = int(input()) - 1

    won[a].append(i)

def height(v):

    if not won[v]: return 0

    hs = [height(op) for op in won[v]]

    ret = 0

    for i,h in enumerate(sorted(hs)):

        ret = max(ret, h + len(hs) - i)

    return ret

print((height(0)))

import sys

sys.setrecursionlimit(10**8)

N = int(input())

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

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

for i,a in enumerate(A):

    wins[a].append(i+1)

depth = [-1] * N

def dep(v):

    if len(wins[v])==0: return 0

    if depth[v] >= 0:

        return depth[v]

    ds = []

    for w in wins[v]:

        ds.append(dep(w))

    ds.sort(reverse=True)

    ret = 0

    for i,d in enumerate(ds):

        ret = max(ret, i+d+1)

    depth[v] = ret

    return ret

print((dep(0)))

import sys

sys.setrecursionlimit(202020)
N = int(input())
won = [[] for i in range(N)]
for i in range(1, N):
    a = int(input()) - 1
    won[a].append(i)

def height(v):
    if not won[v]:
        return 0
    hs = [height(op) for op in won[v]]
    ret = 0
    for i, h in enumerate(sorted(hs)):
        ret = max(ret, h + len(hs) - i)
    return ret

print((height(0)))

import sys

sys.setrecursionlimit(10**8)
N = int(input())
A = [int(input()) - 1 for i in range(N - 1)]
wins = [[] for _ in range(N)]
for i, a in enumerate(A):
    wins[a].append(i + 1)
depth = [-1] * N

def dep(v):
    if len(wins[v]) == 0:
        return 0
    if depth[v] >= 0:
        return depth[v]
    ds = []
    for w in wins[v]:
        ds.append(dep(w))
    ds.sort(reverse=True)
    ret = 0
    for i, d in enumerate(ds):
        ret = max(ret, i + d + 1)
    depth[v] = ret
    return ret

print((dep(0)))

+A = [int(input()) - 1 for i in range(N - 1)]

-        ret = max(ret, h + len(hs) - i)


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

count = 0

for i in range(N):

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

    if (a**2 + b**2) <= D**2:

        count += 1

print(count)

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

count = 0

for i in range(N):

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

    if (a*a + b*b) <= D*D:

        count += 1

print(count)

N, D = list(map(int, input().split()))
count = 0
for i in range(N):
    a, b = list(map(int, input().split()))
    if (a * a + b * b) <= D * D:
        count += 1
print(count)


Input:
# ABC102C - Linear Approximation (ARC100C)

from statistics import median

def main():

    n = int(input())

    A = tuple(map(int, input().rstrip().split()))

    A = tuple(j - i for i, j in enumerate(A, start=1))

    b = median(A)

    ans = sum(abs(a - b) for a in A)

    print((int(ans)))

if __name__ == "__main__":

    main()

# ABC102C - Linear Approximation (ARC100C)

def main():

    n = int(input())

    A = tuple(map(int, input().rstrip().split()))

    A = sorted(j - i for i, j in enumerate(A, start=1))

    b = A[n // 2]

    ans = sum(abs(a - b) for a in A)

    print(ans)

if __name__ == "__main__":

    main()

-    A = tuple(j - i for i, j in enumerate(A, start=1))

+    A = sorted(j - i for i, j in enumerate(A, start=1))


Input:
a=65280; b=61680; c=52428; d=43690; e=65535

L = {el: 1 for el in [a, b, c, d, e, 0]}

for i in range(6):

    R = sorted(L.items(), key=lambda x: x[1])

    for p, l in R:

        if l < 16:

            L[p ^ e] = min(L.get(p ^ e, 16), l+1)

            if l+3 < 16:

                for q, r in R:

                    if l+r+3 <= 16:

                        L[p & q] = min(L.get(p & q, 16), l+r+3)

                        L[p ^ q] = min(L.get(p ^ q, 16), l+r+3)

                    else: break

        else: break

print(*(L[e & eval(s)] for s in open(0).read().replace(*"-~").replace(*"*&").replace(*"1e").split()[:-1]),sep='\n')

a=65280; b=61680; c=52428; d=43690; e=65535

from heapq import heappush, heappop

base = [a, b, c, d, e, 0]

Q = [(1, el) for el in base]

L = {el: 1 for el in base}

H = []

while Q:

    l, p = heappop(Q)

    if L[p] < l: continue

    if l+1 < L.get(p ^ e, 17):

        L[p^e] = l+1

        if l+1 < 16: heappush(Q, (l+1, p^e))

    if l+3 < 16:

        for q, r in H:

            if l+r+3 <= 16:

                if l+r+3 < L.get(p & q, 17):

                    L[p & q] = l+r+3

                    if l+r+3 < 16: heappush(Q, (l+r+3, p & q))

                if l+r+3 < L.get(p ^ q, 17):

                    L[p ^ q] = l+r+3

                    if l+r+3 < 16: heappush(Q, (l+r+3, p ^ q))

            else: break

    if l < 7: H.append((p, l))

print(*(L[e & eval(s)] for s in open(0).read().replace(*"-~").replace(*"*&").replace(*"1e").split()[:-1]),sep='\n')

a = 65280
b = 61680
c = 52428
d = 43690
e = 65535
L = {el: 1 for el in [a, b, c, d, e, 0]}
for i in range(6):
    R = sorted(L.items(), key=lambda x: x[1])
    for p, l in R:
        if l < 16:
            L[p ^ e] = min(L.get(p ^ e, 16), l + 1)
            if l + 3 < 16:
                for q, r in R:
                    if l + r + 3 <= 16:
                        L[p & q] = min(L.get(p & q, 16), l + r + 3)
                        L[p ^ q] = min(L.get(p ^ q, 16), l + r + 3)
                    else:
                        break
        else:
            break
print(
    *(
        L[e & eval(s)]
        for s in open(0)
        .read()
        .replace(*"-~")
        .replace(*"*&")
        .replace(*"1e")
        .split()[:-1]
    ),
    sep="\n"
)

a = 65280
b = 61680
c = 52428
d = 43690
e = 65535
from heapq import heappush, heappop

base = [a, b, c, d, e, 0]
Q = [(1, el) for el in base]
L = {el: 1 for el in base}
H = []
while Q:
    l, p = heappop(Q)
    if L[p] < l:
        continue
    if l + 1 < L.get(p ^ e, 17):
        L[p ^ e] = l + 1
        if l + 1 < 16:
            heappush(Q, (l + 1, p ^ e))
    if l + 3 < 16:
        for q, r in H:
            if l + r + 3 <= 16:
                if l + r + 3 < L.get(p & q, 17):
                    L[p & q] = l + r + 3
                    if l + r + 3 < 16:
                        heappush(Q, (l + r + 3, p & q))
                if l + r + 3 < L.get(p ^ q, 17):
                    L[p ^ q] = l + r + 3
                    if l + r + 3 < 16:
                        heappush(Q, (l + r + 3, p ^ q))
            else:
                break
    if l < 7:
        H.append((p, l))
print(
    *(
        L[e & eval(s)]
        for s in open(0)
        .read()
        .replace(*"-~")
        .replace(*"*&")
        .replace(*"1e")
        .split()[:-1]
    ),
    sep="\n"
)

-L = {el: 1 for el in [a, b, c, d, e, 0]}

-    R = sorted(L.items(), key=lambda x: x[1])

+            heappush(Q, (l + 1, p ^ e))

+                        heappush(Q, (l + r + 3, p & q))

+                        heappush(Q, (l + r + 3, p ^ q))


Input:
#python3

from collections import defaultdict

from collections import namedtuple

P = namedtuple('P', ['front', 'end'])

def f(x):

    return P(str(x)[0], str(x)[-1])

def main():

    n = int(input())

    freq = defaultdict(int)

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

        p = f(i)

        freq[p]+=1

    ans = 0

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

        p = f(i)

        q = (p.end, p.front)

        ans += freq[q]

    print(ans)

main()

import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

from collections import defaultdict

def f(x):

    return (int(str(x)[0]), int(str(x)[-1]))

def main():

    N = int(readline())

    df = defaultdict(int)

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

        df[f(i)] += 1

    ans = 0

    for i in range(1, 10):

        for j in range(1, 10):

            ans +=  df[(i, j)]*df[(j, i)]

    print(ans)

if __name__ == '__main__':

    main()

# python3
from collections import defaultdict
from collections import namedtuple

P = namedtuple("P", ["front", "end"])

def f(x):
    return P(str(x)[0], str(x)[-1])

def main():
    n = int(input())
    freq = defaultdict(int)
    for i in range(1, n + 1):
        p = f(i)
        freq[p] += 1
    ans = 0
    for i in range(1, n + 1):
        p = f(i)
        q = (p.end, p.front)
        ans += freq[q]
    print(ans)

main()

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import defaultdict

def f(x):
    return (int(str(x)[0]), int(str(x)[-1]))

def main():
    N = int(readline())
    df = defaultdict(int)
    for i in range(1, N + 1):
        df[f(i)] += 1
    ans = 0
    for i in range(1, 10):
        for j in range(1, 10):
            ans += df[(i, j)] * df[(j, i)]
    print(ans)

if __name__ == "__main__":
    main()

+    return (int(str(x)[0]), int(str(x)[-1]))


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

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

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

bc.sort(key=lambda x: x[1], reverse=True)

a.sort()

i = 0

for b, c in bc:

    for _ in range(b):

        if i < n and a[i] < c:

            a[i] = c

            i += 1

        else:

            break

ans = sum(a)

print(ans)

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

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

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

bc.sort(reverse=True, key=lambda x: x[1])

li = []

l = 0

i = 0

while i < m and l < n:

    b, c = bc[i]

    li += [c] * b

    i += 1

    l += b

a += li

a.sort(reverse=True)

ans = sum(a[:n])

print(ans)

-bc.sort(key=lambda x: x[1], reverse=True)

+bc.sort(reverse=True, key=lambda x: x[1])


Input:
def f(s):

    s=list(map(int,s.split(':')))

    return (s[0]*60+s[1])*60+s[2]

a=86401

while 1:

    t=[0]*a

    n=int(input())

    if n==0:break

    for _ in range(n):

        b,c=input().split()

        t[f(b)]+=1;t[f(c)]-=1

    d=0

    for i in range(1,a):

        t[i]+=t[i-1]

        d=max(d,t[i])

    print(d)

def f(s):

    return (s[0]*60+s[1])*60+s[2]

a=86400

while 1:

    t=[0]*a

    n=int(input())

    if n==0:break

    for _ in range(n):

        b,c = [list(map(int,x.split(':'))) for x in input().split()]

        t[f(b)]+=1;t[f(c)]-=1

    d=0

    for i in range(1,a):

        t[i]+=t[i-1]

        if d<t[i]:d=t[i]

    print(d)

def f(s):
    s = list(map(int, s.split(":")))
    return (s[0] * 60 + s[1]) * 60 + s[2]

a = 86401
while 1:
    t = [0] * a
    n = int(input())
    if n == 0:
        break
    for _ in range(n):
        b, c = input().split()
        t[f(b)] += 1
        t[f(c)] -= 1
    d = 0
    for i in range(1, a):
        t[i] += t[i - 1]
        d = max(d, t[i])
    print(d)

def f(s):
    return (s[0] * 60 + s[1]) * 60 + s[2]

a = 86400
while 1:
    t = [0] * a
    n = int(input())
    if n == 0:
        break
    for _ in range(n):
        b, c = [list(map(int, x.split(":"))) for x in input().split()]
        t[f(b)] += 1
        t[f(c)] -= 1
    d = 0
    for i in range(1, a):
        t[i] += t[i - 1]
        if d < t[i]:
            d = t[i]
    print(d)

+        b, c = [list(map(int, x.split(":"))) for x in input().split()]


Input:
import math

n = int(input())

print((math.factorial(n)%(10**9+7)))

n = int(input())

mod = 10**9 + 7

pow = 1

for i in range(n):

    pow = pow*(i+1)%mod

print(pow)

import math

n = int(input())
print((math.factorial(n) % (10**9 + 7)))

n = int(input())
mod = 10**9 + 7
pow = 1
for i in range(n):
    pow = pow * (i + 1) % mod
print(pow)

-print((math.factorial(n) % (10**9 + 7)))


Input:
S = list(input())

num_one = S.count("1")

num_zero = S.count("0")

ans = min(num_one, num_zero) *2

print(ans)

S = input()

ans = min(S.count("0"), S.count("1")) * 2

print(ans)

S = list(input())
num_one = S.count("1")
num_zero = S.count("0")
ans = min(num_one, num_zero) * 2
print(ans)


Input:
import sys

can = True; input()

e = [[0, 0, 0]] + [list(map(int, e.split())) for e in sys.stdin]

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

    t = a[0] - b[0] - abs(a[1] - b[1]) - abs(a[2] - b[2])

    if t < 0 or t % 2 == 1: can = False; break

print((['No', 'Yes'][can]))

import sys

ans = 'Yes'; input()

for e in sys.stdin:

    t, x, y = list(map(int, e.split()))

    t = t - x - y

    if t < 0 or t % 2 == 1: ans = 'No'; break

print(ans)

import sys

can = True
input()
e = [[0, 0, 0]] + [list(map(int, e.split())) for e in sys.stdin]
for a, b in zip(e[1:], e):
    t = a[0] - b[0] - abs(a[1] - b[1]) - abs(a[2] - b[2])
    if t < 0 or t % 2 == 1:
        can = False
        break
print((["No", "Yes"][can]))

import sys

ans = "Yes"
input()
for e in sys.stdin:
    t, x, y = list(map(int, e.split()))
    t = t - x - y
    if t < 0 or t % 2 == 1:
        ans = "No"
        break
print(ans)

-e = [[0, 0, 0]] + [list(map(int, e.split())) for e in sys.stdin]

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


Input:
import sys

readline = sys.stdin.readline

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

INF = 10 ** 10

dp = [INF] * (2 ** N)

dp[0] = 0

for i in range(M):

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

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

  key = 0

  for j in range(len(c)):

    key += (1 << (c[j] - 1))

  for j in range(len(dp)):

    if dp[j] == INF:

      continue

    if j | key == j:

      continue

    dp[j | key] = min(dp[j | key], dp[j] + a)

if dp[-1] == INF:

  print((-1))

else:

  print((dp[-1]))

import sys

readline = sys.stdin.readline

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

INF = 10 ** 10

dp = [INF] * (2 ** N)

dp[0] = 0

for i in range(M):

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

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

  key = 0

  for j in range(len(c)):

    key += (1 << (c[j] - 1))

  for j in range(len(dp)):

    if dp[j] == INF:

      continue

    if j | key == j:

      continue

    if dp[j | key] > dp[j] + a:

      dp[j | key] = dp[j] + a

if dp[-1] == INF:

  print((-1))

else:

  print((dp[-1]))

import sys

readline = sys.stdin.readline
N, M = list(map(int, readline().split()))
INF = 10**10
dp = [INF] * (2**N)
dp[0] = 0
for i in range(M):
    a, b = list(map(int, readline().split()))
    c = list(map(int, readline().split()))
    key = 0
    for j in range(len(c)):
        key += 1 << (c[j] - 1)
    for j in range(len(dp)):
        if dp[j] == INF:
            continue
        if j | key == j:
            continue
        dp[j | key] = min(dp[j | key], dp[j] + a)
if dp[-1] == INF:
    print((-1))
else:
    print((dp[-1]))

import sys

readline = sys.stdin.readline
N, M = list(map(int, readline().split()))
INF = 10**10
dp = [INF] * (2**N)
dp[0] = 0
for i in range(M):
    a, b = list(map(int, readline().split()))
    c = list(map(int, readline().split()))
    key = 0
    for j in range(len(c)):
        key += 1 << (c[j] - 1)
    for j in range(len(dp)):
        if dp[j] == INF:
            continue
        if j | key == j:
            continue
        if dp[j | key] > dp[j] + a:
            dp[j | key] = dp[j] + a
if dp[-1] == INF:
    print((-1))
else:
    print((dp[-1]))

-        dp[j | key] = min(dp[j | key], dp[j] + a)


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

S = input()

latest = [None]*K

i = len(S)+C

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

  i = S.rindex("o", 0, i-C)

  latest[j] = i

if i<=C or "o" not in S[:i-C]:

  i = -C-1

  for j in latest:

    i = S.index("o", i+C+1)

    if i == j:

      print((i+1))

def solve():

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

  workable = [i for i, s in enumerate(input()) if s=="o"]

  if len(workable) == K:

    return workable

  prev = workable[-1]

  latest = {prev}

  i = len(workable)-1

  while i > 0:

    i -= 1

    if prev - workable[i] > C:

      latest.add(workable[i])

      prev = workable[i]

      if len(latest) > K:

        return []

  must = []

  i = -1

  prev = -C-1

  while i < len(workable)-1:

    i += 1

    if workable[i] - prev > C:

      if workable[i] in latest:

        must.append(workable[i])

      prev = workable[i]

  return must

for i in solve():

  print((i+1))

N, K, C = list(map(int, input().split()))
S = input()
latest = [None] * K
i = len(S) + C
for j in range(K - 1, -1, -1):
    i = S.rindex("o", 0, i - C)
    latest[j] = i
if i <= C or "o" not in S[: i - C]:
    i = -C - 1
    for j in latest:
        i = S.index("o", i + C + 1)
        if i == j:
            print((i + 1))

def solve():
    N, K, C = list(map(int, input().split()))
    workable = [i for i, s in enumerate(input()) if s == "o"]
    if len(workable) == K:
        return workable
    prev = workable[-1]
    latest = {prev}
    i = len(workable) - 1
    while i > 0:
        i -= 1
        if prev - workable[i] > C:
            latest.add(workable[i])
            prev = workable[i]
            if len(latest) > K:
                return []
    must = []
    i = -1
    prev = -C - 1
    while i < len(workable) - 1:
        i += 1
        if workable[i] - prev > C:
            if workable[i] in latest:
                must.append(workable[i])
            prev = workable[i]
    return must

for i in solve():
    print((i + 1))

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

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

+    workable = [i for i, s in enumerate(input()) if s == "o"]

+                must.append(workable[i])


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

sunuke = [True]*N

for i in range(K):

    d = int(input())

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

    for a in A:

        sunuke[a-1] = False

ans = 0

for i in range(N):

    if sunuke[i]:

        ans += 1

print(ans)

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

flag = [True]*N

for i in range(K):

    d = int(input())

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

    for a in A:

        flag[a-1] = False

ans = 0

for i in range(N):

    if flag[i]:

        ans += 1

print(ans)

N, K = list(map(int, input().split()))
sunuke = [True] * N
for i in range(K):
    d = int(input())
    A = list(map(int, input().split()))
    for a in A:
        sunuke[a - 1] = False
ans = 0
for i in range(N):
    if sunuke[i]:
        ans += 1
print(ans)

N, K = list(map(int, input().split()))
flag = [True] * N
for i in range(K):
    d = int(input())
    A = list(map(int, input().split()))
    for a in A:
        flag[a - 1] = False
ans = 0
for i in range(N):
    if flag[i]:
        ans += 1
print(ans)

-sunuke = [True] * N
+flag = [True] * N
-        sunuke[a - 1] = False
+        flag[a - 1] = False
-    if sunuke[i]:
+    if flag[i]:


Input:
import sys

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

def resolve():

    import math

    n=int(input())

    print((math.factorial(n)%(10**9+7)))

resolve()

import sys

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

def resolve():

    answer=1

    n=int(input())

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

        answer*=i

        answer%=10**9+7

    print(answer)

resolve()

import sys

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

def resolve():
    import math

    n = int(input())
    print((math.factorial(n) % (10**9 + 7)))

resolve()

import sys

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

def resolve():
    answer = 1
    n = int(input())
    for i in range(1, n + 1):
        answer *= i
        answer %= 10**9 + 7
    print(answer)

resolve()

-    print((math.factorial(n) % (10**9 + 7)))


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

j = 0

for i in range(A,B+1):

  l = list(str(i))

  l_reverse = list(reversed(l))

  if l == l_reverse:

    j += 1

print(j)

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

ans = 0

for n in range(A, B+1):

    n = str(n)

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

        ans += 1

print(ans)

A, B = list(map(int, input().split()))
j = 0
for i in range(A, B + 1):
    l = list(str(i))
    l_reverse = list(reversed(l))
    if l == l_reverse:
        j += 1
print(j)

A, B = list(map(int, input().split()))
ans = 0
for n in range(A, B + 1):
    n = str(n)
    if n == n[::-1]:
        ans += 1
print(ans)

-j = 0
-for i in range(A, B + 1):
-    l = list(str(i))
-    l_reverse = list(reversed(l))
-    if l == l_reverse:
-        j += 1
-print(j)
+ans = 0
+for n in range(A, B + 1):
+    n = str(n)
+    if n == n[::-1]:
+        ans += 1
+print(ans)


Input:
s = int(input())

m, s = s // 60, s % 60

h, m = m // 60, m % 60

print((':'.join(map(str, [h,m,s]))))

s = int(input())

second = s % 60

s = s // 60

min = s % 60

hour = s // 60

print(f'{hour}:{min}:{second}')

s = int(input())
second = s % 60
s = s // 60
min = s % 60
hour = s // 60
print(f"{hour}:{min}:{second}")


Input:
import math

N = int(input())

print((math.factorial(N)%(10**9+7)))

import math

N = int(input())

a = 1

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

    a = a*n % (10**9+7)

print(a)

import math

N = int(input())
print((math.factorial(N) % (10**9 + 7)))

import math

N = int(input())
a = 1
for n in range(2, N + 1):
    a = a * n % (10**9 + 7)
print(a)

-print((math.factorial(N) % (10**9 + 7)))


Input:
import sys

input = sys.stdin.readline

def main():

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

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

  BIT = [0]*(m+2)

  def add(i, a):

    while i <= m+1:

      BIT[i] += a

      i += i&(-i)

  def bit_sum(i):

    res = 0

    while i > 0:

      res += BIT[i]

      i -= i&(-i)

    return res

  S = sorted([(r-l+1, l, r) for l, r in LR], reverse=True)

  cnt = n

  L = []

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

    while S and S[-1][0] == i:

      c, l, r = S.pop()

      cnt -= 1

      add(l, 1)

      add(r+1, -1)

    res = cnt

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

      res += bit_sum(j)

    L.append(res)

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

if __name__ == "__main__":

  main()

import sys

input = sys.stdin.readline

def main():

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

  S = [[] for _ in range(m+1)]

  for _ in range(n):

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

    S[r-l+1].append((l, r))

  BIT = [0]*(m+2)

  def add(i, a):

    while i <= m+1:

      BIT[i] += a

      i += i&(-i)

  def bit_sum(i):

    res = 0

    while i > 0:

      res += BIT[i]

      i -= i&(-i)

    return res

  cnt = n

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

    for l, r in S[i]:

      cnt -= 1

      add(l, 1)

      add(r+1, -1)

    res = cnt

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

      res += bit_sum(j)

    print(res)

if __name__ == "__main__":

  main()

import sys

input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    LR = [list(map(int, input().split())) for _ in range(n)]
    BIT = [0] * (m + 2)

    def add(i, a):
        while i <= m + 1:
            BIT[i] += a
            i += i & (-i)

    def bit_sum(i):
        res = 0
        while i > 0:
            res += BIT[i]
            i -= i & (-i)
        return res

    S = sorted([(r - l + 1, l, r) for l, r in LR], reverse=True)
    cnt = n
    L = []
    for i in range(1, m + 1):
        while S and S[-1][0] == i:
            c, l, r = S.pop()
            cnt -= 1
            add(l, 1)
            add(r + 1, -1)
        res = cnt
        for j in range(0, m + 1, i):
            res += bit_sum(j)
        L.append(res)
    print(*L, sep="\n")

if __name__ == "__main__":
    main()

import sys

input = sys.stdin.readline

def main():
    n, m = list(map(int, input().split()))
    S = [[] for _ in range(m + 1)]
    for _ in range(n):
        l, r = list(map(int, input().split()))
        S[r - l + 1].append((l, r))
    BIT = [0] * (m + 2)

    def add(i, a):
        while i <= m + 1:
            BIT[i] += a
            i += i & (-i)

    def bit_sum(i):
        res = 0
        while i > 0:
            res += BIT[i]
            i -= i & (-i)
        return res

    cnt = n
    for i in range(1, m + 1):
        for l, r in S[i]:
            cnt -= 1
            add(l, 1)
            add(r + 1, -1)
        res = cnt
        for j in range(0, m + 1, i):
            res += bit_sum(j)
        print(res)

if __name__ == "__main__":
    main()

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

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

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

-    S = sorted([(r - l + 1, l, r) for l, r in LR], reverse=True)


Input:
import functools

print((len(functools.reduce(lambda x, y: x&y,[set(input().split()[1:]) for _ in [0]*int(input().split()[0])]))))

print((len(set.intersection(*[set(input().split()[1:]) for _ in [0]*int(input().split()[0])]))))

import functools

print(
    (
        len(
            functools.reduce(
                lambda x, y: x & y,
                [set(input().split()[1:]) for _ in [0] * int(input().split()[0])],
            )
        )
    )
)

print(
    (
        len(
            set.intersection(
                *[set(input().split()[1:]) for _ in [0] * int(input().split()[0])]
            )
        )
    )
)

-                [set(input().split()[1:]) for _ in [0] * int(input().split()[0])],

+                *[set(input().split()[1:]) for _ in [0] * int(input().split()[0])]


Input:
#!/usr/bin/env python3

# coding=utf-8

import sys

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

l = [_s is "1" for _s in list(s)]

l_r = l[::-1]

index = 0

for i, (c, n, c_r, n_r) in enumerate(

        zip(l[:len(s) // 2], l[1:len(s) // 2 + 1], l_r[:len(s) // 2], l_r[1:len(s) // 2 + 1])):

    if c ^ n or c_r ^ n_r:

        index = i + 1

print((len(s) - index))

def solve(string):

    l = [s == "1" for s in string]

    l_r = l[::-1]

    index = 0

    h = len(string) // 2

    for i, (c, n, c_r, n_r) in enumerate(zip(l[:h], l[1:h + 1], l_r[:h], l_r[1:h + 1])):

        if c ^ n or c_r ^ n_r:

            index = i + 1

    return str(len(string) - index)

if __name__ == '__main__':

    print((solve(input())))

#!/usr/bin/env python3
# coding=utf-8
import sys

s = sys.stdin.readline().strip()
l = [_s is "1" for _s in list(s)]
l_r = l[::-1]
index = 0
for i, (c, n, c_r, n_r) in enumerate(
    zip(
        l[: len(s) // 2],
        l[1 : len(s) // 2 + 1],
        l_r[: len(s) // 2],
        l_r[1 : len(s) // 2 + 1],
    )
):
    if c ^ n or c_r ^ n_r:
        index = i + 1
print((len(s) - index))

def solve(string):
    l = [s == "1" for s in string]
    l_r = l[::-1]
    index = 0
    h = len(string) // 2
    for i, (c, n, c_r, n_r) in enumerate(
        zip(l[:h], l[1 : h + 1], l_r[:h], l_r[1 : h + 1])
    ):
        if c ^ n or c_r ^ n_r:
            index = i + 1
    return str(len(string) - index)

if __name__ == "__main__":
    print((solve(input())))

+    for i, (c, n, c_r, n_r) in enumerate(


Input:
N = int(input())

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

SUM = 0

for i in A:

    count = 0

    while i%2 == 0:

        i//=2

        count += 1

    SUM+=count

print(SUM)

N = int(input())

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

SUM = 0

for i in A:

    while i%2 == 0:

        i//=2

        SUM += 1

print(SUM)

N = int(input())
A = list(map(int, input().split()))
SUM = 0
for i in A:
    count = 0
    while i % 2 == 0:
        i //= 2
        count += 1
    SUM += count
print(SUM)

N = int(input())
A = list(map(int, input().split()))
SUM = 0
for i in A:
    while i % 2 == 0:
        i //= 2
        SUM += 1
print(SUM)

-    count = 0
-        count += 1
-    SUM += count
+        SUM += 1


Input:
n = int(input())

INF = 10**9 + 7

ans = [0] * (10**5 + 1)

ans[0] = 1

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

    ans[i] = ans[i-1] * i % INF

print((ans[n]))

n = int(input())

mod = 10**9 + 7

ans = 1

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

    ans = ans * i % mod

print(ans)

n = int(input())
mod = 10**9 + 7
ans = 1
for i in range(1, n + 1):
    ans = ans * i % mod
print(ans)


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

ans = a * x + b * y

m = max(x, y)

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

  x -= 1

  y -= 1

  if x < 0:

    x = 0

  if y < 0:

    y = 0

  temp = c*(i*2) + x*a + y*b

  if temp < ans:

    ans = temp

print(ans)

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

ans = a * x + b * y

ans = min(c * max(x, y) * 2, ans)

if x < y:

    ans = min(c * x * 2 + (y - x) * b, ans)

else:

    ans = min(c * y * 2 + (x - y) * a, ans)

print(ans)

a, b, c, x, y = list(map(int, input().split()))
ans = a * x + b * y
m = max(x, y)
for i in range(1, m + 1):
    x -= 1
    y -= 1
    if x < 0:
        x = 0
    if y < 0:
        y = 0
    temp = c * (i * 2) + x * a + y * b
    if temp < ans:
        ans = temp
print(ans)

+    ans = min(c * x * 2 + (y - x) * b, ans)

+    ans = min(c * y * 2 + (x - y) * a, ans)


Input:
n=int(input())

s=input()

x=["SS","SW","WS","WW"]

def check0(i):

    if x[i][0]=="S":

        if s[0]=="o":

            if x[i][-1]=="S":

                return x[i][1]=="S"

            else:

                return x[i][1]=="W"

        else:

            if x[i][-1]=="S":

                return x[i][1]=="W"

            else:

                return x[i][1]=="S"

    else:

        if s[0]=="o":

            if x[i][-1]=="S":

                return x[i][1]=="W"

            else:

                return x[i][1]=="S"

        else:

            if x[i][-1]=="S":

                return x[i][1]=="S"

            else:

                return x[i][1]=="W"

def check1(i):

    if x[i][n-1]=="S":

        if s[n-1]=="o":

            if x[i][n-2]=="S":

                return x[i][0]=="S"

            else:

                return x[i][0]=="W"

        else:

            if x[i][n-2]=="S":

                return x[i][0]=="W"

            else:

                return x[i][0]=="S"

    else:

        if s[n-1]=="o":

            if x[i][n-2]=="S":

                return x[i][0]=="W"

            else:

                return x[i][0]=="S"

        else:

            if x[i][n-2]=="S":

                return x[i][0]=="S"

            else:

                return x[i][0]=="W"

for i in range(4):

    for j in range(n-2):

        if x[i][j+1]=="S":

            if s[j+1]=="o":

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

                    x[i]+="S"

                else:

                    x[i]+="W"

            else:

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

                    x[i]+="W"

                else:

                    x[i]+="S"

        else:

            if s[j+1]=="o":

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

                    x[i]+="W"

                else:

                    x[i]+="S"

            else:

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

                    x[i]+="S"

                else:

                    x[i]+="W"

    #print(x[i])

    if check0(i) and check1(i):

        print((x[i]))

        break

else:

    print((-1))


Input:
# coding: utf-8

import sys

input = sys.stdin.readline

def f(n, abc):

    dp = [[0] * 3 for _ in range(n + 1)]

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

        for j in range(3):

            dp[i][j] = max(dp[i - 1][k] + abc[i - 1][j] \

                for k in range(3) if k != j)

    return(max(dp[n]))

n = int(input())    # 1 <= n <= 10^5

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

print((f(n, abc)))

# coding: utf-8

import sys

input = sys.stdin.readline

def f(n, abc):

    dp = [0] * 3

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

        a, b, c = abc[i - 1]

        dp = [ max(dp[1] + a, dp[2] + a), \

               max(dp[0] + b, dp[2] + b), \

               max(dp[0] + c, dp[1] + c) ]

    return(max(dp))

n = int(input())    # 1 <= n <= 10^5

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

print((f(n, abc)))

# coding: utf-8
import sys

input = sys.stdin.readline

def f(n, abc):
    dp = [[0] * 3 for _ in range(n + 1)]
    for i in range(1, n + 1):
        for j in range(3):
            dp[i][j] = max(dp[i - 1][k] + abc[i - 1][j] for k in range(3) if k != j)
    return max(dp[n])

n = int(input())  # 1 <= n <= 10^5
abc = [list(map(int, input().rstrip().split())) for _ in range(n)]
print((f(n, abc)))

# coding: utf-8
import sys

input = sys.stdin.readline

def f(n, abc):
    dp = [0] * 3
    for i in range(1, n + 1):
        a, b, c = abc[i - 1]
        dp = [
            max(dp[1] + a, dp[2] + a),
            max(dp[0] + b, dp[2] + b),
            max(dp[0] + c, dp[1] + c),
        ]
    return max(dp)

n = int(input())  # 1 <= n <= 10^5
abc = [list(map(int, input().rstrip().split())) for _ in range(n)]
print((f(n, abc)))

-            dp[i][j] = max(dp[i - 1][k] + abc[i - 1][j] for k in range(3) if k != j)


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

point = []

for i in range(N):

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

ct = 0

D2 = D * D

for i in point:

    if (i[0]**2 + i[1]**2) <= D2:

        ct += 1

print(ct)

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

ct = 0

D2 = D * D

for i in range(N):

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

    if (X**2 + Y**2) <= D2:

        ct += 1

print(ct)

N, D = list(map(int, input().split()))
point = []
for i in range(N):
    point.append(list(map(int, input().split())))
ct = 0
D2 = D * D
for i in point:
    if (i[0] ** 2 + i[1] ** 2) <= D2:
        ct += 1
print(ct)

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

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


Input:
from math import factorial

mod = 10**9 + 7

n = int(input())

ans = factorial(n) % mod

print(ans)

N = int(input())

MOD = 10**9 + 7

ans = 1

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

    ans *= i

    ans %= MOD

print(ans)

N = int(input())
MOD = 10**9 + 7
ans = 1
for i in range(2, N + 1):
    ans *= i
    ans %= MOD
print(ans)

-from math import factorial
-mod = 10**9 + 7
-n = int(input())
-ans = factorial(n) % mod
+N = int(input())
+MOD = 10**9 + 7
+ans = 1
+for i in range(2, N + 1):
+    ans *= i
+    ans %= MOD


Input:
import heapq

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

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

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

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

def diff(l):

    m = max(l)

    return sorted(m - v for v in l)[1:]

s = sum(map(max, [a, b, c]))

sa, sb, sc = list(map(diff, [a, b, c]))

da, db, dc = [0], [0], [0]

q = [0]

while k > 0:

    while True:

        if len(sa) > 0 and (len(q) == 0 or q[0] > sa[0]):

            for v in [sa[0] + bb + cc for bb in db for cc in dc]:

                heapq.heappush(q, v)

            da.append(sa[0])

            sa = sa[1:]

        elif len(sb) > 0 and (len(q) == 0 or q[0] > sb[0]):

            for v in [sb[0] + aa + cc for aa in da for cc in dc]:

                heapq.heappush(q, v)

            db.append(sb[0])

            sb = sb[1:]

        elif len(sc) > 0 and (len(q) == 0 or q[0] > sc[0]):

            for v in [sc[0] + aa + bb for aa in da for bb in db]:

                heapq.heappush(q, v)

            dc.append(sc[0])

            sc = sc[1:]

        else:

            break

    v = heapq.heappop(q)

    print(s - v)

    k -= 1

import heapq

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

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

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

c = sorted(map(int, input().split()))

q = []

memo = set()

def qpush(q, ai, bi, ci):

    t = (-(a[ai] + b[bi] + c[ci]), ai, bi, ci)

    if not t in memo:

        memo.add(t)

        heapq.heappush(q, t)

qpush(q, len(a) - 1, len(b) - 1, len(c) - 1)

for _ in range(k):

    s, ai, bi, ci = heapq.heappop(q)

    if ai > 0:

        qpush(q, ai - 1, bi, ci)

    if bi > 0:

        qpush(q, ai, bi - 1, ci)

    if ci > 0:

        qpush(q, ai, bi, ci - 1)

    print(-s)

-    return sorted(m - v for v in l)[1:]

-sa, sb, sc = list(map(diff, [a, b, c]))

-            for v in [sa[0] + bb + cc for bb in db for cc in dc]:

-        elif len(sb) > 0 and (len(q) == 0 or q[0] > sb[0]):

-            for v in [sb[0] + aa + cc for aa in da for cc in dc]:

-        elif len(sc) > 0 and (len(q) == 0 or q[0] > sc[0]):

-            for v in [sc[0] + aa + bb for aa in da for bb in db]:

+qpush(q, len(a) - 1, len(b) - 1, len(c) - 1)


Input:
N = int(input())

A = [0]*N

X = []

Y = []

for i in range(N):

    A[i] = int(input())

    X.append([])

    Y.append([])

    for j in range(A[i]):

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

        X[i].append(x-1)

        Y[i].append(y)

ans = 0

for bit in range(1<<N):

    honest = 0

    ok = True

    for i in range(N):

        if bit&(1<<i):

            honest += 1

            for j in range(A[i]):

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

                    if bit&(1<<X[i][j]):

                        ok = False

                        break

                else:

                    if not bit&(1<<X[i][j]):

                        ok = False

                        break

            if not ok:

                break

    if ok:

        ans = max(ans, honest)

print(ans)

N = int(input())

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

for i in range(N):

    A = int(input())

    for _ in range(A):

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

        XY[i].append((x-1,y))

ans = 0

for bit in range(1<<N):

    cnt = bin(bit).count('1')

    ok = True

    for i in range(N):

        if bit&(1<<i):

            for x,y in XY[i]:

                if y == 1:

                    if not bit&(1<<x):

                        ok = False

                        break

                else:

                    if bit&(1<<x):

                        ok = False

                        break

            if not ok:

                break

    if ok:

        ans = max(ans, cnt)

print(ans)

N = int(input())
A = [0] * N
X = []
Y = []
for i in range(N):
    A[i] = int(input())
    X.append([])
    Y.append([])
    for j in range(A[i]):
        x, y = list(map(int, input().split()))
        X[i].append(x - 1)
        Y[i].append(y)
ans = 0
for bit in range(1 << N):
    honest = 0
    ok = True
    for i in range(N):
        if bit & (1 << i):
            honest += 1
            for j in range(A[i]):
                if Y[i][j] == 0:
                    if bit & (1 << X[i][j]):
                        ok = False
                        break
                else:
                    if not bit & (1 << X[i][j]):
                        ok = False
                        break
            if not ok:
                break
    if ok:
        ans = max(ans, honest)
print(ans)

N = int(input())
XY = [[] for _ in range(N)]
for i in range(N):
    A = int(input())
    for _ in range(A):
        x, y = list(map(int, input().split()))
        XY[i].append((x - 1, y))
ans = 0
for bit in range(1 << N):
    cnt = bin(bit).count("1")
    ok = True
    for i in range(N):
        if bit & (1 << i):
            for x, y in XY[i]:
                if y == 1:
                    if not bit & (1 << x):
                        ok = False
                        break
                else:
                    if bit & (1 << x):
                        ok = False
                        break
            if not ok:
                break
    if ok:
        ans = max(ans, cnt)
print(ans)

+                    if not bit & (1 << x):


Input:
from collections import Counter

import sys

input = sys.stdin.readline

def solve():

    N = int(input())

    Sss = [input().rstrip() for _ in range(N)]

    cnt = Counter(Sss)

    #print('cnt:', cnt)

    maxNum = max(cnt.values())

    #print('maxNum:', maxNum)

    anss = []

    for key, value in list(cnt.items()):

        if value == maxNum:

            anss.append(key)

    #print('anss:', anss)

    anss.sort()

    print(('\n'.join(anss)))

solve()

from collections import Counter

import sys

input = sys.stdin.readline

N = int(input())

Sss = [input().rstrip() for _ in range(N)]

cnt = Counter(Sss)

num = max(cnt.values())

anss = []

for key in sorted(cnt.keys()):

    if cnt[key] == num:

        anss.append(key)

print(('\n'.join(anss)))

from collections import Counter
import sys

input = sys.stdin.readline

def solve():
    N = int(input())
    Sss = [input().rstrip() for _ in range(N)]
    cnt = Counter(Sss)
    # print('cnt:', cnt)
    maxNum = max(cnt.values())
    # print('maxNum:', maxNum)
    anss = []
    for key, value in list(cnt.items()):
        if value == maxNum:
            anss.append(key)
    # print('anss:', anss)
    anss.sort()
    print(("\n".join(anss)))

solve()

from collections import Counter
import sys

input = sys.stdin.readline
N = int(input())
Sss = [input().rstrip() for _ in range(N)]
cnt = Counter(Sss)
num = max(cnt.values())
anss = []
for key in sorted(cnt.keys()):
    if cnt[key] == num:
        anss.append(key)
print(("\n".join(anss)))

-    Sss = [input().rstrip() for _ in range(N)]

-    for key, value in list(cnt.items()):

+Sss = [input().rstrip() for _ in range(N)]


Input:
"""Minimum cost Sort."""

def min_cost_sort(A):

    """Sort list A in ascending order.

    And return the switching cost in sorting.

    """

    B = list(A)

    B.sort()

    cost = 0

    min_w = B[0]

    for i, b in enumerate(B):

        tmp_cost = 0

        bi = A.index(b)

        n = 1

        while bi != i:

            n += 1

            st = B[bi]

            si = A.index(st)

            tmp_cost += b + st

            A[bi], A[si] = st, b

            bi = si

        dec = (n - 1) * (b - min_w)

        inc = 2 * (min_w + b)

        if dec < inc:

            cost += tmp_cost

        else:

            cost += tmp_cost - dec + inc

    return cost

n = input()

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

ans = min_cost_sort(A)

print(ans)

"""Minimum cost Sort."""

def min_cost_sort(A):

    """Sort list A in ascending order.

    And return the switching cost in sorting.

    """

    B = list(A)

    B.sort()

    cost = 0

    min_w = B[0]

    for i, b in enumerate(B):

        tmp_cost = 0

        bi = A.index(b)

        cnt = 0

        while bi != i:

            cnt += 1

            st = B[bi]

            si = A.index(st)

            tmp_cost += b + st

            A[bi], A[si] = st, b

            bi = si

        if cnt:

            dec = cnt * (b - min_w)

            inc = 2 * (min_w + b)

            if dec < inc:

                cost += tmp_cost

            else:

                cost += tmp_cost - dec + inc

    return cost

n = input()

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

ans = min_cost_sort(A)

print(ans)

-            cost += tmp_cost - dec + inc

+                cost += tmp_cost - dec + inc


Input:
from functools import lru_cache

import sys

sys.setrecursionlimit(2000)

s = int(input())

mod = 10 ** 9 + 7

@lru_cache(maxsize=None)

def dfs(n):

    if n <= 2:

        return 0

    elif 3<=n<=5:

        return 1

    else:

        count = 1

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

            count += dfs(n - i)

            count %= mod

        return count % mod

ans = dfs(s)

print(ans)

s = int(input())

mod = 10 ** 9 + 7

dp = [0] * (s + 1)

dp[0] = 1

x = 0

for i in range(3, s + 1):

    x += dp[i - 3]

    dp[i] = x % mod

ans = dp[s] % mod

print(ans)

from functools import lru_cache
import sys

sys.setrecursionlimit(2000)
s = int(input())
mod = 10**9 + 7

@lru_cache(maxsize=None)
def dfs(n):
    if n <= 2:
        return 0
    elif 3 <= n <= 5:
        return 1
    else:
        count = 1
        for i in range(3, n + 1):
            count += dfs(n - i)
            count %= mod
        return count % mod

ans = dfs(s)
print(ans)

s = int(input())
mod = 10**9 + 7
dp = [0] * (s + 1)
dp[0] = 1
x = 0
for i in range(3, s + 1):
    x += dp[i - 3]
    dp[i] = x % mod
ans = dp[s] % mod
print(ans)

-from functools import lru_cache
-import sys
-sys.setrecursionlimit(2000)
-@lru_cache(maxsize=None)
-def dfs(n):
-    if n <= 2:
-        return 0
-    elif 3 <= n <= 5:
-        return 1
-    else:
-        count = 1
-        for i in range(3, n + 1):
-            count += dfs(n - i)
-            count %= mod
-        return count % mod
-ans = dfs(s)
+dp = [0] * (s + 1)
+dp[0] = 1
+x = 0
+for i in range(3, s + 1):
+    x += dp[i - 3]
+    dp[i] = x % mod
+ans = dp[s] % mod


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

num = 0

q = []

for i in range(n):

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

    q.append((a,b))

q.sort()

for i in range(n):

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

    num += b

    if num >= k:

        print(a)

        exit()

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

cnt = 0

num = []

for i in range(n):

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

    num.append((a,b))

num.sort()

for i in range(n):

    cnt += num[i][1]

    if cnt >= k:

        print((num[i][0]))

        exit()

n, k = list(map(int, input().split()))
num = 0
q = []
for i in range(n):
    a, b = list(map(int, input().split()))
    q.append((a, b))
q.sort()
for i in range(n):
    a, b = q[i][0], q[i][1]
    num += b
    if num >= k:
        print(a)
        exit()

n, k = list(map(int, input().split()))
cnt = 0
num = []
for i in range(n):
    a, b = list(map(int, input().split()))
    num.append((a, b))
num.sort()
for i in range(n):
    cnt += num[i][1]
    if cnt >= k:
        print((num[i][0]))
        exit()

-num = 0
-q = []
+cnt = 0
+num = []
-    q.append((a, b))
-q.sort()
+    num.append((a, b))
+num.sort()
-    a, b = q[i][0], q[i][1]
-    num += b
-    if num >= k:
-        print(a)
+    cnt += num[i][1]
+    if cnt >= k:
+        print((num[i][0]))