peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
import re

s = "".join("." if i == "?" else i for i in input())
t = input()

lent = len(t)
mgroup = ""
mstart = 0
for start in range(len(s) - lent + 1):
    m = re.match(re.compile(s[start:start+lent]), t)    
    if m:
        mgroup, mstart = m.group(), start
else:
    if mgroup:
        s = s[:mstart] + t + s[mstart+lent:]
        print(s.replace(".", "a"))
    else:
        print("UNRESTORABLE")
# Judge status: Accepted
t=input()
print(t.replace("?","D"))
# Judge status: Accepted
n, k = map(int, input().split())

print(min(n%k, abs(n%k - k)))
# Judge status: Accepted
# -*- coding:utf-8 -*-
a, b = map(int, input().strip().split())
m = (a + b + 1)//2
print(m)
# Judge status: Accepted
n,k = map(int,input().split())
X = [int(i) for i in input().split()]
ans = 10**9

for i in range(n-k+1):
    Max = X[i+k-1]
    Min = X[i]
    
    if Max<0 and Min<0:
        tmp_ans = abs(Min)
    elif Max>0 and Min >0:
        tmp_ans = abs(Max)
    else:
        tmp_ans = abs(Max) + abs(Min) + min(abs(Max),abs(Min))
    ans = min(ans,tmp_ans)
print(ans)
# Judge status: Accepted
n,k=map(int, input().split())
list1=list(map(int,input().split()))
list1.sort()
if k >= n:
    print(0)
else:
    sum1=0
    for i in range(n-k):
        sum1+=list1[i]
    print(sum1)
# Judge status: Accepted
x, a, b = map(int, input().split())
if abs(x - a) > abs(x - b):
    print('B')
else:
    print('A')
# Judge status: Accepted
n = int(input())
a = [int(int(x)/400) for x in input().split()]
b = [x if x <= 7 else 8 for x in a]

ans = len(set(b))
if (8 in b):
   ans -= 1
   ans2 = b.count(8) + ans
   if (ans == 0):
      print(1, ans2)
   else:
      print(ans, ans2)
else:
   print(ans, ans)
# Judge status: Accepted
n, k = map(int, input().split())
h = []
for _ in range(n):
    h.append(int(input()))

h.sort(reverse=True)
ans = 10**9
for i in range(n-k+1):
    ans = min(ans, h[i]-h[i+k-1])
print(ans)
# Judge status: Accepted
#C - Same Integers
ABC = list(map(int,input().split()))
ABC = sorted(ABC,reverse = True)
A = ABC[0]#max
B = ABC[1]
C = ABC[2]#min
count = 0
while A != B:
    C += 1
    B += 1
    count += 1
while (B - C)%2 == 1:
    A += 1
    B += 1
    count += 1
while A!=C:
    C += 2
    count += 1
print(count)
# Judge status: Wrong Answer
N = int(input())
ans = [0,0,0,0]

for _ in range(N):
    a = input()
    if a == "AC":
        ans[0] += 1
    elif a == "WA":
        ans[1] += 1
    elif a == "TLE":
        ans[2] += 1
    else:
        ans[3] += 1

print("AC × "+ str(ans[0]))
print("WA × "+ str(ans[1]))
print("TLE × "+ str(ans[2]))
print("RE × "+ str(ans[3]))
# Judge status: Wrong Answer
n = int(input())
if n%2==0 or n%5==0:
    print(-1)

ans,c = 0,0

while 1:
    c+=1
    for i in range(10):
        if ((ans%10)+((n%10)*i)%10)%10==1:
            ans += n*i
            #print(ans,i)
            break
    ans = ans//10
    if ans==0:
        break
print(c)
# Judge status: Accepted
sx, sy, tx, ty = map(int, input().split())
ans = 'D'
ans += 'R'*(tx-sx+1)
ans += 'U'*(ty-sy+1)
ans += 'L'*(tx-sx+1)
ans += 'D'*(ty-sy)
ans += 'R'*(tx-sx)
ans += 'U'*(ty-sy+1)
ans += 'L'*(tx-sx+1)
ans += 'D'*(ty-sy+1)
ans += 'R'
print(ans)
# Judge status: Accepted
X = int(input())

