Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

n,k,q = map(int,input().split())
l_a = [k]*n
for i in range(q):
    i = int(input()) -1
    if l_a[i]>=0:
        l_a[i]+= 1
    l_a = [m-1 for m in l_a]
for i in l_a:
    if i > 0:
        print('Yes')
    else:
        print('No')

### FIXED CODE ###

n,k,q = map(int,input().split())
l_a = [0]*n
for i in range(q):
    i = int(input()) -1
    l_a[i]+= 1
for i in l_a:
    if q-i < k:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

import itertools

n, m, q = map(int, input().split())
abcd_lis = []
for i in range(q):
    abcd = list(map(int, input().split()))
    abcd_lis.append(abcd)
L = []
for i in range(1, m+1):
    L.append(i)
H = list(itertools.combinations_with_replacement(L, n))
max_score = 0
for h in H:
    score = 0
    for j in range(q):
        if list(h)[abcd_lis[j][1]-1]-list(h)[abcd_lis[j][0]-1] == abcd_lis[j][2]:
            score += abcd_lis[j][3]
    if score > max_score:
        max_score = score
print(max_score)

### FIXED CODE ###

import itertools

n, m, q = map(int, input().split())
abcd_lis = []
for i in range(q):
    abcd = list(map(int, input().split()))
    abcd_lis.append(abcd)
L = []
for i in range(1, m+1):
    L.append(i)
H = list(itertools.combinations_with_replacement(L, n))
max_score = 0
for h in H:
    score = 0
    for j in range(q):
        if list(h)[abcd_lis[j][1]-1]-list(h)[abcd_lis[j][0]-1] == abcd_lis[j][2]:
            score += abcd_lis[j][3]
    if score > max_score:
        max_score = score
print(max_score)
### BUGGY CODE ###

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

#A
def A():
    return

#B
def B():
    return

#C
def C():
    n = I()
    a = LI()
    for i in range(n):
        a[i] -= i+1
    a.sort()
    ans = float("inf")
    for b in a:
        m = 0
        for i in range(n):
            m += abs(a[i]-b)
        ans = min(ans,m)
    print(ans)

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

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


### FIXED CODE ###

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

#A
def A():
    return

#B
def B():
    return

