peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Wrong Answer
N=int(input())
A=[]
B=[]
for _ in range(N):
  a,b=map(int,input().split())
  A.append(a)
  B.append(b)
if N%2==0:
  A.sort()
  B.sort()
  c=int(N/2)
  d=A[c-1]+B[c-1]
  e=A[c]+B[c]
  f=e-d
  print(f+1)
else:
  A.sort()
  B.sort()
  c=int(N/2)
  print(B[c]-A[c]+1)
# Judge status: Accepted
import math
n,m = map(int,input().split())
mod = 10**9+7
fact_n = math.factorial(n) % mod
fact_m = math.factorial(m) % mod

if abs(n-m) >= 2:
  print(0)
  exit()
elif n == m:
  print((fact_n * fact_m * 2) % mod)
else:
  print((fact_n * fact_m) % mod)
# Judge status: Accepted
a, b, k = map(int, input().split())
ls = []
for i in range(1, min(a, b)+1):
    if a%i==0 and b%i==0:
        ls.append(i)
ls = ls[::-1]
print(ls[k-1])
# Judge status: Accepted
N = int(input())
print(f"{-N % 1000}")
# Judge status: Wrong Answer
A,B,C = map(int,input().split())
if A == B and  B == C and C == A:
  print(-1)
else:
  count = 0
  while(A%2==0 and B%2 == 0 and C%2==0):
    A_ = A
    B_ = B
    A = (B+C)/2
    B = (A_+C)/2
    C = (A_+B_)/2
    print(A,B,C)
    count+=1
  print(count)
# Judge status: Wrong Answer
n = int(input())
L = list(map(int,input().split()))
L = [x for x in L if x%2 ==0]
for i in range(len(L)):
    if L[i]%3 == 0 or L[i]%5== 0:
        flag = True
    else:
        flag =False
        break
#print(L)
if len(L) == 0:
    print("DENIED")
    exit()
if flag:
    print("APPROVED")
else:
    print("DENIED")
# Judge status: Accepted
a = []
for i in range(5):
    tmp = input()
    a.append(int(tmp))
k = int(input())
ans = True
for i in range(len(a)):
    for j in range(i, len(a)):
        if(a[j] - a[i] > k):
            ans = False
if ans:
    print("Yay!")
else:
    print(":(")
# Judge status: Accepted
A, B, C = map(int, input().split())
if C >= A and C <= B :
  print("Yes")
else :
  print("No")
# Judge status: Accepted
a, b = map(int,input().split())
print(int(str(min(a, b)) * max(a, b)))
# Judge status: Accepted
K,X = map(int,input().split())
ans = []
for i in range(X-K+1,X+K):
    ans.append(i)
print(*ans)
# Judge status: Accepted
#ABC158C
import sys
a, b = map(int, sys.stdin.readline().split())
#print(a,b)

for num in range(0, 1001):
    A = int(num*0.08)
    B = int(num*0.1)
    #print(A, B, num)
    if a==A and b ==B:
        print(num)
        break
else:
    print(-1)
# Judge status: Accepted
import sys
input = sys.stdin.buffer.readline

def main():
    N = int(input())
    def attack(x):
        if x == 1:
            return 1
        else:
            x //= 2
            return 2*attack(x)+1
            
    print(attack(N))
    
if __name__ == "__main__":
    main()
# Judge status: Accepted
k, x = map(int, input().split())
k_yen = 500 * k
if k_yen >= x:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
N=int(input())
R=[]
for i in range(N):
    X,L=map(int, input().split())
    R.append((X-L,X+L))

R=sorted(R)
now=-(10**9+1)
minr=-(10**9+1)
count=0
for t in R:
    l,r=t
    if now<=l:
        if l<minr:
            minr=min(r,minr)
        else:
            count+=1
            now=l
            minr=r
    else:
        continue

print(count)
# Judge status: Accepted
S=input()
T=input()