h1k = X // 500

h5 = (X - h1k * 500) // 5

happiness = h1k*1000 + h5*5

print(happiness)
# Judge status: Accepted

N, K = list(map(int, input().split()))
point= list(map(int, input().split()))
T = list(input())
d = dict()
d['s'] = point[0]
d['p'] = point[1]
d['r'] = point[2]
res = 0
ans = []
flag = [0,0,0]

for i in range(K):
  res += d[T[i]]
  ans.append(T[i])
for i in range(K,N):
  if ans[i-K] == T[i]:
    ans.append("n")
  else:
    res += d[T[i]]
    ans.append(T[i])
print(res)
# Judge status: Accepted
from collections import defaultdict
from collections import OrderedDict
n = int(input())
answer = dict()
for _ in range(n):
    z = str(input())
    if z in answer:
        answer[z]+=1
    else:
        answer.update({z:1})
groupedByValue = defaultdict(list)
for key, value in sorted(answer.items()):
    groupedByValue[value].append(key)
M = groupedByValue[max(groupedByValue)]
for i in M:
    print(i)
# Judge status: Accepted
from math import gcd
print(360//gcd(360,int(input())))
# Judge status: Wrong Answer
def hantei(s):
    return len(s) == len(set(s))

def main():
    s = input()
    s = list(s)

    if hantei(s) == True:
        print('yes') 
    else:
        print('No')
        
if __name__ == '__main__':
    main()
# Judge status: Accepted
import collections

n,k=map(int,input().split())
a=list(map(int,input().split()))
a=collections.Counter(a)
A=a.most_common()[::-1]
x=len(A)-k

if x<=0:
  print("0")
else:
  ans=0
  for i in range(x):
    ans+=A[i][1]
  print(ans)
# Judge status: Accepted
h, n, *a = map(int, open(0).read().split())
print(["No", "Yes"][h <= sum(a)])
# Judge status: Wrong Answer
def main():
  A = list(map(int, input().split()))
  
  if sum(A) <= 22:
    print('win')
  else:
    print('dust')
  
  
main()
# Judge status: Wrong Answer
import sys
import collections as cc
import math as mt
I=lambda:list(map(int,input().split()))
n,=I()
if n==1:
	print(1)
else:
	print(0)
# Judge status: Accepted
import math

def combinations_count(n, r):
    if n == 1 or n == 0:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N, M = [int(i.strip()) for i in input().split(' ')]


print(combinations_count(N,2) + combinations_count(M,2))
# Judge status: Accepted
s=input()
ss=set(s)
ans="Yes"
for sss in ss:
  if s.count(sss)%2==1:
    ans="No"

print(ans)
# Judge status: Wrong Answer
k = int(input())
i = 0
a = []
while len(a) <= k:
    if len(str(i)) == 1:
        a.append(i+1)
    else:
        flg = True
        for j in range(len(str(i))):
            if j != len(str(i))-1:
                t = abs(int(str(i)[j]) - int(str(i)[j+1]))
                if t > 1:
                    flg = False
        if flg == True:
            a.append(i)
    i = i+1

print(a[k])
# Judge status: Accepted
n = int(input())
a = input().split()
b = set(a)
if len(b)<len(a):
    print("NO")
else:
    print("YES")
# Judge status: Accepted
X, Y = map(int, input().split())

y = Y // 2

a = X + y

print(a)
# Judge status: Accepted
q,h,s,d=map(int,input().split())
n=int(input())
print((n//2)*min(8*q,4*h,2*s,d)+(n%2)*min(4*q,2*h,s))
# Judge status: Accepted
N=int(input())
A=list(map(int,input().split()))

A_={}
for _ in range(-1,10**5+10):
    A_[_]=0

for a in A:
    a_b = a-1
    a_a = a+1
    A_[a] +=1
    A_[a_b] +=1
    A_[a_a] +=1    

ans = 0
ans_idx = 0
for k in A_.keys():
    a = A_[k]
    if ans < a:
        ans = a
        ans_idx = k
        
# print(ans_idx,ans)
print(ans)
# Judge status: Accepted
n,k,s = map(int,input().split())
ans = []
if s==10**9:
    for i in range(n):
        if i < k:
            ans.append(s)
        else:
            ans.append(1)
else:
    for i in range(n):
        if i < k:
            ans.append(s)
        else:
            ans.append(s+1)
print(*ans)
# Judge status: Accepted
n = int(input())
s = sorted([int(input()) for _ in range(n)])

grade = 0 if sum(s) % 10 == 0 else (sum(s))

if grade == 0:
    for i in s:
        if i % 10 != 0:
            print(sum(s) - i)
            exit()

print(grade)
# Judge status: Accepted
n = input()
l = input()
ans = True
#print(n[0])
#print(n[])
for i in range(len(n)):
    if i ==0:
        if n[0] == l[-1]:
            continue
        else :
            ans = False
            break
        
    elif n[i] == l[-i-1]:
        continue
    else :
        ans = False
        break
if ans:
    print("YES")
else:
    print("NO")
# Judge status: Accepted
def main():
    n, m, k = map(int, input().split())
    f = False
    for i in range(n+1):
        for j in range(m+1):
            if i*j + (n-i)*(m-j) == k:
                f = True
    if f:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()
# Judge status: Wrong Answer
import math

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

d_a = h * 30 + m * 0.5
d_b = m * 6
if d_a > d_b:
    d_a, d_b = d_b, d_a

d = d_b - d_a
if d > 180:
    d -= 180

# print(d)

if d == 180:
    print(a + b)
else:
    print(math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(d))))
# Judge status: Accepted
n = 500
x, y = map(int, input().split())
if x*n >= y: 
    print("Yes")
else: 
    print("No")
# Judge status: Wrong Answer
n=int(input())
a=list(map(int,input().split()))
b=[a.index(i)+1-i for i in a]
c=[a.index(i)+1+i for i in a]
from collections import defaultdict
B=defaultdict(int)
C=defaultdict(int)
for i in range(len(a)):
  B[b[i]]+=1
  C[c[i]]+=1
ans=0
for i in B:
  ans+=B[i]*C[i]
print(ans)
# Judge status: Accepted
k,x = map(int,input().split())

if 500*k>=x:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
n,m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]

