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

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

if((a[0]+a[1]) == a[2]):
    print("0 0")

if((a[0]+a[1]) != a[2]):
    for i in range(0, a[2]):
        if(a[0] >= 1):
            a[0] -= 1
        elif(a[1] >= 1):
            a[1] -= 1
    print("%d %d"%(a[0],a[1]))    

### FIXED CODE ###

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

t = a[0]-a[2]

if t<0:

    a[1] = a[1] +t
    if(a[1] < 0):
        a[1] = 0
    t = 0

print("%d %d"%(t,a[1]))
### BUGGY CODE ###

k = int(input());
i= list(map(int,input().split()));

a = int(i[0]);
b = int(i[1]) ;
flag = False;

while a <= b:
    if a % k == 0:
        flag = True;
        break;
    else:
        continue;
    a += 1;

if(flag):
    print("OK");
else:
    print("NG");



### FIXED CODE ###

k = int(input());
i= list(map(int,input().split()));

a = int(i[0]);
b = int(i[1]) ;
flag = False;


while(a <= b):
    if a % k == 0:
        flag = True;
        break;
    else:
        a += 1;

if(flag):
    print("OK");
else: print("NG");
### BUGGY CODE ###


# coding: utf-8

# In[51]:

import sys
#input = sys.stdin.readline
N, K = map(int, input().split())
S = input()


# In[59]:

tmp = S[0]
f = S[0]
c_list = [0]*N
counter = 1
nb = 0
for i in range(1, N):
    #counter += 1
    #print(S[i], i)
    if S[i] != tmp:
        c_list[nb] = counter
        nb += 1
        counter = 0
        tmp = S[i]
    counter += 1
    if i == N-1:
        c_list[nb] = counter
    #print(S[i], i,counter, c_list)

#print(c_list)
pl = [0]*N
if len(c_list) <= K*2:
    #print("a")
    print(N)
else:
    #print("b")
    if f == "0":
        #print("c")
        for i in range(-1, len(c_list)-K*2, 2):
            #print(i, i+K*2+1)
            j = 0 if i < 0 else i
            pl[i] = sum(c_list[j:i+K*2+1])
    else:
        #print("d")
        for i in range(0, len(c_list)-K*2, 2):
            #print(i, i+K*2+1)
            j = i
            pl[i] = sum(c_list[j:i+K*2+1])
    #print(pl)
    print(max(pl))


# In[ ]:





### FIXED CODE ###


# coding: utf-8

# In[5]:

import sys
#input = sys.stdin.readline
N, K = map(int, input().split())
S = input()


# In[6]:

#print(N, K)
#print(len(S), S)


# In[21]:

tmp = S[0]
sums = [0]*(N+2)
counter = 1
gc = N
nb = 0
for i in range(1, N):
    if S[i] != tmp:
        sums[nb+1] = i
        nb += 1
        counter = 0
        tmp = S[i]
    else:
        gc -= 1
    counter += 1
    if i == N-1:
        sums[nb+1] = i+1

#print(N, gc)
sums = sums[:gc+2]
#print(S)
#print(sums)
#print(gc)
#print(gc-K*2)
pl = [0]*(gc+2)
if gc < K*2:
    print(N)
else:
    if S[0] == "0":
        if S[-1] == "0":
            for i in range(-1, gc-K*2+1, 2):
                #print(i, i+1+K*2, gc)
                j = 0 if i < 0 else i
                l = gc if i+1+K*2>gc else i+1+K*2
                #print(j, l)
                pl[i] = sums[l]-sums[j]
        else:
            for i in range(-1, gc-K*2, 2):
                j = 0 if i < 0 else i
                pl[i] = sums[i+1+K*2]-sums[j]
    else:
        if S[-1] == "0":
            for i in range(0, gc-K*2+1, 2):
                #print(i, i+1+K*2, gc)
                j=i
                l = gc if i+1+K*2>gc else i+1+K*2
                #print(j, l)
                pl[i] = sums[l]-sums[j]
        else:
            for i in range(0, gc-K*2, 2):
                j = i
                pl[i] = sums[i+1+K*2]-sums[j]
    #print(pl)
    print(max(pl))


# In[ ]:
### BUGGY CODE ###

N = int(input())
sX = input()
 
origin_count = sX.count('1')
one_r_count = origin_count -1
zero_r_count = origin_count +1
 
