CodeEff/ECCO huggingface dataset:
# Original solution
N,M,C = list(map(int,input().split()))
B = list(map(int,input().split()))
A = [list(map(int,input().split())) for _ in range(N)]
ans = 0 
for i in range(N):
    res = C
    for j in range(M):
        res += A[i][j]*B[j]
    if res > 0:
        ans += 1
print(ans)

# Optimized solution
N, M, C = list(map(int,input().split()))
B = list(map(int,input().split()))
A = [list(map(int,input().split())) for _ in range(N)]

ans = 0
for i in range(N):
    res = C
    for j in range(M):
        res += B[j] * A[i][j]
    if res > 0:
        ans += 1

print(ans)
# Original solution

import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline

n=int(eval(input()))
s=input().strip()

memo={}
def getans(a,b,c):
    while a and c and a[0]==c[-1]:
        a=a[1:]
        c=c[:-1]
    if b=="":
        if a=="" and c=="": return 1
        else: return 0
    key=a+"/"+b+"/"+c
    if key in memo: return memo[key]
    # select first letter
    ans=0
    for i in range(1,len(b)):
        if b[0]==b[i]:
            ans+=getans(a,b[1:i],b[i+1:]+c)
    # don't select first letter
    ans+=getans(a+b[0],b[1:],c)
    memo[key]=ans
    #print(key,ans)
    return ans

print((getans("",s,"")*2))

#print(len(memo))


# Optimized solution

import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline

n=int(eval(input()))
s=input().strip()

memo={}
def getans(a,b,c):
    while a and c and a[0]==c[-1]:
        a=a[1:]
        c=c[:-1]
    if a and c: return 0
    if b=="":
        if a=="" and c=="": return 1
        else: return 0
    key=a+"/"+b+"/"+c
    if key in memo: return memo[key]
    # select first letter
    ans=0
    for i in range(1,len(b)):
        if b[0]==b[i]:
            ans+=getans(a,b[1:i],b[i+1:]+c)
    # don't select first letter
    ans+=getans(a+b[0],b[1:],c)
    memo[key]=ans
    #print(key,ans)
    return ans

print((getans("",s,"")*2))

#print(len(memo))
# Original solution
import sys
input = sys.stdin.readline
from collections import defaultdict

