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

k = int(input())
def judge_Lunlun(x):
    if (x in list(range(12+1))):return True
    x_str = str(x)
    tmp_rs = []
    lunlun_js = [ abs(int(x_str[i]) - int(x_str[i+1])) for i in range(len(x_str)-1)]
    return sum(list(map(lambda x:True if x<=1 else False, lunlun_js))) == len(lunlun_js)

lunlun_numbers = []
n = 1
while len(lunlun_numbers) != k:
    if(judge_Lunlun(n)):
        lunlun_numbers.append(n)
    n += 1
print(lunlun_numbers[-1])

### FIXED CODE ###

def func(n):
    if (n==0):return [n,n+1]
    if (n==9):return [n-1,n]
    return [n-1,n,n+1]
k = int(input())
k_su = 0
lunlun_fl = [1,2,3,4,5,6,7,8,9]
while True:
    k_su += 1
    lunlun_fl_ = lunlun_fl
    #print('{} 桁目探索開始'.format(k_su+1))
    for i in lunlun_fl_:
        if (len(str(i)) != k_su):
            continue
        lunlun_n = list(map(lambda x:int(str(i)+str(x)),func(int(str(i)[-1]))))
        lunlun_fl.extend(lunlun_n)
        if (len(lunlun_fl) >= k):break
    #print(lunlun_fl)
    if (len(lunlun_fl) >= k):break
print(lunlun_fl[k-1])
### BUGGY CODE ###

import numpy as np
from functools import reduce
from operator import mul

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

ans = reduce(mul, b)
if ans > (10 ** 18):
    ans = -1
print(ans)


### FIXED CODE ###

input_number = int(input())
int_list = list(map(int, input().split()))

check = 10 ** 18
ans = int_list[0]
for i in int_list[1:]:
    ans = ans * i

    if ans > check:
        ans = -1
        break

for i in int_list:
    if i == 0:
        ans = 0
        break

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

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

### FIXED CODE ###

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

n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
if n == 1:
    print(abs(x-a[0]))
    exit()
else:
    box = [a[i+1]-a[i] for i in range(n-1)]
    box.sort()
    for i in range(1,box[0]+1):
        for j in range(n-1):
            if box[j]%i:
                break
            if j == n-2:
                ans = i
    d = abs(x-a[0])
    if ans <= d:
        for i in range(1,ans+1):
            if d%i:
                continue
            else:
                temp = i
        print(temp)
    else:
        for i in range(1,d+1):
            if ans%i:
                continue
            else:
                temp = i
        print(temp)



### FIXED CODE ###

n, x = map(int, input().split())
a = list(map(int, input().split()))
if n == 1:
    print(abs(x-a[0]))
    exit()
else:
    a.append(x)
    a.sort()
    box = [a[i+1]-a[i] for i in range(n)]
    b = min(box)
    for i in range(1,b+1):
        for j in range(n-1):
            if box[j]%i:
                break
            if j == n-2:
                ans = i
    print(ans)
### BUGGY CODE ###

f = lambda :[int(i) for i in input().split()]

ans = 0
N,M = f()

stat = [[0 for i in range(M)] for j in range(N)]

for h in range(N):
    for k in range(M):
        for ypos in range(-1,2):
            for xpos in range(-1,2):
                if 0 <= h+ypos < N and 0 <= k +xpos < M:
                    stat[h+ypos][k+xpos] += 1

for a in stat:
    for b in a:
        if b % 2 == 1:
            ans += 1
print(ans)

### FIXED CODE ###

f = lambda :[int(i) for i in input().split()]

N,M = f()

print(abs(N*M-(N*2+M*2-4)))
### BUGGY CODE ###

import copy
h,w = map(int,input().split())
a = []
for i in range(h+2):
  a.append([2] * (w+2))
d = 0
for i in range(h):
  b = input()
  c = 0
  for k in b:
    if k == '.':
      a[i+1][c+1] = 0
      d += 1
    else:
      a[i+1][c+1] = 1
    c += 1
