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

k, s = map(int, input().split())

xyz = [0, 0, 0]
index = 0
while min(k, s) != 0:
    xyz[index] = min(k, s)
    s = s - min(k, s)
    index = index + 1

count = 0

def cal(lis, n, m):
    lis[n] = lis[n] - 1
    lis[m] = lis[m] + 1

while xyz[0] >= 0:
    xyzCopy = list(xyz)

    while xyzCopy[1] >= 0 and xyzCopy[2] <= k:
        count = count + 1
        cal(xyzCopy, 1, 2)

    if xyz[1] == k:
        cal(xyz, 0, 2)
    else:
        cal(xyz, 0, 1)

print(count)

### FIXED CODE ###

k, s = map(int, input().split())

count = 0

for i in range(k+1):
    for j in range(k+1):
        if 0 <= s-i-j <= k:
            count = count + 1

print(count)
### BUGGY CODE ###

def main():
    from collections import defaultdict,deque
    from itertools import count
    (n,),*a=[list(map(int,t.split()))for t in open(0)]
    d=defaultdict(count().__next__)
    es=[]
    for i,b in enumerate(a,1):
        for j,k in zip(b,b[1:]):
            x,y=i,j
            if y<x:x,y=y,x
            v,w=i,k
            if w<v:v,w=w,v
            es+=(d[x*n+y],d[v*n+w]),
    s=max(d.values())+1
    e=[[]for _ in range(s)]
    for i,j in es:e[i]+=j,
    outs=[[]for _ in range(s)]
    ins=[0]*s
    f=set(range(s))
    for i,j in es:
        outs[i]+=j,
        f-={j}
        ins[j]+=1
    q=deque(f)
    r=[]
    while q:
        i=q.popleft()
        r+=i,
        for j in outs[i]:
            ins[j]-=1
            if ins[j]<1:q+=j,
    if len(r)<s:
        print(-1)
        return
    data=[1]*s
    for i in r:
        t=data[i]+1
        for j in e[i]:
            if t>data[j]:data[j]=t
    print(max(data))
main()

### FIXED CODE ###

def main():
    from collections import defaultdict,deque
    from itertools import count
    (n,),*a=[list(map(int,t.split()))for t in open(0)]
    d=defaultdict(count().__next__)
    es=[]
    for i,b in enumerate(a,1):
        for j,k in zip(b,b[1:]):
            x,y=i,j
            if y<x:x,y=y,x
            v,w=i,k
            if w<v:v,w=w,v
            es+=(d[x*n+y],d[v*n+w]),
    s=len(d)
    outs=[[]for _ in range(s)]
    ins=[0]*s
    f=set(range(s))
    for i,j in es:
        outs[i]+=j,
        f-={j}
        ins[j]+=1
    q=deque(f)
    r=[]
    data=[0]*s
    m=0
    while q:
        i=q.popleft()
        r+=i,
        t=data[i]+1
        if t>m:m=t
        for j in outs[i]:
            ins[j]-=1
            if ins[j]<1:q+=j,
            if t>data[j]:data[j]=t
    print(-(len(r)<s)or m)
main()
### BUGGY CODE ###

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

class Node:
  def __init__(self, data):
    self.left = None
    self.right = None
    self.data = data

  def insert(self, data):
    if self.data:
      if data < self.data:
        if self.left is None:
          self.left = Node(data)
        else:
          self.left.insert(data)
      elif data > self.data:
        if self.right is None:
          self.right = Node(data)
        else:
          self.right.insert(data)
    else:
      self.data = data

  def PrintTree(self):
    if self.left:
      return self.left.PrintTree() + 1
    else:
      return 1

root = Node(P[0])
for i in range(1, len(P)):
  root.insert(P[i])

print(root.PrintTree())

### FIXED CODE ###

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

cnt = 1
min_p = P[0]
for i in range(1, len(P)):
  if P[i] < min_p:
    cnt += 1
    min_p = P[i]

print(cnt)
### BUGGY CODE ###

N = int(input())
AB = [[], []]
ab = [0, 0]

