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

Alist = sorted(Alist, reverse=True)

cnt = 0
while cnt <= M:
    cnt += 1
    Alist[0] = Alist[0]//2
    if Alist[0] <= Alist[1]:
        Alist = sorted(Alist, reverse=True)

print(sum(Alist))

### FIXED CODE ###

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

q = []
for a in Alist:
    heapq.heappush(q, -a)

for i in range(M):
    m = heapq.heappop(q)
    heapq.heappush(q, -((-m)//2))

print(-sum(q))
d,t,s = input().split()

if(t*s>=d):
    print('Yes')
else:
    print('No')

### FIXED CODE ###

d,t,s = map(int,input().split())

if(t*s>=d):
    print('Yes')
else:
    print('No')
def solution(X, N, P):
    if N <= 0 or X not in P:
        return X

    P.sort()
    diff = [abs(p - X) for p in P]
    X_idx = diff.index(0)
    left = sorted(diff[:X_idx])
    right = sorted(diff[X_idx+1:])

    for i in range(1, len(P)):
        left = X - i
        right = X + i

        nearest_l = None
        nearest_r = None
        if left not in P:
            nearest_l = left
            break
        if right not in P:
            nearest_r = right
            break
    else:
        nearest_r = len(P) + 1
    if nearest_l and nearest_r:
        nearest = min(nearest_l, nearest_r)
    elif nearest_l is not None:
        nearest = nearest_l
    elif nearest_r is not None:
        nearest = nearest_r
    return nearest

X, N = map(int, input().split())
P = list(map(int, input().split()))

print(solution(X, N, P))


### FIXED CODE ###

def solution(X, N, P):
    if N <= 0 or X not in P:
        return X

    P.sort()
    diff = [abs(p - X) for p in P]
    X_idx = diff.index(0)
    left = sorted(diff[:X_idx])
    right = sorted(diff[X_idx+1:])

    for i in range(1, len(P) + 1):
        left = X - i
        right = X + i

        nearest_l = None
        nearest_r = None
        if left not in P:
            nearest_l = left
            break
        if right not in P:
            nearest_r = right
            break
    else:
        nearest_r = len(P) + 1
    if nearest_l and nearest_r:
        nearest = min(nearest_l, nearest_r)
    elif nearest_l is not None:
        nearest = nearest_l
    elif nearest_r is not None:
        nearest = nearest_r
    return nearest

X, N = map(int, input().split())
P = list(map(int, input().split()))

print(solution(X, N, P))
s = input()
z = int(input())
list = [chr(i) for i in range(97,97+26)]
d = []
flag = 0
for j in list:
  indexes = [i for i,x in enumerate(s) if x==j]
  if len(indexes)==0:
    continue
  for k in indexes:
    for l in range(len(s)-k):
      d.append(s[k:l+k+1])
  if len(d)==k:
    break
print(sorted(set(d))[z-1])

### FIXED CODE ###

N, M = map(int, input().split())
p = list(map(lambda x: int(x) - 1, input().split()))
class UnionFind:
  def __init__(self, n):
    self.table = [-1 for _ in range(n)]
    
  def root(self, x):
    if self.table[x] < 0:
      return x
    else:
      self.table[x] = self.root(self.table[x])
      return self.table[x]
  
  def unite(self, x, y):
    s1, s2 = self.root(x), self.root(y)
    if s1 != s2:
      if self.table[s1] != self.table[s2]:
        if self.table[s1] < self.table[s2]:
          self.table[s2] = s1
        else:
          self.table[s1] = s2
      else:
        self.table[s1] += -1
        self.table[s2] = s1
    return
  
  def findSet(self, x, y):
    return self.root(x) == self.root(y)
uf = UnionFind(N)
for i in range(M):
  px, py = map(int, input().split())
  px -= 1
  py -= 1
  uf.unite(px, py)
ans = 0
for i, v in enumerate(p):
  if uf.findSet(i,v):
    ans += 1
print(ans)
import sys
from itertools import accumulate
n, c = [int(i) for i in sys.stdin.readline().split()]
ls = [0 for i in range(10**5+1)]
for i in range(n):
    s, t, c = [int(i) for i in sys.stdin.readline().split()]
    ls[s] += 1
    ls[t+1] -= 1
ls = [i for i in accumulate(ls)]
print(max(ls))

### FIXED CODE ###

import sys
from itertools import accumulate
N, C = [int(i) for i in sys.stdin.readline().split()]
ls = {j : [0 for i in range(2*10**5)] for j in range(1,C+1)}
for i in range(N):
    s, t, c = [int(i) for i in sys.stdin.readline().split()]
    ls[c][s] += 1
    ls[c][t+1] -= 1

res = [0 for i in range(2*10**5)]
for _c in range(1, C+1):
    for i, j in enumerate(accumulate(ls[_c])):
        res[i] += min(1,j)
print(max(res))
h,w,m=[int(x) for x in input().split()]

hnm=[0]*h
wnm=[0]*w
hw=[[0]*w for _ in range(h)]
for _ in range(m):
    hi,wi=[int(x)-1 for x in input().split()]
    hnm[hi]+=1
    wnm[wi]+=1
    hw[hi][wi]+=1

hm_idx=[]
hm_val=-1
for i in range(h):
    if hnm[i]>hm_val:
        hm_idx=[i]
        hm_val=hnm[i]
    elif hnm[i]==hm_val:
        hm_idx.append(i)

mn1=True
wm_val=-1
for i in range(w):
    if wnm[i]>wm_val:
        wm_val=wnm[i]
        mn1=True
        for j in hm_idx:
            if hw[j][i]==0:
                mn1=False
                break
    elif wnm[i]==wm_val:
        mn1=True
        for j in hm_idx:
            if hw[j][i]==0:
                mn1=False
                break
                
print(hm_val+wm_val+(-1 if mn1 else 0))

### FIXED CODE ###

from collections import Counter
from collections import defaultdict
from heapq import heapify
from heapq import heappop
from heapq import heappush
from _collections import defaultdict

h,w,m=[int(x) for x in input().split()]

hcnt=defaultdict(int)
wcnt=defaultdict(int)
bomb=set()
for _ in range(m):
    hi,wi=[int(x)-1 for x in input().split()]
    hcnt[hi]+=1
    wcnt[wi]+=1
    bomb.add((hi,wi))

hmax=max(hcnt.values())
wmax=max(wcnt.values())

hidx=[x for x,y in hcnt.items() if y==hmax]
widx=[x for x,y in wcnt.items() if y==wmax]

ofst=-1
for i in hidx:
    for j in widx:
        if not (i,j) in bomb:
            ofst=0
            break
                
print(hmax+wmax+ofst)
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 12 04:56:52 2020

@author: Kanaru Sato
"""

n,k = list(map(int, input().split()))
p = list(map(int, input().split()))

sum = 0
sumlist = []
for i in range(n):
    sum += a[i]
    sumlist.append(sum)

Max = -100000
for i in range(n-k+1):
    e = sumlist[i+k-1]-sumlist[i]
    if Max < e:
        Max = e

print((Max+k)/2)

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Sun Apr 12 04:56:52 2020

@author: Kanaru Sato
"""

n,k = list(map(int, input().split()))
p = list(map(int, input().split()))

sum = 0
sumlist = [0]
for i in range(n):
    sum += p[i]
    sumlist.append(sum)


Max = -100000
for i in range(n-k+1):
    e = sumlist[i+k]-sumlist[i]
    if Max < e:
        Max = e

print((Max+k)/2)
n=int(input())

def is_prime(n):
    if n < 2:
        return False
    else:
        for i in range(2, n):
            if i * i > n:
                break
            elif n % i == 0:
                return False
        return True

for i in range(i,i+30):
  if is_prime(i):
    print(i)

### FIXED CODE ###

n=int(input())
 
def is_prime(n):
    if n < 2:
      return False
    else:
      for i in range(2, n):
        if i * i > n:
            break
        elif n % i == 0:
            return False
    return True

for i in range(n,n+400):
  if is_prime(i):
    print(i)
    break
N,T = map(int,input().split())
cost = 1001
for i in range(N):
  c,t = map(int,input().split())
  if t<=T:cost=min(m,c)
print("TLE" if cost==1001 else m)


### FIXED CODE ###

n,tl = map(int,input().split())
cost = []
time = []
cost2 = []
for i in range(n):
  c,t = map(int,input().split())
  cost.append(c)
  time.append(t)
for y,z in zip(cost,time):
  if z<=tl:
    cost2.append(y)    
print("TLE" if min(time)>tl else min(cost2))
N=int(input())
A=[int(i) for i in input().split()]
def CountMinusAndZeroAndMin(lis):#マイナスの個数とabs挿話とabs最小の値を返す
    curmin=1000000000000000
    plussum=0
    minus=0
    for i in lis:
        j=abs(i)
        plussum+=j
        curmin=min(j,curmin)
        if i<0:
           minus+=1
        elif i==0:
            zeros+=1
    return(minus,plussum,curmin)
minus,plussum,minabs=CountMinusAndZeroAndMin(A)
if minabs==0 or minus%2==0:
    print(plussum)
else:
    print(plussum-2*minabs)

### FIXED CODE ###

N=int(input())
A=[int(i) for i in input().split()]
def CountMinusAndZeroAndMin(lis):#マイナスの個数とabs挿話とabs最小の値を返す
    curmin=1000000000000000
    plussum=0
    minus=0
    for i in lis:
        j=abs(i)
        plussum+=j
        curmin=min(j,curmin)
        if i<0:
           minus+=1
    return(minus,plussum,curmin)
minus,plussum,minabs=CountMinusAndZeroAndMin(A)
if minabs==0 or minus%2==0:
    print(plussum)
else:
    print(plussum-2*minabs)
import math
N = int(input())
neck = int(input())
for i in range(N-1):
  neck = min(min, int(input()))
res = math.ceil(N/neck)
print(res)

### FIXED CODE ###

import math
N = int(input())
neck = int(input())
for i in range(4):
  neck = min(neck, int(input()))
res = math.ceil(N/neck)
print(res + 4)
from collections import *
mod=10**6+3
fac=[0 for i in range(mod-1)]
fac[0]=1
for i in range(0,len(fac)-1):
    fac[i+1]=(fac[i]*(i+1))%mod
Q=int(input())
for q in range(Q):
    x,d,n=map(int,input().split())
    D=pow(d,mod-2,mod)
    a,b=x*D%mod,(x+(n-1)*d)*D%mod
    if a>=0 and a<b and b-1<mod:
        if a>0:
            value=fac[b]*pow(fac[a-1],mod-2,mod)*pow(d,n,mod)
        elif a==0:
            value=fac[b]*pow(d,n,mod)

        print(value%mod)

    else:
        print(0)


### FIXED CODE ###

from collections import *
mod=10**6+3
fac=[0 for i in range(mod)]
fac[0]=1
for i in range(0,len(fac)-1):
    fac[i+1]=(fac[i]*(i+1))%mod
fac[0]=0
Q=int(input())
for q in range(Q):
    x,d,n=map(int,input().split())
    if d>0:
        D=pow(d,mod-2,mod)
        a=(x-d%mod)*D%mod
        b=(a+n)%mod
        if a<b and a+n<mod:
            if a>0:
                value=fac[b]*pow(fac[a],mod-2,mod)*pow(d,n,mod)
            else:
                value=fac[b]*pow(d,n,mod)
            print(value%mod)
        else:
            print(0)
    else:
        print(pow(x,n,mod))
a, b = map(int, input().split())
ans = 0

for i in range(1,min(a,b)):
    if a%i==0 and b%i==0:
        ans=i

print(a*b//ans)

### FIXED CODE ###

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

n = max(a,b)
m = min(a,b)
ans=0

for i in range(1,m+1):
    ans = n*i
    if (ans)%m==0:
        print(ans)
        exit(0)
a = [int(input()) for i in range(4)]
count = 0
y = a[3]
i = y / 500; if i > a[0] : i = a[0]; y -= i * 500
j = y / 100; if j > a[1] : j = a[1]; y -= j * 100
k = y /  50; if k > a[2] : k = a[2]; y -= k * 50
if (y == 0) :
  count += 1
  while (i > 0 && j + 5 < a[1]) :
    i -= 1
    j += 5
    tmp1 = j
    tmp2 = k
    count += 1
    while (tmp1 > 0 && tmp2 + 2 < a[2]) :
      tmp1 -= 1
      tmp2 += 2
      count += 1
    tmp1 = j
    tmp2 = k

print(count)


### FIXED CODE ###

a = [int(input()) for i in range(4)]
count = 0

for i in range(a[0]+1) :
  for j in range(a[1]+1) :
    for k in range(a[2]+1) :
      sum = 500*i + 100*j + 50*k
      if sum == a[3] :
        count += 1
print(count)
N,M=map(int,input().split())
A=[int(i) for i in input().split()]
Match=[0,2,5,5,4,5,6,3,7,6]
A.sort(reverse=True)
dp=[0]*(N+1)
dp[0]=1
for i in range(1,N+1):
  for a in A:
    if i>=Match[a]:
      dp[i]|=dp[i-Match[a]]<<1

for k in range(N)[::-1]:
  if dp[N]&(1<<k):
    S=k
    break
ans=[]
m=0
for k in range(S):
  if dp[N-Match[A[m]]]&(1<<(S-k-1)):
    ans.append(str(A[m]))
    N-=Match[A[m]]
  else:
    for l in range(m+1,len(A)):
      if dp[N-Match[A[l]]]&(1<<(S-k-1)):
        m=l
        ans.append(str(A[m]))
        N-=Match[A[m]]
        break
print("".join(ans))


### FIXED CODE ###

N,M=map(int,input().split())
A=[int(i) for i in input().split()]
Match=[0,2,5,5,4,5,6,3,7,6]
A.sort(reverse=True)
dp=[0]*(N+1)
dp[0]=1
for i in range(1,N+1):
  for a in A:
    if i>=Match[a]:
      dp[i]|=dp[i-Match[a]]<<1

for k in range(N)[::-1]:
  if dp[N]&(1<<k):
    S=k
    break
ans=[]
m=0
for k in range(S):
  if N-Match[A[m]]>=0:
    if dp[N-Match[A[m]]]&(1<<(S-k-1)):
      ans.append(str(A[m]))
      N-=Match[A[m]]
    else:
      for l in range(m+1,len(A)):
        if N-Match[A[l]]>=0:
          if dp[N-Match[A[l]]]&(1<<(S-k-1)):
            m=l
            ans.append(str(A[m]))
            N-=Match[A[m]]
            break
  else:
    for l in range(m+1,len(A)):
      if N-Match[A[l]]>=0:
        if dp[N-Match[A[l]]]&(1<<(S-k-1)):
          m=l
          ans.append(str(A[m]))
          N-=Match[A[m]]
          break
print("".join(ans))
H,W=map(int,input().split())
C=list(map(int,input().split()))
C[0]+=1
C[1]+=1
D=list(map(int,input().split()))
D[0]+=1
D[1]+=1
S=["#"*(W+4)]
S.append("#"*(W+4))
for _ in range(H):
    tmp=input()
    tmp="##"+tmp+"##"
    S.append(tmp)
S.append("#"*(W+4))
S.append("#"*(W+4))

def walk(k,alk,x,y):
    global found
    if x==D[0] and y==D[1]:
        S[x]=S[x][:y]+"{}".format(k)+S[x][y+1:]
        found=True
        return 0
    if S[x][y]==".":
        alk.append([x,y])
        S[x]=S[x][:y]+"{}".format(k)+S[x][y+1:]
        walk(k,alk,x-1,y)
        walk(k,alk,x,y-1)
        walk(k,alk,x+1,y)
        walk(k,alk,x,y+1)

def warp(k,arp,x,y):
    for i in range(-2,3):
        for j in range(-2,3):
            if S[x+i][y+j]==".":
                arp.append([x+i,y+j])
                S[x+i]=S[x+i][:y+j]+"{}".format(k)+S[x+i][y+j+1:]

k=0
alk=[]
arp=[[C[0],C[1]]]
found=False
while not found:
    alk=arp
    for i in range(len(arp)):
        x,y=arp[i][0],arp[i][1]
        walk(k,alk,x,y)
        if found:
            print(k)
            break
    if found:
        break
    k+=1
    arp=[]
    for i in range(len(alk)):
        x,y=alk[i][0],alk[i][1]
        warp(k,arp,x,y)
    if len(arp)==0:
        print(-1)
        break


### FIXED CODE ###

from collections import deque

H,W=map(int,input().split())
sy,sx=map(int,input().split())
gy,gx=map(int,input().split())
field=[list(input()) for _ in range(H)]
sy,sx,gy,gx=sy-1,sx-1,gy-1,gx-1

Walk=[[1,0],[0,1],[-1,0],[0,-1]]
Warp=[[i,j] for i in range(-2,3) for j in range(-2,3)] 

dist=[[-1]*W for _ in range(H)]
que=deque()
dist[sy][sx]=0
que.append([sy,sx])

while que:
    y,x=que.popleft()
    for walk in Walk:
        nx,ny=x+walk[0],y+walk[1]
        if nx<0 or nx>=W or ny<0 or ny>=H: continue
        if field[ny][nx]=="#": continue
        if dist[ny][nx]!=dist[y][x]:
            dist[ny][nx]=dist[y][x]
            que.appendleft([ny,nx])
    
    for warp in Warp:
        nx,ny=x+warp[0],y+warp[1]
        if nx<0 or nx>=W or ny<0 or ny>=H: continue
        if field[ny][nx]=="#": continue
        if dist[ny][nx]==-1:
            dist[ny][nx]=dist[y][x]+1
            que.append([ny,nx])

print(dist[gy][gx])
from math import ceil
h,w,a,b = map(int, input().split())
se = w//a
if b>ceil(h/se):
    print('No')
else:
    for i in range(h):
        s='0'*(i%se)*a
        s+='1'*a
        s+='0'*(w-a-(i%se)*a)
        print(s)


### FIXED CODE ###

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

s='0'*a
s+='1'*(w-a)
for i in range(b):
    print(s)
s='1'*a
s+='0'*(w-a)
for i in range(h-b):
    print(s)
import numpy as np
import itertools

H, W, K = map(int, input().split())
choco = []
for i in range(H):
    choco.append([int(x) for x in list(input())])

arr = np.array(choco)

# W方向にGREEDY
count = (H-1) + (W-1)

for k in range(H):
    
    # この時点で同じ回数以上切ることが確定なら終了
    if count <= k:
        break

    # H 方向に切り込み
    for comb in itertools.combinations(range(1,H),k):

        # スライスを作っておく
        t = (None,) + comb + (None,)
        s = [slice(t[j],t[j+1],) for j in range(len(t)-1)]
        
        # print(t)
        
        sum_p = [0] * (k+1)
        
        cut = k
        
        for col in zip(*choco):
                        
            # 全 H で成立するか？
            sum_a = [sum(col[b]) for b in s]
            # print(sum_a)
            
            if any(map(K.__lt__, sum_a)):
                # 不成立
                break
            
            sum_b = [x+y for x,y in zip(sum_p, sum_a)]

            if any(map(K.__lt__, sum_b)):
                cut += 1
                sum_p = [0] * (k+1)
            else:
                sum_p = sum_b
                
                # 割った位置を記録
        
        else:
            count = min(count,cut)

print(count)

### FIXED CODE ###

import math

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

# 両方ともNから選ぶ
a = 0
if N > 1:
    a = int(math.factorial(N) / (math.factorial(N-2)*2))

# 両方ともMから選ぶ
b = 0
if M > 1:
    b = int(math.factorial(M) / (math.factorial(M-2)*2))

print(a + b)
import math
a,b,c,d=map(int,input().split())
yoso=b-a+1
kobai=math.gcd(c,d)
BC=b%c
BD=b%d
Bkobai=b%kobai
C=0
if BC>=(yoso%c):
  C=yoso//c
else:
  C=(yoso//c)+1
D=0
if BD>=(yoso%d):
  D=yoso//d
else:
  D=(yoso//d)+1
CD=0
if Bkobai>=(yoso%kobai):
  CD=yoso//kobai
else:
  CD=(yoso//kobai)+1
print(yoso+CD-C-D)
  


### FIXED CODE ###

import fractions
a,b,c,d=map(int,input().split())
CD=fractions.gcd(c,d)
cd=(c*d)//CD
width=b-a
cnt=0
if width%c==0:
  if a%c==0:
    cnt+=(width//c)+1
  else:
    cnt+=(width//c)
else:
  if c-(a%c)+b%c>=c:
    if a%c==0 or b%c==0:
      cnt+=(width//c)+1
    else:
      cnt+=(width//c)
  else:
    cnt+=(width//c)+1

if width%d==0:
  if a%d==0:
    cnt+=(width//d)+1
  else:
    cnt+=(width//d)
else:
  if d-(a%d)+b%d>=d:
    if a%d==0 or b%d==0:
      cnt+=(width//d)+1
    else:
      cnt+=(width//d)
  else:
    cnt+=(width//d)+1

if width%cd==0:
  if a%cd==0:
    cnt-=(width//cd)+1
  else:
    cnt-=(width//cd)
else:
  if cd-(a%cd)+b%cd>=cd:
    if a%cd==0 or b%cd==0:
      cnt-=(width//cd)+1
    else:
      cnt-=(width//cd)
  else:
    cnt-=(width//cd)+1

print(b-a+1-cnt)
import numpy as np
def f(n):
    m = np.matrix('1 1 ; 1 0') ** n
    return m.item(0)
print(f(int(input())),end="")

### FIXED CODE ###

def g(a,b,n):
    if n==1:return a
    else:return g(a+b,a,n-1)
print(g(1,1,int(input())))
import reduce from functools
import mul from operator

def solve():
	L = [int(i) for i in input().split()]
	return reduce(mul, L) // (2 * max(L))

print(solve())


### FIXED CODE ###

from functools import reduce
from operator import mul

def solve():
	L = [int(i) for i in input().split()]
	return reduce(mul, L) // (2 * max(L))

print(solve())
from scipy.special import comb
N,M = map(int,input().split())

print(comb(N, 2,exact=True)+(comb(M, 2,exact=True)))

### FIXED CODE ###

from itertools import combinations

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

a=["A" for i in range(0,N)]
b=["B" for i in range(0,M)]

tmp1=(len(list(combinations(a,2))))
tmp2=(len(list(combinations(b,2))))

print(tmp1+tmp2)
N,M = list(map(int,input().split()))

ref = [i+1 for i in range(M)]
LIKE = [i+1 for i in range(M)]

for i in range(N):
    myLIKE = list(map(int,input().split()[1:]))
    for j in ref:
        if j not in myLIKE:
            LIKE.remove(j)
print(len(LIKE))

### FIXED CODE ###

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

ref = [i+1 for i in range(M)]
LIKE = [i+1 for i in range(M)]

for i in range(N):
    myLIKE = list(map(int,input().split()[1:]))
    for j in ref:
        try:
            if j not in myLIKE:
                LIKE.remove(j)
        except ValueError:
            pass
            
print(len(LIKE))
n=int(input())
*A=sorted(map(int,input().split()))

a=True
if n%2==0:
  for i in range(1,n,2):
    if A[i-1]!=i or A[i]!=i:
      a=False
      break
else:
  if A[0]!=0:a=False
  else:
    for i in range(2,n,2):
      if A[i-1]!=i or A[i]!=i:
        a=False
        break
print(2**(n//2)%(10**9+7) if a else 0)


### FIXED CODE ###

N=int(input())
*A,=sorted(map(int,input().split()))
 
a=True
if N%2==0:
 for i in range(1,N,2):
  if A[i-1]!=i or A[i]!=i:
    a=False
    break
else:
 if A[0]!=0:a=False
 else:
    for i in range(2,N,2):
     if A[i-1]!=i or A[i]!=i:
        a=False
        break
print(2**(N//2)%(10**9+7) if a else 0)
S=input()
if S[0]=S[1] or S[1]=S[2] or S[2]=S[3]:
  print("Bad")
else:
  print("Good")

### FIXED CODE ###

S=input()
count=1
for i in range(3):
    if S[i] == S[i+1]:
        print('Bad')
        break
else:
    print('Good')
n = int(input())
print((n/3)**3)

### FIXED CODE ###

s = input()
n = len(s)
ss = s[:(n - 1) // 2]
sss = s[(n + 3) // 2 - 1:]
flag = True;
for i in range(len(s)//2):
    if s[i] != s[n - 1 - i]:
        flag = False
if not flag:
    print("No")
    exit()

for i in range(len(ss)//2):
    if ss[i] != ss[len(ss) - 1 - i]:
        flag = False
if not flag:
    print("No")
    exit()

for i in range(len(sss)//2):
    if sss[i] != sss[len(sss) - 1 - i]:
        flag = False
if not flag:
    print("No")
    exit()
print("Yes")
x,n = map(int,input().split())
if n:
    p = set(map(int,input().split()))
mini = float('inf')
ans = float('inf')
for i in range(0,110):
    if i not in p:
        if abs(x-i)<mini:
            mini = abs(x-i)
            ans = i
        elif abs(x-i)==mini and ans>i:
            ans=i
print(ans)

### FIXED CODE ###

x,n = map(int,input().split())
p = set()
if n:
    p = set(map(int,input().split()))
mini = float('inf')
ans = float('inf')
for i in range(-400,400):
    if i not in p:
        if abs(x-i)<mini:
            mini = abs(x-i)
            ans = i
        elif abs(x-i)==mini and ans>i:
            ans=i
print(ans)
n = input()
lst = []
for i in range(3,n+1):
	if i%3==0:
		lst.append(i)
	elif i%10==3:
		lst.append(i)
print " "+lst

### FIXED CODE ###

n=input()
print"",
for i in range(1,n+1):
	if i%3==0 or str(i).count('3'):
		print i,
N = int(input())
S = input()
count = 0
ans = 1
m = 10**9 + 7
 
for i in range(N):
  if S[2*i] == "W":
    ans = (ans * ((2*i) - (count*2)))%m
    count += 1
  if S[2*i + 1] == "B":
    ans = (ans * ((2*i + 1) - (count*2)))%m
    count += 1
 
if count != N:
  print(0)
else:
  for o in range(1, N+1):
    ans *= o
    ans %= m
  print(ans % m)

### FIXED CODE ###

M, D = map(int, input().split())
m_list = {m for m in range(1, M + 1)}
ans = 0
 
for d in range(11, D+1):
  d_10 = int(d/10)
  d_1 = d - (d_10 * 10)
  if (d_10 < 2) or (d_1 < 2):
    continue
  else:
    if (d_10 * d_1) in m_list:
      ans += 1
      
print(ans)
from sys import stdin

h,w,a,b = [int(x) for x in stdin.readline().rstrip().split()]

li = [[0 for _ in range(w)]for _ in range(h)]

if a > w//2 or b > h//2:
    print("No")
    exit()
elif h%a != 0 or w%b != 0:
    if a != 0 and b != 0:
        print("No")
        exit()
    else:
        if a == 0:
            a = 1
        elif b == 0:
            b = 1
        p = 0
        for i in range(h):
            for s in range(a):
                li[i][p*a+s] = 1
                p += 1
        for p in range(h):
            print(''.join(map(str, li[p])))
else:
    p = 0
    for i in range(h):
        for s in range(a):
            li[i][p*a+s] = 1
            p += 1
    li2 = [li[q][0] for q in range(h)]
    if li2.count(0) == b or li2.count(1) == b:
        for p in range(h):
            print(''.join(map(str, li[p])))
    else:
        print("No")

### FIXED CODE ###

from sys import stdin
h,w,b,a = map(int,stdin.readline().rstrip().split())
li = []
for i in range(a):
    s = "0"*b+"1"*(w-b)
    li.append(s)
for j in range(h-a):
    s = "1"*b+"0"*(w-b)
    li.append(s)
for i in li:
    print(i)
def p_e():
    s = input()
    t = input()
    l = defaultdict(list)

    for i, c in enumerate(list(s)):
        l[c].append(i + 1)

    for c in list(t):
        if c not in l.keys():
            print(-1)
            exit()

    N = 0
    current = 0
    for c in list(t):
        if current >= l[c][-1]:
            current = l[c][0]
            N += 1
            continue

        for i in l[c]:
            if current < i:
                current = i
                break

    print(N * len(s) + current)


if __name__ == '__main__':
    p_e()


### FIXED CODE ###

from collections import defaultdict
from bisect import *


def p_e():
    s = input()
    t = input()
    l = defaultdict(list)

    for i, c in enumerate(list(s)):
        l[c].append(i + 1)

    for c in list(t):
        if c not in l.keys():
            print(-1)
            exit()

    N = 0
    current = -1
    for c in list(t):
        R = l[c]

        x = bisect(R, current)

        if len(R) == x:
            N += 1
            current = R[0]
        else:
            current = R[x]

    print(N * len(s) + current)


if __name__ == '__main__':
    p_e()