ok=True
a,b={},{}
for i in range(len(S)):
  s=S[i]
  t=T[i]
  if s in a:
    if a[s]!=t:
      ok=False
  if t in b:
    if b[t]!=s:
      ok=False
  a[s]=t
  b[t]=s

print("Yes" if ok else "No")
# Judge status: Accepted
A, B = map(int, input().split())
C = A + B

print("Possible" if A%3==0 or B%3==0 or C%3==0 else "Impossible")
# Judge status: Wrong Answer
# input1 = list(map(int, (input().split())))

s = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]

N = int(input())

# for i in range(N):
print("aaa")
print("aab")
print("aba")
print("abb")
print("abc")
# Judge status: Accepted
l, r, d = map(int,input().rstrip("\n").split(" "))
 
answer = (r // d) - ((l-1) // d)
 
print(answer)
# Judge status: Wrong Answer
import math
n, m = map(int, input().split())
mod = 10 ** 9 + 7
res = 2 * math.factorial(n) * math.factorial(m)
print(res % mod)
# Judge status: Wrong Answer
s = list(input())

ans = 0
flag = 1
while (flag):
    flag = 0
    i = 0
    loop_len = len(s)
    while (i < (loop_len - 1)):
        print(loop_len)
        print(s)
        if (s[i] != s[i + 1]):
            flag = 1
            ans += 2
            del s[i: i + 2]
        loop_len = len(s)
        i += 1

print(ans)
# Judge status: Accepted
def gcd(a, b):
    if a > b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b
def lcm(a, b):
    return a * b // gcd(a, b)

a, b = map(int, input().split())
print(lcm(a, b))
# Judge status: Wrong Answer
import sys

input = sys.stdin.readline


def S():
    return input().rstrip()


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


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


n = I()
al = set(MI())


s = 0
for a in al:
    s ^= a

ans = []
for a in al:
    ans.append(str(s ^ a))

print(" ".join(ans[::-1]))
# Judge status: Wrong Answer
C = input()
print(chr(ord('C') + 1))
# Judge status: Wrong Answer
A=[]
A+=list(map(int, input().split()))
A+=list(map(int, input().split()))
A+=list(map(int, input().split()))
N=int(input())

b=[]
for _ in range(N):
    b.append(int(input()))

found=set()
for num in b:
    if num in A:
        found.add(A.index(num))
BINGO=[{0, 3, 6}, {1, 4, 7}, {2, 5, 8},  {0, 1, 2}, {3, 4, 5}, {6, 7, 8}, {0, 4, 8}, {2, 4, 6}]
for tri in BINGO:
    if tri < found:
        print('Yes')
        break
else:
    print('No')
# Judge status: Accepted
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    new_s=""
    i=0
    if n==0:
        print(0)
        sys.exit()
    while n:
        x=(n>>i)&1
        new_s=str(x)+new_s
        n-=x*(-2)**i
        i+=1
    print(new_s)


if __name__=='__main__':
    main()
# Judge status: Accepted
n = int(input())
s = input()
t = ""
for i in s:
  a = ord(i) + n
  if a > ord("Z"):
    a = a - 26
  t += chr(a)
print(t)
# Judge status: Accepted
a=int(input())
print(int(a+a**2+a**3))
# Judge status: Accepted
n,k = map(int,input().split())
A = list(map(int,input().split()))

for j in range(min(k,45)):
  B = [0]*(n)
  for i in range(n):
    l = max(0,i-A[i])
    r = min(n-1,i+A[i])
    B[l] += 1
    if r+1 < n:
      B[r+1] -= 1  
      
  for i in range(1,n):
    B[i]+=B[i-1]
  
  A = B.copy()
print(*B)
# Judge status: Accepted
a,b,x=map(int,input().split())
start=((a-1)//x+1)*x
if start>b:
    print(0)
else:
    print((b-start)//x+1)
# Judge status: Wrong Answer
s = str(input())
k = int(input())
ans = 0
count = 0
for i in s:
    if i == "1":
        count += 1
    else:
        if k <= count:
            print(1)
            break
        else:
            print(i)
            break
# Judge status: Accepted
a, b = map(int, input().split())
print(a if a % b != 0 else -1)
# Judge status: Accepted
import math
n, d = map(int, input().split())
x = []
for i in range(n):
    x.append(list(map(int, input().split())))

count = 0
eps = 10**-6
for i in range(n-1):
    for j in range(i+1, n):
        total = 0
        for k in range(d):
             total += pow(x[i][k] - x[j][k], 2)
        v = math.sqrt(total)
        if math.ceil(v + eps) != math.ceil(v - eps):
            count += 1
print(count)
# Judge status: Wrong Answer
import numpy
input_x = [int(i) for i in input().split(" ")]
for i in range(5):
    if not i in input_x:
        print(i)
# Judge status: Wrong Answer
list = list(map(int, input().split()))
print(list[1] // list[2]-list[0] // list[2])
# Judge status: Accepted
N, M=map(int, input().split())
ans=[0]*N
for i in range(M):
  a, b=map(int, input().split())
  ans[a-1]+=1
  ans[b-1]+=1
[print(i) for i in ans]
# Judge status: Accepted
import copy

def main():
    A, V = map(int, input().split())
    B, W = map(int, input().split())
    T = int(input())

    if V <= W:
        print('NO')
    elif (abs(A-B) / (V-W)) <= T:
        print('YES')
    else:
        print('NO')

main()
# Judge status: Wrong Answer
tmp=input()
n=int(tmp)
l=len(tmp)
rev=tmp[::-1]
pay_rev=""
next_bit=0
for i in range(l):
    val=int(rev[i])+next_bit
    if val>5:
        val=0
        next_bit=1
    else:
        next_bit=0
    pay_rev+=str(val)
if pay_rev[-1]=="0":
    pay_rev+="1"
pay=pay_rev[::-1]

print(pay)
zankin=int(pay)-n
print(zankin)
ans=0
for i in pay:
    ans+=int(i)
for i in str(zankin):
    ans+=int(i)

print(ans)
# Judge status: Wrong Answer
n = int(input())
a = list(map(int, input().split()))
mx = max(a)

ans = 0
for i in a:
    if mx == i:
        continue
    if mx - i <= i:
        if ans <= mx-i:
            ans = i
    else:
        if ans <= i:
            ans = i

print(mx, ans, sep=" ")
# Judge status: Accepted
import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    a, b = list(map(str, sys.stdin.readline().split()))
    c = int(a + b)
    print('Yes' if int(c**0.5)**2 == c else 'No')



if __name__ == '__main__':
    main()
# Judge status: Accepted
import sys
read = sys.stdin.read
def main():
    n, q = map(int, input().split())
    s = input()
    acs = [0] * (n + 1)
    cnt = 0
    for i1 in range(1, n):
        if s[i1-1] =='A' and s[i1] == 'C':
            cnt += 1
        acs[i1+1] = cnt
    for _ in range(q):
        l, r = map(int, input().split())
        r = acs[r] - acs[l]
        print(r)


if __name__ == '__main__':
    main()
# Judge status: Accepted
n = int(input())
A = []
for i in range(n):
    x, l = map(int, input().split())
    a = x - l
    b = x + l
    A.append((a, b))
A = sorted(A, key = lambda x:x[1])
cnt = 0
right = -float('inf')
for i in range(n):
    if right <= A[i][0] :
        cnt += 1
        right = A[i][1]
print(cnt)
# Judge status: Accepted
s = len(input())
print('x'*s)
# Judge status: Accepted
n = int(input())
s = input()
lst = [0]*n

lst[0] = s[1:].count("E")
for i in range(1,n):
    lst[i] = lst[i-1]
    if s[i-1]=="W":
        lst[i]+=1
    if s[i]=="E":
        lst[i]-=1

print(min(lst))
# Judge status: Accepted
a= (input().split())
d = int(''.join(a))
if d % 4 == 0:
    print("YES")
else:
    print("NO")
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split( )))
a.sort()

l1 = a[-1]
i=-2
try:
    while a[i]!=l1:
        l1 = a[i]
        i-=1
    i-=1
    l2 = a[i]
    i-=1
    while a[i]!=l2:
        l2 = a[i]
        i-=1
except:
    print(0)
    exit()
print(l1*l2)
# Judge status: Accepted
N, K = map(int, input().split())
hn = []
for i in range(N):
  hn.append(int(input()))
hn = sorted(hn,reverse=True)
min = 10**9+7
for i in range(N-K+1):
#  print("hn[i] is {} , hn[K+i] is {}".format(hn[i],hn[K+i-1]))
  if min > (hn[i]-hn[K+i-1]):
    min = hn[i]-hn[K+i-1]
print(min)
# Judge status: Wrong Answer
import numpy as np
D = int(input())
c = list(map(int,input().split()))
s=[]
for i in range(D):
  x = np.array(list(map(int, input().split())))
  s.append(c[x.argmax()])
for i in range(D):
  print(s[i])
# Judge status: Accepted
A,B,K = map(int,input().split())
lsans = []
for i in range(A,A+K):
    if i <= B:
        lsans.append(i)
for j in range(B+1-K,B+1):
    if j >= A and not(j in lsans):
        lsans.append(j)
for i in lsans:
    print(i)
# Judge status: Accepted
from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
cnt_i = defaultdict(lambda :0)
cnt_j = defaultdict(lambda :0)
for i in range(n):
    temp_i = a[i] + i + 1
    temp_j = i + 1 - a[i]
    cnt_i[temp_i] += 1
    cnt_j[temp_j] += 1

ans = sum(v * cnt_j[i] for i,v in cnt_i.items())
print(ans)
# Judge status: Accepted
S = input()
print(S.replace("2017","2018"))
# Judge status: Accepted
a,b,c = map(int,input().split())
if (a%2==0)or(b%2==0)or(c%2==0):
    print(0)
else:
    x = [a,b,c]
    x.sort()
    print(x[0]*x[1])
# Judge status: Accepted
print(len([i for i in range(1, int(input())+1) if len(str(i)) % 2 == 1]))
# Judge status: Wrong Answer
N = int(input())

if N < 2 or N % 2 == 1:
  print(0)
  exit()
  
res = 0

de = 10
while de < N + 1:
  res += int(N / de)
  de *= 5
print(res)
# Judge status: Wrong Answer
a, b, c = map(int, input().split())

print(b//c + a //c)
# Judge status: Accepted
x = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"]
y = input()
print(7-x.index(y))
# Judge status: Wrong Answer
def LI():
    return list(map(int, input().split()))


L, R = LI()
ans = 2020
for i in range(L, R+1):
    x = (i*i) % 2019
    for j in range(i, R+1):
        y = (i*j) % 2019
        ans = min(ans, x)
        if x == y:
            break
    if ans == 0:
        break
print(ans)
# Judge status: Accepted
s = input()
ans = 'Good'
for i in range(3):
	if s[i] == s[i + 1]:
		ans = 'Bad'
print(ans)
# Judge status: Wrong Answer
import sys
def input(): return sys.stdin.readline().rstrip()
import heapq

N, M = map(int,input().split())
A = list(map(int,input().split()))
A = [(-1)*num for num in A]
heapq.heapify(A)

ans = 0
for i in range(M):
    a = heapq.heappop(A)
    a *= -1
    a /= 2
    a *= -1    
    heapq.heappush(A,a)

price = 0
for a in A:
    price += (-1) * a

print(price)
# Judge status: Accepted
n = int(input().rstrip())
line = input().rstrip().split(' ')

a = []
d = [0] * n
for i in range(n):
    num = int(line[i])
    a.append(num)
    d[num - 1] += 1

ans_list = [0] * n
for i in range(n):
    ans_list[i] = int(d[i] * (d[i] - 1) / 2)

total = 0
for i in range(n):
    total += ans_list[i]

for i in range(n):
    ans = total

    ans -= ans_list[a[i] - 1]
    num = d[a[i] - 1] - 1
    ans += num * (num - 1) / 2

    print(int(ans))
# Judge status: Accepted
import os, sys, re, math

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

A = sorted(A)
for i in range(N - 1):
    if A[i] + A[i + 1] < 0:
        A[i] *= -1
        A[i + 1] *= -1

print(sum(A))
# Judge status: Accepted
from collections import deque
s=deque(list(input()))
q=int(input())
r = False
for i in range(q):
    tmp = list(input().split(' '))
    if tmp[0]=='1':
        r = not r
    elif (not r and tmp[1]=='1') or (r and tmp[1] =='2'):
        s.appendleft(tmp[2])
    else:
        s.append(tmp[2])
if not r:
    for i in s:
        print(i,end='')
else:
    for i in reversed(s):
        print(i,end='')
# Judge status: Accepted
n = int(input())
mi = 10**9

def f(n):
    sums = 0
    while n>0:
        sums += n%10
        n //= 10
    return sums

for a in range(1, n+1):
    b = n-a
    if mi > f(a)+f(b) and b>0:
        mi = f(a)+f(b)
print(mi)
# Judge status: Wrong Answer
N,D = map(int,input().split())
print(N//(2*D+1)+1)
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))

ans, cnt, node = 0, sum(a), 1
for i in range(n + 1):
    ans += node
    cnt -= a[i]
    node = min(cnt, (node - a[i]) * 2)
    if node < 0:
        print(-1)
        break
else:
    print(ans)
# Judge status: Wrong Answer
import sys
import math
import time
readline = sys.stdin.readline


def main():
    listSum = [6, 3, 1]
    k = int(input())
    sumGCD = 0
    for a in range(1, k + 1):
        for b in range(a, k + 1):
            for c in range(b, k + 1):
                sumGCD += gcd(a, b, c) * listSum[len(set([a, b, c])) - 1]
    print(sumGCD)


def gcd(a, b, c):
    return math.gcd(math.gcd(a, b), c)


if __name__ == '__main__':
    s = time.time()
    main()
    # print(time.time() - s)
# Judge status: Accepted
import sys

y, m, d = map(int, sys.stdin.readline().rstrip().split('/'))

def main():
    ans = 'Heisei' if m <= 4 else 'TBD'
    print(ans)

if __name__ ==  '__main__':
    main()
# Judge status: Accepted
n = int(input())
P = list(map(int,input().split()))

c=0
for i in range(n-2):
    P2 = sorted(P[i:i+3])
    if P2[1]==P[i+1] :
        c+=1

print(c)
# Judge status: Wrong Answer
N = int(input())
A = list(map(int,input().split()))
R = [0]*9

for a in A:
  if a<400:
    R[0]+=1
  elif a<800:
    R[1]+=1
  elif a<1200:
    R[2]+=1
  elif a<1600:
    R[3]+=1
  elif a<2000:
    R[4]+=1
  elif a<2400:
    R[5]+=1
  elif a<2800:
    R[6]+=1
  elif a<3200:
    R[7]+=1
  else:
    R[8]+=1

M = 8-R[:-1].count(0)+R[-1]
m = 8-R[:-1].count(0)

print(m,M)
# Judge status: Wrong Answer
import math
x = int(input())
for b in range(-100, 100):
    v = b ** 5 + x
    p = pow(v, 0.2)
    if p == p.real:
       print(p.real, b)
       break
# Judge status: Accepted
x,y = map(int,input().split())
print(abs(abs(x)-abs(y)) + int(x>y)*(abs(int(x*y>0))+1) + int(x<y)*(abs(int(x*y<0))))
# Judge status: Accepted
def step(arr):
    res = 0
    for i in range(1,len(arr)):
        if arr[i] >= arr[i-1]:
            continue
        else:
            res += abs(arr[i-1] - arr[i])
            arr[i] = arr[i - 1]
    return res

def start():
    n = int(input())
    arr = [int(x) for x in input().split(" ")]
    print(step(arr))
start()
# Judge status: Wrong Answer
n = map(int, input().split())
alist = list(map(int, input().split()))
m = max(alist)
sbn = 10**10
for a in alist:
    if m/2 - a < sbn:
        ans = a
        sbn = m/2 - a
print(m, ans)
# Judge status: Accepted
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    cnt_a = 0
    cnt_b = 0
    for a, b in zip(A, B):
        if a > b:
            cnt_a += a - b
        elif a < b:
            cnt_b += (b - a) // 2

    if cnt_a > cnt_b:
        return "No"
    else:
        return "Yes"


print(solve())
# Judge status: Wrong Answer
from collections import deque
d = deque()
s = input()
d.append(s)
q = int(input())
for i in range(q):
    tfc = input().split()
    if int(tfc[0]) == 1:
        d.reverse()
#         print('reverse:', d)
    else:
        if int(tfc[1]) == 1:
            d.appendleft(tfc[2])
#             print('appendleft:', d)
        else:
            d.append(tfc[2])
#             print('append:', d)
print(''.join(d))
# Judge status: Accepted
K,X = map(int,input().split())

for i in range(1,2*K):
    print(X-K+i,end=" ")
# Judge status: Accepted
a, b = map(int, input().split())
print((a+b) % 24)
# Judge status: Accepted
a, b, c, x, y = map(int, input().split())

# i組みのabを買うことについて全探索
ans = float("inf")
for i in range(max(x, y)+1):
    price = i * 2 * c + max(x-i, 0) * a + max(y-i, 0) * b
    ans = min(ans, price)
print(ans)
# Judge status: Wrong Answer
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int):
    print(YES if (N//100 == 7 or N//10 == 7 or N%10 == 7) else NO)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
N = int(input())
T,A = map(int,input().split())
H = list(map(int,input().split()))

a_meter = (12-A*1000)//6

ans = -1
diff = 10**6
for i in range(N):
    temp = abs(a_meter - H[i])
    # print("temp:" + str(temp))
    # print("diff:" + str(diff))
    if diff > temp:
        diff = temp
        ans = i+1

print(ans)
# Judge status: Accepted
s=input()
ans=1000
for i in range(len(s)-2):
    n=''
    n+=s[i]
    n+=s[i+1]
    n+=s[i+2]
    n=int(n)
    ans=min(abs(n-753),ans)
print(ans)
# Judge status: Accepted
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(abs(n - r)) * math.factorial(r))

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

print(combinations_count(N, 2) + combinations_count(M, 2))
# Judge status: Accepted
import collections

n = int(input())
a = list(map(int,input().split()))
cnt = collections.Counter(a)
#print(cnt)
a.sort()
dp = [1]*(max(a)+1)

sum = 0
for i in range(n):
    for j in range(a[i]*2,len(dp),a[i]):
            dp[j] = 0
    if dp[a[i]] == 1 and cnt[a[i]]==1:
        sum += 1

print(sum)
# Judge status: Accepted
import sys
input = sys.stdin.readline

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

if (h==1)or(w==1):
    print(1)
    exit()

allmas = h*w

if allmas % 2 == 1:
    print(int((allmas/2) + 0.5))
else:
    print(int(allmas/2))
# Judge status: Accepted
a = int(input())
b = int(input())
c = int(input())
x = int(input())
cnt = 0
for i in range(a+1):
        for j in range(b+1):
                for k in range(c+1):
                        d = 500*i+100*j+50*k
                        if d == x:
                                cnt += 1
print (cnt)
# Judge status: Accepted
H = int(input())
W = int(input())
N = int(input())

if H > W:
    if N % H == 0:
        print(N // H)
    else:
        print(N//H + 1)
else:
    if N % W == 0:
        print(N // W)
    else:
        print(N//W + 1)
# Judge status: Accepted
s=list(input())
t=list(input())
ans=len(t)
for i in range(len(s)-len(t)+1):
    tmp=0
    for j in range(len(t)):
        if s[i+j]!=t[j]:
            tmp+=1
    ans=min(ans,tmp)

print(ans)
# Judge status: Wrong Answer
N,M = map(int,input().split())
A = list(map(int,input().split()))
BC = [list(map(int,input().split())) for _ in range(M)]
ans = []
A.sort()
count = 0
for b,c in BC:
  if count < N:
    if c <= A[count]:
      break
  else:
    if c <= A[N-1]:
      break
  ans += [c]*b
  count += b
ans.extend(A)
ans = sorted(ans,reverse = True)
print(sum(ans[:N]))
# Judge status: Accepted
n, m = map(int, input().split())

if n == m:
	print("Yes")
else:
	print("No")
# Judge status: Accepted
N,P = map(int, input().split())
A = [int(a) for a in input().split()]

even = 0
odd = 0
for a in A:
    if a%2 == 0:
        even += 1
    else:
        odd += 1

L = [1]*(N+1)
for i in range(N):
    L[i+1] = L[i]*(i+1)
    
def cmb(n, r):
    return L[n]//L[r]//L[n-r]

ans = pow(2, N)    
for i in range(1, odd+1, 2):
    ans -= cmb(odd, i)*pow(2, even)
if P == 1:
    ans = pow(2, N) - ans

print(ans)
# Judge status: Accepted
import sys
input = sys.stdin.readline
def main():
    W, H, x, y = map(int, input().split())
    if 2*x == W:
        Fx = True
    else:
        Fx = False
    if 2*y == H:
        Fy = True
    else:
        Fy = False
    if Fx and Fy:
        way = 1
    else:
        way = 0
    area = H*W/2
    # print(area," ", way)
    print(area, way)

if __name__ == '__main__':
    main()
# Judge status: Accepted
#!/usr/bin/env python3

S = input()

if int(S[5:7]) < 5:
    print("Heisei")
else:
    print("TBD")
# Judge status: Accepted
n=int(input())
L=[int(i) for i in input().split()]
count=0
for i in range(1,n+1,2):
  if(L[i-1]%2!=0):
    count+=1
print(count)
# Judge status: Wrong Answer
N = input()

cnt = len(str(N))

if cnt <= 3:
    print("ABC" + N)
else:
    print("ABD" + N[cnt-3:])
# Judge status: Accepted
import sys


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


def resolve():
    l = list(map(int, input().split()))
    l.sort(reverse=True)
    x=(l[0]-l[1])+(l[0]-l[2])
    if x%2==0:
        print(x//2)
    else:
        print(x//2+2)
resolve()
# Judge status: Accepted
S = list(input())
cnt = 0
for i in range(len(S)//2):
    if S[i] != S[-1-i]:
        cnt +=1
print(cnt)
# Judge status: Accepted
a = int(input())
b = int(input())
h = int(input())

print(int((a+b)*h/2))
# Judge status: Wrong Answer
# S = list(input().split())
# a = int(S[0])
# b = S[1].replace('.', '')
# B = int(b)
#
# ans = (a * B) // 100
# print(ans)

a, b = input().split()
A = int(a)
b = b.replace('.', '')
B = int(b)
ans = A * B // 100
print(ans)
# Judge status: Accepted
import math
n = int(input())
a = []
for i in range(int(math.sqrt(n))):
  if n%(i+1) == 0:
    a.append((i+1)+(n//(i+1))-2)
print(min(a))
# Judge status: Accepted
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

def main():
    X = int(input())
    while True:
        tmp = make_divisors(X)
        if len(tmp) == 2:
            break
        X += 1

    print(X)


if __name__ == "__main__":
    main()
# Judge status: Wrong Answer
S=input

if S=='Sunny':
    print('Cloudy')
elif S=='Cloudy':
    print('Rainy')
else:
    print('Sunny')
# Judge status: Accepted
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

if n != 100:
    print((100 ** d) * n)
else:
    print((100 ** d) * (n + 1))
# Judge status: Accepted
N = int(input())
*h, = map(int, input().split())
dp = [0] * N
for i in range(1, N):
    if i == 1:
        dp[i] = dp[i-1] + abs(h[i] - h[i-1])
    else:
        dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]))
print(dp[-1])