def main():
  n = int(eval(input()))
  s = input().strip()
  pc = defaultdict(lambda: 0)
  for i in range(pow(2, n)):
    rd = ""
    bl = ""
    for b in range(n):
      if (i // pow(2, b))%2 == 1:
        rd += s[b]
      else:
        bl += s[b]
    pc[(rd, bl)] += 1

  ans = 0
  s = s[::-1]
  for i in range(pow(2, n)):
    rd = ""
    bl = ""
    for b in range(n):
      if (i // pow(2, b)) % 2 == 1:
        bl += s[b]
      else:
        rd += s[b]
    ans += pc[(rd, bl)]

  print(ans)


if __name__ == '__main__':
  main()


# Optimized solution
import sys
input = sys.stdin.readline
sys.setrecursionlimit(pow(10, 6))

from collections import defaultdict

def main():
    n = int(eval(input()))
    s = input().strip()

    tmp = defaultdict(lambda : 0)
    for state in range(1 << n):
        rs, bs = "", ""
        for i in range(n):
            if (state >> i) & 1:
                rs += s[i]
            else:
                bs += s[i]
        tmp[(rs, bs)] += 1
    
    ans = 0
    for state in range(1 << n):
        rs, bs = "", ""
        for i in range(n):
            if (state >> i) & 1:
                rs += s[-i - 1]
            else:
                bs += s[-i - 1]
        ans += tmp[(rs, bs)]
    print(ans)


if __name__ == '__main__':
    main()
# Original solution
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N = I()
S = LS2()

# 左N個のマスをどう塗るかで半分全列挙

ans = 0
left = []
right = []
for i in range(2**N):
    red = []
    blue = []
    for j in range(N):
        if (i >> j) & 1:
            red.append(S[j])
        else:
            blue.append(S[j])
    red = ''.join(red)
    blue = ''.join(blue)
    left.append((red,blue))
for i in range(2**N):
    red = []
    blue = []
    for j in range(N):
        if (i >> j) & 1:
            red.append(S[j+N])
        else:
            blue.append(S[j+N])
    red,blue = blue,red
    red.reverse()
    blue.reverse()
    red = ''.join(red)
    blue = ''.join(blue)
    right.append((red,blue))

from operator import itemgetter

right = sorted(right,key = itemgetter(0,1))

from bisect import bisect_left,bisect

ans = 0
for i in range(2**N):
    ans += bisect(right,left[i]) - bisect_left(right,left[i])

print(ans)

# Optimized solution
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N = I()
S = LS2()

from collections import defaultdict

d_left = defaultdict(int)
d_right = defaultdict(int)

for i in range(2**N):
    left_red = ''
    left_blue = ''
    right_red = ''
    right_blue = ''
    for j in range(N):
        if (i >> j) & 1:
            left_red += S[j]
        else:
            left_blue += S[j]
    for j in range(2*N-1,N-1,-1):
        if (i >> (j-N)) & 1:
            right_red += S[j]
        else:
            right_blue += S[j]
    d_left[(left_red,left_blue)] += 1
    d_right[(right_red,right_blue)] += 1

ans = 0
for key in list(d_left.keys()):
    ans += d_left[key]*d_right[key]

print(ans)
# Original solution
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():

    return
#B
def B():

    return

#C
def C():
    n = I()
    s = S()
    d = defaultdict(lambda : 0)
    m = 1<<n
    for i in range(m):
        r = []
        b = []
        for j in range(n):
            if i&(1<<j):
                r.append(s[j])
            else:
                b.append(s[j])
        r,b = b[::-1],r[::-1]
        d[(tuple(r),tuple(b))] += 1
        
    ans = 0
    for i in range(m):
        r = []
        b = []
        for j in range(n):
            if i&(1<<j):
                r.append(s[j+n])
            else:
                b.append(s[j+n])
        ans += d[(tuple(r),tuple(b))]
    print(ans)
    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

#Solve
if __name__ == "__main__":
    C()


# Optimized solution
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():

    return
#B
def B():

    return

#C
def C():
    n = I()
    s = S()
    d = defaultdict(lambda : 0)
    m = 1<<n
    p = [1<<j for j in range(n)]
    for i in range(m):
        r = []
        b = []
        for j in range(n):
            if i&p[j]:
                r.append(s[j])
            else:
                b.append(s[j])
        r,b = b[::-1],r[::-1]
        d[(tuple(r),tuple(b))] += 1

    ans = 0
    for i in range(m):
        r = []
        b = []
        for j in range(n):
            if i&p[j]:
                r.append(s[j+n])
            else:
                b.append(s[j+n])
        ans += d[(tuple(r),tuple(b))]
    print(ans)
    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

#Solve
if __name__ == "__main__":
    C()
# Original solution
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():

    return
#B
def B():

    return

#C
def C():
    n = I()
    s = S()
    for i in range(2*n):
        s[i] = ord(s[i])-96
    for i in range(n>>1):
        s[i],s[n-i-1] = s[n-i-1],s[i]
    k = 27
    m = 1<<n
    p = [1<<j for j in range(n)]
    d = defaultdict(lambda : 0)
    for i in range(m):
        r = 0
        b = 0
        for j in range(n):
            if i&p[j]:
                r *= k
                r += s[j]
            else:
                b *= k
                b += s[j]
        d[(r,b)] += 1
    ans = 0
    for i in range(m):
        r = 0
        b = 0
        for j in range(n):
            if i&p[j]:
                r *= k
                r += s[j+n]
            else:
                b *= k
                b += s[j+n]
        ans += d[(r,b)]
    print(ans)
    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

#Solve
if __name__ == "__main__":
    C()


# Optimized solution
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():

    return
#B
def B():

    return

#C
def C():
    n = I()
    s = S()
    for i in range(2*n):
        s[i] = ord(s[i])-96
    k = 27
    m = 1<<n
    p = [1<<j for j in range(n)]
    d = defaultdict(lambda : 0)
    l = [(0,0)]
    for i in s[:n][::-1]:
        l = [(x[0]*k+i, x[1]) for x in l]+[(x[0], x[1]*k+i) for x in l]
    for i in l:
        d[i] += 1
    ans = 0
    l = [(0,0)]
    for i in s[n:]:
        l = [(x[0]*k+i, x[1]) for x in l]+[(x[0], x[1]*k+i) for x in l]
    for i in l:
        ans += d[i]
    print(ans)
    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

#Solve
if __name__ == "__main__":
    C()
# Original solution
n, m = list(map(int, input().split()))
ab = []
for _ in range(n):
  a, b = list(map(int, input().split()))
  ab.extend([a for _ in range(b)])
  
ab.sort()
print((sum(ab[:m])))

# Optimized solution
n,m,*t = list(map(int, open(0).read().split()))
ans = 0
for a, b in sorted(zip(t[::2], t[1::2])):
  ans += min(b, m)*a
  m -= b
  if m <= 0:
    print(ans)
    break
# Original solution
def main():
    n, m = list(map(int, input().split()))
    answer = 0
    cost = [list(map(int, input().split())) for _ in range(n)]
    cost.sort(key=lambda x: x[0])
    for c, num in cost:
        if m < 0:
            break
        answer += c * min(m, num)
        m -= min(m, num)
    print(answer)


if __name__ == '__main__':
    main()



# Optimized solution
def main():
    n, m = list(map(int, input().split()))
    info = []
    for _ in range(n):
        info.append(list(map(int, input().split())))
    info.sort(key=lambda x: x[0])
    answer = 0
    for a, b in info:
        if m <= 0:
            break
        answer += a * min(b, m)
        m -= min(b, m)
    print(answer)


if __name__ == '__main__':
    main()
# Original solution
n,m=list(map(int,input().split()))
ab=[list(map(int,input().split())) for _ in range(n)]
sorted_ab=sorted(ab, key=lambda x: x[0])
ans=0
i=0
for a, b in sorted_ab:
  for _ in range(b):
    if i < m:
      ans+=a
      i+=1
print(ans)

# Optimized solution
n,m=list(map(int,input().split()))
ab=[list(map(int,input().split())) for _ in range(n)]
sorted_ab=sorted(ab, key=lambda x: x[0])
ans=0
i=0
for a, b in sorted_ab:
  for _ in range(b):
    if i < m:
      ans+=a
      i+=1
    else:
      break
print(ans)
# Original solution
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))
def LI2(): return [int(eval(input())) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print(('\n'.join(x)))
def printni(x): print(('\n'.join(list(map(str,x)))))
inf = 10**17
mod = 10**9 + 7

n,m=MI()
lis=[LI() for i in range(n)]
lis.sort()
#print(lis)
price=0
i=0
while m>0:
    price+=lis[i][0]*min(m,lis[i][1])
    m-=min(m,lis[i][1])
    #print(price)
    i+=1
print(price)
    
    

    
            
        
        
    
    
    
    

    
    


    
    

        
        
    


    

# Optimized solution
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))
def LI2(): return [int(eval(input())) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print(('\n'.join(x)))
def printni(x): print(('\n'.join(list(map(str,x)))))
inf = 10**17
mod = 10**9 + 7

n,m=MI()
lis=[LI() for i in range(n)]
lis.sort()
pay=0
i=0
while m>0:
    pay+=lis[i][0]*min(m,lis[i][1])
    m-=min(m,lis[i][1])
    i+=1
print(pay)
# Original solution
from functools import reduce
N, M = list(map(int,input().split()))
ary1 =[]
for x in range(N):
  ary1.append(list(map(int,input().split())))

ary2 = sorted(ary1)
print((sum(reduce(lambda a,b: a+b ,[[x[0]]*x[1] for x in ary2])[0:M])))



# Optimized solution
from functools import reduce
N, M = list(map(int,input().split()))
ary1 =[]
for x in range(N):
  ary1.append(list(map(int,input().split())))

ary2 = sorted(ary1)
count = 0
total_sum = 0
for i in range(N):
  if count + ary2[i][1] <= M:
    total_sum += ary2[i][0] * ary2[i][1]
    count += ary2[i][1]
  elif count > M :
    break
  else:
    zan = M - count
    total_sum += ary2[i][0] * zan
    count += zan

print(total_sum)
# Original solution
from sys import stdin


def a(input_string):
    N, M = [int(x) for x in input_string[0].split()]
    C = input_string[1:]
    temp = [string.split() for string in C]
    D = []
    for i in range(len(temp)):
        D.append([int(word) for word in temp[i]])
    #print(D)
    get_count = 0
    min_cost = 10000000000000000
    cost = 0
    D = sorted(D, key=lambda x: x[0])
    for i in range(N):
        for j in range(D[i][1]):
            get_count += 1
            cost += D[i][0]
            if get_count >= M:
                if cost < min_cost:
                    min_cost = cost
    return min_cost


def main():
    input_line = stdin.readlines()
    answer = a(input_line)
    print(answer)


if __name__ == '__main__':
    main()


# Optimized solution
from sys import stdin


def a(input_string):
    N, M = [int(x) for x in input_string[0].split()]
    C = input_string[1:]
    temp = [string.split() for string in C]
    D = []
    for i in range(len(temp)):
        D.append([int(word) for word in temp[i]])
    #print(D)
    get_count = 0
    min_cost = 10000000000000000
    cost = 0
    D = sorted(D, key=lambda x: x[0])
    for i in range(N):
        for j in range(D[i][1]):
            get_count += 1
            cost += D[i][0]
            if get_count >= M:
                return cost
    return cost


def main():
    input_line = stdin.readlines()
    answer = a(input_line)
    print(answer)


if __name__ == '__main__':
    main()
# Original solution
N,M=list(map(int,input().split()))
AB=list(list(map(int,input().split())) for _ in range(N))
AB.sort(key=lambda x:x[0])
cost=0
for ab in AB:
    for i in range(ab[1]):
        if M>0:
            M-=1
            cost+=ab[0]
print(cost)

# Optimized solution
N,M=list(map(int,input().split()))
AB=list(list(map(int,input().split())) for _ in range(N))
AB.sort(key=lambda x:x[0])
cost=0
for ab in AB:
    if M>=ab[1]:
        M-=ab[1]
        cost+=ab[0]*ab[1]
    else:
        cost+=ab[0]*M
        break
print(cost)
# Original solution
from collections import deque
N, M = list(map(int, input().split()))

A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = list(map(int, input().split()))

C = deque()

while len(C) < M:
    for j in range(B[A.index(min(A))]):
        if len(C) < M:
            C.append(min(A))
        else:
            break
    B.pop(A.index(min(A)))
    A.remove(min(A))

C = sorted(C)
print((sum(C[:M])))

# Optimized solution
import sys
from collections import deque
from operator import itemgetter
input = sys.stdin.readline
N, M = list(map(int, input().split()))

A = deque()
for i in range(N):
    A.append(list(map(int, input().split())))

A = sorted(A, key=itemgetter(0))

m=0
cost=0

for i in range(N):
    if m >= M:
        break
    buy = min(M - m, A[i][1])
    cost += A[i][0] * buy
    m += buy

print(cost)
# Original solution
n, m = list(map(int, input().split()))
x = [[int(j) for j in input().split()] for i in range(n)]
a = []
b = []
for i in range(n):
  a.append(x[i][0])
  b.append(x[i][1])
mon = 0
cnt = 0
ind = 100000
while(cnt < m):
  min = 10000000000
  for i in range(n):
    if a[i] < min:
      min = a[i]
      ind = i
  while(b[ind] > 0 and cnt != m):
    cnt += 1
    mon += a[ind]
    b[ind] -= 1
  a[ind] = 100000000000
print(mon)

# Optimized solution
import math
n, m = list(map(int, input().split()))
a = []
for i in range(n):
    l = list(map(int, input().split()))
    a.append(l)
a.sort(key=lambda x: x[0])
sum = 0
cnt = 0
for i in range(n):
    if cnt + a[i][1] >= m:
        sum += (m-cnt)*a[i][0]
        cnt += m-cnt
        break
    else:
        sum += a[i][0]*a[i][1]
        cnt += a[i][1]
print(sum)
# Original solution
n,m=list(map(int,input().split()))
xy=[]

for i in range(n):
    a,b=list(map(int,input().split()))
    xy.append((a,b))

xy=sorted(xy)

ans=0
for p,c in xy:
    if m>=c:
        ans+=p*c
        m-=c
    else:
        ans+=p*m
        m=0
        break
print(ans)


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

drinks = []

for i in range(n):
	a,b= list(map(int,input().split()))
	drinks.append((a,b))
drinks.sort()

ans = 0
for x,y in drinks:
	if y < m:
		ans += x*y
		m -= y
	else:
		ans += x*m
		break

print(ans)
# Original solution
N, M = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(N)]
X.sort()

