Harryxun/stf_run huggingface dataset:
import math

n, m = [int(i) for i in input().split()]
s = input()
t = input()

ans = n * m // math.gcd(n, m)

for scnt in range(n):
    if scnt * m % n == 0:
        tcnt = scnt * m // n
        if s[scnt] != t[tcnt]:
            ans = -1
            break

print(ans)

### FIXED CODE ###

import math
import fractions

n, m = [int(i) for i in input().split()]
s = input()
t = input()

ans = n * m // fractions.gcd(n, m)

for scnt in range(n):
    if scnt * m % n == 0:
        tcnt = scnt * m // n
        if s[scnt] != t[tcnt]:
            ans = -1
            break

print(ans)
X,Y=sorted(list(map(int,input().split())))
#移動方法を(i+1,j),(i,j+1)となるようにどうにかする
if (X-abs(Y-X))%3!=0:
  print(0)
  exit(0)
n=(X-abs(Y-X))//3
X=n+abs(Y-X)
Y=n

  
mod=10**9+7
a=1
for i in range(1,X+Y+1):
  a*=i
  a%=mod
b=1
for i in range(1,X+1):
  b*=i
  b%=mod
c=1
for i in range(1,Y+1):
  c*=i
  c%=mod
print(a*pow(b,-1,mod)*pow(c,-1,mod)%mod)


### FIXED CODE ###

X,Y=sorted(list(map(int,input().split())))
#移動方法を(i+1,j),(i,j+1)となるようにどうにかする
if (X-abs(Y-X))%3!=0 or X*2<Y:
  print(0)
  exit(0)
n=(X-abs(Y-X))//3
X=n+abs(Y-X)
Y=n

  
mod=10**9+7
a=1
for i in range(1,X+Y+1):
  a*=i
  a%=mod
b=1
for i in range(1,X+1):
  b*=i
  b%=mod
c=1
for i in range(1,Y+1):
  c*=i
  c%=mod

print(a*pow(b,-1,mod)*pow(c,-1,mod)%mod)
nab=list(map(int,input().split()))
v=list(map(int,input().split()))
v.sort(reverse=True)
vmin=v[:nab[1]]
print(sum(vmin)/len(vmin))
mini=1
if len(vmin)>1:
    for i in range(nab[1]):
        if vmin[-2-i]==vmin[-1]:
            mini+=1
        else:
            break
ex=0
if nab[1]<nab[2]:
    for i in range(nab[0]-nab[1]):
        if v[nab[1]+i]==vmin[-1]:
            ex+=1
        else:
            break
def f(n):
    out=1
    for i in range(1,n+1):
        out*=i
    return out
m=min(nab[2]-nab[1],ex)
ans=1
for i in range(m):
    ans+=int(f(mini+m)/(f(mini+i)*f(m-i)))
print(ans)


### FIXED CODE ###

nab=list(map(int,input().split()))
v=list(map(int,input().split()))
v.sort(reverse=True)
vmin=v[:nab[1]]
print(sum(vmin)/len(vmin))
mini=1
if nab[1]>1:
    for i in range(nab[1]-1):
        if vmin[-2-i]==vmin[-1]:
            mini+=1
        else:
            break
ex=0
for i in range(nab[0]-nab[1]):
    if v[nab[1]+i]==vmin[-1]:
        ex+=1
    else:
        break
def f(n):
    out=1
    for i in range(1,n+1):
        out*=i
    return out
ans=0
if vmin[0]!=vmin[-1]:
    ans=f(mini+ex)//(f(mini)*f(ex))
    print(ans)
else:
    m=min(nab[2]-nab[1],ex)
    for i in range(m+1):
        ans+=f(mini+ex)//(f(mini+i)*f(ex-i))
    print(ans)
N, Q = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(lambda x:int(x)-1, input().split())
    G[a].append(b)

points = [0] * N 
for _ in range(Q):
    p, x = map(int, input().split())
    points[p-1] += x

from collections import deque
st = deque([[0, points[0]]])
result = [0] * N
while st:
    idx, count = st.pop()
    result[idx] = str(count)
    for ni in G[idx]:
        st.append([ni, count+points[ni]])

print(" ".join(result))

### FIXED CODE ###

