peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Wrong Answer
import itertools
from collections import Counter
N, M = list(map(int,input().split()))
city_list = [list(map(int,input().split())) +[i+1]  for i in range(M)]
city_list_sorted = sorted(city_list,key=lambda x: (x[0],x[1]) )
city_list_grouped = itertools.groupby(city_list_sorted,key=lambda x:x[0])
ans = [None for i in range(M)]
m =0
for k, v in city_list_grouped:
  print(k)
  counter1 = 1
  for x1 in v:
    ans[m] = [x1[2],format(k,'0>6')+format(counter1,'0>6')]
    counter1 += 1 
    m+=1

for x in sorted(ans):
  print(x[1])
# Judge status: Accepted
print('vowel' if input() in 'aeiou' else 'consonant')
# Judge status: Accepted
h, n = map(int, input().split())
ab = [map(int, input().split()) for _ in range(n)]

dp = [[float("inf")] * (h + 1) for _ in range(n + 1)]
for i in range(n + 1):
    dp[i][0] = 0

for i, (a, b) in enumerate(ab, 1):
    for j in range(h + 1):
        dp[i][j] = min(dp[i-1][j], dp[i][max(j-a, 0)] + b)

ans = dp[n][h]
print(ans)
# Judge status: Accepted
from collections import OrderedDict


a = OrderedDict()
for i in range(3):
    for j in input().split():
        a[j] = 0

n = int(input())
for i in range(n):
    inp = input()
    if inp in a.keys():
        a[inp] = 1

anss = list(a.values())
lines = [(0,1,2), (3,4,5), (6,7,8), (0,3,6), (1,4,7), (2,5,8), (0,4,8), (2,4,6)]

for x,y,z in lines:
    if anss[x] + anss[y] + anss[z] == 3:
        print("Yes")
        exit()
print("No")
# Judge status: Accepted
n = int(input())
s = input()
e = s.count('E')
w = 0
for i in s:
    if i == 'W':
        n = min(n, w + e)
        w += 1
    else:
        w -= 1
        n = min(n, w + e)
print(n)
# Judge status: Accepted
import math
K = int(input())
ans = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            ans += math.gcd(math.gcd(a,b), c)

print(ans)
# Judge status: Wrong Answer
N = int(input())

answer = N*(N-1)//2
print(answer)
# Judge status: Accepted
l,r = map(int,input().split())

ans = 2018
for i in range(l,l+2019):
    for j in range(i+1,min(r+1,i+2019)):
        ans = min(ans,(i*j)%2019)
print(ans)
# Judge status: Wrong Answer
# nabc123_b.py
# 調理時間%10=0 をとった後、調理時間%10 が大きい順にとって行く
dishes = [int(input()) for i in range(5)]
lest_time = 0
ans = 0
for dish in dishes:
    if dish%10==0:
        ans += (dish)
    else:
        ans += (dish+10-dish%10)
    if lest_time < 10-dish%10 and dish%10!=0:
        lest_time = 10-dish%10
    print(ans,dish,lest_time)
print(ans-lest_time)
# Judge status: Accepted
from collections import deque
N = int(input())
A = list(map(int, input().split()))
#N=3
#A=[1,2,3]
q=deque(A)
#print(q)
ans=0
sums=sum(q)
#print(sums)
for i in range(N-1):
    qwe=q.popleft()
    ans+=qwe *(sums-qwe)
    sums-=qwe
print(ans%(10**9+7))
# Judge status: Wrong Answer
n = int(input())

count = 0
number = 0

for i in range(n+1):
    temp = 0
    j = i
    while j > 0 and j % 2 == 0:
        j //= 2
        temp += 1
    if temp > count:
        count = temp
        number = i