count = 0
while d != 0:
  count += 1
  d = 0
  b = copy.deepcopy(a)
  for i in range(h):
    for k in range(w):
      if a[i+1][k+1] == 0:
        if b[i][k+1] == 1 or b[i+2][k+1] == 1 or b[i+1][k] == 1 or b[i+1][k+2] == 1:
          a[i+1][k+1] = 1
        else:
          d += 1
print(count)

### FIXED CODE ###

h,w = map(int,input().split())
a1 = [[5000] * (w+2) for i in range(h+2)]
a2 = [['.'] * (w+2) for i in range(h+2)]
for i in range(h):
  a2[i+1][1:-1] = list(input())
for i in range(h):
  for j in range(w):
    if a2[i+1][j+1] == '#':
      a1[i+1][j+1] = 0
for i in range(w):
  for j in range(h):
    a1[j+1][i+1] = min(a1[j][i+1]+1,a1[j+1][i+1])
for i in range(w):
  for j in range(h):
    a1[h-j][i+1] = min(a1[h-j+1][i+1]+1,a1[h-j][i+1])
for i in range(h):
  for j in range(w):
    a1[i+1][j+1] = min(a1[i+1][j]+1,a1[i+1][j+1])
for i in range(h):
  for j in range(w):
    a1[i+1][w-j] = min(a1[i+1][w-j+1]+1,a1[i+1][w-j])
m = 0
for i in range(h):
  for j in range(w):
    m = max(m,a1[i+1][j+1])
print(m)
### BUGGY CODE ###

N,Q=map(int,(input()).split())
S=input()
l_list=[]
r_list=[]
for i in range(Q):
  l,r=input().split()
  l_list.append(int(l))
  r_list.append(int(r))
f=0
j=0
AC=[]
while f>=0:
  f=S.find("AC",j,len(S))
  if f>=0:
    AC.append(f+1)
    j=f+1
for i in range(Q):
  n=sum(1 for x in AC if x>=l_list[i] and x<=r_list[i]-1)
  print(n)


### FIXED CODE ###

N,Q=map(int,(input()).split())
S=input()
l_list=[]
r_list=[]
for i in range(Q):
  l,r=input().split()
  l_list.append(int(l))
  r_list.append(int(r))
count=0
AC_count=[0]
for i in range(1,N+2):
  if S[i-1:i+1]=="AC":
    count+=1
  AC_count.append(count)
AC_count.append(count)
k=0
for j in range(Q):
  k=AC_count[r_list[j]-1]-AC_count[l_list[j]-1]
  print(k)
### BUGGY CODE ###

n = int(input())

s = 0
for i in range(n):
    s += i

print(s)

### FIXED CODE ###

n = int(input())
s = n * (n-1)//2
print(s)
### BUGGY CODE ###

from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

import sys
sys.setrecursionlimit(100000)

# N <= 2*10^5
# Q <= 2*10^5
N, Q = [int(x) for x in stdin.readline().rstrip().split()]
ab = [list(map(int, stdin.readline().rstrip().split())) for _ in range(N-1)]
px = [list(map(int, stdin.readline().rstrip().split())) for _ in range(Q)]

ans = [0] * (N+1)
child = []
for _ in range(N+1):
    child.append([])

def add(node, num):
    for x in child[node]:
        add(x, num)

    ans[node] += num

for a, b in ab:
    child[a].append(b)

#print(child)

for p, x in px:
    add(p, x)

print(*ans[1:], sep=" ")

### FIXED CODE ###

from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

# N <= 2*10^5
# Q <= 2*10^5
N, Q = [int(x) for x in stdin.readline().rstrip().split()]
ab = [list(map(int, stdin.readline().rstrip().split())) for _ in range(N-1)]
px = [list(map(int, stdin.readline().rstrip().split())) for _ in range(Q)]

node_value = [0] * (N+1)
parent = [-1] * (N+1)