N, Q = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(lambda x:int(x)-1, input().split())
    G[a].append(b)
    G[b].append(a)

points = [0] * N 
for _ in range(Q):
    p, x = map(int, input().split())
    points[p-1] += x

from collections import deque
st = deque([[0, points[0]]])
result = ['0'] * N
visited = [0] * N
visited[0] = 1
while st:
    idx, count = st.pop()
    result[idx] = str(count)
    for ni in G[idx]:
        if visited[ni] != 1:
            visited[ni] = 1
            st.append([ni, count+points[ni]])

print(" ".join(result))
a=int(input())
b=map(int,input().split())
c=[]
d=0
for i in range(a):
  c.append(b[i])
  if min(c)>=b[i]:
    d+=1
  else:
    pass
print(d)
    
    


### FIXED CODE ###

N=int(input())
P=list(map(int,input().split()))
b=N
a=0
for i in range(N):
  if P[i]<=b:
    b=P[i]
    a+=1
print(a)
a,b,k = map(int,input().split())
l =list[a:b]
mimi = l[:a-k]
maxi = l[b-k:]
print(mini+maxi)


### FIXED CODE ###

a,b,k=map(int,input().split())
l=range(a,b+1)
ans=sorted(set(l[:k])|set(l[-k:]))
for i in ans:
    print(i)
i = int(input())
print("ABC"i)

### FIXED CODE ###

i = int(input())
print("ABC"+str(i))
T = list(map(int, (input() for _ in range(5))))
T2 = [math.ceil(t / 10) * 10 for t in T]
m = max(t2 - t for t, t2 in zip(T, T2))
print(sum(T2) - m)

### FIXED CODE ###

import math
 
T = list(map(int, (input() for _ in range(5))))
T2 = [math.ceil(t / 10) * 10 for t in T]
m = max(t2 - t for t, t2 in zip(T, T2))
print(sum(T2) - m)
import sys
sys.setrecursionlimit=10**12

def modinv(a,m=10**9+7):
    if a==0: return 1
    else:
        b=m
        (x, lastx) = (0, 1)
        (y, lasty) = (1, 0)
        while b != 0:
            q = a // b
            (a, b) = (b, a % b)
            (x, lastx) = (lastx - q * x, x)
            (y, lasty) = (lasty - q * y, y)
        return lastx % m

def cur(p):
        for x in neighbor[p]:
            try:
                if x==par[p]: continue
            except: print(0);sys.exit()
            par[x]=p
            descend[p]+=cur(x)
        return descend[p]


def cur2(p):
    for x in neighbor[p]:
        if x==par[p]: continue
        ans[x]=ans[p]*descend[x]*modinv(n-descend[x])
        ans[x]%=mod
        cur2(x)

mod=10**9+7
n=int(input())
neighbor=[[]  for _ in range(n+1)]
descend=[1]*(n+1)
par=[1]+[0]*(n)

for _ in range(n-1):
    a,b=map(int,input().split())
    neighbor[a].append(b)
    neighbor[b].append(a)
cur(1)

ans=[1]*(n+1)
ans1=1
for i in range(1,n+1):
    ans1=ans1*i*modinv(descend[i])
    ans1%=mod
ans[1]=ans1

cur2(1)

for i in range(1,n+1):
    print(ans[i])

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)

def modinv(a,m=10**9+7):
    if a==0: return 1
    else:
        b=m
        (x, lastx) = (0, 1)
        (y, lasty) = (1, 0)
        while b != 0:
            q = a // b
            (a, b) = (b, a % b)
            (x, lastx) = (lastx - q * x, x)
            (y, lasty) = (lasty - q * y, y)
        return lastx % m

def cur(p):
    if neighbor[p]==[]: return
    for x in neighbor[p]:
        par[x]=p
        neighbor[x].remove(p)
        cur(x)
    descend[par[p]]+=descend[p]

def cur2(p):
    for x in neighbor[p]:
        ans[x]=ans[p]*descend[x]*modinv(n-descend[x])
        ans[x]%=mod
        cur2(x)

mod=10**9+7
n=int(input())
neighbor=[set()  for _ in range(n+2)]
descend=[1 for i in range(n+1)]
par=[0]+[0]*(n+1)

for _ in range(n-1):
    a,b=map(int,input().split())
    neighbor[a].add(b)
    neighbor[b].add(a)