ans = 'No'
for di,dj in [(pi,pj) for pi in range(n-m+1) for pj in range(n-m+1)]:
    for i,j in [(pi,pj) for pi in range(m) for pj in range(m)]:
        if a[di+i][dj+j] != b[i][j]:
            break
    else:
        ans = 'Yes'
        break
print(ans)
# Judge status: Accepted
a,b,c,d=map(int,input().split())
if abs(a-b)<=d and abs(b-c)<=d or abs(a-c)<=d:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
n,m=map(int,input().split())
d=[[]for i in range(m+1)]
from heapq import heappush,heappop,heapify
q=[]
for i in range(n):
    a,b=map(int,input().split())
    if a<=m:
        d[-a-1].append(b)
ans=0
for i in d[::-1]:
    for j in i:
        heappush(q,-j)
    if q:
        ans+=-heappop(q)
print(ans)
# Judge status: Wrong Answer
N,M=list(map(int, input().split()))
K=N-2*M
print(max(N+K//3,N))
# Judge status: Accepted
n,m=map(int,input().split())
diffs=set()
idxs=set()
i=1
diff=n-1
cnt=0
while 1:
    if i>m:
      break
    while (diff in diffs and n-diff in diffs) or (i+diff in idxs) or (diff==n-diff):
        diff-=1
    diffs.add(n-diff)
    diffs.add(diff)
    idxs.add(i+diff)
    print(i,i+diff)
    i+=1
# Judge status: Wrong Answer
N, D = map(int, input().split(" "))

print(N//(2*(D+1)) + 1)
# Judge status: Wrong Answer
n=int(input())
s=list(input())
switch=0
count=0
for i in s:
    if i=='#':
        if switch==0:
            switch=1
    else:
        if switch==1:
            count += 1
print(count)
# Judge status: Accepted
a,b,c,d = map(int,input().split())

if (abs(a-b)<=d and abs(c-b)<=d) or abs(a-c)<=d:
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
import math

n,m = map(int, input().split())
A = list(map(int, input().split()))
line = math.floor(sum(A) / (4 * m))
cnt = 0
for a in A:
    if a >= line:
        cnt += 1
    if cnt >= m:
        print('Yes')
        break
else:
    print('No')
# Judge status: Wrong Answer
n,m = map(int, input().split())
b = [0]*(n+1)
AC,WA = 0,0
for _ in range(m):
    p,s = map(str, input().split())
    if b[int(p)] == 0:
        if s == "AC":
            AC += 1
            b[int(p)] = 1
        else:
            WA += 1
print(AC,WA)
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))

c4 = 0
c2 = 0
for i in a:
    if i % 4 == 0:
        c4 += 1
    elif i % 2 == 0:
        c2 += 1

if n - c4 - c2 <= c4:
    print('Yes')
elif n - c4 - c2 - 1 <= c4 and c2 == 0:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
a = list(int(i) for i in input().split())
a.sort()
print("Yes" if a[0]+a[1]==a[2] else "No")
# Judge status: Wrong Answer
def resolve():
	a = [1, 3, 5, 6, 8, 10, 12]
	b = [4, 6, 9, 11]
	c = [2]

	x, y = map(int, input().split())
	if x in a and y in a:
		print("Yes")
	elif x in b and y in b:
		print("Yes")
	elif x in c and y in c:
		print("Yes")
	else:
		print("No")
resolve()
# Judge status: Accepted
from math import*
n=int(input())
a=list(map(int,input().split()))
b=[a[0]]
c=[a[-1]]
for i in range(1,n):
  b+=[gcd(b[-1],a[i])]
  c+=[gcd(c[-1],a[-i-1])]
ans=0
c=c[::-1]
for i in range(n):
  if i==0:ans=max(ans,c[i+1])
  elif i==n-1:ans=max(ans,b[i-1])
  else:
    ans=max(ans,gcd(c[i+1],b[i-1]))
print(ans)
# Judge status: Wrong Answer
n = int(input())
a = list(map(int, input().split()))

cnt = 0
if n == 1:
  print (1)
  exit()
c = 0
for i in range(n-1):
  if c == 2 and a[i+1] < a[i]:
    cnt += 1
    c = -1
  elif c == 1 and a[i+1] > a[i]:
    cnt += 1
    c = -1
  else:
    if a[i+1] > a[i]:
      c = 2
    elif a[i+1] == a[i]:
      c = 0
    else:
      c = 1
print (cnt+1)
# Judge status: Accepted
a, b = map(lambda x: int(x), input().split())

if a == 1:
  a = 1 + 13
if b == 1:
  b = 1 + 13
  
if a < b:
  print('Bob')
elif a > b:
  print('Alice')
else:
  print('Draw')
# Judge status: Wrong Answer
w = str(input())
for i in range(len(w)):
  for j in range(len(w)):
    if i != j:
      w[i] == w[j]
      f = True
      break
    else:
      f = False
print('no' if f else 'yes')
# Judge status: Wrong Answer
A, B = map(int,input().split())

if A % 3 == 0 or B % 3 ==0 or (A + B) % 3 ==0:
    print("possible")
else:
    print("impossible")
# Judge status: Accepted
print('A%sC'%'BR'[input()<'AR'])
# Judge status: Accepted
N,M = map(int,input().split())
target = list()
for i in range(N):
	target_list = list(map(int,input().split()))
	target_list.pop(0)
	target.append(target_list)

# print(target)

ans = dict()
for i in range(0,len(target)):
	for j in range(len(target[i])):
		if i == 0:
			ans[target[i][j]] = 1
		else:
			if target[i][j] in ans:
				ans[target[i][j]] += 1

ans_num = 0
for k in ans.keys():
	if ans[k] == N:
		ans_num += 1
print(ans_num)
# Judge status: Accepted
N, R = map(int, input().split())
if N < 10:
    n2=100*(10-N)
    R2 = R+n2
    
elif N >= 10:
    R2 = R
    
print(R2)
# Judge status: Accepted
s = input()
L = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"]
print(7 - L.index(s))
# Judge status: Accepted
n, k = map(int, input().split())
print(min(n%k,1))
# Judge status: Accepted
from itertools import chain

l = [[] for _ in range(11)]
l[0] = list(map(str, range(1, 10)))
for i in range(10):
    for x in l[i]:
        last = int(x[-1])
        for m in {max(0, last-1), last, min(9 ,last+1)}:
            m = str(m)
            l[i+1].append(x+m)

q = list(map(int, chain(*l)))
q.sort()
# print(len(q))
K = int(input())

print(q[K-1])
# Judge status: Wrong Answer
n = int(input())

ab = [list(map(int, input().split())) for _ in range(n)]
ab = sorted(ab, key=lambda x:int(x[1]))

c = [ab[i][1]-ab[i][0] for i in range(n)]

if n%2 == 1:
    center = n//2
    answer = ab[center][1]-ab[center][0]
else:
    center = [n//2-1,n//2]
    answer1 = ab[center[0]][1] - ab[center[0]][0]+1
    answer2 = ab[center[1]][1] - ab[center[1]][0]+1
    answer = answer1*answer2 - max(0,ab[center[0]][1]-min(ab[center[0]][0],ab[center[1]][1]))

print(answer)
# Judge status: Wrong Answer
A,B,C,K=map(int, input().split())
if A >= K:
    maxnum = A
elif A<K and A+B>=K:
    maxnum = A
else:
    maxnum = A - (K-A-B)
print(maxnum)
# Judge status: Accepted
S = list(input())
T = list(input())
count = 0

for i in range(len(S)):
    if S[i] == T[i]:
        continue
    else:
        count += 1
print(count)
# Judge status: Accepted
s=input()
ans=0
for i in range(len(s)):
    for j in range(len(s)):
        new_s=list(s[i:(len(s)-j)])
        if all((i in ["A","T","G","C"]) for i in new_s) and len(new_s)>ans:
            ans=len(new_s)
print(ans)
# Judge status: Accepted
n,m = map(int,input().split())
a = list(map(int, input().split()))
popular = list(filter(lambda e: e>=(1/(4*m))*sum(a),a))
print("Yes" if len(popular) >= m else "No")
# Judge status: Wrong Answer
n = int(input())
l = []
ans = 'Yes'
ps = 'a'
for i in range(n):
  s = input()
  if s in l:
    ans = 'No'
  l.append(s)
  if i != 0 and ps[-1] != s[0]:
    ans = 'No'

print(ans)
# Judge status: Accepted
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

mod = 10**9+7
def comb(n, k):
    c = 1
    for i in range(k):
        c *= n - i
        c %= mod
    d = 1
    for i in range(1, k + 1):
        d *= i
        d %= mod
    return (c * pow(d, mod - 2, mod)) % mod


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

if (x + y) % 3 != 0:
    print(0)
    exit()

n = (x + y) // 3
x -= n
y -= n
if x < 0 or y < 0:
    print(0)
    exit()

print(comb(x + y, x))
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))
A = sorted(a, reverse = True)