for a, b in ab:
    parent[b] = a

for p, x in px:
    node_value[p] += x

#print(parent)

ans = [0] * (N+1)

for i in range(1, N+1):
    ans[i] = node_value[i]
    if parent[i] != -1:
        ans[i] += ans[parent[i]]

print(*ans[1:], sep=" ")
### BUGGY CODE ###

n,m=map(int,input().split())
broken=[0]*m
for i in range(m):
  broken[i]=int(input())
  
dp=[0]*(n+1)
dp[0]=1
dp[1]=1 if 1 not in broken else 0

for i in range(2,len(dp)):
  if i in broken:
    dp[i]=0
  else:
    dp[i]=(dp[i-2]+dp[i-1])%1000000007
  
print(dp[-1])

### FIXED CODE ###

n,m=map(int,input().split())
broken=[False]*(n+1)
for i in range(m):
  broken[int(input())]=True
dp=[0]*(n+1)
dp[0]=1
dp[1]=0 if broken[1] else 1

for i in range(2,len(dp)):
  if broken[i]:
    dp[i]=0
  else:
    dp[i]=(dp[i-2]+dp[i-1])%1000000007
  
print(dp[-1])
### BUGGY CODE ###

from math import ceil
from collections import deque


def start_pos():
    for r in range(H):
        for c in range(W):
            if a[r][c] == 'S':
                return r, c
    return -1, -1


def shortest_len(y, x):
    return min(y, H - 1 - y, x, W - 1 - x)


H, W, K = map(int, input().split())
a = [input() for _ in range(H)]
b = [[False for _ in range(W)] for _ in range(H)]
sy, sx = start_pos()
need_len = shortest_len(sy, sx)

q = deque()
q.append((sy, sx, 0))
while len(q) > 0:
    y, x, k = q.popleft()
    if not (0 <= y < H and 0 <= x < W): continue
    if a[y][x] == '#': continue
    if b[y][x]: continue
    b[y][x] = True
    sl = shortest_len(y, x)
    need_len = min(need_len, sl)
    if sl - (K - k) >= need_len: continue
    if k == K: continue
    for dy, dx in (-1, 0), (1, 0), (0, -1), (0, 1):
        q.append((y + dy, x + dx, k + 1))

print(1 + ceil(need_len / K))


### FIXED CODE ###

# https://beta.atcoder.jp/contests/agc014/submissions/1268295
from collections import deque

dr = (0, 1, 0, -1)
dc = (1, 0, -1, 0)


def solve():
    H, W, K = map(int, input().split())
    a = [[False for _ in range(W)] for _ in range(H)]

    sy, sx = -1, -1
    for r in range(H):
        s = input()
        for c, x in enumerate(s):
            if x == '.':
                a[r][c] = True
            elif x == 'S':
                a[r][c] = True
                sy, sx = r, c

    visited = [[False for _ in range(W)] for _ in range(H)]
    visited[sy][sx] = True

    t = max(H, W)
    q = deque([(sy, sx, 0)])
    while q:
        r, c, k = q.popleft()

        t = min(t, r, H - 1 - r, c, W - 1 - c)
        # print(t)
        if t == 0:
            print(1)
            return

        for d_i in range(4):
            nr, nc = r + dr[d_i], c + dc[d_i]
            if 0 <= nr < H and 0 <= nc < W and a[nr][nc] and not visited[nr][nc] and k + 1 <= K:
                visited[nr][nc] = True
                q.append((nr, nc, k + 1))

    ans = 1 + (t + K - 1) // K

    print(ans)


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

def resolve():
    from collections import Counter
    n = int(input())
    s = []
    for i in range(n):
        s.append(input())
    d = Counter(s).most_common()
    e = d[0][1]
    f = ([i for i in set(s) if s.count(i) == e])
    f = sorted(set(f))
    for i in f:
        print(i)
resolve()

### FIXED CODE ###