#C
def C():
    n = I()
    a = LI()
    for i in range(n):
        a[i] -= i+1
    a.sort()
    b = sum(a)//n
    ans = 0
    for i in range(n):
        ans += abs(a[i]-b)
    ans2 = 0
    b += 1
    for i in range(n):
        ans2 += abs(a[i]-b)
    ans3 = 0
    b = a[n//2]
    for i in range(n):
        ans3 += abs(a[i]-b)
    print(min(ans,ans2,ans3))

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

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

import math
N = (int(input()))
items = list(map(int,input().split()))
for i in range(len(items)):    
    rest = items[:i] + items[i+1:]
    rest_unique = set(rest)
    out = 0
    for j in rest_unique:
        cnt = sum([1 for x in rest if x == j])
        if cnt >= 2:
            out = out + math.factorial(cnt)/math.factorial(cnt-2)/2
    print(int(out))

### FIXED CODE ###

import math
input()
items = list(map(int,input().split()))
d = {}
for i in items:
    if i in d.keys():
        d[i] = d[i]+1
    else:
        d[i] = 1

p = {}
for k in d.keys():
    cnt = d[k]
    p[k] = (cnt*(cnt-1))/2

total = sum(p.values())

for item in items:
    print(int(total - d[item] + 1))
### BUGGY CODE ###

n,v=[int(k) for k in input().split()]
li=[]
for i in range(n):
  li.append([int(k) for k in input().split()])
  
dp=[[0 for i in range(v+1)] for j in range(n+1)]
for a in range(1,n+1):
  for b in range(1,v+1):
    if(li[a-1][0]<=b):
      dp[a][b]=max(li[a-1][1]+dp[a-1][b-li[a-1][0]],dp[a-1][b])
    else:
      dp[a][b]=dp[a-1][b]
print(dp[n][v])      
      
  


### FIXED CODE ###

n,w=[int(k) for k in input().split()]
li=[]
 
 
ans=0
for i in range(n):
    li.append([int(k) for k in input().split()])
dp=[[0 for i in range(100001)] for j in range(n+1)]
for i in range(1,100001):
    dp[0][i]=10**10
dp[0][0]=0    
for a in range(1,n+1):
    for b in range(0,100001):
        if(li[a-1][1]<=b):
            x=li[a-1][0]+dp[a-1][b-li[a-1][1]]
            y=dp[a-1][b]
            dp[a][b]=min(x,y)
        else:
            dp[a][b]=dp[a-1][b]
        if dp[a][b]<=w:
          ans=max(ans,b)
 
 
print(ans)
### BUGGY CODE ###

import sys
import os
import math


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = int(sys.stdin.buffer.readline().rstrip())
    A = list(map(int, sys.stdin.buffer.readline().split()))
    P = set(A)

    for n in range(N):
        ary = A[n + 1:] + A[:-len(A) + n]
        tmp = 0
        for p in P:
            t = ary.count(p)
            tmp += (t * (t - 1)) // 2

        print(tmp)



if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
import os
import collections

def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = int(sys.stdin.buffer.readline().rstrip())
    A = list(map(int, sys.stdin.buffer.readline().split()))

    obj = collections.Counter(A)

    p = 0
    for v in obj.values():
        if v > 1:
            p += v * (v - 1) // 2

    for a in A:
        print(p - (obj[a] - 1))


if __name__ == '__main__':
    main()
### BUGGY CODE ###

N = int(input())
L = sorted([int(i) for i in input().split()])

def count(ls, n):
    left = 0
    right = len(ls)
    while right - left > 1:
        mid = (left + right) // 2

        if ls[mid] < n: left = mid
        if ls[mid] >= n: right = mid

    return left

ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        ans += count(L, L[i]+L[j]) - j

print(ans)

### FIXED CODE ###

from bisect import bisect_left

N = int(input())
L = sorted([int(i) for i in input().split()])

ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        ans += bisect_left(L, L[i]+L[j]) - (j + 1)

print(ans)
### BUGGY CODE ###

import numpy as np

N = int(input())

N_list = [i+1 for i in range(N-1)]

N_np   = np.sum(np.array(N_list))

print(int(N_np))

### FIXED CODE ###

N = int(input())

print((N*(N-1))//2)
### BUGGY CODE ###

N = int(input())
A = list(int(x) for x in input().split())
ans = [None] * N
for i in range(N):
    b = A.index(i + 1)
    ans[i] = b
for i in range(N):
    c = ans[i] + 1
    print(c)

### FIXED CODE ###

N = int(input())
A = list(int(x) for x in input().split())
ans = [None] * N
for i in range(N):
    ans[A[i] - 1] = i + 1
for i in range(N):
    print(ans[i])
### BUGGY CODE ###

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

for i in range(1, n+1):
    print(str(a.index(i)+1)+" ", end = "")

### FIXED CODE ###

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

b = [0 for _ in range(n)]
for i in range(n):
    b[ a[i] - 1] = i+1
for i in range(n):
    print(str(b[i]) + " ", end = "")
### BUGGY CODE ###

from collections import deque


def bfs():
    q = deque()
    for i in range(h):
        for j in range(w):
            if grid[i][j] == "#":
                q.append((i, j))
                cost[i][j] = 0

    while q:
        x, y = q.popleft()
        for dx, dy in nb:
            nx = x + dx
            ny = y + dy
            if 0 <= nx and nx < h and 0 <= ny and ny < w and cost[nx][ny] == float("inf"):
                cost[nx][ny] = cost[x][y] + 1
                q.append((nx, ny))


h, w = map(int, input().split())
grid = [list(input()) for _ in range(h)]
cost = [[float("inf")] * w for _ in range(h)]
nb = [(-1, 0), (0, -1), (1, 0), (0, 1)]

bfs()

print(max([max(c) for c in cost]))

### FIXED CODE ###

from collections import deque
 
H, W = map(int, input().split())
A = [input() for i in range(H)]
q = deque()
c = [[-1] * W for i in range(H)]
for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            q.append((i, j))
            c[i][j] = 0
D = [[0, 1], [1, 0], [0, -1], [-1, 0]]
while q:
    y, x = q.popleft()
    for dy, dx in D:
        ny, nx = y+dy, x+dx
        if 0 <= ny < H and 0 <= nx < W and c[ny][nx] == -1:
            q.append((ny, nx))
            c[ny][nx] = c[y][x]+1
print(max([max(l) for l in c]))
### BUGGY CODE ###

import sys
from itertools import combinations
input = sys.stdin.readline
n = int(input())
a = [int(x) for x in input().strip().split()]
b = [int(x) for x in input().strip().split()]

all_cards = []
for i, (aa, bb) in enumerate(zip(a, b)):
    all_cards.append((aa, bb, i))

def check(cards):
    pre = -1
    for c in cards:
        print(c)
        if c[0] >= pre:
            pre = c[0]
        else:
            return False
    else:
        return True

def cnt(l):
    ret = 0
    for i in range(len(l)-1):
        for j in range(i+1, len(l)):
            if l[i] > l[j]:
                ret += 1
    return ret

def dp(all_cards, l, p):
    i = len(l) + 1
    if len(l) == n:
        return cnt(l)
    ret = float('inf')
    for card in all_cards:
        if card[2] not in l and card[0] < p and card[1] < p:
            return ret
    for card in all_cards:
        if card[2] in l:
            continue
        if card[(i-(card[2]+1))%2] >= p:
            ret = min(ret, dp(all_cards - set(card), l+[card[2]], card[(i-(card[2]+1))%2]))
    return ret

ans = dp(set(all_cards), [], -float('inf'))
if ans == float('inf'):
    ans = -1
print(ans)

### FIXED CODE ###

import sys
from itertools import combinations
input = sys.stdin.readline
n = int(input())
a = [int(x) for x in input().strip().split()]
b = [int(x) for x in input().strip().split()]

all_cards = []
for i, (aa, bb) in enumerate(zip(a, b)):
    if i % 2:
        aa, bb = bb, aa
    all_cards.append([aa, bb, i])

def cnt(l):
    ret = 0
    for i in range(len(l)-1):
        for j in range(i+1, len(l)):
            if l[i][1] > l[j][1]:
                ret += 1
    return ret

ans = float('inf')
for cards in combinations(all_cards, (n + 1)// 2):
    acards = []
    for card in cards:
        acards.append([card[0],card[2]])
    bcards = []
    for card in all_cards:
        if [card[0],card[2]] not in acards:
            bcards.append([card[1],card[2]])

    acards.sort()
    bcards.sort()
    abcards = []
    # print(acards, bcards)
    for i in range(len(bcards)):
        abcards.extend([acards[i], bcards[i]])
    else:
        if n % 2:
            abcards.append(acards[-1])
    # print(abcards)
    if abcards != sorted(abcards, key=lambda x: x[0]):
        continue
    ans = min(ans, cnt(abcards))

if ans == float('inf'):
    ans = -1
print(ans)
### BUGGY CODE ###

n = int(input())
a = [int(i) for i in input().split()]

b = [0]
for i in a:
    b.append(b[-1] + i)


def get(i, j):
    i, j = min(i, j), max(i, j)
    return b[j]-b[i]


j = 0
k = 0
ans = 10**18
for i in range(n):
    while j < n and abs(get(0, j) - get(j, i)) > abs(get(0, j + 1) - get(j + 1, i)):
        j += 1
    while k < n and abs(get(i, k) - get(k, n)) > abs(get(i, k + 1) - get(k + 1, n)):
        k += 1
    an = [get(0, j), get(j, i), get(i, k), get(k, n)]
    ans = min(ans,max(an)-min(an))
print(ans)

### FIXED CODE ###

n = int(input())
a = [int(i) for i in input().split()]

b = [0]
for i in a:
    b.append(b[-1] + i)


def get(i, j):
    i, j = min(i, j), max(i, j)
    return b[j]-b[i]


j = 0
k = 0
ans = 10**18
for i in range(n):
    while j < n and abs(get(0, j) - get(j, i)) > abs(get(0, j + 1) - get(j + 1, i)):
        j += 1
    while k < n and abs(get(i, k) - get(k, n)) > abs(get(i, k + 1) - get(k + 1, n)):
        k += 1
    an = [get(0, j), get(j, i), get(i, k), get(k, n)]
    ans = min(ans,max(an)-min(an))
print(ans)
### BUGGY CODE ###

n = int(input())

sumOfDigits = 0

while n != 0:
	r = n % 10
	sumOfDigits += r
	n = n // 10

if sumOfDigits % 9 == 0:
	print("Yes")
else:
	print("No")

### FIXED CODE ###

n = input()

sumOfDigits = 0

for i in n:
	sumOfDigits += int(i)

if sumOfDigits % 9 == 0:
	print("Yes")
else:
	print("No")
### BUGGY CODE ###

S = input()
K = int(input())
N = len(S)
al = [chr(ord('a') + i) for i in range(26)]
tmp_al = []
if K==1:
    for s in al:
        if s in S:
            print(s)
            exit()

for s in al:
    if s in S:
        if len(tmp_al) == 3:
            break
        if N - S.rfind(s) >= K:
            tmp_al.append(s)
            break
        else:
            if N - S.find(s) >= K:
                tmp_al.append(s)
                break
            else:
                tmp_al.append(s)
                continue

count = [[] for _ in range(len(tmp_al))]
for i in range(len(tmp_al)):
    for k in range(N):
        if S[k] == tmp_al[i]:
            count[i].append(k)
ans_list = []
ans_list.append(tmp_al[0])
for i in count[0]:
    cnt = 1
    while i + cnt <= N:
        ans_list.append(S[i:i+cnt])
        cnt += 1
ans_list = list(set(ans_list))
if len(ans_list) < K:
    for i in count[1]:
        cnt = 1
        while i + cnt <= N:
            ans_list.append(S[i:i+cnt])
            cnt += 1
ans_list = list(set(ans_list))
if len(ans_list) < K:
    for i in count[2]:
        cnt = 1
        while i + cnt <= N:
            ans_list.append(S[i:i+cnt])
            cnt += 1
ans_list = list(set(ans_list))
ans_list.sort()
##print(ans_list)
print(ans_list[K-1])

### FIXED CODE ###

S = input()
K = int(input())
N = len(S)

al = [chr(ord('a') + i) for i in range(26)]
tmp_al = []
if K==1:
    for s in al:
        if s in S:
            print(s)
            exit()

for s in al:
    if s in S:
        if len(tmp_al) == 3:
            break
        if N - S.rfind(s) >= K:
            tmp_al.append(s)
            break
        else:
            if N - S.find(s) >= K:
                tmp_al.append(s)
                break
            else:
                tmp_al.append(s)
                continue

count = [[] for _ in range(len(tmp_al))]
for i in range(len(tmp_al)):
    for k in range(N):
        if S[k] == tmp_al[i]:
            count[i].append(k)
ans_list = []
ans_list.append(tmp_al[0])
for i in count[0]:
    cnt = 1
    while (i + cnt <= N):
        if cnt == 7:
            break
        ans_list.append(S[i:i+cnt])
        cnt += 1

ans_list = list(set(ans_list))

if len(ans_list) < K:
    for i in count[1]:
        cnt = 1
        while (i + cnt <= N):
            if cnt == 7:
                break
            ans_list.append(S[i:i+cnt])
            cnt += 1
ans_list = list(set(ans_list))

if len(ans_list) < K:
    for i in count[2]:
        cnt = 1
        while i + cnt <= N:
            ans_list.append(S[i:i+cnt])
            cnt += 1
ans_list = list(set(ans_list))


ans_list.sort()
##print(ans_list)
print(ans_list[K-1])
### BUGGY CODE ###

def resolve():
    # 整数 1 つ
    # n = int(input())
    # 整数複数個
    n, k = list(map(int, input().split()))
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    A = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

    Unique = list(set(A))
    Dic = {}
    for i in range(len(Unique)):
        Dic[Unique[i]] = A.count(Unique[i])

    numU = len(Unique)
    cnt = 0
    while numU > k:
        cnt += min(Dic.values())
        del Dic[min(Dic, key=Dic.get)]
        numU -= 1

    print(cnt)
resolve()

### FIXED CODE ###

N,K = map(int,input().split())
A = list(map(int,input().split()))

Ad = {x:0 for x in set(A)}
if len(set(A)) <= K:
    print(0)
else:
    count = 0
    for a in A:
        Ad[a] += 1
    Ad = sorted(Ad.items(), key=lambda x:x[1])
    for i in range(len(set(A))-K):
        count += Ad[i][1]
    print(count)
### BUGGY CODE ###

import sys
from collections import defaultdict
from copy import deepcopy

sys.setrecursionlimit(10 ** 5 + 5)

n, q = list(map(int, input().split()))
edge = defaultdict(set)
for _ in range(n - 1):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    edge[a].add(b)
    edge[b].add(a)

tree = defaultdict(lambda: {"count": 0, "children": set()})
ROOT = 0


def rec(parent, ancestors):
    # print(parent)
    for child in edge[parent]:
        if child in ancestors:
            continue

        for ancestor in ancestors:
            tree[ancestor]["children"].add(child)
        new_ancestors = deepcopy(ancestors)
        new_ancestors.add(child)
        rec(child, new_ancestors)


rec(ROOT, set([ROOT]))

# print(tree)

opr = []
for _ in range(q):
    p, x = list(map(int, input().split()))
    p -= 1
    opr.append((p, x))

score = [0] * n
for p, x in opr:
    score[p] += x
    for child in tree[p]["children"]:
        score[child] += x

answer = " ".join(map(str, score))
print(answer)

### FIXED CODE ###

n, q = list(map(int, input().split()))
# NG: [set()] * n <- all points same set
edge = [set() for _ in range(n)]
for _ in range(n - 1):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    edge[a].add(b)
    edge[b].add(a)

opr = [0] * n
for _ in range(q):
    p, x = list(map(int, input().split()))
    p -= 1
    opr[p] += x

score = [-1] * n
q = [(0, 0)]
while q:
    # print(*q)
    node, w = q.pop()
    w += opr[node]
    score[node] = w
    # print(*score)
    for child in edge[node]:
        if score[child] == -1:
            q.append((child, w))

print(*score)
### BUGGY CODE ###

from collections import deque

N=int(input())
deg=[0 for v in range(N+1)];deg[0]=None
out=[set() for v in range(N+1)];deg[0]=None
for e in range(1,N):
    a,b=map(int,input().split())
    out[a].add((b,e));out[b].add((a,e))
for v in range(N+1):
    deg[v]=len(out[v])

# print(out) #DB
# print(deg) #DB

K=max(deg[1:])

# print(K) #DB


vcol=[set() for v in range(N+1)];vcol[0]=None # 頂点vから出る辺に含まれる色
ecol=[0 for e in range(N)];ecol[0]=None # 辺eの色
r=[False for v in range(N+1)];r[0]=None # その頂点にたどり着いたか

q=deque()
q.append(1);r[1]=True
while q:
    u=q.popleft() # 今いる頂点
    for vs in out[u]: # 今いる頂点の隣にある頂点と，その頂点に行くための辺の番号
        if not r[vs[0]]: # その頂点にまだ辿り着いていなければ
            for col in range(1,K+1): # 各色を順に選び
                if col not in vcol[u]: # その色が，今いる頂点から生える辺にまだ使われていなければ
                    ecol[vs[1]]=col # その辺をその色で塗り
                    vcol[u].add(col) # 今いる頂点から生える辺の色の集合に加え
                    vcol[vs[0]].add(col) # 進んだ先の頂点から生える辺の色の集合に加える。
                    break
            r[vs[0]]=True # その頂点にたどり着いたこととし
            q.append(vs[0]) # その頂点をキューに加える。

# print(vcol) #DB
# print(ecol) #DB

print(K)
for ecoli in ecol[1:]:
    print(ecoli)

### FIXED CODE ###

# アイデア：（これまでどおり）BFS。
# まず頂点に色を塗り，次に，その頂点から出る辺に色を塗ってゆく。
# 頂点に塗られた色及び「その頂点から出る何本目の辺か」によって，その辺に塗る色を決定する。
# 頂点に入ってくるときには，その際に取った辺の色を頂点に塗る。

from collections import deque

N=int(input())
d={} # 辺の両端の頂点→辺の番号を辿れるようにしておく
out=[set() for v in range(N+1)];out[0]=None # 隣接リスト，頂点の番号も問題文どおり1-initial,1~N
for i in range(1,N): # 問題文どおり辺の番号は1-initial,1~N-1
    u,v=map(int,input().split())
    out[u].add(v);out[v].add(u)
    u,v=min(u,v),max(u,v);d[(u,v)]=i
K=max([len(out[v]) for v in range(1,N+1)])
    
vcol=[0 for v in range(N+1)];vcol[0]=None
ecol=[0 for e in range(N)];ecol[0]=None

vr=[False for v in range(N+1)];vr[0]=None

q=deque()
q.append(1);vr[1]=True
vcol[1]=1 # 頂点1を色1で塗る
while q:
    u=q.popleft() # 今いる頂点    
    i=1 # その頂点から塗り始める何本目の辺か(1-initial),1<=i<=K
    for v in out[u]:
        if not vr[v]:
            col=(vcol[u]+i-1)%K+1
            vcol[v]=ecol[d[(min(u,v),max(u,v))]]=col
            vr[v]=True
            q.append(v)
            i+=1

print(K)
for i in range(1,N):
    print(ecol[i])
### BUGGY CODE ###

n, m  = map(int, input().split())
a, b = [], []
for i in range(n):
    x, y = map(int, input().split())
    a.append([x, i])
    b.append([y, i])
a.sort()
ans = 0
idx = 0
while True:
    if m <= 0:
        break
    i = a[idx][1]
    for j in range(len(b)):
        if b[j][1] == i:
            kosuu = b[j][0]
    if kosuu <= m:
        ans += kosuu * a[idx][0]
        m -= kosuu
        idx += 1
    else:
        ans += m * a[idx][0]
        m = 0
print(ans)


### FIXED CODE ###

n, m  = map(int, input().split())
arr = []
for i in range(n):
    a, b = map(int, input().split())
    arr.append([a, b])
arr.sort()
ans = 0
idx = 0
while True:
    if m <= 0:
        break
    ans += arr[idx][0] * min(arr[idx][1], m)
    m -= min(arr[idx][1], m)
    idx += 1
print(ans)
### BUGGY CODE ###

a = int(input())
b =list(input().split())


c = 0

for i in range(a):
  for j in range(i,a):
      if (int(b[i]) - int(b[j]))>1:
          c=1
if c==1:
  print("No")
else:
  print("Yes")

### FIXED CODE ###

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

c = 0

for i in range(a):
  if i>0:
    if (b[i] - b[i-1])<-1:
      c+=2
    if (b[i] - b[i-1])==-1:
      c+=1
    if (b[i] - b[i-1])>0:
      c=0
  if c>=2: break
if c<=1: print("Yes")
else: print("No")
### BUGGY CODE ###

N = int(input())
S = input().strip()
D = {}
for i in range(N):
    a = S[i]
    if a not in D:
        D[a] = []
    D[a].append(i)
dp = [0 for _ in range(N)]
if S[0]==S[1]:
    dp[1]=1
else:
    dp[1] = 0
for i in range(2,N):
    a = S[i]
    cntmax = 0
    for j in D[a]:
        cnt = 1
        while 1:
            if i-j>=cnt+1 and j-cnt>=0 and S[j-cnt:j+1]==S[i-cnt:i+1]:
#                 print("i,j,cnt={},{},{}".format(i,j,cnt))
                cntmax = max(cntmax,cnt+1)
            else:break
            cnt += 1
    dp[i] = max(dp[i-1],cntmax)
print(dp[N-1])   

### FIXED CODE ###

N = int(input())
S = input().strip()
cmax = 0
for k in range(1,N):
    X = S[:N-k]
    Y = S[k:]
    cur = 0
    cnt = 0
    for i in range(N-k):
        if X[i]!=Y[i]:
            cmax = max(cmax,min(cnt,k))
            cur = i
            cnt = 0
        else:
            cnt += 1
    cmax = max(cmax,min(cnt,k))
print(cmax)
### BUGGY CODE ###

import itertools
L,R=map(int,input().split())

A=[]
D=[]

for i in range(R-L+1):
    A.append((i+L)%2019)

if A.count(1)>=2:
    B=set(A)
    B.add(1)
else:
    B=set(A)

C=list(itertools.combinations(B,2))
for j in range(len(C)):
    D.append(C[j][0]*C[j][1]%2019)
    if 0 in D:
        break
E=sorted(D)
print(E[0])


### FIXED CODE ###

import itertools
L,R=map(int,input().split())

A=[]
D=[]

if R-L+1<2019:
    for i in range(R-L+1):
        A.append((i+L)%2019)

    if A.count(1)>=2:
        B=set(A)
        B.add(1)
    else:
        B=set(A)

    C=list(itertools.combinations(B,2))
    for j in range(len(C)):
        D.append(C[j][0]*C[j][1]%2019)
    E=sorted(D)
    print(E[0])
else:
    print(0)