You have a playlist consisting of $n$ songs. The $i$-th song is characterized by two numbers $t_i$ and $b_i$ — its length and beauty respectively. The pleasure of listening to set of songs is equal to the total length of the songs in the set multiplied by the minimum beauty among them. For example, the pleasure of listening to a set of $3$ songs having lengths $[5, 7, 4]$ and beauty values $[11, 14, 6]$ is equal to $(5 + 7 + 4) \cdot 6 = 96$.

You need to choose at most $k$ songs from your playlist, so the pleasure of listening to the set of these songs them is maximum possible.


-----Input-----

The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 3 \cdot 10^5$) – the number of songs in the playlist and the maximum number of songs you can choose, respectively.

Each of the next $n$ lines contains two integers $t_i$ and $b_i$ ($1 \le t_i, b_i \le 10^6$) — the length and beauty of $i$-th song.


-----Output-----

Print one integer — the maximum pleasure you can get.


-----Examples-----
Input
4 3
4 7
15 1
3 6
6 8

Output
78

Input
5 3
12 31
112 4
100 100
13 55
55 50

Output
10000



-----Note-----

In the first test case we can choose songs ${1, 3, 4}$, so the total pleasure is $(4 + 3 + 6) \cdot 6 = 78$.

In the second test case we can choose song $3$. The total pleasure will be equal to $100 \cdot 100 = 10000$.

Difficulty: interview

Starter code:

Solutions:
import heapq

n,k=list(map(int,input().split()))
S=[list(map(int,input().split())) for i in range(n)]

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

ANS=0
LENGTH=0
H=[]

for x,y in S:
    heapq.heappush(H,x)
    LENGTH+=x
    if len(H)>k:
        z=heapq.heappop(H)
        LENGTH-=z
        
    if ANS<LENGTH*y:
        ANS=LENGTH*y

print(ANS)


import heapq
import sys
input = sys.stdin.readline

n,k=list(map(int,input().split()))
S=[list(map(int,input().split())) for i in range(n)]

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

ANS=0
LENGTH=0
H=[]

for x,y in S:
    heapq.heappush(H,x)
    LENGTH+=x
    if len(H)>k:
        z=heapq.heappop(H)
        LENGTH-=z
        
    if ANS<LENGTH*y:
        ANS=LENGTH*y

print(ANS)


import heapq
n, k = list(map(int, input().split()))
music = []
for i in range(n):
    length, beauty = list(map(int, input().split()))
    music.append((beauty, length))
music.sort(reverse=True)
s = []
ma = 0
sumlength = 0
# print(music)
for i in range(n):
    if len(s) == k:
        t = heapq.heappushpop(s, music[i][1])
    else:
        heapq.heappush(s, music[i][1])
        t = 0
    sumlength += music[i][1] - t
    # print(sumlength)
    ma = max(sumlength * music[i][0], ma)
print(ma)


import heapq
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, K = list(map(int, input().split()))
songs = [list(map(int, input().split())) for _ in range(N)]

songs = sorted(songs, key=lambda x: x[1], reverse=True)

# print(songs)
ans = -float('inf')
S = []
tmpS = 0
for t, v in songs:
    if len(S) < K:
        heapq.heappush(S, t)
        tmpS += t
        minB = v
    else:
        # print(S)
        if S[0] <= t:
            tmpS = tmpS-S[0]+t
            heapq.heappop(S)
            heapq.heappush(S, t)
            minB = v
    #print("tmp->", minB*tmpS)
    ans = max(ans, minB*tmpS)
print(ans)


import sys
import heapq


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


n, k = list(map(int, input().split()))
arr = [(0, 0)] * n
for i in range(n):
    t, b = list(map(int, input().split()))
    arr[i] = (t, b)
arr.sort(key=lambda x: (-x[1], -x[0]))
sum_length = 0
heap_length = []
for i in range(k):
    sum_length += arr[i][0]
    heapq.heappush(heap_length, arr[i][0])
min_beauty = arr[k-1][1]
answer = sum_length * min_beauty
for i in range(k, n):
    min_beauty = arr[i][1]
    min_length = heapq.heappop(heap_length)
    temp = arr[i][0] - min_length
    if temp > 0:
        sum_length += temp
        heapq.heappush(heap_length, arr[i][0])
    else:
        heapq.heappush(heap_length, min_length)
    answer = max(answer, sum_length * min_beauty)
sum_length = 0
for i in range(k):
    sum_length += arr[i][0]
    min_beauty = arr[i][1]
    answer = max(answer, sum_length * min_beauty)
print(answer)