def resolve():
    import sys
    from collections import Counter
    n = int(input())
    s = [sys.stdin.readline().rstrip() for i in range(n)]
    d = Counter(s).most_common()
    e = d[0][1]
    ans = []
    for i in range(len(d)):
        if d[i][1] != e:
            break
        else:
            ans.append(d[i][0])
    for j in sorted(ans):
        print(j)
resolve()
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
#A = [int(x) for x in input().split()]
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()

total = 0

for i in range(N):
    low = -1
    high = N
    while low < high:
        mid1 = (low + high) // 2
        if A[mid1] < B[i]:
            low = mid1
        if A[mid1] >= B[i]:
            high = mid1
        if high == low:
            break
    low = -1
    high = N
    while low < high:
        mid2 = (low + high) // 2
        if C[mid2] <= B[i]:
            low = mid2
        if C[mid2] > B[i]:
            high = mid2
        if high == low:
            break
    total = total + (mid1 + 1) * (N - mid2)

print(total)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
#A = [int(x) for x in input().split()]
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
A = [-float('inf')] + A + [float('inf')]
B.sort()
C.sort()
C = [-float('inf')] + C + [float('inf')]

total = 0

for i in range(N):
    low = 0
    high = N + 1
    while high - low > 1:
        mid1 = (low + high) // 2
        if A[mid1] < B[i]:
            low = mid1
        else:
            high = mid1
    mid1 = low
    low = 0
    high = N + 1
    while high - low > 1:
        mid2 = (low + high) // 2
        if C[mid2] <= B[i]:
            low = mid2
        else:
            high = mid2
    mid2 = high
    total += mid1 * (N + 1 - mid2)

print(total)
### BUGGY CODE ###

from collections import deque
import sys
input=sys.stdin.readline


def solve():
    H, W = map(int, input().split())
    m = [[-1]*W for _ in range(H)]
    q = deque([])
    l = [input() for _ in range(H)]
    for i in range(H):
        for j in range(W):
            if l[i][j]=="#":
                q.append((i, j, 0))
    
    dx = [-1, 1, 0, 0]
    dy = [0, 0, -1, 1]

    while q:
        y, x, cost = q.popleft()
        m[y][x] = cost

        for px, py in zip(dx, dy):
            x1, y1 = x + px, y + py
            if not (0<=x1<W and 0<=y1<H):
                continue
            if m[y1][x1] == -1:
                q.append((y1, x1, cost+1))

    print(max(map(max, m)))


if __name__ == "__main__":
    solve()


### FIXED CODE ###

from collections import deque


def solve():
    H, W = map(int, input().split())
    m = [[-1]*W for _ in range(H)]
    l = [list(input()) for _ in range(H)]
    dx = [-1, 1, 0, 0]
    dy = [0, 0, -1, 1]
    q = deque([])

    for i in range(H):
        for j in range(W):
            if l[i][j]=="#":
                q.append((i, j))
                m[i][j] = 0
    
    while q:
        y, x = q.popleft()

        for px, py in zip(dx, dy):
            x1, y1 = x + px, y + py
            if not (0<=x1<W and 0<=y1<H):
                continue
            if m[y1][x1] == -1:
                q.append((y1, x1))
                m[y1][x1] = m[y][x] + 1

    print(max(map(max, m)))


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

import numpy as np
n=int(input())
dam=[int(x)*2 for x in input().split()]
a=[[0]*n for x in range(n)]
for i in range(n):
    a[i][i],a[i][(i+1)%n]=1,1
# a=np.array(a)
# dam=np.array(dam)
ans=np.linalg.solve(a,dam)
print(" ".join([str(int(ans[i])) for i in range(n)]))

### FIXED CODE ###

n=int(input())
dam=[int(x) for x in input().split()]
yama=[0]*n
dam_sum=sum(dam)//2
diff=0
if n in (1,2):
    for j in range(n):
        diff=0
        for i in range(n):
            if i%2==0:
                continue
            diff+=dam[(i+j)%n]
        yama[j]=dam_sum - diff
        yama[j]*=2