for i in range(N):
    inp = list(map(int, input().split()))
    AB[0].append(inp[0])
    AB[1].append(inp[1])

for i in range(N):
    m = max(AB[i%2])
    indexs = [j for j, x in enumerate(AB[i%2]) if x == max(AB[i%2])]
    B = []
    for j in range(len(indexs)):
        B.append(AB[(i+1)%2][indexs[j]])
    index = AB[(i+1)%2].index(max(AB[(i+1)%2]))
    ab[i%2] += m
    del AB[0][index]
    del AB[1][index]

print(ab[0] - ab[1])

### FIXED CODE ###

N = int(input())
ABab = []
for i in range(N):
    a, b = list(map(int, input().split()))
    ABab.append([a+b, a, -1*b])
ABab.sort(reverse = True)
ans = 0
for i in range(N):
    ans += ABab[i][i%2 + 1]
print(ans)
### BUGGY CODE ###

import itertools
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
lst = [i[0]*i[1] for i in itertools.combinations(A,2)]
lst.sort()
print(lst[K - 1])

### FIXED CODE ###

import numpy as np

N, K = map(int, input().split())
A = np.array([int(i) for i in input().split()])
A.sort()

A_max = max(np.abs(A))
A_minus = A[A<0]
A_zero = A[A==0]
A_plus = A[A>0]