import heapq

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

songs = [(0, 0) for i in range(n)]

for i in range(n):
    songs[i] = tuple(map(int, input().split()))

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

heap = []
max_ = 0
length = 0
for i in range(n):
    if i >= k:
        l = heapq.heappushpop(heap, songs[i][0])
        length = length - l + songs[i][0]
    else:
        length += songs[i][0]
        heapq.heappush(heap, songs[i][0])
    max_ = max(max_, length * songs[i][1])

print(max_)

# -*- coding: utf-8 -*-
# @Time    : 2019/3/22 23:41
# @Author  : LunaFire
# @Email   : gilgemesh2012@gmail.com
# @File    : C. Playlist.py

import atexit
import io
import sys

_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER


@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())


import heapq


def main():
    n, k = map(int, input().split())
    songs = []
    for _ in range(n):
        t, b = map(int, input().split())
        songs.append((b, t))
    songs.sort(reverse=True)
    # print(songs)

    ret = 0
    curr_count, curr_sum = 0, 0
    h = []
    for i in range(n):
        b, t = songs[i]
        heapq.heappush(h, t)
        curr_sum += t
        curr_count += 1
        if curr_count > k:
            curr_sum -= heapq.heappop(h)
            curr_count -= 1
        ret = max(ret, curr_sum * b)
    print(ret)


def __starting_point():
    main()
__starting_point()

#!/usr/bin/env python3
import sys
import heapq

def rint():
    return list(map(int, sys.stdin.readline().split()))
#lines = stdin.readlines()

n, k = rint()

t = []
b = []
ind = []
for i in range(n):
    tt, bb =  rint()
    t.append(tt)
    b.append(bb)
    ind.append(i)

ind.sort(key = lambda i: (-b[i], -t[i]))
#print(ind)

candi = 0
s = 0
cnt = 0
minb = 0
ans = 0
h = []
for i in range(n):
    bb = b[ind[i]]
    tt = t[ind[i]]
    if bb != minb:
        minb = bb
    heapq.heappush(h, (t[ind[i]], i))
    s += tt
    cnt += 1
    if cnt > k:
        tc, ic = heapq.heappop(h)
        s -= tc
        cnt -= 1
    candi = s*minb
    ans = max(candi, ans)

#for i in range(n):
#    print(heapq.heappop(h))
print(ans)


#import resource
import sys
#resource.setrlimit(resource.RLIMIT_STACK, [0x100000000, resource.RLIM_INFINITY])
mod=(10**9)+7
#fact=[1]
#for i in range(1,1001):
#    fact.append((fact[-1]*i)%mod)
#ifact=[0]*1001
#ifact[1000]=pow(fact[1000],mod-2,mod)
#for i in range(1000,0,-1):
#    ifact[i-1]=(i*ifact[i])%mod
from sys import stdin, stdout
#from bisect import bisect_left as bl
#from bisect import bisect_right as br
#import itertools
#import math
#import heapq
#from random import randint as rn
#from Queue import Queue as Q
def modinv(n,p):
    return pow(n,p-2,p)
def ncr(n,r,p):
    t=((fact[n])*((ifact[r]*ifact[n-r])%p))%p
    return t
def ain():
    return list(map(int,sin().split()))
def sin():
    return stdin.readline()
def GCD(x, y):
   while(y):
       x, y = y, x % y
   return x
"""**************************************************************************"""
def merge1(arr, l, m, r):
    n1 = m - l + 1
    n2 = r- m
    L = [0 for i in range(n1)]
    R = [0 for i in range(n2)]
    for i in range(0 , n1):
        L[i] = arr[l + i]
    for j in range(0 , n2):
        R[j] = arr[m + 1 + j]
    i,j,k=0,0,l
    while i < n1 and j < n2 :
        if L[i][1] < R[j][1]:
            arr[k] = L[i]
            i += 1
        elif L[i][1] > R[j][1]:
            arr[k] = R[j]
            j += 1
        else:
            if L[i][0] < R[j][0]:
                arr[k] = L[i]
                i += 1
            else:
                arr[k] = R[j]
                j += 1
        k += 1
    while i < n1:
        arr[k] = L[i]
        i += 1
        k += 1
    while j < n2:
        arr[k] = R[j]
        j += 1
        k += 1
def mergesort1(arr,l,r):
    if l < r:
        m = (l+(r-1))//2
        mergesort1(arr, l, m)
        mergesort1(arr, m+1, r)
        merge1(arr, l, m, r)