else:
    diff_same=0
    for i in range(n):
            if i%2==0:
                continue
            diff_same+=dam[(i)%n]
    yama[0]=dam_sum - diff_same
    yama[0]*=2
    diff_odd=0
    for i in range(n):
            if i%2==0:
                continue
            diff_odd+=dam[(i+1)%n]
    yama[1]=dam_sum - diff_odd
    yama[1]*=2
    for j in range(2,n):
        if j%2==0:
            diff_same-=dam[(j-1)%n]
            diff_same+=dam[(j-2)%n]
            yama[j]=dam_sum - diff_same
        else:
            diff_odd-=dam[(j-1)%n]
            diff_odd+=dam[(j-2)%n]
            yama[j]=dam_sum - diff_odd
        yama[j]*=2
print(" ".join([str(x) for x in yama]))
### BUGGY CODE ###

import sys
input = sys.stdin.readline
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix
from collections import deque

N, M = map(int, input().split())
graph = [[] for i in range(N)]
for i in range(M):
  u, v = map(int, input().split())
  u -= 1; v -= 1
  graph[u].append(v)

# 距離が3のノード間にだけ辺を張り直す
row = []
col = []
for i in range(N):
  d = deque([i])
  for _ in range(3):
    n = len(d)
    s = set()
    for j in range(n):
      node = d.popleft()
      if node in s:
        continue
      s.add(node)
      children = graph[node]
      d.extend(children)
  _g = list(set(d))
  row.extend([i] * len(_g))
  col.extend(_g)

d = [1] * len(row)
graph = csr_matrix((d, (row, col)), shape=(N, N))
S, T = map(int, input().split())
S -= 1; T -= 1
dist = dijkstra(graph, indices=S).astype(int)
if dist[T] > 0:
  print(dist[T])
else:
  print(-1)

### FIXED CODE ###

from collections import deque

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

graph = [[] for i in range(3*N)]
for i in range(M):
  u, v = map(int, input().split())
  u, v = 3*(u - 1), 3*(v - 1)
  graph[u].append(v+1)
  graph[u+1].append(v+2)
  graph[u+2].append(v)

s, t = map(int, input().split())
s, t = 3*(s - 1), 3*(t - 1)


dist = [10**9] * 3*N
dist[s] = 0
d = deque([s])
while d:
  node = d.popleft()
  children = graph[node]
  for child in children:
    if dist[child] > dist[node] + 1:
      d.append(child)
      dist[child] = dist[node] + 1

if dist[t] < 10**9:
  print(dist[t]//3)
else:
  print(-1)
### BUGGY CODE ###

import sys, math, copy
def input():
    return sys.stdin.readline()[:-1]
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial

sys.setrecursionlimit(10**7)
H, W = map(int, input().split())
maze = [[c for c in input()] for _ in range(H)]

moves = [[-1, 0], [1, 0], [0, -1], [0, 1]]

def chkcell(maze_copy, h, w):
    if 0<=h and h<H and 0<=w and w<W and maze_copy[h][w]=='.':
        return True

def count_steps(q, maze_copy):
    steps = -1
    while len(q):
#        print('q:', q)
#        print('maze:')
#        for row in maze_copy:
#            print(row)
        steps += 1
        next_cells = []
        cells = q.pop()
        for cell in cells:
            maze_copy[cell[0]][cell[1]] = '#'
            for move in moves:
                newcell = [i+j for i, j in zip(cell, move)]
                if chkcell(maze_copy=maze_copy, h=newcell[0], w=newcell[1]):
                    next_cells.append(newcell)
        if next_cells:
            q.append(next_cells)

#    print('max_step:', steps)
    return steps

res = 0
for i in range(H):
    for j in range(W):
#        print('i, j', i, j)
        if maze[i][j] == '#':
            continue
        q = deque()
        q.append([[i, j]])
        maze_copy = copy.deepcopy(maze)
        val = count_steps(q, maze_copy)
        if res < val: res = val

print(res)



### FIXED CODE ###

from copy import deepcopy
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]