ans = 0
res = M
for v in X:
    ans += v[0] * min(v[1], res)
    res -= v[1]
    if res <= 0:
        break
        
print(ans)


# Optimized solution

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

X.sort()
res = M
ans = 0
for a, b in X:
    if res <= 0:
        break

    tmp = min(b, res)
    res -= tmp
    ans += tmp * a

print(ans)
# Original solution
n, m = list(map(int, input().split()))
a, b = [0]*n, [0]*n
for i in range(n):
    a[i], b[i] = list(map(int, input().split()))

flag = 1
while flag:
    flag = 0
    for j in range(n-1):
        if a[j] > a[j+1]:
            tmp = a[j]
            a[j] = a[j+1]
            a[j+1] = tmp
            res = b[j]
            b[j] = b[j+1]
            b[j+1] = res
            flag = 1

ans = 0
for i in range(n):
    if m > b[i]:
        ans += a[i]*b[i]
        m -= b[i]
    else:
        ans += m*a[i]
        break

print(ans)

# Optimized solution
n, m = list(map(int, input().split()))
a = [0]*n
for i in range(n):
    a[i] = list(map(int, input().split()))

a.sort(key=lambda x: x[0])

ans = 0
for i in range(n):
    if m > a[i][1]:
        ans += a[i][0]*a[i][1]
        m -= a[i][1]
    else:
        ans += m*a[i][0]
        break

