peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
w,h,n = map(int,input().split())
up = h
down = 0
left = 0
right = w
for i in range(n):
    x, y, a = map(int,input().split())
    if a == 1:
        left = max(left,x)
    elif a == 2:
        right = min(right,x)
    elif a == 3:
        down = max(down,y)
    else:
        up = min(up,y)
print(max(0, right - left) * max(0, up - down))
# Judge status: Wrong Answer
N, P = map(int, input().split())
A = list(map(int, input().split()))
B = 0
C = 0
for i in range(N):
  if A[i] % 2 == 0:
    B += 1
  else:
    C += 1
ans = (2**B)*(C**2 // 2)
print(ans)
# Judge status: Accepted
#べき乗関数powを使った逆元の計算
def modinv2(a,m):
    return pow(a,m-2,m)
 
X,Y = map(int,input().split())
 
X,Y = min(X,Y),max(X,Y)
 
if (X+Y)%3 != 0 or X*2-Y < 0:
    ans = 0
else:
    a = (2*X-Y)//3
    b = (2*Y-X)//3
    m = 10**9+7
    ans = 1
    for i in range(b+1,a+b+1):
        ans = ans*i%m
    for i in range(1,a+1):
        ans = ans*modinv2(i,m)%m
print(ans)
# Judge status: Wrong Answer
A, B = list(map(int, input().split()))

ans = max(A, B) * 2 - 1

print(ans)
# Judge status: Wrong Answer
import numpy as np
INF = 10 **18
N= int(input())
ans =1
A= list(map(int,input().split()))
# if 0 in A:
#     print(0)
# else:
def calc(A):
    ans = 1
    for  a in A:
        ans *= a
        if ans > INF:
            # print(-1)
            return -1
    return ans

# ans = np.prod(A)
# ans = -1 if ans > INF else ans
print(calc(A))
# Judge status: Accepted
# -*- coding: utf-8 -*-
n, k = map(int, input().split())

n_af = n % k
if k - n_af <= n_af:
    n_af = k - n_af

print(n_af)
# Judge status: Accepted
n,x=map(int,input().split())
a=sorted(list(map(int,input().split())))
s=0
ans=0
for i in range(n):
    s+=a[i]
    if s<=x:
        ans+=1
    else:
        break
if s<x:
    ans=n-1
print(ans)
# Judge status: Wrong Answer
import collections


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


sorted_A = list(reversed(sorted(A)))

maxiuam = sorted_A[0]
is_there_tow_maximum = A.count(maxiuam) >= 2

if is_there_tow_maximum:
    answer = str(maxiuam * (N - 1))
    print(answer)

second = None
for Ai in sorted_A:
    if Ai < maxiuam:
        second = Ai
        break

answer = []
for Ai in A:
    if Ai == maxiuam:
        answer.append(second)
    else:
        answer.append(maxiuam)
answer = "\n".join(map(str, answer))

print(answer)
# Judge status: Accepted
s = input()
t = input()
for i in range(len(s)):
    if s[i:] + s[:i] == t:
        print("Yes")
        exit()
print("No")
# Judge status: Accepted
#B
from collections import deque
l=list(input())
ans=[]
for i in l:
    if i=="B":
        if len(ans)!=0:
            ans.pop()
    else:
        ans+=i
for i in ans:
    print(i,end="")
# Judge status: Accepted
a=input()
if a=="Sunny":
  print("Cloudy")
elif a=="Cloudy":
  print("Rainy")
elif a=="Rainy":
  print("Sunny")
# Judge status: Wrong Answer
n, m = map(int, input().split())
ql = [tuple(map(int, input().split())) for i in range(2*m)]
a = ql[1::2]
ans = n - len(set(a))
if ans <= 0:
    print(0)
else:
    print(ans)
# Judge status: Wrong Answer
x = input()
x = "T" + x + "S"
ar = []
c = 1
for i in range(1, len(x)):
    if x[i-1] == x[i]:
        c += 1
    else:
        ar.append(c)
        c = 1
ar.append(c)
mi = 0
for i in range((len(ar)-2)//2):
    k = i*2 + 1
    mi += min(ar[k], ar[k+1])*2
print(len(x)-2-mi)
# Judge status: Accepted
n = input()
m = len(n)
n = int(n)
if n%2==1:
    print(0)
else:
    if m==1:
        print(0)
    else:
        ans = 0
        i = 1
        while  True:
            ans_plus=n//(2*5**i)
            if ans_plus==0:
                break
            ans += ans_plus
            
            i += 1
        print(ans)
# Judge status: Wrong Answer
N, K, S = map(int, input().split())
ans = [S] * N

if S < 10e9:
    for i in range(N-K):
        ans[i] = S+1
else:
    for i in range(N-K):
        ans[i] = 1

print(" ".join([str(x) for x in ans]))
# Judge status: Accepted
D,T,S=map(int,input().split())
if D/S>T:
    print("No")
else:
    print("Yes")
# Judge status: Wrong Answer
s = input()
i = 0
ans = 0
while i < len(s):
    if s[i] == "A" or s[i] == "T" or s[i] == "C" or s[i] == "G":
        for j in range(len(s) - i):
            if s[i + j] != "A" and s[i + j] != "T" and s[i + j] != "C" and s[i + j] != "G":
                break
        
        ans = max(ans, j)
    
    i += 1
print(ans)
# Judge status: Accepted
def split_sum(n):
    return sum(map(int, str(n)))


N, A, B = map(int, input().split())
ans = 0
for i in range(1, N + 1):
    n = split_sum(i)
    if A <= n <= B:
        ans += i
print(ans)
# Judge status: Wrong Answer
N = int(input())
l = [int(n) for n in input().split()]

base = 0
for i in range(N):
  if i == 0:
    base = l[i]
  else:
    base = base * l[i]

if base > 10**8:
  print('-1')
else:
  print(base)
# Judge status: Accepted
n,a,b = map(int,input().split())

one_set = a + b
amari = n % one_set
ans = (n // one_set) * a

if amari > a:
    ans += a
else:
    ans += amari

print(ans)
# Judge status: Accepted
import math
A, B = map(int,input().split())

x = math.ceil(1+(B-A)/(A-1))

print(x)
# Judge status: Accepted
s=input()
for i in range(len(s)):
    print('x',end='')
# Judge status: Accepted
n,k = map(int,input().split())


ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
abc = "abcdefghijklmnopqrstuvwxyz"

s = list(input())

s[k-1] = abc[ABC.find(s[k-1])]
  
print("".join(s))
# Judge status: Accepted
X,Y=map(int,input().split())
print(int(X+Y/2))
# Judge status: Accepted
n = int(input())
a = sorted(list(map(int, input().split())))
i = n - 1
p = 0
q = 0
while i > 0:
  if a[i] == a[i-1]:
    if p == 0:
      p = a[i]
      i -= 1
    else:
      q = a[i]
      break
  i -= 1
print(p*q)
# Judge status: Wrong Answer
x, n = list(map(int, input().split()))
ps = list(map(int, input().split())) if n else []

pss = [0] * 101
for p in ps:
    pss[p] = 1

#print(pss)
for i in range(101):
    if x - i > -1 and pss[x - i] == 0:
        print(x - i)
        break
    if x + i < 101 and pss[x + i] == 0:
        print(x + i)
        break
# Judge status: Wrong Answer
from math import ceil

N = int(input())
D = ceil(N/2)
A = [0] + [int(i) for i in input().split()]

boxes = [0] * (N+1) # 1-indexed

for i in range(D, N+1):
    boxes[i] = A[i]

for i in range(N-D, 0, -1):
    c = 0
    for j in range(N, i, -i):
        if A[j]:
            c ^= 1
    if c==A[i]:
        boxes[i]=0
    else:
        boxes[i]=1

res = set()
for i in range(1, N+1):
    if boxes[i]:
        res.add(i)

print(len(res))
print(*res)
# Judge status: Wrong Answer
a,b,c=map(int,input().split())
if b+c>=a:
  print(0)
else:
  print(c-a+b)
# Judge status: Accepted
from math import ceil
n, k = map(int, input().split())
print(ceil((n-1)/(k-1)))
# Judge status: Accepted
nn = int(input())
aa = list(map(int, input().split()))
bb = [0]*(nn-1)
mysum = sum(aa)
mydiff = 0

for i in range(1,nn):
    mydiff += aa[i - 1]
    bb[i-1] = mysum - mydiff

finalsum = 0
for i in range(nn-1):
        finalsum += aa[i]*bb[i]
        finalsum = finalsum % (10**9 + 7)

print(finalsum)
# Judge status: Accepted
s = input()



for i in range(8):
    ans = int(s[0])
    f = s[0]
    for j in range(3):
        if i >> j & 1:
            ans += int(s[j + 1])
            f = f + "+" + s[j + 1]
        else:
            ans -= int(s[j + 1])
            f = f + "-" + s[j + 1]
    #print(bin(i), ans, f)
    if ans == 7:
        print(f + "=7")
        break
# Judge status: Accepted
N = int(input())
A = sorted(list(map(int, input().split())))

Ans = sum(A[N::2])
print(Ans)
# Judge status: Wrong Answer
N, M = map(int, input().split())
h = list(map(int, input().split()))
li = []
for m in range(M):
  a, b = map(int, input().split())
  if h[a-1] < h[b-1]:
    li.append(a)
  if h[a-1] == h[b-1]:
    li.append(a)
    li.append(b)
  else:
    li.append(b)

answer = N - len(set(li))
print(answer)
# Judge status: Wrong Answer
n=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
import itertools
li=[i for i in range(1,n+1)]
cnt=0
a=-1
for x in itertools.permutations(li):
    x=list(x)
    if x==p or x==q:
        if a>=0:
            print(abs(cnt-a))
            exit()
        else:
            a=cnt    
    cnt+=1
# Judge status: Accepted
s = input()

ans = 0
before = ""
tmp = ""
for i in range(len(s)):
  tmp += s[i]
  if tmp != before:
    ans += 1
    before = tmp
    tmp = ""
  else:
    before = tmp

print(ans)
# Judge status: Accepted
import itertools
import math
import fractions
import functools
import copy

n = int(input())
l  = list(map(int, input().split()))
minimum = 10*10

for i in range(n):
    minimum = min(abs(sum(l[:i])-sum(l[i:])),minimum)

print(minimum)
# Judge status: Wrong Answer
N = int(input())
arr = list(map(int, input().split()))
ans = [0]*N

for i in range(N-1):
    ans[(arr[i])-1] += 1

print(ans)
# Judge status: Accepted
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    N,M=map(int,readline().split())
    if N==1 and M==1:
        print(1)
    elif N==1 or M==1:
        print(max(N,M)-2)
    else:
        print((N-2)*(M-2))
if __name__=="__main__":
    main()
# Judge status: Accepted
from collections import Counter

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

kouho = CA.most_common()[::-1]
ans = 0
idx = 0
while idx < len(CA) - k:
    key, val = kouho[idx]
    ans += val
    idx += 1
print(ans)
# Judge status: Accepted
def main():
    D = int(input())
    c = list(map(int, input().split()))
    s = [list(map(int, input().split())) for _ in range(D)]

    for i in range(D):
        print(1)


if __name__ == "__main__":
    main()
# Judge status: Wrong Answer
N,M = map(int, input().split())
X = list(map(int,input().split()))
if N >= M:
  print(0)
else:
  X = sorted(X)
  list = []
  for i in range(M-1):
    list.append(X[i+1]-X[i])
    list = sorted(list)
    list1 = list[:N+1]
  print(sum(list1))
# Judge status: Accepted

N = int(input())

A = []
B = []

for i in range(N):

    a,b = map(int,input().split())
    A.append(a)
    B.append(b)

A.sort()
B.sort()

if N % 2 == 1:
    am = A[N//2]
    bm = B[N//2]

    print (bm-am+1)

else:
    am = (A[N//2] + A[N//2-1])/2
    bm = (B[N//2] + B[N//2-1])/2

    print ( int((bm-am)/0.5) + 1)
# Judge status: Accepted
N, M = map(int, input().split())

n = M
# 約数列挙(1,N)も含まれる
prime, i = set(), 1
while i * i <= n:
    if n % i == 0:
        prime.add(i)
        prime.add(n//i)
    i += 1

ans = 1
l = list(prime)
for i in l:
    if i * N <= M:
        ans = max(ans, i)

print(ans)
# Judge status: Accepted
import string
n = int(input())
cs = string.ascii_lowercase
cm = {cs[i]:i for i in range(len(cs))}
t = 1
def rec(st):
    global t
    if (len(st) >= n):
        print(st)
        t += 1
        return 0
    k = max(cm[st[i]]+1 for i in range(len(st)))
    for c in cs[: k + 1]:
        rec(st+c)
    
    
rec('a')
# Judge status: Accepted
x = input()
if x in "aiueo":
  print("vowel")
else:
  print("consonant")
# Judge status: Accepted
a,b = map(int,input().split())
ans,sum = 0,1
while sum<b:
    sum+=a-1
    ans+=1
print(ans)
# Judge status: Accepted
print("YES"if input()==input()[::-1]else"NO")
# Judge status: Accepted
n = int(input())
p = [int(i) for i in input().split()]
count = 0
for i in range(len(p)):
    if i+1 != p[i]:
        count += 1
if count <= 2:
    print('YES')
else:
    print('NO')
# Judge status: Wrong Answer
S = input('曜日を入力してください ＞ ')

if S == 'MON':
    print('6')
elif S == 'TUE':
    print('5')
elif S == 'WED':
    print('4')
elif S == 'THU':
    print('3')
elif S == 'FRI':
    print('2')
elif S == 'SAT':
    print('1')
elif S == 'SUN':
    print('7')
else:
    print('曜日が無効です')
# Judge status: Wrong Answer
N,K = list(map(int,input().split()))
per = 0
def f(x,y):
    count = 0
    while (x <= y):
        x = 2*x
        count += 1
    return count

for i in range(N):
    b = int(f(i+1,K))
    per += (1/N)*((1/2)**b)
print(per)
# Judge status: Accepted
def first_multiple(k):
    n = 0
    for i in range(1, k + 1):
        n = (n * 10 + 7) % k
        if n % k == 0:
            return i
    return -1


k = int(input())
print(first_multiple(k))
# Judge status: Wrong Answer
n,k=map(int,input().split())
sum=k
tmp=abs(k)
for i in range(1,n):
  sum+=k+i
  if tmp>abs(k+i):
    tmp=abs(k+i)
print(sum+tmp)
# Judge status: Wrong Answer
import sys
# input=sys.stdin.readline

val = input()

array = val.split(' ')
a = array[0]*500

if a<array[1]:
    print("Yes")
else:
    print("No")

print (array)
sys.exit()
# Judge status: Accepted
a,b,c,d = map(int,input().split())
lsx = [a,b]
lsy = [c,d]
ans = -10**20
for x in lsx:
    for y in lsy:
        ans = max(ans,x*y)
print(ans)
# Judge status: Accepted
n, m = map(int, input().split())
if n * 2 >= m:
  print(m // 2)
  exit()
res = n
m -= (2 * n)
res += (m // 4)
print(res)
# Judge status: Accepted
import numpy as np

N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))
H = np.array(H)
C = list(abs(A - (T - H * 0.006)))
answer = C.index(min(C))+1

print(answer)
# Judge status: Accepted
n, k = map(int,input().split())

goukei = 0
for j in range(k,n+2):
    goukei += ((2*n-j+1)*(j)/2) - ((j-1)*j/2) + 1
    
print(int(goukei % (1e9 + 7)))
# Judge status: Accepted
n = int(input())
s = input()

r=s.count('R')
ans=r

for i in range(r):
  if s[i]=='R':
    ans-=1
    
print(ans)
# Judge status: Accepted
import sys
def main():
    input = sys.stdin.readline
    N = int(input())
    ans = 0
    for i in range(2, int(N ** 0.5) + 1):
        c = 0
        while N % i == 0:
            c += 1
            N //= i
        i = 0
        while c > i:
            ans += 1
            i += 1
            c -= i
    if N > 1:
        ans += 1
    print(ans)

if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
s = {'Sunny':'Cloudy', 'Cloudy':'Rainy', 'Rainy':'Cloudy'}
print(s[input()])
# Judge status: Wrong Answer
N, M, X, Y = map(int, input().split())
x = max(list(map(int, input().split())))
y = min(list(map(int, input().split())))
if x >= y or x <= Y or X <= y: print("War")
else: print("No War")
# Judge status: Accepted
import numpy as np
n=int(input())
X=list(map(int,input().split()))
X=np.array(X)
ans=10**100
for i in range(1,101):
  tmp=np.sum((X-i)**2)
  if tmp<ans:
    ans=tmp
print(ans)
# Judge status: Wrong Answer
s = input()

cnt = 0
ans = 0
for i in s:
    if i == "A" or i == "C" or i == "G" or i == "T":
        cnt += 1
    elif i != "A" and i != "C" and i != "G" and i != "T":
        ans = max(ans,cnt)
        cnt = 0

print(ans)
# Judge status: Accepted
from decimal import *

a,b,c = map(Decimal,input().split())

if a**Decimal(0.5) + b**Decimal(0.5) < c**Decimal(0.5):
    print('Yes')
else:
    print('No')
# Judge status: Accepted
n=int(input())
l=list(map(int,input().split()))
ans=0
m=l[0]
for i in l[1:]:
    if i<m:
        ans+=m-i
    else:
        m=i
print(ans)
# Judge status: Accepted
a,b = map(int, input().split())
for i in range(1, 1100):
    if i * 0.08 //1 == a and i * 0.1 //1 == b:
        print(i)
        break
else:
    print(-1)
# Judge status: Accepted
import itertools
import numpy as np
N, M, X = [int(_) for _ in input().split()]
CA = np.array([[int(_) for _ in input().split()] for _ in range(N)], dtype=int)
ans = 10**10
for bs in itertools.product(range(2), repeat=N):
    s = np.zeros(M + 1, dtype=int)
    for i, b in enumerate(bs):
        if b:
            s += CA[i]
    if np.all(s[1:] >= X):
        ans = min(ans, s[0])
if ans == 10**10:
    print(-1)
else:
    print(ans)
# Judge status: Accepted
from collections import Counter
N = int(input())
A = map(int, input().split())
A = Counter(A)

cnt = 0
for i, j in A.items():
    if i > j:
        cnt += j
    elif i < j:
        cnt += j-i
print(cnt)
# Judge status: Wrong Answer
from collections import deque
from sys import stdin


def main():
    N, K = [int(x) for x in stdin.readline().rstrip().split()]
    As = [int(x) for x in stdin.readline().rstrip().split()]
    pos = 1
    tmp = deque([pos])
    while True:
        pos = As[pos - 1]
        if pos in tmp:
            idx_s = tmp.index(pos)
            break
        tmp.append(pos)
    K = K - idx_s
    tmp = list(tmp)
    print(tmp[idx_s:][K % (len(tmp) - idx_s)])


if __name__ == "__main__":
    main()
# Judge status: Wrong Answer
N,K = list(map(int, input().split()))
S = input()

print(S.replace(S[K-1], S[K-1].lower()))
# Judge status: Accepted
N=int(input())
P=list(map(int,input().split()))
Q=sorted(P)
X=0
for i in range(N):
  if P[i]!=Q[i]:
    X+=1
if X==2 or X==0:
  print('YES')
else:
  print('NO')
# Judge status: Accepted
O=input()
E=input()

for i in range(len(E)):
    print(O[i],end="")
    print(E[i],end="")
    
if len(O)>len(E):
    print(O[len(O)-1])
# Judge status: Accepted
def main():
    A, B, X = map(int, input().split())
    ans = B // X - (A - 1) // X
    print(ans)


if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if a == b:
    print("YES")
elif v<=w:
    print("NO")
else:
    if -(-(b-a)//(v-w)) <= t:
        print("YES")
    else: print("NO")
# Judge status: Accepted
import numpy as np

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

if np.count_nonzero(a < 0) % 2 == 0:
    print(np.abs(a).sum())
else:
    b = np.abs(a)
    m = b.min()
    print(b.sum() - 2 * m)
# Judge status: Wrong Answer
# -*- coding: utf-8 -*-
# A - One Card Poker
# 標準入力の取得
A,B = list(map(int, input().split()))

# 1⇒14と見なしてから、大きさを比較
if A == 1:
    A = 14
if B == 1:
    B = 14

if A == B:
    print("Draw")
elif A > B:
    print("Alica")
else:
    print("Bob")
# Judge status: Accepted
n = int(input())
s = list(input())

cnt = [s.count('.'), s.count('#')]

cnt0 = 0
cnt1 = 0
ans = float("inf")
for i in range(n):
    if s[i] == '.':
        cnt0 += 1
    if s[i] == '#':
        cnt1 += 1
    ans = min(ans, cnt1 + cnt[0] - cnt0)

if ans > min(cnt):
    print(min(cnt))
else:
    print(ans)
# Judge status: Accepted
n, k = map(int, input().split())
p = list(map(int, input().split()))

p_sort = sorted(p)
ans = 0

for i in range(k):
    ans += p_sort[i]
print(ans)
# Judge status: Accepted
x,k,d=map(int,input().split())

x=abs(x)

cnt=abs(x)//d


if cnt>=k:
    print(x-d*k)
else:
    k-=cnt

    if k%2==0:
        print(abs(x-d*cnt))
    else:
        print(abs(x-d*(cnt+1)))
# Judge status: Accepted
def main():
    N, A, B = (int(i) for i in input().split())
    if (N == 1 and A != B) or (B - A < 0):
        print(0)
    elif N == 1:
        print(1)
    elif N == 2:
        print(1)
    else:
        print((N-2)*B - (N-2)*A + 1)


if __name__ == '__main__':
    main()
# Judge status: Accepted
n = int(input())
A = list(map(int, input().split()))
B = [0] * n

al = 0
for i in range(n):
  al = al^A[i]
  
for i in range(n):
  B[i] = al^A[i]

  
print(*B)
# Judge status: Accepted
S = int(input())

x2 = 10**9
x3 = (x2 - S%x2) % x2
y3 = (S + x3) // x2

print('0 0 {} 1 {} {}'.format(x2,x3,y3))
# Judge status: Accepted
L, R = map(int, input().split())

MOD = 2019

if R - L >= MOD or L%MOD == 0 or R%MOD == 0:
    print(0)
else:
    LR = list(range(L, R+1))
    minimum = 2*10**9
    for i in range(len(LR)):
        l = LR[i]
        for r in LR[i+1:]:
            minimum = min(l*r%MOD, minimum)
    print(minimum)
# Judge status: Accepted
K, X = map(int, input().split())
if 500*K<X:
  print('No')
else:
  print('Yes')
# Judge status: Accepted
N = int(input())
d_list = list(map(int,input().split()))

dist = [0] * 10**5
max_d = 0
for d in d_list:
    dist[d] += 1
    max_d = max(max_d, d)

MOD = 998244353
if d_list[0] != 0:
    print(0)
    exit()
elif dist[0]>1:
    print(0)
    exit()

ans = 1
for i in range(max_d):
    if dist[i] == 0 or dist[i+1] ==0:
        print(0)
        exit()
    ans *= (dist[i]**dist[i+1])
    ans %= MOD

print(ans)
# Judge status: Wrong Answer
sList = list(input())
tList = list(input())
numList = []
 
for ti,t in enumerate(tList):
  num = 0
  for si,s in enumerate(sList):
    tnum = ti
    snum = si
    while tList[tnum] == sList[snum]:
      num += 1
      tnum += 1
      snum += 1
      if tnum >= len(tList): break
      if snum >= len(sList): break
  numList.append(num)
  if max(numList) > (len(sList) - ti): break

if len(tList) - max(numList) > 0:
  print(len(tList) - max(numList))
else:
  print(0)
# Judge status: Wrong Answer
def main():
	N, M = map(int, input().split())
	if N % 2 == 0:
		for i in range(M):
			print(int(N/2-i),int(N/2+1+i))
	else:
		N = N - 1
		for i in range(M):
			print(int(N/2-i),int(N/2+1+i))
			
if __name__ == "__main__":
  main()
  pass
# Judge status: Accepted
N,M=map(int,input().split())
B=[]
AB=[]
S=[]
for i in range(N):
    a,b=map(int,input().split())
    AB.append([a,b])
    B.append(b)

S=sorted(AB)
D=[]
check=0
ans=0
for i in range(N):
    check+=S[i][1]
    if check<=M:
        D+=[S[i][1]]
    else:
        b=check-M
        D+=[S[i][1]-b]
        break
for i in range(len(D)):
    ans+=D[i]*S[i][0]
print(ans)
# Judge status: Accepted
d = int(input())
if d == 25:
    print('Christmas')
elif d == 24:
    print('Christmas Eve')
elif d == 23:
    print('Christmas Eve Eve')
elif d == 22:
    print('Christmas Eve Eve Eve')
# Judge status: Accepted
h, m, hh, mm, k = map(int, input().split())
print(hh*60 + mm - h*60 - m - k)
# Judge status: Accepted
n=int(input())
ans=1
for b in range(2,100):
    tmp=b
    for p in range(2,10):
        tmp*=b
        if tmp<=n :
            ans=max(ans,tmp)
print(ans)
# Judge status: Accepted
s = input()
t = input()

ans = 0
for i, j in zip(s, t):
    if i != j:
        ans += 1

print(ans)
# Judge status: Accepted
def main():
    paints = list(map(int, input().split()))
    ans = len(set(paints))
    print(ans)


if __name__ == "__main__":
    main()
# Judge status: Accepted
import heapq

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

a=[[] for _ in range(m)]

d=[]

heapq.heapify(d)

for i in range(n):
  x,y=map(int,input().split())
  if x<=m:
    a[x-1].append(-y)
    
ans=0

for j in range(1,m+1):
  for h in a[j-1]:
    heapq.heappush(d,h)
  if len(d)>0:
    c=heapq.heappop(d)
    ans+=c
  
print(ans*(-1))
# Judge status: Accepted
import math
a, b, c, d = map(int, input().split())

s1 = (a-1) // c
s2 = (a-1) // d
s3 = (a-1) // (c*d//math.gcd(c,d))
S = (a-1) - (s1 + s2 -s3)

l1 = b // c
l2 = b // d
l3 = b // (c*d//math.gcd(c,d))
L = b - (l1 + l2 - l3)

print(L-S)
# Judge status: Accepted
from collections import defaultdict
d=defaultdict(int)
s=input()
for i in s:
    d[i]+=1
for v in d.values():
    if v%2==1:
        print("No")
        exit()
print("Yes")
# Judge status: Wrong Answer
N,M,X,Y=map(int,input().split())
L1=list(map(int,input().split()))
L2=list(map(int,input().split()))
if max(L1)>min(L2):
    print("War")
elif X<=max(L1)<=Y and X<=min(L2)<=Y:
    print("No War")
# Judge status: Accepted
x,y=map(int,input().split())
print(x + y//2)
# Judge status: Wrong Answer
K, N = map(int, input().split())
A = list(map(int, input().split()))
r1 = A[N-1] - A[0]
r2 = (K - A[N-1]) + A[N-2]
print(min(r1, r2))
# Judge status: Accepted
import itertools

n, m , q = (int(x) for x in input().split())
list=[]
for i in range(q):
    a, b, c, d = (int(x) for x in input().split())
    list.append((a,b,c,d))
ans = 0
for i in itertools.combinations_with_replacement(range(1,m+1),n):
    score = 0
    for j in range(q):
        if i[list[j][1]-1]-i[list[j][0]-1]==list[j][2]:
            score+=list[j][3]
    if ans<score:
        ans=score
print(ans)
# Judge status: Accepted
n=int(input())
s=input()
t=0
m=0
for i in range(len(s)):
    if s[i]=="I":
        t+=1
    else:
        t-=1
    if m<t:
        m=t
print(m)
# Judge status: Accepted
a,b,c=map(int,input().split())
if (a*b*c)%2==0:
    print(0)
else:
    print(min(a*b,b*c,c*a))
# Judge status: Wrong Answer
a,b,c=(int(x) for x in input().split())
if a == b:
    if a != c:
        print('yes')
    else:
        print("no")
elif a == c:
    if a != b:
        print('yes')
    else:
        print("no")
elif b == c:
    if b != a:
        print('yes')
    else:
        print("no")
else:
    print("no")