def merge2(arr, l, m, r):
    n1 = m - l + 1
    n2 = r- m
    L = [0 for i in range(n1)]
    R = [0 for i in range(n2)]
    for i in range(0 , n1):
        L[i] = arr[l + i]
    for j in range(0 , n2):
        R[j] = arr[m + 1 + j]
    i,j,k=0,0,l
    while i < n1 and j < n2 :
        if L[i][0] > R[j][0]:
            arr[k] = L[i]
            i += 1
        else:
            arr[k] = R[j]
            j += 1
        k += 1
    while i < n1:
        arr[k] = L[i]
        i += 1
        k += 1
    while j < n2:
        arr[k] = R[j]
        j += 1
        k += 1
def mergesort2(arr,l,r):
    if l < r:
        m = (l+(r-1))//2
        mergesort2(arr, l, m)
        mergesort2(arr, m+1, r)
        merge2(arr, l, m, r)
n,k=ain()
b=[]
for i in range(n):
    b.append(ain())
mergesort1(b,0,n-1)
r=[]
for i in range(n):
    r.append([b[i][0],i])
mergesort2(r,0,n-1)
g=[0 for i in range(n)]
s=0
for i in range(k):
    s+=r[i][0]
    g[r[i][1]]=1
p=k
s1=0
for i in range(n):
    q=s*b[i][1]
    s1=max(s1,q)
    if(g[i]==1):
        s-=b[i][0]
        while(p<n):
            if(r[p][1]>i):
                s+=r[p][0]
                g[r[p][1]]=1
                p+=1
                break
            p+=1
print (s1)


#import resource
import sys
#resource.setrlimit(resource.RLIMIT_STACK, [0x100000000, resource.RLIM_INFINITY])
mod=(10**9)+7
#fact=[1]
#for i in range(1,1001):
#    fact.append((fact[-1]*i)%mod)
#ifact=[0]*1001
#ifact[1000]=pow(fact[1000],mod-2,mod)
#for i in range(1000,0,-1):
#    ifact[i-1]=(i*ifact[i])%mod
from sys import stdin, stdout
#from bisect import bisect_left as bl
#from bisect import bisect_right as br
#import itertools
#import math
#import heapq
#from random import randint as rn
#from Queue import Queue as Q
def modinv(n,p):
    return pow(n,p-2,p)
def ncr(n,r,p):
    t=((fact[n])*((ifact[r]*ifact[n-r])%p))%p
    return t
def ain():
    return list(map(int,sin().split()))
def sin():
    return stdin.readline()
def GCD(x, y):
   while(y):
       x, y = y, x % y
   return x
"""**************************************************************************"""
def merge1(arr, l, m, r):
    n1 = m - l + 1
    n2 = r- m
    L = [0]*n1
    R = [0]*n2
    for i in range(0 , n1):
        L[i] = arr[l + i]
    for j in range(0 , n2):
        R[j] = arr[m + 1 + j]
    i,j,k=0,0,l
    while i < n1 and j < n2 :
        if L[i][1] < R[j][1]:
            arr[k] = L[i]
            i += 1
        elif L[i][1] > R[j][1]:
            arr[k] = R[j]
            j += 1
        else:
            if L[i][0] < R[j][0]:
                arr[k] = L[i]
                i += 1
            else:
                arr[k] = R[j]
                j += 1
        k += 1
    while i < n1:
        arr[k] = L[i]
        i += 1
        k += 1
    while j < n2:
        arr[k] = R[j]
        j += 1
        k += 1
def mergesort1(arr,l,r):
    if l < r:
        m = (l+(r-1))//2
        mergesort1(arr, l, m)
        mergesort1(arr, m+1, r)
        merge1(arr, l, m, r)
def merge2(arr, l, m, r):
    n1 = m - l + 1
    n2 = r- m
    L = [0]*n1
    R = [0]*n2
    for i in range(0 , n1):
        L[i] = arr[l + i]
    for j in range(0 , n2):
        R[j] = arr[m + 1 + j]
    i,j,k=0,0,l
    while i < n1 and j < n2 :
        if L[i][0] > R[j][0]:
            arr[k] = L[i]
            i += 1
        else:
            arr[k] = R[j]
            j += 1
        k += 1
    while i < n1:
        arr[k] = L[i]
        i += 1
        k += 1
    while j < n2:
        arr[k] = R[j]
        j += 1
        k += 1
def mergesort2(arr,l,r):
    if l < r:
        m = (l+(r-1))//2
        mergesort2(arr, l, m)
        mergesort2(arr, m+1, r)
        merge2(arr, l, m, r)
n,k=ain()
b=[]
for i in range(n):
    b.append(ain())