cur(1)


ans=[1]*(n+1)
ans1=1
for i in range(1,n+1):
    ans1=ans1*i*modinv(descend[i])
    ans1%=mod
ans[1]=ans1

cur2(1)

for i in range(1,n+1):
    print(ans[i])
a,s,b = input(str, input().split())
if s == "+":
    print(int(a) + int(b))
else:
    print(int(a) - int(b))

### FIXED CODE ###

a,s,b = map(str, input().split())
if s == "+":
    print(int(a) + int(b))
else:
    print(int(a) - int(b))
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n = k()
a = l()

i=1
while i < n:
    if a[i] == a[i+1]:
        ans += 1
        i += 1
    i += 1

print(ans)


### FIXED CODE ###

import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n = k()
a = l()

i=1
while i < n:
    if a[i] == a[i-1]:
        ans += 1
        i += 1
    i += 1

print(ans)
N = int(input())
nums = [int(s) for s in input().split()]
 
min_breaks = -1
 
count_num = 1
break_index = 1

for i in range(N):
  if nums[i] == count_num:
      if min_breaks == -1:
          min_breaks = 0
      if count_num == 1:
      	 min_breaks += ((i+1) - break_index)
      else:
         min_breaks += ((i+1) - break_index - 1)
      
      break_index = (i+1)
      count_num+=1

if break_index < N and min_breaks != -1:
  min_breaks += ((i+1) - break_index)
  
print(min_breaks)

### FIXED CODE ###

num = sum([int(input()) for s in range(2)])

if num == 5:
  print(1)
elif num == 4:
  print(2)
else:
  print(3)
n = input()
sum = 0

for i in range(1,n+1,1):
  if(i%3 == 0 or i%5 == 0):
    continue
  sum += i
  
print(sum)



### FIXED CODE ###

n = int(input())
sum = 0

for i in range(1,n+1,1):
  if(i%3 == 0 or i%5 == 0):
    continue
  sum += i
  
print(sum)
H = list(map(int,input().split()))

SUP = 10 ** 6

dp = [SUP] * N

#0 ~ K - 1
for i in range(0,min(N,K)):
  dp[i] = abs(H[i] - H[0])
  
if N <= K:
  print(dp[-1])
  
else:
  #K ~ N
  for i in range(K,N):
    d = SUP
    
    for j in range(K,0,-1):
      dm = abs(H[i] - H[i - j]) + dp[i - j]
      print(abs(H[i] - H[i - j]),dp[i - j],dm)
      if d > dm:
        d = dm
    dp[i] = d
  
  print(dp[-1])

### FIXED CODE ###

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

dp = [0] * N

#Hの値Hiとそのインデックスiを取り出す
#dpの初期値は0なので1から始める
for i,Hi in enumerate(H[1:],1):
  #過去範囲の切り取り、リスト範囲をはみ出ないようにmaxが0になるように
  s = max(0,i-K)
  
  #K個分の範囲について、zip関数で各iについてコストを計算し、
  #最小値を計算
  dp[i] = min([t + abs(Hi - hl) for hl,t in zip(H[s:i], dp[s:i])])

#dpリストの最後尾
print(dp[N - 1])
a, b, x =map(int, inpit().split())

if a > x:
  print('No')
else:
  if a + b < x:
    print('No')
  else:
    if x-a > b:
      print('No')
    else:
      print('Yes')


### FIXED CODE ###

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

if 0 <= x-a <= b:
  print('YES')
else:
  print('NO')
a=list(input())
b=lsit(input())
if a==b:
  print("No")
else:
  a.sort()
  a="".join(a)
  b.sort()
  b=b[::-1]
  b="".join(b)
  list_ = [a,b]
  list_.sort()
  if list_[0]==a:
    print("Yes")
  else:
    print("No")

### FIXED CODE ###

a=list(input())
b=list(input())
if a==b:
  print("No")
else:
  a.sort()
  a="".join(a)
  b.sort()
  b=b[::-1]
  b="".join(b)
  list_ = [a,b]
  list_.sort()
  if list_[0]==a:
    print("Yes")
  else:
    print("No")
X,Y=int(input().split())
C=X+Y/2
print(C)

### FIXED CODE ###