print(ans)
# Original solution
#import sys
#import numpy as np
#import math
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
n,m=list(map(int,input().split()))
b=[list(map(int,input().split())) for _ in range(n)]
res=0
ans=0
b.sort(key=lambda x: x[0])
for i in range(n):
    if res+b[i][1]<=m:
        ans+=b[i][0]*b[i][1]
        res+=b[i][1]
    else:
        ans+=b[i][0]*(m-res)
        break
print(ans)

# Optimized solution
#python 2.7
n,m=list(map(int,input().split()))
ab=[list(map(int,input().split())) for i in range(n)]
ab=sorted(ab,key=lambda x:x[0])
res=ans=0
for i in range(n):
  if res+ab[i][1]>=m:
    ans+=(ab[i][0])*(m-res)
    break
  else:
    ans+=(ab[i][0])*ab[i][1]
    res+=ab[i][1]
print(ans)
# Original solution
N, M = list(map(int, input().split()))

A = []
#B = []
for i in range(N):
#    print(i)
#    a, b = map(int, input().split())
    A.append(list(map(int, input().split())))
#    B.append(b)
    
    A.sort(key=lambda x: x[0])

ans = 0
for i in range(N):
    if A[i][1] > M:
        ans += A[i][0] * M
        break
    else:
        ans += A[i][0] * A[i][1]
        M -= A[i][1]