print(number)
# Judge status: Accepted
s = list(input())
s.pop(-1)
while len(s) % 2 != 0 or s[:len(s)//2] != s[len(s)//2:]:
  s.pop(-1)
print(len(s))
# Judge status: Wrong Answer
a = int(input())

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

dp = [1000000000]* len(hs)

if a == 0:
  print(0)
  exit()
if a == 1:
  print(hs[0])
  exit()

dp[0] = 0
dp[1] = abs(hs[1] - hs[0])

if a == 2:
  print(dp[1])
  exit()

limit_a = max(0, a-2)


for i in range(a):
  
  if i + 1 < len(hs):
  	dp[i+1] = min(abs(hs[i+1]- hs[i]), dp[i+1]) 
  if(i+2 < len(hs)):
  	dp[i+2] = min(abs(hs[i+2]- hs[i]), dp[i+2]) 

print(dp[-1])
# Judge status: Wrong Answer
n = int(input())
l = [list(input().split()) for i in range(n)]
s,p = [list(i) for i in zip(*l)]
p = [int(i) for i in p]
z = list(set(s))
z.sort()
m = list(p)
m.sort(reverse = True)
l = []

k = 0
for i in range(len(z)):
    l.append(k)
    k += 200

o = []
for i in range(n):
    w = l[z.index(s[i])]
    w += m.index(p[i])
    o.append(w)

r = list(o)
r.sort()
for i in range(n):
    print(r.index(o[i]) + 1)
# Judge status: Accepted
s = str(input())

if s[2]==s[3] and s[4]==s[5]:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
n = int(input())
*a, = map(int, input().split())
b1 = b2 = b4 = 0
for i in a:
    if i%4==0:
        b4 += 1
    elif i%2==0:
        b2 += 1
    else:
        b1 += 1
b1 += b2>0
print('Yes' if b1<=b4+1 else 'No')
# Judge status: Accepted
n, m = map(int, input().split())
W, V = [], []
for i in range(n):
    w, v = map(int, input().split())
    W.append(w)
    V.append(v)
A = [0 for j in range(m+1)]
for i in range(n):
    B = []
    for j in range(W[i]):
        B.append(A[j])
    for j in range(W[i], m+1):
        B.append(max(A[j], A[j-W[i]]+V[i]))
    A = B
print(A[m])
# Judge status: Wrong Answer
l =[list(map(int, input().split())) for i in range(3)]

total1 = 0
total2 = 0
 
for i in range(3):
    total1 += sum(l[i])
    total2 += l[i][i]
    print(total1, total2)
    
if total1 == total2 * 3:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
a = input()
b = input()
c = input()
first_str = a[0]
a = a[1:]
if len(a)==0:
  print('A')
  exit()
while(1):
  if first_str == 'a':
    first_str = a[0]
    a = a[1:]
    if len(a)==0:
      print('A')
      break
  elif first_str == 'b':
    first_str = b[0]
    b = b[1:]
    if len(b)==0:
      print('B')
      break
  elif first_str == 'c':
    first_str = c[0]
    c = c[1:]
    if len(c)==0:
      print('C')
      break
# Judge status: Accepted
n, k = list(map(int,input().split()))
c = []
res = 0

for i in range(1, n + 1):
    cnt = 0
    while i <= k - 1:
        i *= 2
        cnt += 1
    res += pow(0.5, cnt)
print(res/n)
# Judge status: Accepted
a, b, c, d = map(int,input().split())

e = a - b
f = b - c
g = c - a

x = abs(e)
y = abs(f)
z = abs(g)

if x <= d and y <= d or z <= d:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
A,B,K=map(int,input().split())
cnt=0
num=1
for i in range(100,1,-1):
    if cnt<K:
        if A%i==0 and B%i==0:
            cnt+=1
            num=i
    else:
        break
print(num)
# Judge status: Wrong Answer
c=[]

for i in range(3):
    c.append(list(map(int, input().split())))

#c_sum = sum(c[0]) + sum(c[1]) + sum(c[2])
c_sum = sum(c[0] + c[1] + c[2])

if c_sum % 3 == 0:
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
import numpy as np

data = input().split(" ")
N = int(data[0])
K = int(data[1])
score = input().split(" ")

num = N-K+1
ten = [1]*(num)
for i in range(num):
  temp = []
  for j in range(K):
    temp.append(int(score[K+i-1-j]))
  ten[i] = temp
ten_n = np.array(ten)
p = np.prod(ten_n, axis = 1)

for i in range(N-K):
  if p[i] >= p[i+1]:
    print("No")
  else:
    print("Yes")
# Judge status: Wrong Answer
s = str(input())
isOK = True
if s[0]=='A':
    tmp = s[2:-1]
    cnt = 0
    for i in range(len(tmp)):
        if tmp[i]=='C':
            cnt += 1
    if cnt!=1:
        isOK = False
else:
    isOK = False

if isOK:
    print('AC')
else:
    print('WA')
# Judge status: Wrong Answer
A,B = map(int,input().split())
if A<=8 and B<=8:
    print("Yey!")
else:
    print(":(")
# Judge status: Accepted
import math;
a,b = map(int,input().split())
x = []
y = []
ans = -1
x.append(math.ceil(a*25/2))
x.append((a+1)*25//2-1)
y.append(b*10)
y.append((b+1)*10-1)
if min(x) < max(y) and min(y) < max(x) and min(y) <= min(x):
  ans = min(x)
elif min(x) < max(y) and min(y) < max(x) and min(x) < min(y):
  ans = min(y)
print(ans)
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))