def check(ny, nx, sS):
    if 0<=ny<H and 0<=nx<W:
        if sS[ny][nx]=='.':
            return True
    else:
        return False

def bfs(sy, sx, sS):
    deq = deque()
    deq.append([(sy-1, sx-1)]) # insert indices
    sS[sy-1][sx-1] = '#'
    ddy = [-1, 0, 1, 0]
    ddx = [0, -1, 0, 1]
    step = 0
    while deq[0]:
        #print('deq', deq)
        nqueue = []
        cqueue = deq.popleft()
        for val in cqueue:
            y, x = val
            for dy, dx in zip(ddy, ddx):
                ny, nx = y+dy, x+dx
                if check(ny, nx, sS):
                    sS[ny][nx] = '#'
                    nqueue.append((ny, nx))
        deq.append(nqueue)
        if not(deq[0]):
            break
        step += 1
    return step

res = 0
for i in range(H):
    for j in range(W):
        #print('i, j:', i, j)
        if S[i][j] == '.':
            sS = deepcopy(S)
            val = bfs(i+1, j+1, sS)
            res = max(res, val)

print(res)
### BUGGY CODE ###

from collections import*
n,k,l=map(int,input().split());d=[-1]*n;t=[-1]*n;M=lambda:map(int,input().split())
def f(l,x):
  if l[x]<0:return x
  else:l[x]=f(l,l[x]);return l[x]
def u(l,x,y):
  if f(l,x)!=f(l,y):l[f(l,y)]=f(l,x)
for _ in range(k):a,b=M();u(d,a-1,b-1)
for _ in range(l):a,b=M();u(t,a-1,b-1)
p=[(f(d,i),f(t,i))for i in range(n)];print(*[Counter(p)[p[i]]for i in range(n)])

### FIXED CODE ###

from collections import*
class u():#UnionFind f-根探し u-連結 s-連結? c-要素数
  def __init__(self,n):self.n,self.r=[-1]*n,[0]*n
  def f(self,x):
    if self.n[x]<0:return x
    else:self.n[x]=self.f(self.n[x]);return self.n[x]
  def u(self,x,y):
    x,y=self.f(x),self.f(y)
    if x==y:return
    elif self.r[x]>self.r[y]:self.n[x]+=self.n[y];self.n[y]=x
    else:self.n[y]+=self.n[x];self.n[x]=y;self.r[y]+=self.r[x]==self.r[y]
  def s(self,x,y):return self.f(x)==self.f(y)
  def c(self,x):return -self.n[self.f(x)]
n,k,l=map(int,input().split())
d=u(n);t=u(n)
for _ in range(k):a,b=map(int,input().split());d.u(a-1,b-1)
for _ in range(l):a,b=map(int,input().split());t.u(a-1,b-1)
p=[(d.f(i),t.f(i))for i in range(n)]
c=Counter(p)
print(*[c[p[i]]for i in range(n)])
### BUGGY CODE ###

n,k=map(int,input().split())
A=[int(i) for i in input().split()]
F=[int(i) for i in input().split()]
A.sort()
F.sort()