one_mod = 0
zero_mod =0
for b in sX:
    if one_r_count != 0:
        one_mod = (one_mod * 2) + int(b) % one_r_count
    zero_mod = (zero_mod * 2 ) + int(b) % zero_r_count
 
f = [0] * 220000
pop = [0]* 220000
 
for i in range(1,220000):
    pop[i] = pop[i//2] + i%2
    f[i] = f[i % pop[i]] + 1
 
onepow = [1] * 220000
zeropow = [1]* 220000
 
for i in range(1,220000):
    if one_r_count != 0:
        onepow[i] = onepow[i-1] * 2 % one_r_count
    zeropow[i] = zeropow[i-1] * 2 % zero_r_count
 
for i in range(1,N+1):
    if sX[i-1] == '1':
        if one_r_count != 0:
            Xi_n = one_mod - onepow[N-i]
            Xi_n %= one_r_count
            print(f[Xi_n]+1)
        else:
            print(0)
    else:
        Xi_n = zero_mod + zeropow[N-i]
        Xi_n %= zero_r_count
        print(f[Xi_n]+1)

### FIXED CODE ###

N = int(input())
sX = input()

origin_count = sX.count('1')
one_r_count = origin_count -1
zero_r_count = origin_count +1

one_mod = 0
zero_mod =0
for b in sX:
    if one_r_count != 0:
        one_mod = (one_mod * 2 + int(b) )% one_r_count
    zero_mod = (zero_mod * 2  + int(b) )% zero_r_count

f = [0] * 220000
pop = [0]* 220000

for i in range(1,220000):
    pop[i] = pop[i//2] + i % 2
    f[i] = f[i % pop[i]] + 1

onepow = [1] * 220000
zeropow = [1]* 220000

for i in range(1,220000):
    if one_r_count != 0:
        onepow[i] = onepow[i-1] * 2 % one_r_count
    zeropow[i] = zeropow[i-1] * 2 % zero_r_count

for i in range(1,N+1):
    if sX[i-1] == '1':
        if one_r_count != 0:
            Xi_n = one_mod - onepow[N-i]
            Xi_n %= one_r_count
            print(f[Xi_n]+1)
        else:
            print(0)
    if sX[i-1] == '0':
        Xi_n = zero_mod + zeropow[N-i]
        Xi_n %= zero_r_count
        print(f[Xi_n]+1)
### BUGGY CODE ###

import itertools
 
N, M, R = map(int, input().split())
rs = map(int, input().split())
rs = list(map(lambda x:x-1 , rs))
ABCs = [list(map(int, input().split())) for i in range(M)]
 
d = [[10**6] * N for i in range(N)]
 
for abc in ABCs:
    d[abc[0]-1][abc[1]-1] = abc[2]
    d[abc[1]-1][abc[0]-1] = abc[2]
 
for i in range(N):
    for j in range(N):
        for k in range(N):
            d[j][k] = min(d[j][k], d[j][i] + d[i][k])
            
for i in range(N):
    d[i][i] = 10**6
 
kyori = 0
ans = 10**6
narabi = list(itertools.permutations(rs,R))
for pt in narabi:
    for i in range(len(pt)-1):
        kyori += d[pt[i]][pt[i+1]]
    if kyori < ans:
        ans = kyori
    kyori = 0

print(ans)

### FIXED CODE ###

from itertools import permutations

N, M, R = map(int, input().split())
r = list(map(int, input().split()))
ARSP = [[float('inf')] * (N+1) for i in range(N+1)]
for i in range(M):
    a, b, c = map(int, input().split())
    ARSP[a][b] = c
    ARSP[b][a] = c


def warshall_floyd(adj_array):
    for k in range(len(adj_array)):
        for i in range(len(adj_array)):
            for j in range(len(adj_array)):
                if adj_array[i][k] + adj_array[k][j] < adj_array[i][j]:
                    adj_array[i][j] = min(adj_array[i][j], adj_array[i][k] + adj_array[k][j])
    return adj_array


ARSP = warshall_floyd(ARSP)

# 訪れ方の全列挙(max 8! = 40320)
journey = list(permutations(r))

ans = float('inf')
for j in journey:
    cost = 0
    for i in range(1, R):
        if ARSP[j[i]][j[i-1]] == float('inf'):
            break
        cost += ARSP[j[i]][j[i-1]]
        if cost >= ans:
            break
    else:
        ans = cost

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

import itertools

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

mod = 10**9 + 7

ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        ans += (a[i]%mod)*(a[j]%mod)

print(ans%mod)

### FIXED CODE ###

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

mod = 10**9 + 7

sum_a = sum(a)%mod
ans = 0
for i in range(n-1):
    sum_a -= a[i]
    ans += (a[i]*sum_a)%mod

print(ans%mod)
### BUGGY CODE ###

#coding:utf-8

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

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def lcm(a, b):
    return (a * b) // gcd(a, b)

def func(x, A):
    ans = 0
    for y in A:
        ans += x%y
    return ans

def hoge(A):
    B = []
    for i in range(len(A)-1):
        for j in range(len(A)-i-1):
            tmp = lcm(A[i], A[i+1+j])
            if tmp not in B: B.append(tmp)
    return B

max_lcm = 0
B = []
for i in range(n-1):
    for j in range(n-i-1):
        tmp = lcm(A[i], A[i+1+j])
        if tmp not in B: B.append(tmp)

while(len(B) > 1):
    B = hoge(B)

print(func(B[0]-1, A))


### FIXED CODE ###

n = int(input())
A = list(map(int, input().split()))
print(sum(A) - n)
### BUGGY CODE ###

import numpy as np

N = int(input())
A = np.array([int(i) for i in input().split()])
ans = 0
for i in range(max(A) + 1):
    ans = max(ans, np.sum(np.abs(A - np.ones(N) * i) <= 1))
print(ans)


### FIXED CODE ###

import numpy as np
N = int(input())
temp = input()
a = np.array([int(i) for i in temp.split()])

list_X = [0]*1000000

for ele in a:
    list_X[ele] += 1
    list_X[ele-1] += 1
    list_X[ele+1] += 1

print(max(list_X))
### BUGGY CODE ###

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

n = int(readline())
p = list(map(int, readline().split()))
cnt = n
for i in range(n):
    if not all(p[i]<=p[j] for j in range(i+1)):
        cnt -= 1
print(cnt)

### FIXED CODE ###

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

cnt = 0
m = 10**6
for i in p:
    if i < m:
        m = i
        cnt += 1
print(cnt)
### BUGGY CODE ###

S = input()
con = 10**9 + 7

T = [s if s != "?" else "0" for s in S]
T = int(''.join(T))
SS = T % 13

def get_mod(S):
    c = {}
    iii = 1
    for i in range(len(S)):
        if S[len(S) - i - 1] != "?":
            iii *= 10
            iii %= 13
            continue
        c[i] = {(j * iii) % 13: 1 for j in range(0, 10)}
        iii *= 10
        iii %= 13
    return c
c = get_mod(S)
lookup = {(i, j): (i + j) % 13 for i in range(13) for j in range(13)}

def get_tdp(pdp):
    tdp = {i: 0 for i in range(13)}
    for r in v.keys():
        for _r, _v in pdp.items():
            tdp[lookup[(r, _r)]] += _v
    for i in range(13):
        tdp[i] %= con
    return tdp

pdp = {i: 0 for i in range(13)}
pdp[SS] += 1
for k, v in c.items():
    pdp = get_tdp(pdp)

ans = pdp[5]
print(ans)

### FIXED CODE ###

S = input()
con = 10**9 + 7

T = [s if s != "?" else "0" for s in S]
T = int(''.join(T))
SS = T % 13

def get_mod(S):
    c = {}
    iii = 1
    for i in range(len(S)):
        if S[len(S) - i - 1] != "?":
            iii *= 10
            iii %= 13
            continue
        c[i] = {(j * iii) % 13: 1 for j in range(0, 10)}
        iii *= 10
        iii %= 13
    return c
c = get_mod(S)

def get_tdp(pdp):
    tdp = {i: 0 for i in range(13)}
    for r in v.keys():
        for _r, _v in pdp.items():
            tdp[(_r + r) % 13] += _v
    for i in range(13):
        tdp[i] %= con
    return tdp

pdp = {i: 0 for i in range(13)}
pdp[SS] += 1
for k, v in c.items():
    pdp = get_tdp(pdp)

ans = pdp[5]
print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32

MOD = 1000000007  # type: int

def solve(N: int, A: "List[int]"):
    ans = [0] * 60
    
    
    for i in range(60):
        # x0 = len([j for j in range(N) if not (A[j]>>i)&1])
        # x1 = len([j for j in range(N) if (A[j]>>i)&1])
        x0 = 0
        x1 = 0
        for j in range(N):
            if (A[j]>>i)&1:
                x1 += 1
            else:
                x0 += 1

        ans[i] = x0*x1

    x = 0
    for i in range(60):
        # print(i, 2**i)
        x += pow(2, i) * ans[i] % MOD

    print(x%MOD)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32

MOD = 1000000007  # type: int

def solve(N: int, A: "List[int]"):
    ans = [0] * 60
    
    
    for i in range(60):
        # x0 = len([j for j in range(N) if not (A[j]>>i)&1])
        # x1 = len([j for j in range(N) if (A[j]>>i)&1])
        x0 = 0
        x1 = 0
        for j in range(N):
            if (A[j]>>i)&1:
                x1 += 1
            else:
                x0 += 1

        ans[i] = x0*x1

    x = 0
    for i in range(len(ans)):
        # print(i, 2**i)
        x += pow(2, i) * ans[i] % MOD

    print(x%MOD)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

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

import numpy as np
N, C = list(map(int,input().split()))

sushi = [[0,0]]
for _ in range(N):
    sushi.append(list(map(int,input().split())))
sushi.append([C,0])
sushi = np.array(sushi)

sum_c = 0
sum_d = 0
ans = 0
for f in range(N+1):
    sum_c += sushi[f,1]
    sum_d = sushi[f,0]
    tmp_c = sum_c
    tmp_d = sum_d
    for b in range(1,N+2-f):
        tmp_c += sushi[-b,1]
        tmp_d = min(sum_d, C-sushi[-b,0])*2 + max(sum_d, C-sushi[-b,0])
        if ans < tmp_c-tmp_d:
            ans = tmp_c-tmp_d

print(ans)

### FIXED CODE ###

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

sushi_front = [0]
sushi_back = [0]
sushi_front2 = [0]
sushi_back2 = [0]
sushi = []

c= 0
d = 0
max_ = 0
max_2 = 0
for _ in range(N):
    sushi.append(list(map(int,input().split())))
    
    c += sushi[-1][1]
    d = sushi[-1][0]
    max_ = max(max_,c-d)
    max_2 = max(max_2, c-2*d)
    sushi_front.append(max_)
    sushi_front2.append(max_2)

sushi.reverse()
c = 0
d = 0
max_ = 0
max_2 = 0
for x in sushi:
    
    c += x[1]
    d = C -x[0]
    max_ = max(max_,c-d)
    max_2 = max(max_2, c-2*d)
    sushi_back.append(max_)
    sushi_back2.append(max_2)

ans = 0
for i in range(N+1):
    ans = max(ans,sushi_front[i]+sushi_back2[N-i],sushi_front2[i]+sushi_back[N-i])
print(ans)
### BUGGY CODE ###

from collections import Counter
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def twonum(n):
    count = Counter(prime_factorize(n))
    return count[2]

n = int(input())
ali = list(map(int, input().split()))
twos = []
for a in ali:
    twos.append(twonum(a))
print(sum(twos))

### FIXED CODE ###

n = int(input())
ali = list(map(int, input().split()))
total = 0
for a in ali:
    while a%2==0:
        a = (a//2)
        total += 1
print(total)
### BUGGY CODE ###

import sys
input=sys.stdin.readline
h, w, d = map(int, input().split())
p = dict()
for i in range(h):
    for j, x in enumerate(map(int, input().split())):
        p[x] = (i, j)

q = int(input())
for i in range(q):
    a, b = map(int, input().split())
    ans = 0
    s, t = p[a]
    while a <= b:
        i, j = p[a]
        ans += abs(s-i)+abs(t-j)
        s, t = i, j
        a += d
    print(ans)



### FIXED CODE ###

import sys
input=sys.stdin.readline
h, w, d = map(int, input().split())
p = dict()

for i in range(h):
    for j, x in enumerate(map(int, input().split())):
        p[x] = (i, j)

dp = [0]*(h*w+1)
for i in range(h*w+1):
    if d < i:
        dp[i] = dp[i-d] + abs(p[i][0]-p[i-d][0])+abs(p[i][1]-p[i-d][1])

q = int(input())
for i in range(q):
    a, b = map(int, input().split())
    ans = dp[b]-dp[a]
    print(ans)
### BUGGY CODE ###

N = int(input())
P = list(map(int, input().split()))
for i in range(len(P)):
    P[i] -= 1

dp = [[1 + min(i, N - 1 - i, j, N - 1 - j) for j in range(N + 1)] for i in range(N + 1)]

presence = [[1 for j in range(N)] for i in range(N)]

ans = 0
for i in range(len(P)):
    x = P[i] // N
    y = P[i] % N
    ans += dp[x][y] - 1
    presence[x][y] = 0

    Q = [(x, y)]
    while Q:
        x, y = Q.pop()
        new_value = presence[x][y] + min(
            dp[x - 1][y], dp[x + 1][y], dp[x][y - 1], dp[x][y + 1]
        )
        if new_value != dp[x][y]:
            dp[x][y] = new_value
            if 1 <= x and dp[x - 1][y] > presence[x - 1][y] + dp[x][y]:
                Q.append((x - 1, y))
            if x < N - 1 and dp[x + 1][y] > presence[x + 1][y] + dp[x][y]:
                Q.append((x + 1, y))
            if 1 <= y and dp[x][y - 1] > presence[x][y - 1] + dp[x][y]:
                Q.append((x, y - 1))
            if y < N - 1 and dp[x][y + 1] > presence[x][y + 1] + dp[x][y]:
                Q.append((x, y + 1))

print(ans)
pass


### FIXED CODE ###

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

dp = [[min(i, N - i - 1, j, N - j - 1) for j in range(N)] for i in range(N)]

presence = [[1 for j in range(N)] for i in range(N)]

ans = 0
for i in range(len(P)):
    P[i] -= 1
    x, y = divmod(P[i], N)
    ans += dp[x][y]
    presence[x][y] = 0

    Q = [(x, y)]
    while Q:
        x, y = Q.pop()
        new_value = dp[x][y] + presence[x][y]
        if 1 <= x and dp[x - 1][y] > new_value:
            dp[x - 1][y] = new_value
            Q.append((x - 1, y))
        if x < N - 1 and dp[x + 1][y] > new_value:
            dp[x + 1][y] = new_value
            Q.append((x + 1, y))
        if 1 <= y and dp[x][y - 1] > new_value:
            dp[x][y - 1] = new_value
            Q.append((x, y - 1))
        if y < N - 1 and dp[x][y + 1] > new_value:
            dp[x][y + 1] = new_value
            Q.append((x, y + 1))


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

import sys
import numpy as np
from numba import njit


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


def update(A):
  N = len(A)
  B = np.zeros_like(A)
  for i,x in enumerate(A):
    l = max(0, i-x)
    r = min(N-1, i+x)
    B[l] += 1
    if r + 1 < N:
      B[r+1] -= 1
  B = np.cumsum(B)
  return B
    
    
N,K = map(int, readline().split())
A = np.array(read().split(), np.int64)

k = min(K, 100)
for _ in range(K):
  A = update(A)
print(' '.join(A.astype(str)))

### FIXED CODE ###

import sys
import numpy as np
from numba import njit
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
@njit('(i8[::1],)', cache=True)
def update(A):
    N = len(A)
    B = np.zeros_like(A)
    for i, x in enumerate(A):
        l = max(0, i - x)
        r = min(N - 1, i + x)
        B[l] += 1
        if r + 1 < N:
            B[r + 1] -= 1
    B = np.cumsum(B)
    return B
 
N, K = map(int, readline().split())
A = np.array(read().split(), np.int64)
 
K = min(K, 100)
for _ in range(K):
    A = update(A)
print(' '.join(A.astype(str)))
### BUGGY CODE ###


def main():
    pass
    N = int(input())
    A = list(map(int, input().split()))

    ans = 0
    for i in range(N-1, 0,-1):
        if i >= A[i] and i-A[i] >= 0:
            for k in range(0,i-A[i]):
                if i-k == A[i] + A[k]:
                    ans += 1
    print(ans)

if __name__ == '__main__':
    main()


### FIXED CODE ###


def main():
    pass
    N = int(input())
    A = list(map(int, input().split()))

    H = [0]*N
    for i in range(0,N):
        if i >= A[i]:
            H[i-A[i]] += 1

    ans = 0
    for k in range(0,N):
        Bk = k+A[k]
        if Bk < N:
            ans += H[Bk]

    print(ans)

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

N, M = map(int, input().split(" "))
bridges = [list(map(int, input().split(" "))) for _ in range(M)]

all_ptn = N * (N-1) // 2
ans = [all_ptn]
trees = [{i} for i in range(N)]
for i in range(M-1, 0, -1):
    tree1 = trees[bridges[i][0]-1]
    tree2 = trees[bridges[i][1]-1]
    if tree1 != tree2:
        tmp = tree1.union(tree2)
        for node in tmp:
            trees[node] = tmp
        ans.append(ans[-1] - len(tree1) * len(tree2))
    else:
        ans.append(ans[-1])
for i in range(M-1, -1, -1):
    print(ans[i])

### FIXED CODE ###

N, M = map(int, input().split(" "))
bridges = [list(map(int, input().split(" "))) for _ in range(M)]

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.par = [-1] * n
        self.rank = [0] * n
        
    def root(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.root(self.par[x])
            return self.par[x]
        
    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        
        if rx == ry:
            return
        elif self.rank[rx] > self.rank[ry]:
            self.par[rx] += self.par[ry]
            self.par[ry] = rx
            
        else:
            self.par[ry] += self.par[rx]
            self.par[rx] = ry
            if self.rank[rx] == self.rank[ry]:
                self.rank[ry] += 1
                
    def same(self, x, y):
        return self.root(x) == self.root(y)
    
    def count(self, x):
        return -self.par[self.root(x)]

all_ptn = N * (N-1) // 2
ans = [all_ptn]
uf = UnionFind(N)
for i in range(M-1, 0, -1):
    x = bridges[i][0] - 1
    y = bridges[i][1] - 1
    if uf.same(x, y):
        ans.append(ans[-1])
    else:
        ans.append(ans[-1] - uf.count(x) * uf.count(y))
        uf.unite(x, y)
        
for i in range(M-1, -1, -1):
    print(ans[i])
### BUGGY CODE ###

s = list(input())
MOD = 10**9 + 7
cnt = [[] for _ in range(len(s))]
i = len(s) - 1
de = 1

while i >= 0:
    if s[i] == '?':
        for j in range(10):
            cnt[i].append((j * de) % 13)
    else: cnt[i].append((int(s[i]) * de) % 13)
    i -= 1
    de *= 10
    de %= 13

dp = [[0]*13 for _ in range(len(s))]
for i in cnt[0]:
    dp[0][i] = 1
for i in range(1, len(s)):
    for j in cnt[i]:
        for k in range(13):
            if dp[i-1][k] != 0:
                dp[i][(j + k)%13] += dp[i - 1][k]
                dp[i][(j + k)%13] %= MOD
print(dp[-1][5])


### FIXED CODE ###

s = list(input())
MOD = 10**9 + 7
cnt = [[] for _ in range(len(s))]
i = len(s) - 1
de = 1

while i >= 0:
    if s[i] == '?':
        for j in range(10):
            cnt[i].append((j * de) % 13)
    else: cnt[i].append((int(s[i]) * de) % 13)
    i -= 1
    de *= 10
    de %= 13

dp = [[0]*13 for _ in range(len(s))]
for i in cnt[0]:
    dp[0][i] = 1
for i in range(1, len(s)):
    for j in cnt[i]:
        for k in range(13):
            if dp[i-1][k] != 0:
                dp[i][(j + k)%13] += dp[i - 1][k]
                dp[i][(j + k)%13] %= MOD
print(dp[-1][5])
### BUGGY CODE ###


def main():
    S = list(input())
    T = list(input())
    sl = len(S)

    Sdic = {}
    for i, s in enumerate(S):
        if not s in Sdic.keys():
            Sdic[s] = [i]
        else:
            Sdic[s].append(i)
    pret = -1
    ans = 0
    for t in T:
        try:
            update = False
            for it in Sdic[t]:
                if it > pret:
                    update = True
                    pret = it
                    break
            if not update:
                ans += sl
                pret = Sdic[t][0]
            #print(t, update, pret)
        except KeyError:
            ans = -1
            break
    if ans != -1:
        ans += pret+1
    print(ans)

if __name__ == "__main__":
    main()

### FIXED CODE ###

from bisect import bisect_left, bisect_right


def main():
    S = list(input())
    T = list(input())
    sl = len(S)

    Sdic = {}
    for i, s in enumerate(S):
        if not s in Sdic.keys():
            Sdic[s] = [i]
        else:
            Sdic[s].append(i)
    pret = -1
    ans = 0
    for t in T:
        try:
            #print(Sdic[t])
            it = bisect_right(Sdic[t], pret)
            #print(it, t)
            if it < len(Sdic[t]):
                pret = Sdic[t][it]
            else:
                ans += sl
                pret = Sdic[t][0]
            #print(t, update, pret)
        except KeyError:
            ans = -1
            break
    if ans != -1:
        ans += pret+1
    print(ans)

if __name__ == "__main__":
    main()