def check(x):
    ret = 0
    if x >= 0:
        ret += N * len(A_zero)
    ret += np.searchsorted(A, x // A_plus, side='right').sum()
    ret += (N - np.searchsorted(A, -(x // -A_minus))).sum()
    ret -= np.count_nonzero(A * A <= x)
    return ret // 2

right = A_max * A_max
left = -right - 1
while (right - left > 1):
    middle = (right + left) >> 1
    if check(middle) < K:
        left = middle
    else:
        right = middle
print(right)
### BUGGY CODE ###

#!/usr/bin/env python


import sys
import re

s= sys.stdin.readline().strip()
pat= re.compile("ABC")

t= 0
while True:
    n= len( pat.findall(s) )
    if n==0: break
    t+= n
    s= s.replace( "ABC","BCA")
#
print( t )


### FIXED CODE ###

#!/usr/bin/env python

import sys
import re

s= sys.stdin.readline().strip()
s= s.replace("BC","D")
s= re.sub("[BC]+"," ",s).split()

t= 0
for seg in s:
    a= 0
    for c in seg:
        if c=="A": a+=1
        elif c=="D": t+= a
#
print( t )
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
import numpy as np
MAX = max(A)
BIG = 10**9+7
L = len(bin(MAX)[2:])
ans = 0
for j in range(L):
    zero = 0
    one = 0
    for i in range(N):
        if (A[i] >> j) & 1:
            one+=1
        else:
            zero+=1
    ans += ((zero*one)%BIG)*2**j 
    ans = ans%BIG
print(ans)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
MAX = max(A)
BIG = 10**9+7
L = len(bin(MAX)[2:])
ans = 0
for j in range(L):
    zero = 0
    one = 0
    for i in range(N):
        if (A[i] >> j) & 1:
            one+=1
        else:
            zero+=1
    ans += ((zero*one)%BIG)*pow(2,j,BIG)
    ans = ans%BIG
print(ans)
### BUGGY CODE ###

import itertools

k = int(input())
l = list(range(1,k+1))
y = list(itertools.combinations_with_replacement(l,3))
n = len(y)
p = 0

for i in range(n):
    a = y[i][0]
    b = y[i][1]
    while b != 0:
        c = a % b
        a = b
        b = c
    b = y[i][2]
    while b != 0:
        c = a % b
        a = b
        b = c
    if y[i][0] == y[i][1] == y[i][2]:
        p += a
    elif y[i][0] != y[i][1] != y[i][2]:
        p += a * 6
    else:
        p += a * 3

print(p)

### FIXED CODE ###

import math
import itertools

k = int(input())
l = list(range(1,k+1))
y = list(itertools.combinations_with_replacement(l,3))
n = len(y)
t = 0

for i in range(n):
    a = y[i][0]
    b = y[i][1]
    c = y[i][2]
    d = math.gcd(math.gcd(a,b),c)
    if a != b != c:
        t += d * 6
    elif a == b == c:
        t += d
    else:
        t += d * 3

print(t)
### BUGGY CODE ###

import math
N = int(input())

for i in range(1, N+1):
    ans = 0
    n = int(math.sqrt(i))+1
    for x in range(1, n+1):
        for y in range(1, x+1):
            for z in range(1, y+1):
                if x**2 + y**2 + z**2 + x*y + y*z + z*x == i:
                    if x == y == z:
                        ans += 1
                    elif x == y or y == z:
                        ans += 3
                    else:
                        ans += 6
    print(ans)

### FIXED CODE ###

import math
N = int(input())

ans = [0] * N
n = int(math.sqrt(N)) 

for x in range(1, n+1):
    for y in range(1, x+1):
        for z in range(1, y+1):
            i = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if i <= N:
                if x == y == z:
                    ans[i-1] += 1
                elif x == y or y == z:
                    ans[i-1] += 3
                else:
                    ans[i-1] += 6

for j in range(N):
    print(ans[j])
### BUGGY CODE ###

from heapq import heappop, heappush, heappushpop

n = int(input())
q = [tuple(int(x) for x in input().split()) for _ in range(n)]

L = []
R = []
a = 1
b = q[0][2]

heappush(L, -q[0][1])

for i in range(1, n):
    #print([L, R])
    temp = q[i]
    if temp[0] == 1:
        a += 1
        if a % 2 == 0:
            p = heappushpop(L, - temp[1])
            heappush(R, - p)
        else:
            p = heappushpop(R, temp[1])
            heappush(L, - p)
        b += temp[2]
    else:
        m = heappop(L)
        heappush(L, m)
        m *= -1
        ans = b
        for x in L:
            ans += abs(m + x)
        for x in R:
            ans += abs(m - x)
        print(m, ans)

### FIXED CODE ###

from heapq import heappop, heappush, heappushpop

n = int(input())
q = [tuple(int(x) for x in input().split()) for _ in range(n)]

L = []
R = []
a = 1
b = q[0][2]

ans = 0

heappush(L, -q[0][1])

for i in range(1, n):
    temp = q[i]
    if temp[0] == 1:
        a += 1
        if a % 2 == 0:
            ans += abs(temp[1] + L[0])
            p = heappushpop(L, - temp[1])
            heappush(R, - p)
        else:
            ans += abs(temp[1] + L[0])
            tl = L[0]
            p = heappushpop(R, temp[1])
            heappush(L, - p)
            if tl != L[0]:
                ans -= abs(tl - L[0])
        b += temp[2]
    else:
        m = - L[0]
        print(m, ans + b)
### BUGGY CODE ###

from fractions import gcd
from math import sqrt

A, B = map(int, input().split())
C = gcd(A, B)
ans = 1
i = 2
while C > 1:
    if C % i == 0:
        ans += 1
        C //= i
        while C % i == 0:
            C //= i
    i += 1
print(ans)

### FIXED CODE ###

from fractions import gcd

A, B = map(int, input().split())
C = gcd(A, B)
ans = 1
i = 2
for i in range(2, int(-(-C**0.5//1))+1):
    if C % i == 0:
        ans += 1
        while C % i == 0:
            C //= i
    i += 1
if C != 1:
    ans += 1
print(ans)
### BUGGY CODE ###

R,G,B,N =map(int,input().split())

cnt =0
    
for r in range(int(N/R)+1):
    
    for g in range(int(N/G)+1):
        
        if r*R+g*G > N:
            continue
            
        temp = N - r*R-g*G
            
        if temp%B ==0:
            cnt+=1
    
print(cnt)
            


### FIXED CODE ###

R,G,B,N =map(int,input().split())

cnt =0
    
for r in range(int(N/R)+1):
  ball = N-r*R 
  for g in range(int(ball/G)+1):
    res = N- (r*R+g*G)
    if  res >=0 and res%B ==0:
      cnt+=1
    
print(cnt)
### BUGGY CODE ###

N = int(input())

RMax = 0
R = []


for i in range(N):
	r = int(input())
	if i == 1:
		RMax = r - R[0]
	if i > 0:
		rmi = min(R)
		rdif = (r - rmi)
		if rdif >= RMax:
			RMax = rdif
	R.append(r)

print(RMax)

### FIXED CODE ###

N = int(input())

RMax = 0
R = []


for i in range(N):
	r = int(input())
	if i == 0:
		rmi = r
	if i == 1:
		RMax = r - R[0]
	if i > 0:		
		rdif = (r - rmi)
		if rdif >= RMax:
			RMax = rdif
	R.append(r)
	if r < rmi:
		rmi = r

print(RMax)
### BUGGY CODE ###

while 1:
    n=int(input())
    if n==0:break
    nlist=[]
    nans=[]
    for i in range(n):
        nlist.append(int(input()))
        for j in range(i+1):
            nn=0
            for k in range(j,i+1):
                nn+=nlist[k]
            nans.append(nn)
    print(max(nans))


### FIXED CODE ###

while 1:
    n=int(input())
    if n==0:break
    nlist=[]
    nans=-100001
    for i in range(n):
        nlist.append(int(input()))
    nkeep=0
    for i in nlist:
        if nkeep<0:
            nkeep=i
        else:
            nkeep+=i
        if nans<nkeep:nans=nkeep
    if max(nlist)<0:nans=max(nlist)
    print(nans)
### BUGGY CODE ###

N = int(input())
s = [[]]*N
for i in range(N):
  k = input()
  s[i] = [c for c in k]
  s[i].sort()

cnt = 0
for i in range(N-1):
  for j in range(i+1,N):
    if s[i] == s[j]:
      cnt += 1
print(cnt)
#print(list(set(s)))

### FIXED CODE ###

N = int(input())
s = [input() for _ in range(N)]
for i in range(N):
  s[i] = "".join(sorted(s[i]))
t = {}
for i in range(N):
  if s[i] in t:
    t[s[i]] += 1
  else:
    t[s[i]] = 1
print(sum(t[k]*(t[k]-1)//2 for k in t))
### BUGGY CODE ###

n,w,h = map(int,input().split())
Yoko = [0] * w
Tate = [0] * h
for i in range(n):
    x,y,r = map(int,input().split())
    for j in range(x - r,x + r):
        if 0 <= j < w:
            Yoko[j] += 1
    for j in range(y- r,y + r):
        if 0 <= j < h:
            Tate[j] += 1
if Yoko.count(0) == 0 or Tate.count(0) == 0:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

import sys
n,w,h = map(int,input().split())
Yoko = []
Tate = []
for i in range(n):
    x,y,r = map(int,input().split())
    Yoko.append([x - r,x + r])
    Tate.append([y - r,y + r])
Yoko = sorted(Yoko)
Tate = sorted(Tate)

if Yoko[0][0] > 0 and Tate[0][0] > 0:
    print("No")
    sys.exit()

Yoko_han = [Yoko[0][0],Yoko[0][1]]
Tate_han = [Tate[0][0],Tate[0][1]]
if Yoko[0][0] <= 0:
    if Yoko_han[1] >= w:
        print("Yes")
        sys.exit()
    else:
        for j in range(1,len(Tate)):
            if Yoko[j][0] <= Yoko_han[1] and Yoko_han[1] < Yoko[j][1]:
                Yoko_han[1] = Yoko[j][1]
                if Yoko_han[1] >= w:
                    print("Yes")
                    sys.exit()
                
            elif Yoko_han[1] < Yoko[j][0]:
                break
if Tate[0][0] > 0:
    print("No")
    sys.exit()
else:
    if Tate_han[1] >= h:
            print("Yes")
            sys.exit()
    else:
        for k in range(1,len(Yoko)):
            if Tate[k][0] <= Tate_han[1] and Tate_han[1] < Tate[k][1]:
                Tate_han[1] = Tate[k][1]
                if Tate_han[1] >= h:
                    print("Yes")
                    sys.exit()
                
            elif Yoko_han[1] < Yoko[k][0]:
                print("No")
                sys.exit()
print("No")
### BUGGY CODE ###

R,G,B,N=list(map(int,input().split()))
cnt=0
for r in range((N//R)+1):
    for g in range(((N-R*r)//G)+1):
        if (N-R*r-G*g)<0: continue
        if (N-R*r-G*g)%B==0:
            cnt=cnt+1
print (cnt)


### FIXED CODE ###

R,G,B,N=list(map(int,input().split()))
cnt=0
for r in range((N//R)+1):
    for g in range(((N-R*r)//G)+1):
        if (N-R*r-G*g)%B==0:
            cnt=cnt+1
print (cnt)
### BUGGY CODE ###

K = int(input()) - 1
todo = list(range(1, 10))
ans = []
counter = 0
while counter <= K:
    seed = todo.pop(0)
    ans.append(seed)
    counter += 1
    last_dig = int(str(seed)[-1])
    for i in range(max(0, last_dig-1), min(10, last_dig+2)):
        todo.append(int(str(seed) + str(i)))
print(ans[-1])

### FIXED CODE ###

from collections import deque
counter = 0
todo = deque(range(1, 10))
ans = []
while counter < 10**5 + 500:
    seed = str(todo.popleft())
    ans.append(int(seed))
    counter += 1
    seed_last = seed[-1]
    for i in range(max(0, int(seed_last)-1), min(10, int(seed_last)+2)):
        todo.append(seed + str(i))

K = int(input())
print(ans[K-1])
### BUGGY CODE ###

N, M = map(int, input().split())
d=[[] for i in range(N)]
for i in range(M):
    b, c = map(int, input().split())
    d[b-1].append(c-1)
    d[c-1].append(b-1)
a=0
while True:
    count = 0
    for i in range(N):
        if len(d[i]) == 1:
            d[d[i][0]].remove(i)
            d[i]=[]
            count += 1
        if count == 0:
            break
        a+=count
print(a)

### FIXED CODE ###

n,m=map(int,input().split())
l=[[] for _ in range(n)]
for _ in range(m):
    a,b=map(int,input().split())
    l[a-1].append(b-1)
    l[b-1].append(a-1)
a=0
while 1:
    x=0
    for i in range(n):
        if len(l[i])==1:
            l[l[i][0]].remove(i)
            l[i]=[]
            x+=1
    if x==0:break
    a+=x
print(a)
### BUGGY CODE ###

N, W = map(int, raw_input().split())

v = [0] * N
w = [0] * N

for i in range(N):
    v[i], w[i] = map(int, raw_input().split())


def rec(i, j):
    if i == N:
        res = 0
    elif j < w[i]:
        res = rec(i + 1, j)
    else:
        res = max(rec(i + 1, j), rec(i + 1, j - w[i]) + v[i])
    return res

print(rec(0, W))

### FIXED CODE ###

N, W = map(int, raw_input().split())

v = [0] * N
w = [0] * N
dp = [[0 for i in range(W + 1)] for j in range(N + 1)]

for i in range(N):
    v[i], w[i] = map(int, raw_input().split())

for i in range(N - 1, -1, -1):
    for j in range(W + 1):
        if j < w[i]:
            dp[i][j] = dp[i + 1][j]
        else:
            dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i])

print(dp[0][W])
### BUGGY CODE ###

a,b,c = map(int, input().split())
arr = [[0 for _ in range(b)] for _ in range(a)]
for _ in range(c):
    x,y = map(int, input().split())
    arr[x-1][y-1] = '#'

ans = 0
for i in range(a):
    for j in range(b):
        if arr[i][j] == '#':
            ans = max(ans, (arr[i].count('#')+list(zip(*arr))[j].count('#'))-1)
        else:
            ans = max(ans, arr[i].count('#')+list(zip(*arr))[j].count('#'))
print(ans)


### FIXED CODE ###

H, W, M = map(int, input().split())

HL, WL = [0]*H, [0]*W
B = []

for _ in range(M):
  h, w = map(lambda x:int(x)-1, input().split())
  B.append((h, w))
  HL[h] += 1
  WL[w] += 1

HM, WM = max(HL), max(WL)
K = HL.count(HM) * WL.count(WM)

cnt = 0
for h, w in B:
  if HL[h] == HM and WL[w] == WM:
    cnt += 1

if K > cnt:
  print(HM+WM)
else:
  print(HM+WM-1)
### BUGGY CODE ###

from heapq import heappop, heappush
from bisect import bisect_right
import numpy as np

n, q = map(int, input().split())
stx = [list(map(int, input().split())) for _ in range(n)]
ds = [int(input()) for _ in range(q)]
INF = 10 ** 18
START = 1
END = 0

tfdi = []
for i, (s, t, x) in enumerate(stx):
    t_start = max(0, s - x)
    t_end = max(0, t - x)
    if t_end == 0:
        continue

    tfdi.append([t_start, START, x, i])
    tfdi.append([t_end, END, x, i])

tfdi.append([INF, START, INF, -1])
tfdi.sort()

hp = [[INF, -1]]
ts = []
dists = []
t_prev = -1
passed = set()
for t, f, d, i in tfdi:
    if t != t_prev:
        ts.append(t_prev)
        while hp[0][1] in passed:
            heappop(hp)

        dists.append(hp[0][0])

    if f == START:
        heappush(hp, [d, i])
    else:
        passed.add(i)

    t_prev = t

ts = np.array(ts, np.int64)
ds = np.array(ds, np.int64)
dists = np.array(dists, np.int64)

idx = np.searchsorted(ts, ds, "right") - 1
ans = dists[idx]
ans[ans==INF] = -1
print(*ans, sep="\n")


### FIXED CODE ###

from bisect import bisect_left

n, q = map(int, input().split())
stx = [list(map(int, input().split())) for _ in range(n)]
d = [int(input()) for _ in range(q)]

INF = 10 ** 9 + 1

stx.sort(key=lambda x: x[2])

nxt = [-1] * q
ans = [-1] * q

for s, t, x in stx:
    l = bisect_left(d, s - x)
    r = bisect_left(d, t - x)

    while l < r:
        if nxt[l] == -1:
            ans[l] = x
            nxt[l] = r
            l += 1
        else:
            l = nxt[l]

print(*ans, sep="\n")
### BUGGY CODE ###

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


def cost(x: int, y: int) -> int:
    global h
    return abs(h[x] - h[y])


dp = [10**9] * n
dp[0] = 0

for i in range(1, n):
    for j in range(k):
        d = i - j - 1
        if d < 0 or d > n:
            break
        dp[i] = min(dp[i], dp[d] + cost(i, d))
print(dp[n-1])


### FIXED CODE ###

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


def cost(x: int, y: int) -> int:
    global h
    return abs(h[x] - h[y])


dp = [10**9] * n
dp[0] = 0

for i in range(1, n):
    for j in range(k):
        d = i - j - 1
        if d < 0 or d > n:
            break
        dp[i] = min(dp[i], dp[d] + cost(i, d))
print(dp[n-1])
### BUGGY CODE ###

def main():
    import numpy as np

    n, k = map(int, input().split())
    A = np.array(list(map(int, input().split())))
    A = np.append(A, 0)
    for _ in range(k):
        l = [0] * (n + 1)
        for i, a in enumerate(A[:-1]):
            l[max(0, i - a)] += 1
            l[min(n, i + a + 1)] -= 1
        A = np.cumsum(l)
    print(*A[:-1])


if __name__ == "__main__":
    main()

### FIXED CODE ###

import numpy as np
from numba import jit


@jit("i8, i8, i8[:]")
def myfunc(n, k, A):
    for _ in range(k):
        l = np.zeros((n + 1,), dtype=np.int64)
        for i, a in enumerate(A[:-1]):
            l[max(0, i - a)] += 1
            l[min(n, i + a + 1)] -= 1
        A = np.cumsum(l)
        if np.all(A[:-1] == n):
            break
    return A


def main():
    n, k = map(int, input().split())
    A = np.array(list(map(int, input().split())), dtype=np.int64)
    A = np.append(A, 0)
    print(*myfunc(n, k, A)[:-1])


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

import sys
import math
sys.setrecursionlimit(200000)
input = sys.stdin.readline

S = input().strip()
T = input().strip()
l = len(S)

m = {}
for i in range(l):
    c = S[i]
    if m.get(c) == None:
        m[c] = []
    m[c].append(i)

a = [None] * len(T)
for i in range(len(T)):
    if m.get(T[i]) == None:
        print(-1)
        exit()
    a[i] = m[T[i]]

bl = 0
before = min(a[0])
for i in range(1, len(T)):
    m = a[i]
    f = True
    while f:
        for j in range(len(m)):
            c = (bl * l) + m[j]
            if before < c:
                before = c
                f = False
                break
        if f:
            bl += 1

print(before + 1)

### FIXED CODE ###

import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial, ceil, floor
from collections import defaultdict
import itertools
sys.setrecursionlimit(200000)
input = sys.stdin.readline

# N, M, = map(int, input().split())
# N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
# S = input().strip()

S = list(input().strip())
T = list(input().strip())

s = set(S)
t = set(T)
f = True
for v in t:
    if v not in s:
        f = False
        break
if f == False:
    print(-1)
    exit()

m = defaultdict(list)
for i in range(len(S)):
    m[S[i]].append(i)

counter = 0
before = -1
for v in T:
    c = m[v]
    index = bisect.bisect_left(c, before+1)
    if index >= len(c):
        before = -1
        index = bisect.bisect_left(c, before+1)
        before = c[index]
        counter += 1
    else:
        before = c[index]

print(counter * len(S) + before + 1)
### BUGGY CODE ###

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

z = 0
std = 1
if K%2 == 0:
    std = int(K/2)
else:
    std = K
for a in range(std,N+1,std):
    for b in range(std,N+1,std):
        for c in range(std,N+1,std):
            if (a+b)%K == 0 and (b+c)%K ==0 and (c+a)%K==0:
                z= z+1
print(z)


### FIXED CODE ###

N,K= list(map(int,input().split()))
import math
if K %2 ==0:
    std = K/2
else:
    std =K
M = N//std
M1 = N//K
if K%2==0:
    print(int((M-M1)**3+M1**3))
else:
    print(M1**3)
### BUGGY CODE ###

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

for x in range(0,Y//10000+1):
    for y in range(0,Y//5000+1):
        if (Y-x*10000-y*5000)%1000 == 0 and Y-x*10000-y*5000 >= 0:
            if x+y+(Y-x*10000-y*5000)//1000 == N:
                print(x,y,(Y-x*10000-y*5000)//1000)
                exit()
            
print(-1,-1,-1)

### FIXED CODE ###

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

for x in range(0,N+1):
    for y in range(0,N+1-x):
        if (Y-x*10000-y*5000)%1000 == 0 and Y-x*10000-y*5000 >= 0:
            if x+y+(Y-x*10000-y*5000)//1000 == N:
                print(x,y,(Y-x*10000-y*5000)//1000)
                exit()
            
print(-1,-1,-1)
### BUGGY CODE ###

def main():
    import sys
    import heapq
    input=sys.stdin.readline
    N,M=map(int,input().split())
    A=list(map(int,input().split()))
    A=[-x for x in A]
    for i in range(M):
        heapq.heapify(A)
        if i==0:
            temp = -(heapq.heappop(A))//2
        else:
            heapq.heappush(A,-temp)
            temp = -(heapq.heappop(A))//2
    print(-sum(A)+temp)
    
if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    import sys
    import heapq
    input=sys.stdin.readline
    N,M=map(int,input().split())
    A=list(map(lambda x:-1*int(x),input().split()))
    heapq.heapify(A)
    for i in range(M):
        if i==0:
            temp = -(heapq.heappop(A))//2
        else:
            heapq.heappush(A,-temp)
            temp = -(heapq.heappop(A))//2
    print(-sum(A)+temp)
    
if __name__ == '__main__':
    main()