def chk(x):
  ct=0
  for i in range(n):
    a,f=A[i],F[-i-1]
    ct+=max(0,a-x//f)
    if ct>k:
      return False
  if ct<=k:
    return True
  else:
    return False
l=0
r=0
for i in range(n):
  r=max(r,A[i]*F[-i-1])

while r-l>1:
  m=(l+r)//2
  if chk(m):
    r=m
  else:
    l=m

if chk(l):
  print(l)
else:
  print(r)


### FIXED CODE ###

n,k=map(int,input().split())
A=[int(i) for i in input().split()]
F=[int(i) for i in input().split()]
A.sort()
F.sort()

def chk(x):
  ct=0
  for i in range(n):
    a,f=A[i],F[-i-1]
    ct+=max(0,a-x//f)
    if ct>k:
      return False
  if ct<=k:
    return True
  else:
    return False
l=0
r=0
for i in range(n):
  r=max(r,A[i]*F[-i-1])

while r-l>1:
  m=(l+r)//2
  if chk(m):
    r=m
  else:
    l=m

if chk(l):
  print(l)
else:
  print(r)
### BUGGY CODE ###

from sys import stdin
n,k,q = map(int, stdin.readline().split())
a = [int(stdin.readline()) for _ in range(q)]
points = list(map(lambda x: x-q, [k for i in range(n)]))
for i in set(a):
    points[i-1] += a.count(i)
for i in points:
  if i <= 0:
    print('No')
  else:
    print('Yes')

### FIXED CODE ###

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

def main():
    s = input()
    t = input()
    dp = [[0]*(len(s)+1) for _ in range((len(t)+1))]
    ans = ""
    for i in range(len(t)):
        for j in range(len(s)):
            tmp1 = dp[i+1][j]
            tmp2 = dp[i][j+1]
            tmp3 = dp[i][j]
            if t[i] == s[j]:
                tmp3 += 1
            dp[i+1][j+1] = max(tmp1,tmp2,tmp3)
    i = len(t)
    j = len(s)
    for k in range(10**6):
        if i < 0 or j < 0:
            break
        if dp[i-1][j-1]+1 == dp[i][j] and t[i-1] == s[j-1]:
            ans += t[i-1]
            i -= 1
            j -= 1
        elif dp[i-1][j] == dp[i][j]:
            i -= 1
        else:
            j -= 1
    # while i > 0 and j > 0:
    #     if dp[i-1][j-1]+1 == dp[i][j] and t[i-1] == s[j-1]:
    #         ans += t[i-1]
    #         i -= 1
    #         j -= 1
    #     elif dp[i-1][j] == dp[i][j]:
    #         i -= 1
    #     else:
    #         j -= 1
    print(ans[::-1])

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    s = input()
    t = input()
    dp = [[0]*(len(s)+1) for _ in range((len(t)+1))]
    ans = ""
    for i in range(len(t)):
        for j in range(len(s)):
            tmp1 = dp[i+1][j]
            tmp2 = dp[i][j+1]
            tmp3 = dp[i][j]
            if t[i] == s[j]:
                tmp3 += 1
            dp[i+1][j+1] = max(tmp1,tmp2,tmp3)
    i = len(t)
    j = len(s)
    while i > 0 and j > 0:
        if dp[i-1][j-1]+1 == dp[i][j] and t[i-1] == s[j-1]:
            ans += t[i-1]
            i -= 1
            j -= 1
        elif dp[i-1][j] == dp[i][j]:
            i -= 1
        else:
            j -= 1
    print(ans[::-1])

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

import sys
input = lambda: sys.stdin.readline()[:-1]
from collections import defaultdict
s =input()
lenth=len(s)
ss=s*2
t =input()
place=defaultdict(list)

for k,l in enumerate(s):
	place[l].append(k+1)
	place[l].append(k+1+lenth)

now=0
ans=0
for i in t:
	if not place[i]:
		print(-1)
		exit()
	mt=min((j for j in place[i] if j>now))
	if mt>lenth:
		mt-=lenth
		ans+=lenth
	now=mt
print(ans+now)

### FIXED CODE ###

import sys
from bisect import bisect_right
input = lambda: sys.stdin.readline()[:-1]
from collections import defaultdict
s =input()
lenth=len(s)
ss=s*2
t =input()
place=defaultdict(list)

for k,l in enumerate(s):
	place[l].append(k+1)
	place[l].append(k+1+lenth)
for i in place.values():
	i.sort()
now=0
ans=0

for i in t:
	if not place[i]:
		print(-1)
		exit()
	mt=place[i][bisect_right(place[i],now)]
	if mt>lenth:
		mt-=lenth
		ans+=lenth
	now=mt
print(ans+now)