Harryxun/stf_run huggingface dataset:
N, M, Q = map(int, input().split())

a = [[0 for i in range(509)] for j in range(509)]
sum = [[0 for i in range(509)] for j in range(509)]

for i in range(M):
  p, q = map(int, input().split())
  a[p][q] += 1

for i in range(1,N+1):
  for j in range(i,N+1):
    sum[i][j] = sum[i][j-1] + a[i][j]


for i in range(Q):
  p, q = map(int, input().split())
  ans = 0
  for j in range(p,q+1):
    ans += sum[j][q] - sum[j][p-1]
  print(ans)


### FIXED CODE ###

A, B =  map(int, input().split())
result = A * B - A - B + 1
print(result)
def resolve():
    '''
    code here
    '''
    Sd = input()
    T = input()

    r_Sd = Sd[::-1]
    r_T = T[::-1]

    for i in range(len(Sd)- len(T)):
        temp_words = r_Sd[i:i+len(T)]
        res = r_Sd[0:i] + ''
        for j in range(len(T)):
            if temp_words[j] == '?' or temp_words[j] == r_T[j]:
                res+=r_T[j]
            else:
                break
        else:
            res = res + r_Sd[i+len(T):]
            break
    else:
        print('UNRESTORABLE')

    print(res.replace('?', 'a')[::-1])

if __name__ == "__main__":
    resolve()


### FIXED CODE ###

def resolve():
    '''
    code here
    '''
    S_dash = input()
    T = input()

    is_flag = False

    res = ''
    res_list = ['zzzzz']
    for i in range(len(S_dash) - len(T) +1):
        res = S_dash[:i]
        # print(i, res)
        if len(S_dash) - len(res) >= len(T):
            for j in range(len(T)):
                if S_dash[i+j] == T[j] or S_dash[i+j] == '?':
                    res += T[j]
                else:
                    # print('bk')
                    break
            else:
                is_flag = True
                res += S_dash[i+len(T):]
                res_list.append(res)


    # print(res_list)

    res2_list = []
    for res in res_list:
        res = res.replace('?','a')
        res2_list.append(res)

    res2_list.sort()
    res = res2_list[0]

    print(res) if is_flag else print('UNRESTORABLE')     

if __name__ == "__main__":
    resolve()
for i in range(9):
    if(N>L[i] and N<=L[i+1]):
        print(L[i+1])
        break
    elif(N==L[i]):
        print(L[i])
        break
    elif(N<111):
        print(111)
        break
    else:
        continue


### FIXED CODE ###

N=input()

str_output=""

for i in range(3):
    if(N[i]=="1"):
        str_output+="9"
    elif(N[i]=="9"):
        str_output+="1"
        
print(int(str_output))
line = input()
A,B = [int(u) for u in line]
def func(a,b)
    return min(a+b,a-b,a*b)
print(func(A,B))

### FIXED CODE ###

a,b = map(int,input().split())
print(max([a+b,a-b,a*b]))
a, b = map(int, input().splid())
if (a + b) % 2 == 0 :
  print((a + b) / 2)
else
  print("IMPOSSIBLE")


### FIXED CODE ###