min_cost = 10 ** 9 + 7
for i in range(-100, 101):
    cost = 0
    for j in range(N):
        cost += (A[j] - i) ** 2
    min_cost = min(cost, min_cost)

print(min_cost)
# Judge status: Wrong Answer
X=int(input())
m=0
for i in range(1,X+1):
    if X<=m:
        break
    if m+i<X:
        m+=1
print(m)
# Judge status: Wrong Answer
n=int(input())
al=['']
b=[chr(i) for i in range(ord('a'), ord('z')+1)]
al+=b
c=''
while n != 0:
    i = n%26
    n=n//26
    c+=al[i]
c=c[::-1]
print(c)
# Judge status: Accepted
a,b=map(int,input().split())
k=b-a-1
print(k*(k+1)//2-a)
# Judge status: Accepted
h, a = map(int, input().split())

if h%a==0:
	print(h//a)
else:
	print(h//a+1)
# Judge status: Accepted
# どこを選んでもかまわん
n, m, k = map(int, input().split())
for i in range(n + 1):
    for j in range(m + 1):
        black = i * m - (j * i) + (n - i) * j
        if black == k:
            print("Yes")
            exit()
print("No")
# Judge status: Wrong Answer
import math

a,b,h,m = map(int,input().split())


x = abs(30 * h + 0.5 * m - m)

if x > 180:
    x = 360 - x

x = x  * math.pi / 180
ans = (a**2 + b**2 - 2 * a * b * math.cos(x))**0.5

print(ans)
# Judge status: Accepted
s = input()
a = s[:2]
b = s[2:]
if int(a) == 0 or int(a) > 12:
	if int(b) == 0 or int(b) > 12:
		print("NA")
	else:
		print ("YYMM")
else:
	if int(b) == 0 or int(b) > 13:
		print ("MMYY")
	else:
		print ("AMBIGUOUS")
# Judge status: Wrong Answer
import math
N = float(input())
x = round(N * 100 / 108)
if math.floor(x * 1.08) == N :
    print(x)
else :
    print(':(')
# Judge status: Accepted
n, m=map(int, input().split())
results=[0]*m

for i in range(n):
    check=list(map(int, input().split()))
    num=check[0]
    for j in range(1, num+1):
        results[check[j]-1]+=1

ans=0  
for result in results:
    if result==n:
        ans+=1

print(ans)
# Judge status: Wrong Answer
N = int(input())
NS = str(N)

if len(NS) == 2:
  print(9)
elif len(NS) == 4:
  print(909)
elif len(NS) == 6:
  print(90909)
elif len(NS) == 5:
  print(N - 9000)
elif len(NS) == 3:
  print(N - 90)
else:
  print(N)
# Judge status: Accepted
import numpy as np


def main():
    N, D = map(int, input().split())
    p = [np.array(list(map(int, input().split()))) for _ in range(N)]
    ans = 0
    for i in range(N - 1):
        for j in range(i + 1, N):
            d = np.sqrt(np.sum(np.power(p[i] - p[j], 2)))
            if d % 1 == 0:
                ans += 1
    print(ans)


if __name__ == '__main__':
    main()
# Judge status: Accepted
A,B=map(int,input().split())
if A>=13:
    print(B)
elif 6<=A<=12:
    print(int(B/2))
else:
    print(0)
# Judge status: Accepted
from collections import Counter
n = int(input())
s = list(input())
mod = 10**9+7
c = Counter(s)
ans = 1
for v in c.values():
    ans *= v+1
    ans %= mod
print((ans-1)%mod)
# Judge status: Wrong Answer
N=int(input())
c=list(input())
c1=c[::-1]
ans=0

w_index=[i for i, x in enumerate(c) if x=="W"]
r_index=[i for i, x in enumerate(c1) if x=="R"]

for i in range(len(r_index)):
    r_index[i]=N-1-r_index[i]


if "R" in c and "W" in c:
    for i in range(min(len(r_index),len(w_index))):
        w=w_index[ans]
        r=r_index[ans]
        if w-r==1:
             ans=ans-1
             break
        ans+=1

print(ans)
# Judge status: Accepted
N,M = map(int,input().split())
L=[]
R=[]

for i in range(M):
  l,r = map(int,input().split())
  L.append(l)
  R.append(r)
  
Rm=min(R)
LM=max(L)

if Rm-LM >= 0:
  print(Rm-LM+1)
  
else:
  print(0)
# Judge status: Accepted
import sys

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


if A.count(1) == 0:
  print(-1)
  sys.exit()
else:
  
  cnt = 0
  for a in range(len(A)):
    if A[a] == cnt+1:
      cnt += 1
  print(len(A)-cnt)
# Judge status: Accepted
n, d = map(int, input().split())
xy = []
for i in range(n):
    x, y = map(int, input().split())
    xy.append([x, y])
count = 0
for pq in xy:
    if (pq[0]**2 + pq[1]**2) <= d**2:
        count+=1
print(count)
# Judge status: Accepted
s = input()
a = s.count('1')
b = s.count('0')
print(2*min(a,b))
# Judge status: Accepted
N=int(input())
a,b=2,1
for i in range(N):
    a,b=b,a+b
print(a)
# Judge status: Wrong Answer
from sys import stdin

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
#長さが2以下の数列に関しては絶対答えは1になる
if n <= 2:
    print(1)
    exit()
#そうでない場合
count = 1
flag = 0
for i in range(1,n-1):
    if flag == 1:
        flag = 0
        continue
    else:
        if li[i-1] > li[i] < li[i+1] or li[i-1] < li[i] > li[i+1]:
            flag = 1
            count += 1
print(count)
# Judge status: Wrong Answer
H, A = map(int, input().split())

a = round(H/A)
if a != 0: a += 1
print(a)
# Judge status: Wrong Answer
n=int(input())

if n<105:
    print(0)
elif 105<=n and n<135:
    print(1)
elif 135<=n and n<189:
    print(2)
else:
    print(3)
# Judge status: Wrong Answer
n = int(input())
k = n/15
x = 800*n - 200*k
print(x)
# Judge status: Accepted
S = input()
T = input()
N = len(S)
ans = "No"
for i in range(N):
  if S == T:
    ans = "Yes"
    break
  S = S[1:] + S[0]
print(ans)
# Judge status: Wrong Answer
a = list(map(int, input().split()))
print(a[2]-(a[0]-a[1]))
# Judge status: Wrong Answer
N = int(input())
v = list(map(int, input().split()))

v.sort()
ans = 0

for i in range(N - 1):
    v1 = v.pop(0)
    v2 = v.pop(0)
    vv = (v1 + v2) / 2
    v.insert(0, vv)
print(int(v[0]))
# Judge status: Wrong Answer
a, b, c = list(map(int, input().split()))
i = 1
while(True):
    if (a * i) % b == 0:
        print('No')
        break
    elif (a * i) % b == c:
            print('Yes')
            break
    i += 1
# Judge status: Wrong Answer
N = str(input())
cnt = 0

while True:
    N = N[0:-1]
    cnt += 1
    if len(N) % 2 == 0:
        if N[0:int(len(N)/2)] == N[int(len(N)/2):]:
            break

print(cnt)
# Judge status: Wrong Answer
n = int(input())
s = 0
for i in range(1, n):
  for j in range(1, n-i+1):
    if (n-1) % j == 0:
      s += 1
print(s)
# Judge status: Accepted
inp = input()
inlist = inp.split()

tD = int(inlist[0])
tA = int(inlist[1])
aD = int(inlist[2])
aA = int(inlist[3])

tlife = tD
alife = aD

while(True):
  alife -= tA
  if( alife <= 0):
    print("Yes")
    break
  
  tlife -= aA
  if( tlife <= 0):
    print("No")
    break
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))

flag = False
el = []
for i in range(N):
  if A[i]%2 == 0:
    el.append(A[i])

flag = True
for val in el:
  if val%3 != 0 and val%5 != 0:
    flag = False

if flag:
  print("APPROVED")
else:
  print("DENIED")
# Judge status: Wrong Answer
a,b=map(int,input().split())

def keisan(a,b):
  if a * b % 2 == 0:
    print("Even")
  else:
      print("odd")

keisan(a,b)
# Judge status: Wrong Answer
N = int(input())
Klist = (input().strip()).split(" ")
Llist = list(map(int, Klist))
#print(Llist)

cnt = 0
for i in range (0, N):
    for j in range (i+1, N):
        for k in range (j+1, N):
            if abs(Llist[j] - Llist[k]) < Llist[i] < Llist[j] + Llist[k]:
                cnt += 1

print(cnt)
# Judge status: Accepted
from math import gcd
X = int(input())
lcm = X * 360 // gcd(X, 360)
print(lcm//X)
# Judge status: Accepted
import sys
input = sys.stdin.readline

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

while a >= b:
    b *= 2
    k -= 1

if k < 0:
    print("No")
else:
    for i in range(k):
        c *= 2
    if b < c:
        print("Yes")
    else:
        print("No")
# Judge status: Accepted
c = input()
vowels = 'aeiou'
if c in vowels:
  print('vowel')
else:
  print('consonant')
# Judge status: Accepted
X, Y = map(int, input().split())
ans = 1
while X * 2**ans <= Y:
    ans += 1
print(ans)
# Judge status: Accepted
a,b,c=map(int,input().split())
sound = b//a
print(sound if sound <= c else c)
# Judge status: Wrong Answer
n, m = map(int,input().split())

if m//n == m/n:
    print(m//n)
else:
    ans = 1
    for i in range(2,min(m,10**5+1)):
        if m-i*(n-1) < i:
            break
        if m%i == 0:#from (M-i*(N-1))%i==0
            ans = i
    print(ans)
# Judge status: Accepted
import fractions
a,b=map(int,input().split())
g=fractions.gcd(a,b)
print((a*b)//g)
# Judge status: Accepted
# coding: utf-8
A,B,N=map(int,input().split())

min_x = 1
max_x = N

def f(x):
    y = (A*x)//B - A*(x//B)
    return y
    
ans=f(min(B-1,N))
print(ans)
# Judge status: Accepted
n,a,b = map(int,input().split())
if abs(a-b)%2:
    print(abs(a-b)//2+1+min((abs(1-a),abs(n-a),abs(1-b),abs(n-b))))
else:
    print(abs(a-b)//2)
# Judge status: Accepted
import math
a,b,h,m = map(int,input().split())

ans = 0

m_r = m/5
# print(m_r)
h_r = h + m/60
# print(h_r)
# print((h_r - m_r)/12*360)
reg = (h_r - m_r)/12*360
ans = math.sqrt(a**2 + b**2 -2*a*b*math.cos(math.radians(reg)))

print(ans)
# Judge status: Accepted
#C - こだわり者いろはちゃん

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

#input D1 ~ Dk as set D
D = set(map(int,input().split()))

while True:
  #整数Nの桁に含まれる整数の集合 set digit_set
  digit_set = set(map(int,str(N)))
  #共通部分が空
  if len(D & digit_set) == 0 :
    break
  N += 1

print(N)
# Judge status: Wrong Answer
import heapq
n=int(input())
s=set()
q=[0,0]
for a in map(int,input().split()):
  if a>q[0]:
    heapq.heapreplace(q,a)
print(q[0]*q[1])
# Judge status: Accepted

X = int(input())

ans = 0
x = 0
while((360-x) % X != 0):
    ans += (360 - x) // X + 1
    x = X - (360-x) % X
ans += (360-x) // X
print(ans)
# Judge status: Accepted
n = int(input())
P = list(map(int,input().split()))
ans = 0
for i in range(1, n - 1):
    now = P[i]
    tmp = [P[i - 1], P[i], P[i + 1]]
    tmp.sort()
    if now == tmp[1]:
        ans += 1
print(ans)
# Judge status: Accepted
N = int(input())

s = [None for _ in range(N)]

for i in range(N):
  s[i] = input()

s.sort()

max_list = []
max_v = 1

count = 1
prev = s[0]


for i in range(1, N):
  # print(s[i], prev, count)
  if s[i] == prev:
    count += 1
  else:
    if max_v == count:
      max_list.append(prev)
    elif max_v < count:
      max_list = [prev]
      max_v = count
    count = 1
    prev = s[i]


if max_v == count:
  max_list.append(prev)
elif max_v < count:
  max_list = [prev]
  max_v = count

for k in max_list:
  print(k)
# Judge status: Accepted
n = int(input())
p = list(map(int, input().split()))
q = sorted(p)
cnt = 0
for i in range(n):
    if p[i] != q[i]:
        cnt += 1
if cnt == 0 or cnt == 2:
    print("YES")
else:
    print("NO")
# Judge status: Accepted
i = list(map(int, input().split()))
li = [i[0], i[1], i[2]]
yn = "NO"
if li.count(5) == 2:
  if li.count(7) == 1:
    yn = "YES"
    
print(yn)
# Judge status: Wrong Answer
x = input()

if x[0]==x[1]==x[2]:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
N,K = map(int, input().split())
A = list(map(int, input().split()))

A.sort()

print(sum(A[:K]))
# Judge status: Wrong Answer
n,t=map(int,input().split())
c=0
for _ in range(n):
  a,b=map(int,input().split())
  if b<=t:
    c=min(c,a)
print("TLE" if c==0 else c)
# Judge status: Accepted
r,g,b=map(int,input().split())
x=(g*10)+b
if x%4==0:
    print("YES")
else:
    print("NO")
# Judge status: Accepted
N = int(input())
L = list(int(input()) for i in range(N))
m = 10**9
sum = sum(L)

for l in L:
  if (l%10) != 0:
    m = min(l,m)

if (sum%10) != 0:
  print(sum)
elif (m%10) == 0:
  print(0)
else:
  print(sum-m)
# Judge status: Wrong Answer
N=int(input())
a=list(map(int,input().strip().split()))

dp=[0 for n in range(max(a)+1)]
for n in range(N):
    dp[a[n]]+=1

ans=0
for n in range(1,len(dp)-1):
    ans=max(ans,dp[n-1]+dp[n]+dp[n+1])

print(ans)
# Judge status: Accepted
N = int(input())
array = [_**5 for _ in range(0,120)]

for x in array[:]:
    for y in array[:]:
        if x - y == N:
            print(array.index(x),array.index(y))
            exit()
        elif x + y == N:
            print(array.index(x),-array.index(y))
            exit()
# Judge status: Wrong Answer
n = int(input())
p = list(map(int, input().split()))

a = []
ans = 0
for i in range(n):
    if i+1 == p[i]:
        a.append(i+1)
        ans += 1

m = len(a)
for i in range(m-1):
    if a[i] + 1 == a[i+1]:
        ans -= 1

print(ans)
# Judge status: Accepted
q,h,s,d = map(int,input().split())
lis = [1, 2, 4, 8]
score = [q,h,s,d]
n = int(input())
all_s = 4*n

tmp_li = [8*q,4*h,2*s,d]
tmp_2 = tmp_li[:]
tmp_2.sort()

jun = []
for t in tmp_2:
    jun.append(tmp_li.index(t))
#print('tmp_li',tmp_li,'tmp_2',tmp_2,'jun',jun,'lis',lis)
#[3, 1, 2, 0]

ans = 0
for j in jun:
    a = all_s // lis[j]
    b = all_s % lis[j]
    #print(all_s,a,b,lis[j])
    all_s -= a*lis[j]
    ans += score[j]*a
print(ans)
# Judge status: Wrong Answer
from math import ceil

N, K = map(int, input().split())
A = list(map(int, input().split()))
# N, K = 2*10**5, 1
# A = [10**9]*N

def solve(x):
    m = 0
    for a in A:
        m += a//x - (a%x == 0)
    # print(x, m)
    return m <= K

ok, ng = max(A), 0
while abs(ok-ng > 0.1**5):
    mid = (ok+ng)/2
    # print(mid)
    if solve(mid):
        ok = mid
    else:
        ng = mid

print(ceil(mid))
# Judge status: Accepted
from fractions import gcd
a,b,c,d = map(int,input().split())
a = a-1
l = int(c*d/gcd(d,c))
cn = b//c-a//c
dn = b//d-a//d
ln = b//l-a//l
ans = b-a-cn-dn+ln
print(ans)
# Judge status: Accepted

import sys
input = sys.stdin.buffer.readline
H, N = map(int, input().split())

INF = 1 << 40
dp = [INF]*(H+1)
dp[H] = 0
for i in range(N):
    a, b = map(int, input().split())
    for j in range(H, -1, -1):
        x = max(0, j-a)
        dp[x] = min(dp[x], dp[j]+b)

print(dp[0])
# Judge status: Accepted
N, K = map(int,input().split())
p = list(map(int,input().split()))

list.sort(p)
total = 0
for i in range(K):
	total += p[i]
print(total)
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))
MAX = 10**18
A.sort()
ans = 1
for i in range(len(A)):
    ans = ans * A[i]
    if ans > MAX:
        print(-1)
        exit()
print(ans)
# Judge status: Wrong Answer
N=int(input())
X=list(map(int,input().split()))

max=max(X)
ans = 100*5*N
for i in range(max+1):
    tmp=0
    for x in X:
        tmp+=(x-i)**2
    ans=min(ans,tmp)
print(ans)
# Judge status: Accepted
a=input()
b=input()
c=input()
d=input()
e=input()
k=input()


if int(e)-int(a)<=int(k):
  print('Yay!')
else :
  print(':(')
# Judge status: Accepted
a, b = map(int, input().split())
print("Yes" if b%2==0 and 2*a<=b<=4*a else "No")
# Judge status: Wrong Answer
def solve(n, m, PS):
    d = {}
    scores = [0, 0]
    for p, s in PS:
        if not p in d:
            d[p] = s
        if d[p] == 'WA':
            scores[0 if s == 'AC' else 1] += 1
            d[p] = s
    return scores

_n, _m = map(int, input().split())
_PS = [input().split() for _ in range(_m)]
_scores = solve(_n, _m, _PS)
print(_scores[0], _scores[1])
# Judge status: Accepted
abc = list(map(int,input().split()))
k = int(input())

abc.sort()

print(abc[0] + abc[1] + abc[2] * (2**k))
# Judge status: Accepted
n,k=map(int,input().split())
arr=sorted([int(x) for x in input().split()],reverse=True)
print(sum(arr[k:]))
# Judge status: Accepted
s = int(input())
a = []

while s not in a:
    a.append(s)
    if s % 2 ==0:
        s = s // 2
    else:
        s = 3 * s + 1

print(len(a) + 1)
# Judge status: Wrong Answer
s=sorted(set(input()))
ro='abcdefghijklmnopqrstuvwxyz'
if len(s)==len(ro):
    print('None')
else:
    for i in range(len(s)):
        if s[i]!=ro[i]:
            print(ro[i])
            break
        if s[len(s)-1]=='y':
            print('z')
            break
# Judge status: Wrong Answer
def main():
    n = int(input())
    A,B = [],[]
    for i in range(n):
        a,b = map(int,input().split())
        A.append(a)
        B.append(b)
    A = sorted(A)
    B = sorted(B)
    if n%2==0:
        print(B[n//2]-A[n//2-1]+1)
    else:
        print(B[n-(n+1)//2]-A[(n+1)//2-1]+1)
if __name__ == "__main__":
    main()
# Judge status: Wrong Answer
a, b, c, d = map(int, input().split())

ans = 0
if b < c or d < a:
  ans = 0
elif a <= c and c <= b and b<= d:
  ans = b- c
elif a <= c and c <= d and d <=b:
  ans = d - c
elif c <= a and a<= b and b <= d:
  ans = b = a
else:
  ans = d - a
  
print(ans)
# Judge status: Accepted
import math


n,a,b=map(int,input().split())
mod=10**9+7

c1=1
c2=1

for i in range(n-a+1,n+1):
    c1*=i
    c1%=mod
for j in range(1,a+1):
    c1*=pow(j,mod-2,mod)
    c1%=mod
    
for i in range(n-b+1,n+1):
    c2*=i
    c2%=mod
for j in range(1,b+1):
    c2*=pow(j,mod-2,mod)
    c2%=mod

ans=pow(2,n,mod)-1

print((ans-c1-c2)%mod)