X,Y=map(int,input().split())
x=int(X+Y/2)
print(x)
A, B = map(int, input().split())
if A > B:
  A, B = B, A

def check(X):
  global A
  global B
  return (int)(X*0.08) == A and (int)(X*0.1) == B
 
for x in range(1, B*11):
  if check(x):
    print(x)
    exit(0)
 
print(-1)

### FIXED CODE ###

S = str(input())
print( "No\n" if (ord(S[0]) + ord(S[1]) + ord(S[2]) == ord(S[0])*3) else "Yes\n")
n=input()
s=input()
a=s.count("R")
b=s.count("B")
if a>b:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

a,b,c=map(int,input().split())
if a==b and b==c and c==a:
    print("Yes")
else:
    print("No")
while True:
    if ((n-k) > 10000):
        n = n // 100
    else:
        an = abs(n-k)
        if n <= an:
            break
        else:
            n = an
print(n)


### FIXED CODE ###

import sys
N, K = map(int, input().split())

ans = N % K
ans = min(ans, abs(K-ans))
print(ans)
n, m = map(int,input().split())
tbin_o = []
for i in range(m):
    xxx = list(map(int,input().split()))
    tbin.append(xxx)

tbin_2 = []
for i in range(len(tbin_o)):
    if tbin_o[i][0] == 1 or tbin_o[i][i] == n:
        tbin_2.append(tbin_o[i])

aaa = 0
for j in range(len(tbin_2)):
    for l in range(len(tbin_2)):
        if tbin_2[j][1] == tbin_2[l][0] and j != l:
            aaa = aaa + 1
            break
            
if aaa == 1 :
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

### FIXED CODE ###

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

boolins =[]
for i in range(n):
    boolins.append(0)
    
for i in range(m):
    xxx = list(map(int,input().split()))
    if xxx[0] == 1:
        boolins[xxx[1]] = boolins[xxx[1]] + 1
    elif xxx[1] == n :
        boolins[xxx[0]]=boolins[xxx[0]]+ 1
    else:
        None


if 2 in boolins:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')
def resolve():
    n,k = map(int, input().split())
    listA = list(map(int,input().split()))
    listA.sort()
    c = sum(listA[:k])
    print(c
resolve()

### FIXED CODE ###

def resolve():
    n,k = map(int, input().split())
    listA = list(map(int,input().split()))
    listA.sort()
    c = sum(listA[:k])
    print(c)
    
resolve()
a = int(input())
b = int(input())
c = int(input())

print((a+b)*h/2)

### FIXED CODE ###

a = int(input())
b = int(input())
h = int(input())


print(int((a+b)*h/2))
from sys import stdin
import collections
import math

n,m,r   = [int(x) for x in stdin.readline().rstrip().split()]
r_arr = [int(x) for x in stdin.readline().rstrip().split()]

ways = [[int(c)  for c in stdin.readline().rstrip().split()] for _ in range(m)]

cost = [[float("inf") for j in range(n)] for i in range(n)]
for i in range(n):
    cost[i][i] = 0

for way in ways:
    cost[way[0]-1][way[1]-1] = way[2]
    cost[way[1]-1][way[0]-1] = way[2]


# ワーシャルフロイド
for k in range(n):
    for i in range(n):
        for j in range(n):
            cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])

# rの訪れ方を全パターン試して、最小の距離のものを答えにする。
tours = []
for perm in itertools.permutations(r_arr):
    d = 0
    for i in range(r-1):
        d += cost[perm[i]][perm[i+1]]
    tours.append(d)
print(min(tours))

### FIXED CODE ###

from sys import stdin
import collections
import math
import itertools

n,m,r   = [int(x) for x in stdin.readline().rstrip().split()]
r_arr = [int(x) for x in stdin.readline().rstrip().split()]

ways = [[int(c)  for c in stdin.readline().rstrip().split()] for _ in range(m)]
inf = float('inf')
cost = [[inf] * n for _ in range(n)]
for i in range(n):
    cost[i][i] = 0

for way in ways:
    cost[way[0]-1][way[1]-1] = way[2]
    cost[way[1]-1][way[0]-1] = way[2]


# ワーシャルフロイド
for k in range(n):
    for i in range(n):
        for j in range(n):
            cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])