a, b = map(int, input().split())
if (a + b) % 2 == 0 :
  print((a + b) // 2)
else :
  print("IMPOSSIBLE")
print chr(ord(input())+1)

### FIXED CODE ###

s = input()
s = chr(ord(s) + 1)
print(s)
import sys
N = int(input().strip())

n_list = [[] for i in range(N)]
d = [0] * N

for i in range(N-1):
    a, b = map(int, input().strip().split())
    a -= 1
    b -= 1
    n_list[a].append([b,i])
    n_list[b].append([a,i])
    d[a] += 1
    d[b] += 1


#print(n_list)
#print(d)

d_dict = {}
for i in range(N):
    d_dict[i] = d[i]
tmp = sorted(d_dict.items(), key = lambda x:x[1], reverse = True)

colors = [0] * (N)

root = tmp[0][0]

def paint(node, parent_edge_id):
    #print(node, parent_edge_id)
    tmp_color = 1
    for edge in n_list[node]:
        #print("ege:", edge)
        if edge[1] != parent_edge_id:
            if parent_edge_id != -1 and tmp_color == colors[parent_edge_id]:
                tmp_color += 1
            colors[edge[1]] = tmp_color
            paint(edge[0], edge[1])
            tmp_color += 1

    
#sys.setrecursionlimit(10**7)
try:
    paint(tmp[0][0], -1)
except RecursionError:
    print(0)
    exit(0)
print(tmp[0][1]) # color num 
for i in range(N-1):
    print(colors[i])

### FIXED CODE ###

import sys
N = int(input().strip())

n_list = [[] for i in range(N)]
d = [0] * N

for i in range(N-1):
    a, b = map(int, input().strip().split())
    a -= 1
    b -= 1
    n_list[a].append([b,i])
    n_list[b].append([a,i])
    d[a] += 1
    d[b] += 1


#print(n_list)
#print(d)

d_dict = {}
for i in range(N):
    d_dict[i] = d[i]
tmp = sorted(d_dict.items(), key = lambda x:x[1], reverse = True)

colors = [0] * (N)

root = tmp[0][0]

def paint(node, parent_edge_id):
    #print(node, parent_edge_id)
    tmp_color = 1
    for edge in n_list[node]:
        #print("ege:", edge)
        if edge[1] != parent_edge_id:
            if parent_edge_id != -1 and tmp_color == colors[parent_edge_id]:
                tmp_color += 1
            colors[edge[1]] = tmp_color
            paint(edge[0], edge[1])
            tmp_color += 1

    
sys.setrecursionlimit(10**7)
paint(tmp[0][0], -1)
print(tmp[0][1]) # color num 
for i in range(N-1):
    print(colors[i])
a,b,n = map(int, input().split())
def f(x):
    return int(a*x/b) - a*int(x/b)
Max = f(min(b-1,n))
print(Max)

### FIXED CODE ###

K = int(input())
a, b = map(int, input().split())
for i in range(1,1000):
    c = K*i
    if a <= c <= b:
        print("OK")
        test = 1
        break
    else:
        test = 0
        continue
if test == 0:
    print("NG")
a, b, k = map(int, input().split())
divs = []

for i in range(1, max(int(max(a, b) / 2), 2)):
    if a % i == 0:
        if b % i == 0:
            divs.append(i)
print(divs[-k])

### FIXED CODE ###

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

for i in range(min(a, b), 0, -1):
    if a % i == 0 and b % i == 0:
        k -= 1
        if k == 0:
            print(i)
while True:
    H,W = map(int,input().split())
    if H == W == 0:
        break
    for i in range(H):
        print(#*W)
        
    print()


### FIXED CODE ###

while True:
    H,W = map(int,input().split())
    if H == W == 0:
        break
    for i in range(H):
        print("#"*W)
        
    print()
import math
import itertools

N=int(input())
xy=[list(map(int,input().split())) for i in range(N)]

li=list(range(N))
co=[]
sum=0

for i in itertools.permutations(li,N):
    co.append(list(i))

for i in range(len(co)):
    for j in range(N-1):
        sum+=((xy[co[i][j]][0]-xy[co[i][j+1]][0])**2+(xy[co[i][j]][1]-xy[co[i][j+1]][1])**2)**(1/2)
print({sum/len(co))

### FIXED CODE ###

import math
import itertools

N=int(input())
xy=[list(map(int,input().split())) for i in range(N)]

li=list(range(N))
co=[]
sum=0

for i in itertools.permutations(li,N):
    co.append(list(i))

for i in range(len(co)):
    for j in range(N-1):
        sum+=((xy[co[i][j]][0]-xy[co[i][j+1]][0])**2+(xy[co[i][j]][1]-xy[co[i][j+1]][1])**2)**(1/2)
print(sum/len(co))
a,b,c=map(int,input().split())
if c-a-b<0:
    print('No')
else:
    if 4ab<(c-b-a)*(c-b-a):
        print('Yes')
    else:
        print('No')

### FIXED CODE ###

a,b,c=map(int,input().split())
if c-a-b<0:
    print('No')
else:
    if 4*a*b<(c-b-a)*(c-b-a):
        print('Yes')
    else:
        print('No')
import math

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

if D[0] != 0:
    print(0)
    exit()


dict = {}

for i in range(len(D)):
    if D[i] not in dict:
        dict[D[i]] = 1
    else:
        dict[D[i]] += 1

for key in dict:
    if key == 0:
        break
    if dict[key] == 0:
        print(0)
        exit()
sum = float(1)
n = 0

#dict = list(sorted(dict.items(), key=lambda x:x[0]))
dict_dm = sorted(dict)
#print(dict)
#print(dict_dm)
flg = 0
for i in range(len(dict_dm)):
    if i == 1:
        #print("check2")
        n = dict[i]
    elif i >=1:
        #print("check1")
        sum *= n**dict[i]%998244353
        n = dict[i]

print(sum%998244353)

### FIXED CODE ###

import math

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

if D[0] != 0:
    print(0)
    exit()

dict = {}

for i in range(len(D)):
    if D[i] not in dict:
        dict[D[i]] = 1
    else:
        dict[D[i]] += 1

for i in range(max(D)):
    if i not in dict:
        dict[i] = 0
    
for key in dict:
    if key == 0:
        if dict[key] != 1:
            print(0)
            exit()       
    if dict[key] == 0:
        print(0)
        exit()
sum = 1
n = 0

#dict = list(sorted(dict.items(), key=lambda x:x[0]))
dict_dm = sorted(dict)
#print(dict)
#print(dict_dm)
flg = 0
for i in range(len(dict_dm)):
    if i == 1:
        #print("check2")
        n = dict[i]
    elif i >=1:
        #print("check1")
        sum = (sum * n**dict[i])%998244353
        n = dict[i]

print(sum%998244353)
def count_section_by_zero(data):
  count = 0
  flg = False
  start = 0
  for i, d in enumerate(data):
    if flg is False and d != 0:
      count += 1
      flg = True
      
    if d == 0:
      flg = False
  return count

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

def input_list_str():
  return list(map(str, input().split()))

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

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

# 2で割り切れる回数
def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c

# 素因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def main():
  n, q = input_list()
  s = input()
  ss = list(s)
  ac_count = s.count('AC')
  index = 1
  for i in range(n):
    if s[i]=='A' and s[i+1]=='C':
      ss[i] = str(index)
      ss[i+1] = str(index)
      index += 1
  for qi in range(q):
    l, r = input_list()
    x = ss[l-1:r]
    ans = 0
    for i in range(1, index+1):
      if x.count(str(i)) == 2:
        ans += 1
    print(ans)
  
import math
import fractions
import collections
import itertools
from functools import reduce
main()

### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
tmp = [0] * (N+1)

for i in range(N):
  w = 1 if S[i:i+2] == 'AC' else 0
  tmp[i+1] = tmp[i] + w
  
for _ in range(Q):
  l, r = map(int, input().split())
  print(tmp[r-1] - tmp[l-1])
import numpy as np
H,N = map(int, input().split())
A = []
B = []
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
    
dp = [np.inf for i in range(10**7+1)]
dp[0] = 0
for i in range(H+1):
    for j in range(N):
        dp[i+A[j]] = min(dp[i+A[j]],dp[i]+B[j])
        
print(min(dp[H:]))

### FIXED CODE ###

import numpy as np
 
h, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab = np.array(ab)
 
a = ab[:, 0]
b = ab[:, 1]
 
dp = np.zeros(100001, dtype=np.int)
for i in range(1, h+1):
    dp[i] = (dp[i-a]+b).min()

print(dp[h])
N=int(input())
s=input().split()

if s[0]*s[1]>10**18:
    print(s[0]*s[1])
else:
    print("-1")

### FIXED CODE ###

N=int(input())
A=list(map(int, input().split()))
A=sorted(A)#小さい順に計算することで処理時間短縮
f=A[0]
for i in range(1,N):
    f*=A[i]
    if f>10**18:
        print(-1)
        exit()
            
print(f)
import math


def main() -> None:
    a, b = input().split()

    print((int(a) * (int(b)*100)) // 100)

    return


if __name__ == '__main__':
    main()


### FIXED CODE ###

import math


def main() -> None:
    a, b = input().split()

    print((int(a)*int(b.replace('.', ''))) // 100)

    return


if __name__ == '__main__':
    main()
n=int(input())
k=int(input())
x=list(map(int,input().split()))
ans=0
for i in x:
    ans+=min(abs(x-k),abs(x))*2
print(ans)

### FIXED CODE ###

n=int(input())
k=int(input())
x=list(map(int,input().split()))
ans=0
for i in range(len(x)):
    ans+=min(abs(x[i]-k),abs(x[i]))*2
print(ans)
A,B,K = map(int,input().split())

als = []
bls = []

for a in range(1,A):
  if A%a == 0:
    als.append(a)
for b in range(1,B):
  if B%b == 0:
    bls.append(b)

common = []

for a in range(0,len(als)):
  if a in bls:
    common.append(a)

common.sort()
print(common[K-1])


### FIXED CODE ###

A,B,K = map(int,input().split())

als = []
bls = []

for a in range(1,A+1):
  if A%a == 0:
    als.append(a)
for b in range(1,B+1):
  if B%b == 0:
    bls.append(b)

common = []

for a in als:
  if a in bls:
    common.append(a)

common.sort()
print(common[-K])
import sys
input = sys.stdin.buffer.readline
 
def main():
    a,b,c,d = map(int,input().split())
    MOD = 10**9+7
    K = c+d+5
    fac = [0 for _ in range(K+1)]
    fac[0],fac[1] = 1,1
 
    for i in range(2,K+1):
        fac[i] = (fac[i-1]*i)%MOD
        
    def comb(x,y):
        return (fac[x+y]*pow(fac[x],MOD-2,MOD)*pow(fac[y],MOD-2,MOD))%MOD
 
    print((comb(c+1,d+1)-comb(c+1,b)-comb(d+1,a)+comb(a,b))%MOD)
    
if _name_ == "_main_":
    main()

### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline
 
def main():
    a,b,c,d = map(int,input().split())
    MOD = 10**9+7
    N = c+d+5
    fac = [0 for _ in range(N+1)]
    fac[0],fac[1] = 1,1
 
    for i in range(2,N+1):
        fac[i] = (fac[i-1]*i)%MOD
        
    def comb(g,h):
        return (fac[g+h]*pow(fac[g],MOD-2,MOD)*pow(fac[h],MOD-2,MOD))%MOD
 
    print((comb(c+1,d+1)-comb(c+1,b)-comb(d+1,a)+comb(a,b))%MOD)
    
if __name__ == "__main__":
    main()
import collections
from scipy.special import comb

n = int(input())
str_L = []

for val in range(n):
    s = input()
    s_L = [i for i in s]
    s_L.sort()
    s = "".join(s_L)
    str_L.append(s)


c = collections.Counter(str_L)

str_L = list(set(str_L))


ans = 0
r = 2

for val in str_L:
    n = c[val]
    ans = ans + comb(n, r, exact=True)

print(ans)


### FIXED CODE ###

import collections
import math

n = int(input())
str_L = []

for val in range(n):
    s = input()
    s_L = [i for i in s]
    s_L.sort()
    s = "".join(s_L)
    str_L.append(s)


c = collections.Counter(str_L)

str_L = list(set(str_L))


ans = 0
r = 2

def combinations_count(n, r):
    try:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    except:
        return 0

for val in str_L:
    n = c[val]
    #print(n,r)
    ans = ans + combinations_count(n,r) #comb(n, r, exact=True)

print(ans)
s = input()
t = input()
data = {}
max = len(s)
for i in range(24):
    data[chr(i + ord('a'))] = max + 1
for i in range(len(s)):
    if data[s[i]] > i + 1:
        data[s[i]] = i + 1
ans = 0
pre = max
for i in range(len(t)):
    if data[t[i]] == max + 1:
        print(-1)
        exit()
    else:
        if pre < data[t[i]]:
            ans += (data[t[i]] - pre)
            pre = data[t[i]]
        else:
            ans += (max + data[t[i]] - pre)
            pre = data[t[i]]
    
print(ans)



### FIXED CODE ###

import bisect
s = input()
t = input()
data = {}
max_s = len(s) + 1
for i in range(26):
    data[chr(i + ord('a'))] = []
for i in range(len(s)):
    data[s[i]].append(i+1)
for i in range(26):
    data[chr(i + ord('a'))].append(max_s)
pre = 0
ans = 0
for i in range(len(t)):
    char = t[i]
    if len(data[char]) == 1:
        print(-1)
        exit()
    else:
        index = bisect.bisect_left(data[char], pre+1)
        if data[char][index] == max_s:
            ans += len(s) - pre
            pre = data[char][0]
            ans += pre
        else:
            ans += data[char][index] - pre
            pre = data[char][index]
print(ans)
n,k,q=map(int,input().split())
a=[int(input()) for _ in range(q)]
if q<k:
  print(0)
  exit()
point=[-k]*n
for i in range(q):
  point[a[i]]+=1
for i in range(n):
  if point(i)>0:
    print('Yes')
  else:
    print('No')
    
  

### FIXED CODE ###

n,k,q=map(int,input().split())
a=[int(input()) for _ in range(q)]
point=[-k]*n
for i in range(q):
  point[a[i]-1]+=1
for i in range(n):
  if point[i]>-2*k+q:
    print('Yes')
  else:
    print('No')
import numpy as np
n = int(input())
l = np.array(map(int, input().split()))

ans = np.sum((l - round(np.mean(l)))**2)
print(ans)

### FIXED CODE ###

import numpy as np
n = int(input())
l = list(map(int, input().split()))

l = np.array(l)
ans = np.sum((l - round(np.mean(l)))**2)
print(int(ans))
n,m=map(int,input().split())
if n==m
   print("Yes")
else:
   print("No")

### FIXED CODE ###

n,m=map(int,input().split())
if n==m:
   print("Yes")
else:
   print("No")
N, K, X, K = [int(input()) for i in range(4)]
print(X*K+Y*(N-K if N-K > 0 else 0))

### FIXED CODE ###

N, K, X, Y = [int(input()) for i in range(4)]
print(X*K+Y*(N-K) if N-K > 0 else X*N)
line = input().rstrip().split(' ')

max_lines = [[int(line[0] + line[1]), int(line[0])],
			 [int(line[0] + line[2]), int(line[1])],
             [int(line[1] + line[0]), int(line[2])],
             [int(line[1] + line[2]), int(line[0])],
             [int(line[2] + line[0]), int(line[1])],
             [int(line[2] + line[1]), int(line[0])]]

max_point = 0
one_point = 0
for max_line in max_lines:
    if max_line[0] >= max_point:
    	max_point = max_line[0]
        one_point = max_line[1]

print(max_point + one_point)

### FIXED CODE ###

x, y, z = map(int,input().split())

max_lines = [[x * 10 + y, z],
                 [x * 10 + z, y],
                 [y * 10 + x, z],
                 [y * 10 + z, x],
                 [z * 10 + x, y],
                 [z * 10 + y, x]]

max_point = 0
one_point = 0
for max_line in max_lines:
    if max_line[0] >= max_point:
        max_point = max_line[0]
        one_point = max_line[1]

print(max_point + one_point)
n = int(input())
s = input()
t = input()
for i in range(n):
  cnt = 0
  for j in range(i, n):
    if s[j] != t[j-i]:
      break
    cnt += 1
  if cnt == n-i:
    ans = n+i
    break
print(ans)

### FIXED CODE ###

n = int(input())
s = input()
t = input()
for i in range(n):
  cnt = 0
  for j in range(i, n):
    if s[j] != t[j-i]:
      break
    cnt += 1
  if cnt == n-i:
    ans = n+i
    break
if cnt == 0:
  ans = 2*n
print(ans)
K = int(input())
A,B = map(int,input().split())

for i in range(A,B+1):
    if i%K==0:
        print("OK")
        break
else:
print("NO")

### FIXED CODE ###

K = int(input())
A,B = map(int,input().split())

for i in range(A,B+1):
    if i%K==0:
        print("OK")
        exit()
print("NG")
L, R = map(int, input().split())
mod = 2019
ans = mod + 100

if R - L >= 3000:
    print(0)
else:
    L %= mod
    R %= mod
    for i in range(L, R):
        for j in range(i + 1, R + 1):
            m = (i * j) % mod
            if m < ans:
                ans = m
print(ans)


### FIXED CODE ###

N, A, B = map(int, input().split())
print(min(A * N, B))
n = int(input())
s = [input() for i in range(n)]
m = int(input())
t = [input() for i in range(n)]
ans = 0

for i in set(s):
  num = s.count(i) - t.count(s)
  if num > ans :
    ans = num
    
    
print(ans)

### FIXED CODE ###

n = int(input())
s = [input() for i in range(n)]
m = int(input())
t = [input() for i in range(m)]
ans = 0

for i in set(s):
  num = s.count(i) - t.count(i)
  if num > ans :
    ans = num
    
    
print(ans)
age,cost= list(map(int, input().split()))
if age<=5:
  print('0')
elif age>=6 and age<=12:
  print(a/2)
else:
  print(a)


### FIXED CODE ###

n,k=tuple(map(int,input().split()))
if n >= 13:
  print(k)
elif 6 <= n <= 12:
  print(k//2)
elif n <= 5:
  print(0)
a,b,c,k=map(int,input().split())
if a>=k:
  print(k)
elif a<k and b>=k-a:
  print(a)
else:
  print(2a+b-k)

### FIXED CODE ###

a,b,c,k=map(int,input().split())
if a>=k:
  print(k)
elif a<k and b>=k-a:
  print(a)
else:
  print(2*a+b-k)
a = raw_input()

if a == "ABC":
  print("ARC")
elif a == "ARC":
  print("ABC")

### FIXED CODE ###

a = input()

if a == "ABC":
  print("ARC")
elif a == "ARC":
  print("ABC")
from math import sqrt
from collections import Counter

def factorize(n):
    rt = int(sqrt(n)+1)
    facts = []
    for i in range(2, rt+1):
        if n % i == 0:
            facts.append(i)
            while n % i == 0:
                n //= i
    if n != 1:
        facts.append(n)
    return facts

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

P = Counter()

for a in A:
    p = Counter(factorize(a))
    P += p
p_max = max(P.values())
if  p_max == 1:
    print('pairwise coprime')
elif  p_max <  n:
    print('setwise coprime')
else:
    print('not coprime')

### FIXED CODE ###

def arrayF(n): 
    F=[0]*(n+1) 
    i=2 
    while i*i<=n:
        if F[i] == 0: 
            k=i*i
            while k <= n:
                if F[k] == 0:
                    F[k] = i
                k += i
        i += 1 
    return F


def factorization(x, F): 
    primeFactors = []
    while F[x] > 0:
        primeFactors.append(F[x])
        x //= F[x] 
    if x != 1:
        primeFactors.append(x)
    return set(primeFactors)

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

amax = max(A)
F  = arrayF(amax)

P = [0] *  (amax+1)
for a in A:
    for p in factorization(a,  F):
        P[p] += 1
p_max = max(P)
if  p_max <= 1:
    print('pairwise coprime')
elif  p_max <  n:
    print('setwise coprime')
else:
    print('not coprime')
d,s,r=map(int,input().split())
print(f"{r} {d} {s}")

### FIXED CODE ###

x,y,z=map(int,input().split())
print(str(z)+" "+str(x)+" "+str(y))
S=int(input(y))
y=700+100*o
print(y.count(o)*100+700)

### FIXED CODE ###

S=input()
print(S.count("o")*100+700)
N,M = map(int,input().split())
A = sorted([list(map(int,input().split())) for _ in range(N)],key=lambda x:x[0])
cnt = 0
cost = 0
i = 0
while True:
    a,b = A[i]
    if cnt+b<=M:
        cnt += b
        cost += a*b
    else:break
    i += 1
if cnt<M:
    a,b = A[i]
    cost += (M-cnt)*a
print(cost)

### FIXED CODE ###

N,M = map(int,input().split())
A = []
for _ in range(N):
    a,b = map(int,input().split())
    A.append((a,b))
A = sorted(A,key=lambda x:x[0])
B = [A[0][1]]
if A[0][1]>=M:
    cnt = A[0][0]*M
else:
    ind = 0
    for i in range(1,N):
        B.append(B[i-1]+A[i][1])
        if B[i]>=M:
            ind = i
            break
    cnt = 0
    for i in range(ind):
        cnt += A[i][0]*A[i][1]
    cnt += A[ind][0]*(M-B[ind-1])
print(cnt)
def eratosthenes2(n):
    lim=int(n**0.5)
    d=[i+1 for i in range(2,n,2)]
    D=[2]*(n+1)
    D[0]=0
    D[1]=1
    while True:
        p=d[0]
        if lim<p:
            for x in d:
                D[x]=x
            break
        D[p]=p
        for x in d:
            if x%p==0:
                D[x]=p
        d=[x for x in d if x%p!=0]
    return D
    
N=int(input())
A=list(map(int,input().split()))
maxA=max(A)
D=eratosthenes2(maxA)
count=[0]*(maxA+1)
for x in A:
    pre=x+1
    while x>1:
        if pre!=D[x]:
            count[D[x]]+=1
            pre=D[x]
        x=int(x/D[x])
maxc=max(count)
if maxc==N:
    print('not coprime')
elif maxc==1:
    print('pairwise coprime')
else:
    print('setwise coprime')

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
maxA=max(A)
count=[0]*(maxA+1)
for x in A:
    count[x]+=1
maxc=0
for i in range(2,maxA+1):
    maxc = max(maxc,sum(count[i::i]))

if maxc==N:
    print('not coprime')
elif maxc<=1:
    print('pairwise coprime')
else:
    print('setwise coprime')
n=int(input())
s=input()

if n%2==0:
    c=n//2:
    if(s[c:] == s[:c]):
        print('yes')
    else:
        print('no')
else:
    print('no')

### FIXED CODE ###

n=int(input())
s=input()

if n%2==0:
    c=n//2
    if s[c:] == s[:c]:
        print('Yes')
    else:
        print('No')
else:
    print('No')
S = int(input())
W = int(input())
if S <= W:
  print('unsafe')
else:
  print('safe')

### FIXED CODE ###

S = list(map(int, input().split()))
if S[0] <= S[1]:
  print('unsafe')
else:
  print('safe')
from collections import Counter

N,A,B = map(int, input().split(" "))

s = ""

while(len(s)<=N):
  s+="b"*A
  if len(s)>N:
      break
  s+="r"*B
ans = Counter(s[:N])["b"]
print(ans)

### FIXED CODE ###

N,A,B = map(int, input().split(" "))

M = A+B

C = N//M

b = N-(C*M)
if b>=A:
    print((C+1)*A)
else:
    print(b+C*A)
A, B=map(int, input().split())

if B%A==0:
    print(A+B)
else
  print(A-B)

### FIXED CODE ###

A, B=map(int, input().split())

if B%A==0:
    print(A+B)
else:
  print(B-A)
n = print(int(int(input())**0.5)**2)

### FIXED CODE ###

C1 = list(input())
C2 = list(input())

for i in range(3):
    if(C1[i] == C2[2-i]):
        continue

    else:
        print('NO')
        exit()

print('YES')