mergesort1(b,0,n-1)
r=[]
for i in range(n):
    r.append([b[i][0],i])
mergesort2(r,0,n-1)
g=[0]*n
s=0
for i in range(k):
    s+=r[i][0]
    g[r[i][1]]=1
p=k
s1=0
for i in range(n):
    q=s*b[i][1]
    s1=max(s1,q)
    if(g[i]==1):
        s-=b[i][0]
        while(p<n):
            if(r[p][1]>i):
                s+=r[p][0]
                g[r[p][1]]=1
                p+=1
                break
            p+=1
print (s1)


import heapq

s = []

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

for _ in range(n):
    t, b = list(map(int, input().split()))
    s.append((t, b))

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



#print(s)


t_max = t = s[0][0] * s[0][1]
i = 1

#print(t)

while i < k:
    t = (t // s[i-1][1] + s[i][0]) * s[i][1]
    #print(t)
    if t > t_max:
        t_max = t

    i+= 1

h = [x[0] for x in s[:k]]

heapq.heapify(h)



for i in range(1, n -k +1):
    #print(s[i - 2+k])
    sm = heapq.heappushpop(h, s[i + k - 1][0])
    t = (t // s[i - 2+k][1] -sm+ s[i+k-1][0]) * s[i+k-1][1]
    
    #print(t)
    if t > t_max:
        t_max = t

print(t_max)


'''input
4 3
4 7
15 1
3 6
6 8
'''
import sys
from collections import defaultdict as dd
from itertools import  permutations as pp
from itertools import combinations as cc
from collections import Counter as ccd
from random import randint as rd
from bisect import bisect_left as bl
import heapq

from heapq import heappush as hp
from heapq import heappop as hhp
mod=10**9+7

def ri(flag=0):
	if flag==0:
		return [int(i) for i in sys.stdin.readline().split()]
	else:
		return int(sys.stdin.readline())

n,k=ri()
a=[]
for i in range(n):
	u,v=ri()
	a.append((v,u))

a.sort(reverse=True)
ans=0
l=[]
cur=0
pos=0
while(pos<n):
	if len(l)==k:
		cur-=hhp(l)
	hp(l,a[pos][1])
	cur+=a[pos][1]
	ans=max(ans,cur*a[pos][0])
	pos+=1
print(ans)

from collections import defaultdict as dd
import math
import heapq


def nn():
	return int(input())

def li():
	return list(input())

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

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






n, k=mi()

songs=[]

for i in range(n):
	songs.append(lm())


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

h=[]
maxsofar=0
newlen=0
#print(songs)
for i in range(k):
	beauty=songs[i][1]
	
	h.append(songs[i][0])
		
	newlen += songs[i][0]
	maxsofar=max(maxsofar,newlen*beauty)



heapq.heapify(h)
for i in range(k,n):
	if songs[i][0]>h[0]:
		beauty=songs[i][1]		
	
		removed=heapq.heappushpop(h, songs[i][0])
		newlen += songs[i][0]-removed
		maxsofar=max(maxsofar,newlen*beauty)
	#print(h)
print(maxsofar)
	
		

	













from collections import defaultdict as dd
import math
import heapq


def nn():
	return int(input())

def li():
	return list(input())

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

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






n, k=mi()

songs=[]

for i in range(n):
	songs.append(lm())


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

h=[]
maxsofar=0
newlen=0
#print(songs)
for i in range(n):
	beauty=songs[i][1]
	heapq.heappush(h,songs[i][0])
	removed=0
	if i>=k:
		removed=heapq.heappop(h)
	
	newlen=newlen+songs[i][0]-removed
	maxsofar=max(maxsofar,newlen*beauty)
	#print(newlen,maxsofar)
print( maxsofar)
	
		


from heapq import heappush, heappop

n,k=map(int,input().split())
a=[]
for i in range(n):
    x,y=map(int,input().split())
    a.append([y,x])

a.sort(reverse=True)
h = []
ans = 0
sum_len = 0
for b, t in a:
    sum_len+=t
    heappush(h, t)
    if len(h)>k:
        sum_len-=heappop(h)
    ans=max(ans, sum_len * b)
print(ans)

import sys
input = sys.stdin.readline
import heapq  
N, K = map(int, input().split())
X = [[0, 0] for _ in range(N)]
for i in range(N):
    t, b = map(int, input().split())
    X[i][0] = t
    X[i][1] = b
X = sorted(X, key = lambda x: -x[1])

a = []
s = 0
ma = 0
for i in range(N):
    heapq.heappush(a, X[i][0])
    s += X[i][0]
    if i >= K:
        s -= heapq.heappop(a)
    ma = max(ma, s * X[i][1])

print(ma)

import sys
input = sys.stdin.readline
import heapq  
N, K = map(int, input().split())
X = [[0, 0] for _ in range(N)]
for i in range(N):
    t, b = map(int, input().split())
    X[i][0] = t
    X[i][1] = b
X = sorted(X, key = lambda x: -x[1])

a = []
s = 0
ma = 0
for i in range(N):
    heapq.heappush(a, X[i][0])
    s += X[i][0]
    if i >= K:
        s -= heapq.heappop(a)
    ma = max(ma, s * X[i][1])

print(ma)

from heapq import heappush,heappop
n,k=map(int,input().split())
a=[]
for i in range(n):
    x,y=map(int,input().split())
    a.append([y,x])
a.sort(reverse=True)
h=[]
ans,sm=0,0
for b,l in a:
    sm+=l
    heappush(h,l)
    if len(h)>k:
        sm-=heappop(h)
    ans=max(ans,sm*b)  
print(ans)

from heapq import heappush, heappop

N, K = [int(s) for s in input().split()]
songs = []
beauties = set()
for _ in range(N):
    t, b = [int(s) for s in input().split()]
    beauties.add(b)
    songs.append((t, b))
songs = sorted(songs, key= lambda x: x[1], reverse=True)
max_pleasure = 0
total_length = 0
max_lengths = []
for i in range(K):
    total_length += songs[i][0]
    heappush(max_lengths, songs[i][0])
    max_pleasure = max(max_pleasure, total_length * songs[i][1])
for i in range(K, N):
    if max_lengths[0] < songs[i][0]:
        min_length = heappop(max_lengths)
        heappush(max_lengths, songs[i][0])
        total_length = total_length - min_length + songs[i][0]
        max_pleasure = max(max_pleasure, total_length * songs[i][1])
print(max_pleasure)



from heapq import heappush, heappop

N, K = [int(s) for s in input().split()]
songs = []
beauties = set()
for _ in range(N):
    t, b = [int(s) for s in input().split()]
    beauties.add(b)
    songs.append((t, b))
songs.sort(key= lambda x: x[1], reverse=True)
max_pleasure = 0
total_length = 0
max_lengths = []
for i in range(K):
    total_length += songs[i][0]
    heappush(max_lengths, songs[i][0])
    max_pleasure = max(max_pleasure, total_length * songs[i][1])
for i in range(K, N):
    if max_lengths[0] < songs[i][0]:
        min_length = heappop(max_lengths)
        heappush(max_lengths, songs[i][0])
        total_length = total_length - min_length + songs[i][0]
        max_pleasure = max(max_pleasure, total_length * songs[i][1])
print(max_pleasure)



from heapq import heappush, heappop

N, K = [int(s) for s in input().split()]
songs = []
for _ in range(N):
    t, b = [int(s) for s in input().split()]
    songs.append((t, b))
songs.sort(key= lambda x: x[1], reverse=True)
max_pleasure = 0
total_length = 0
max_lengths = []
for i in range(K):
    total_length += songs[i][0]
    heappush(max_lengths, songs[i][0])
    max_pleasure = max(max_pleasure, total_length * songs[i][1])
for i in range(K, N):
    if max_lengths[0] < songs[i][0]:
        min_length = heappop(max_lengths)
        heappush(max_lengths, songs[i][0])
        total_length = total_length - min_length + songs[i][0]
        max_pleasure = max(max_pleasure, total_length * songs[i][1])
print(max_pleasure)



import heapq

def argsort(seq):
    return sorted(range(len(seq)), key=seq.__getitem__)

n, k = map(int, input().split())
a = []
b = []
c  =[]
for i in range(n):
  x, y = map(int, input().split())
  a.append(x)
  b.append(y)
  c.append([x, y])


ind = argsort(b)
b = sorted(b)
b = b[::-1]
ind = ind[::-1]
na = []

for i in range(n):
  na.append(a[ind[i]])

a = na
ta = [a[0]]
sm = sum(ta)
mnd = b[0]
count = 1
p = 0

res = sm*mnd

queue = [a[0]]

for i in range(1, n):
  if count>=k:
    heapq.heappush(queue, a[i])
    sm = sm-heapq.heappop(queue)+a[i]
    mnd = b[i]
    res = max(res, sm*mnd)
  else:
    sm = sm+a[i]
    mnd = b[i]
    heapq.heappush(queue, a[i])
    count+=1
    res = max(res, sm*mnd)

print(res)