ali = []
bob = []
for i in range(n):
    if i % 2 == 0:
        ali.append(A[i])
    else:
        bob.append(A[i])
        
print(sum(ali) - sum(bob))
# Judge status: Accepted
a,b,x = map(int, input().split())
print(b//x - (a-1)//x)
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))

a_even = [elm_a for i, elm_a in enumerate(a) if i % 2 == 0]
a_odd = [elm_a for i, elm_a in enumerate(a) if i % 2 == 1]

ans = a_even[::-1] + a_odd
if n % 2 == 0:
  ans = ans[::-1]

print(' '.join(map(str, ans)))
# Judge status: Accepted
N = int(input())
T,A = map(int,input().split())
H = list(map(int,input().split()))
ans = 0
min_height = 10**18
for i in range(N):
  if abs(A - T + H[i]*0.006) < min_height:
    ans = i+1
    min_height = abs(A - T + H[i]*0.006)
print(ans)
# Judge status: Accepted
a,b,c=map(int,input().split())
if a==b and b==c:
    print(1)
elif a==b or b==c or c==a:
    print(2)
else:
    print(3)
# Judge status: Accepted
A, B = map(int, input().split())
for i in range(B*100):
    if i*8//100 == A and i * 10 // 100 == B:
        print(i)
        exit()