print(ans)

# Optimized solution
N, M = list(map(int, input().split()))

A = []
#B = []
for i in range(N):
#    print(i)
#    a, b = map(int, input().split())
    A.append(list(map(int, input().split())))
#    B.append(b)
    
A.sort(key=lambda x: x[0])

ans = 0
for i in range(N):
    if A[i][1] > M:
        ans += A[i][0] * M
        break
    else:
        ans += A[i][0] * A[i][1]
        M -= A[i][1]

print(ans)
# Original solution
import sys
input=sys.stdin.readline

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

A = []
for i in range(N):
    a,b = list(map(int, input().split()))
    A.append([a,b])
A.sort()

x = 0
for a in A:
    if M == 0:
        break
    while a[1] > 0:
        a[1] -= 1
        M -= 1
        x += a[0]
        if M == 0:
            break
print(x)


# Optimized solution
import sys
input=sys.stdin.readline

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

A = []
for i in range(N):
    a,b = list(map(int, input().split()))
    A.append((a,b))

A.sort()
ans = 0
for a,b in A:
    if M == 0:
        break
    n = M if M <= b else b
    M -= n
    ans += n * a
print(ans)
# Original solution
import sys
input=sys.stdin.readline

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

A = []
for i in range(N):
    a,b = list(map(int, input().split()))
    A.append((a,b))

A.sort()
ans = 0
for a,b in A:
    if M == 0:
        break
    n = M if M <= b else b
    M -= n
    ans += n * a
print(ans)


# Optimized solution
import sys
input=sys.stdin.readline

def main():
    N,M = list(map(int, input().split()))

    A = []
    for _ in range(N):
        a,b = list(map(int, input().split()))
        A.append((a,b))

    A.sort()
    ans = 0
    for a,b in A:
        if M == 0:
            break
        n = M if M <= b else b
        M -= n
        ans += n * a
    print(ans)

if __name__ == '__main__':
    main()