# rの訪れ方を全パターン試して、最小の距離のものを答えにする。
tours = []
for perm in itertools.permutations(r_arr):
    d = 0
    for i in range(r-1):
        d += cost[perm[i]-1][perm[i+1]-1]
    tours.append(d)
print(min(tours))
import sys
sys.setrecursionlimit(2 << 30)

n, m = [int(i) for i in input().split()]
al = [set() for _ in range(n)]
for _ in range(m):
    x, y = [int(i) for i in input().split()]
    al[x-1].add(y-1)

dp = [-1] * n


def rec(v):
    if dp[v] != -1:
        return dp[v]
    ret = 0
    for nv in al[v]:
        ret = max(ret, rec(nv) + 1)
    dp[v] = ret
    return ret


ans = 0
for v in range(n):
    ans = max(ans, rec(v))

print(ans)


### FIXED CODE ###

import sys
sys.setrecursionlimit(2 << 28)

n, m = [int(i) for i in input().split()]
al = [set() for _ in range(n)]
for _ in range(m):
    x, y = [int(i) for i in input().split()]
    al[x-1].add(y-1)

dp = [-1] * n


def rec(v):
    if dp[v] != -1:
        return dp[v]
    ret = 0
    for nv in al[v]:
        ret = max(ret, rec(nv) + 1)
    dp[v] = ret
    return ret


ans = 0
for v in range(n):
    ans = max(ans, rec(v))

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

t = 0
now = 1
footprint = [1]

while t < K:
  if A[now-1] not in footprint:
    footprint.append(A[now-1])
    now = A[now-1]
    t += 1
    continue
  else:
    s = footprint.index(A[now-1])
    l = t - s + 1
    e = K % l
    now = footprint[i+e]
    break

print(now)

### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
 
t = 0
now = 1
footprint = [1]
past = [0]*N
past[0] = 1

while t < K:
  if past[A[now-1]-1] == 0:
    now = A[now-1]
    footprint.append(now)
    past[now-1]=1
    t += 1
  else:
    s = footprint.index(A[now-1])
    l = t - s + 1
    e = (K-s) % l
    now = footprint[s+e]
    break
    
print(now)
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0

for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      if 500*i + 100*j + 50*k == X:
        ans += 1

print(ans)

### FIXED CODE ###

a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0

for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      if 500*i + 100*j + 50*k == x:
        ans += 1

print(ans)
n,x = map(int,input().split())
ans = n
mi = 10**4
for i in range(n):
  m = int(input())
  x -= m
  mi = min(m,mi)