print(-1)
# Judge status: Wrong Answer
a = list(input())
b = list(input())
c = list(input())
ans = 'A'
d = {'a': a, 'b': b, 'c': c}
card = d['a'].pop()

while a and b and c:
    card = d[card].pop()

if not d['b']:
    ans = 'B'
if not d['c']:
    ans = 'C'

print(ans)
# Judge status: Accepted
import itertools
N,K=map(int,input().split())
A=[]
for i in range(K*2):
    a=list(map(int,input().split()))
    if i%2==1:
        A.append(a)
x=list(itertools.chain.from_iterable(A))
print(N-len(set(x)))
# Judge status: Wrong Answer
from bisect import bisect_left

N = int(input())

A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()

alters_count = 0
for a in A:
    bidx = bisect_left(B, a)
    if bidx == N:
        continue
    for b in B[bidx:]:
        cidx = bisect_left(C, b)
        if cidx == N:
            continue
        alters_count += N - cidx

print(alters_count)
# Judge status: Accepted
#!/usr/bin/env python
# coding: utf-8

# In[25]:


H = int(input())


# In[26]:


import math


# In[28]:


print(int(2**(math.log2(H)//1 + 1)-1))


# In[ ]:
# Judge status: Accepted
L=list(map(int,input().split()))
print(L[0]*L[1]//2)
# Judge status: Wrong Answer
S = input()

sc = ["dreameraser", "dreamerase", "dreamer", "dream", "eraser", "erase"]
for i in sc:
    S = S.replace(i, '')

if len(S) == 0:
    print("YES")
else:
    print("NO")
# Judge status: Wrong Answer
import math
n = int(input())
ans = 0.5 * (n-1)*n
print(int(ans))
# Judge status: Accepted
N = int(input())

ans = 0
for j in range(1, N+1):
    # ある数jのNまでの倍数をすべて足す。等差数列の和
    n = N // j
    tmp = n * (2 * j + (n-1) * j) // 2
    ans += tmp

print(ans)
# Judge status: Wrong Answer
S = str(input())
x = len(S)
while '01' in S:
  S = S.replace('01', '')
S = S.replace('10', '')
  
print (x-len(S))
# Judge status: Accepted
N=int(input())

print((N+1)//2)
# Judge status: Wrong Answer
a,b,c,d = map(int,input().split())
if b<c:
  print(0)
else:
  print(min(b,d)-c)
# Judge status: Accepted
# https://atcoder.jp/contests/agc036/tasks/agc036_a

s = int(input())

x1, y1 = 0, 0
x2 = 10 ** 9
y2 = 1

y3 = (s + x2 -1) // x2
x3 = x2 * y3 - s
print(x1, y1, x2, y2, x3, y3)
# Judge status: Wrong Answer
s = list(input())
s1 = s[::-1]
count = 0
for i in range(len(s)):
  if s[i]!=s1[i]:
    count += 1
print(count)
# Judge status: Wrong Answer
"""
author : halo2halo
date : 4, Feb, 2020
"""

import sys

# import itertools
# import math

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

H, N,*A = map(int, read().split())
print('YES' if H<=sum(A) else 'No')
# Judge status: Accepted
n = int(input())
x = list(map(int,input().split()))
ans_list = []
for i in range(max(x)):
  ans = 0
  for j in x:
    ans += (j-(i+1))**2
  ans_list.append(ans)
print(min(ans_list))
# Judge status: Wrong Answer
#133 b
import itertools
n,d=map(int,input().split())
N=[i for i in range(n)]
k=[i*i for i in range(1,100)]
x=[]
for i in range(n):
    a=list(map(int,input().split()))
    x.append(a)
ans=0
kumi=itertools.combinations(N,2)

for a,b in kumi:
    s=0
    for j in range(d):
        s+=(x[a][j]-x[b][j])**2
    if s in k:
        ans+=1
print(ans)
# Judge status: Accepted
import numpy as np

c = [[0]*3] * 3

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

c = np.array(c)

if len(set(c[0] - c[1])) == 1 and len(set(c[1] - c[2])) == 1 and len(set(c[:,0] - c[:,1])) == 1 and len(set(c[:,1] - c[:,2])) == 1:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
H=int(input())
W=int(input())
N=int(input())

if W>=H:
    cnt=(N-1+W)//W
else:
    cnt=(N-1+H)//H

print(cnt)
# Judge status: Accepted
a, b = map(int, input().split())
if max(a,b) <= 8:
  print('Yay!')
else:
  print(':(')
# Judge status: Accepted
a,b,c=map(int,input().split())
print("Yes" if a<c<b or b<c<a else "No")
# Judge status: Accepted
n,k=map(int,input().split())
x=sorted(list(map(int,input().split())))
a=[]
for i in range(n-k+1):
    l=x[i]
    r=x[i+k-1]
    a.append(min(abs(l)+abs(r-l),abs(r)+abs(l-r)))
print(min(a))
# Judge status: Wrong Answer
N, L = map(int, input().split())

if abs(L-1) <= N:
  i = abs(L - 1)
else:
  i = N

A = (N-1)*(L-1) + sum([n for n in range(1, N+1)]) - i
print(A)
# Judge status: Accepted
N,K = map(int,input().split())
if N % K != 0:
    print(1)
else:
    print(0)
# Judge status: Accepted
S = input()
c = "keyence"
if S[-7:] == c or S[:7] == c:
    print("YES")
else:
    for i in range(1, 7):
        c_, _c = c[:i], c[i:]
        if S[:i] == c_ and S[-(7-i):] == _c:
            print("YES")
            break
    else:
        print("NO")
# Judge status: Accepted
S = input()
T = input()
L = 0
for i in range(len(S)):
    if S[i] != T[i]:
        L += 1
    else:
        continue
print(L)
# Judge status: Wrong Answer
n, l = map(int, input().split())
pie = 0
comp = 300

for i in range(1, n+1):
    pie = pie + l + i - 1
    if abs(l + i -1) < comp:
        comp = l + i -1
        print(comp)

print(pie - comp)
# Judge status: Accepted
X,Y = map(int,input().split())

con = 0

while X <= Y:
  con += 1
  X = X * 2  
  
print(con)
# Judge status: Accepted
n = int(input())
a = list(int(input()) for _ in range(n))
aa = sorted(a.copy())
mx, sd = aa[n - 1], aa[n - 2]
for i in a:
    print(mx if i < mx else sd)
# Judge status: Accepted
s = len(str(input()))
print('x'*s)
# Judge status: Accepted
from fractions import gcd
A, B, C, D = map(int,input().split())
total = B - A + 1
divC = B//C - (A-1)//C
divD = B//D - (A-1)//D
lcm = int(C * D / gcd(C, D))
divCD = B//lcm - (A-1)//lcm
print(total - divC - divD + divCD)
# Judge status: Accepted
import sys
sys.setrecursionlimit(10**6)

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

if a<=8 and b<=8:
    print("Yay!")
else:
    print(":(")
# Judge status: Accepted
n, m = map(int, input().split())
l = 0
r = n
for i in range(m):
    lt, rt = map(int, input().split())
    l = max(l, lt)
    r = min(r, rt)
if(l<=r):
    print(r - l + 1)
else:
    print(0)
# Judge status: Accepted
n,t = map(int, input().split())

cl = []
tl = []

for i in range(n):
    cw,tw = map(int, input().split())

    if tw <= t:
        cl.append(cw)
        tl.append(tw)

if len(cl) == 0:
    print('TLE')
else:
    print(min(cl))
# Judge status: Accepted
def resolve():
    s = input()
    if s == 'ABC':
        print('ARC')

    else:
        print('ABC')
        
resolve()
# Judge status: Wrong Answer
def resolve():
    n, m = map(int, input().split())
    l = [list(map(int, input().split())) for _ in range(n)]
    l.sort()
    ans = 0
    drink = 0
    for i in range(n):
        cost = l[i][0]
        num = l[i][1]
        if drink + num >=m:
            ans += cost*(m-drink)
            print(ans)
        else:
            drink += num
            ans += num*cost

resolve()