asn += (x//mi)*mi
print(ans)
  


### FIXED CODE ###

n,x = map(int,input().split())
ans = n
mi = 10**4
for i in range(n):
  m = int(input())
  x -= m
  mi = min(m,mi)
ans += (x//mi)
print(ans)
# -*- coding: utf-8 -*-
N = int(input())
def fact(n):
  if n == 0:
    return 1
  elif n == 1:
    return 1
  else:
    return fact(n-1)*n
print(fact(N) % (10**9 +7))

### FIXED CODE ###

# -*- coding: utf-8 -*-
N = int(input())
A = 1
for i in range(N):
  A = A*(i+1) % (10 ** 9 + 7)
print(A)
s=input()
c=0
for i in range(int(len(s)/2)):
  if s[i] != s[N-1-i]:
    c=c+1
print(c)

### FIXED CODE ###

s=input()
c=0
for i in range(int(len(s)/2)):
  if s[i] != s[len(s)-1-i]:
    c=c+1
print(c)
def main():
    n = int(input())
    s = ["".join(sorted(input())) for i in range(n)]
    
    from collections import Counter
    c = Counter(s)
    res = 0
    for i in c.values:
        if i < 2:
            continue
        else:
            res += i * (i-1) // 2
    print(res)
    
if __name__ == '__main__':
    main()
                

### FIXED CODE ###

def main():
    n = int(input())
    s = ["".join(sorted(input())) for i in range(n)]
    
    from collections import Counter
    c = Counter(s)
    res = 0
    for i in c.values():
        if i < 2:
            continue
        else:
            res += i * (i-1) // 2
    print(res)
    
if __name__ == '__main__':
    main()
n,k=map(int,input().split())
step=list(map(int,input().split()))
dp=[0]*n
for i in range(1,n):
  cost=[dp[j] + abs(step[i]-step[j]) for j range(max(i-k,0),i)].min()
  dp[i]=cost
print(dp[n-1])

### FIXED CODE ###

def solve():
  n,k=[int(i) for i in input().split()]
  step=[int(i) for i in input().split()]
  dp=[0]*n
  for i in range(1,n):
    dp[i]=min([dp[j] + abs(step[i]-step[j]) for j in range(max(i-k,0),i)])
  return dp[n-1]
print(solve())
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()

# 例外処理
if N == 3:
    print(2, 5, 63)
    exit()

# ・全体のgcdが1になるように2と3を含める
# ・要素は全て2か3の倍数を使う
# ・全体の合計は6の倍数にする
# ・これでgcd(総和, 各要素)は常に2か3になる
A = [2, 4, 3, 9]

li1, li2, li3 = [], [], []
for a in range(5, 30001):
    # 9は既に使用済
    if a == 9:
        continue
    # 3の倍数で奇数(mod6で3)
    if a % 3 == 0 and a % 2 == 1:
        li1.append(a)
    # 3の倍数で偶数(mod6で0)
    elif a % 6 == 0:
        li2.append(a)
    # 3の倍数ではなくて偶数(mod6で2,4)
    elif a % 3 != 0 and a % 2 == 0:
        li3.append(a)

# リスト1,3はペアで使うとmod6で0にできる
while len(A) + 2 <= N:
    A.append(li1.pop())
    A.append(li1.pop())
while len(A) + 2 <= N:
    A.append(li3.pop())
    A.append(li3.pop())
# リスト2は元々mod6で0なので1つずつ使える
while len(A) + 1 <= N:
    A.append(li2.pop())
print(*A)


### FIXED CODE ###

# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()

# 例外処理
if N == 3:
    print(2, 5, 63)
    exit()

# ・全体のgcdが1になるように2と3を含める
# ・要素は全て2か3の倍数を使う
# ・全体の合計は6の倍数にする
# ・これでgcd(総和, 各要素)は常に2か3になる
A = [2, 4, 3, 9]

li1, li2, li3 = [], [], []
for a in range(5, 30001):
    # 9は既に使用済
    if a == 9:
        continue
    # 3の倍数で奇数(mod6で3)
    if a % 3 == 0 and a % 2 == 1:
        li1.append(a)
    # 3の倍数で偶数(mod6で0)
    elif a % 6 == 0:
        li2.append(a)
    # 3の倍数ではなくて偶数(mod6で2,4)
    elif a % 3 != 0 and a % 2 == 0:
        li3.append(a)

# リスト1,3はペアで使うとmod6で0にできる
while li1 and len(A) + 2 <= N:
    A.append(li1.pop())
    A.append(li1.pop())
while li3 and len(A) + 2 <= N:
    A.append(li3.pop())
    A.append(li3.pop())
# リスト2は元々mod6で0なので1つずつ使える
while li2 and len(A) + 1 <= N:
    A.append(li2.pop())
print(*A)
A, B = map(int, input().split())
plug = 1
cnt = 0
while plug < B:
  plug += A - 1
  cnt += 1
print(cnt)

### FIXED CODE ###

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

X = 0
j = A[0]
for i in A:
  X += B[i-1]
  if i == j+1:
    X+= C[j-1]
  j = i
print(X)
n,m = map(int,input().split())

dic,new_dic = {},{}
for val in range(n):
    a,b = map(int,input().split())
    dic[a] = b

dic = sorted(dic.items(),key=lambda x:x[0])

for val in dic:
    new_dic[val[0]] = val[1]

ans = 0

print(new_dic)

for k,v in new_dic.items():
    if m - v > 0:
        ans += k*v

    elif m - v <=s 0:
        ans += k*m
        print(ans)
        exit()

    m = m-v

print(ans)


### FIXED CODE ###

N, M = [int(x) for x in input().split()]
AB = [[int(x) for x in input().split()] for _ in range(N)]

#print(AB)
rest = M
ans = 0
for a, b in sorted(AB, key=lambda x: x[0]):
	
    if (b < rest):
        ans += a*b
        rest -= b
    else:
        ans += (a*rest)
        break
print(ans)