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

import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################


H,W = II()
A = []
B = []
for i in range(H):
    A.append(III())
for i in range(H):
    B.append(III())


d = [[set() for _ in range(W)] for _ in range(H)]
for i in range(H):
    for j in range(W):
        if i==0 and j==0:
            d[i][j].add(abs(A[i][j]-B[i][j]))
        elif j==0:
            for k in d[i-1][j]:
                d[i][j].add(abs(k+A[i][j]-B[i][j]))
                d[i][j].add(abs(-k+A[i][j]-B[i][j]))
        elif i==0:
            for k in d[i][j-1]:
                d[i][j].add(abs(k+A[i][j]-B[i][j]))
                d[i][j].add(abs(-k+A[i][j]-B[i][j]))
        else:
            for k in d[i-1][j]:
                if abs(k+A[i][j]-B[i][j])<=(H+W-1)*20:
                    d[i][j].add(abs(k+A[i][j]-B[i][j]))
                if abs(-k+A[i][j]-B[i][j])<=(H+W-1)*20:
                    d[i][j].add(abs(-k+A[i][j]-B[i][j]))
            for k in d[i][j-1]:
                if abs(k+A[i][j]-B[i][j])<=(H+W-1)*20:
                    d[i][j].add(abs(k+A[i][j]-B[i][j]))
                if abs(-k+A[i][j]-B[i][j])<=(H+W-1)*20:
                    d[i][j].add(abs(-k+A[i][j]-B[i][j]))

ans = 2*(H+W-1)*80+1
for i in d[H-1][W-1]:
        now = i
        if ans>now:
            ans = now
print(ans)


### FIXED CODE ###

import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

H,W = II()
A,B,C = [],[],[]
for i in range(H):
    A.append(III())
for i in range(H):
    B.append(III())
for i in range(H):
    C.append([abs(A[i][j]-B[i][j]) for j in range(W)])

def calc(n):
    return n+80*(H+W-1)

d = [[0]*W for _ in range(H)]
for i in range(H):
    for j in range(W):
        if i==0 and j==0:
            d[i][j] = 2**calc(-C[i][j]) | 2**calc(C[i][j])
        elif i==0:
            d[i][j] = (d[i][j-1]<<C[i][j]) | (d[i][j-1]>>C[i][j])
        elif j==0:
            d[i][j] = (d[i-1][j]<<C[i][j]) | (d[i-1][j]>>C[i][j])
        else:
            d[i][j] = (d[i][j-1]<<C[i][j]) | (d[i][j-1]>>C[i][j]) | \
                        (d[i-1][j]<<C[i][j]) | (d[i-1][j]>>C[i][j])

ans = (H+W-1)*80+1
for i in range(160*(H+W-1)+1):
    if (d[H-1][W-1]>>i)&1:
        val = abs(i-80*(H+W-1))
        if val<ans:
            ans = val

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

k,s=map(int,input().split())
upper  = min(k,s)+1
lower = max(0,s-2*k)
ans = 0
for i in range(lower,upper):
  for j in range(lower,upper):
    if i + j > s:
      break
    for k in range(lower,upper):
      if i+j+k == s:
        ans += 1
        break
print(ans)

### FIXED CODE ###

k,s=map(int,input().split())
upper  = min(k,s)+1
lower = max(0,s-2*k)
ans = 0
for i in range(lower,upper):
  for j in range(lower,upper):
    if 0 <= s-(i+j) <= k:
      ans += 1
print(ans)
### BUGGY CODE ###

# coding: utf-8
from functools import lru_cache
from itertools import accumulate as accum
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

@lru_cache(maxsize = None)
def f(l, r):
    if l == r:
        return(0)
    cost = float('inf')
    for x in range(l, r):
        cost_ = f(l, x) + f(x + 1, r)
        if cost_ < cost:
            cost = cost_
    return(cost + acsum[r] - acsum[l - 1])

n = int(input()) # 2 <= n <= 400
acsum = list(accum(map(int, input().split()))) + [0]
print(f(0, n - 1))


### FIXED CODE ###

# coding: utf-8

from itertools import accumulate as accum
import sys
input = sys.stdin.readline

def f2(n, a):
    acsum = list(accum(a)) + [0]
    dp = [[float('inf')] * n for _ in range(n)]
    for i in range(n):
        dp[i][i] = 0
        if i + 1 != n:
            dp[i][i + 1] = a[i] + a[i + 1]
    for i in range(n - 3, -1, -1):
        for j in range(i + 2, n):
            c = float('inf')
            dpi = dp[i]
            for x in range(i, j):
                c_ = dpi[x] + dp[x + 1][j]
                if c_ < c:
                    c = c_
            dpi[j] = c + acsum[j] - acsum[i - 1]
    return(dp[0][n - 1])

n = int(input()) # 2 <= n <= 400
a = list(map(int, input().split()))
print(f2(n, a))
### BUGGY CODE ###

import sys

N = int(input())
A = [int(x) for x in input().split(" ")]
product = 1
for a in A:
    product = product * a
if product > 10 ** 18:
    print(-1)
    sys.exit(0)

print(product)


### FIXED CODE ###

import sys

N = int(input())
A = [int(x) for x in input().split(" ")]
if 0 in set(A):
    print(0)
    sys.exit(0)

product = 1
for a in A:
    product = product * a
    if product > 10 ** 18:
        print(-1)
        sys.exit(0)


print(product)
### BUGGY CODE ###

n=int(input())
a,b=map(int,input().split())
if n!=1:
	for _ in range(n-1):
		A,B=map(int,input().split())
		c=0
		d=0
		k=1
		while a>c or b>d:
			c=k*A
			d=k*B
			k+=1
		a=c
		b=d
print(a+b)

### FIXED CODE ###

n=int(input())
a,b=map(int,input().split())
if n!=1:
	for _ in range(n-1):
		A,B=map(int,input().split())
		k=max(1,(a+A-1)//A,(b+B-1)//B)
		a=k*A
		b=k*B
print(a+b)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict

# UnionFind
class UnionFind:
    def __init__(self, n):
        self.parent = [i for i in range(n)]

    def root(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.root(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x != y:
            self.parent[x] = y

    def same(self, x, y):
        return self.root(x) == self.root(y)

N, K, L = map(int, input().split())
un = UnionFind(N)
for i in range(K):
    p, q = map(int, input().split())
    p -= 1
    q -= 1
    un.unite(p, q)
G = [[] for i in range(N)]
for i in range(L):
    r, s = map(int, input().split())
    r -= 1
    s -= 1
    G[r].append(s)
    G[s].append(r)
done = [False]*N
D = []
gid = 0
def dfs(i, gid):
    D[gid][un.root(i)] += 1
    done[i] = True
    for nex in G[i]:
        if done[nex]: continue
        dfs(nex, gid)
for i in range(N):
    if not done[i]:
        D.append(defaultdict(int))
        dfs(i, gid)
        gid += 1
ans = [0]*N
done = [False]*N
gid = 0
def dfs2(i, gid):
    done[i] = True
    ans[i] = D[gid][un.root(i)]
    for nex in G[i]:
        if done[nex]: continue
        dfs2(nex, gid)
for i in range(N):
    if not done[i]:
        dfs2(i, gid)
        gid += 1
print(*ans)


### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict

# UnionFind
class UnionFind:
    def __init__(self, n):
        self.parent = [i for i in range(n)]

    def root(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.root(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x != y:
            self.parent[x] = y

    def same(self, x, y):
        return self.root(x) == self.root(y)

N, K, L = map(int, input().split())
un = UnionFind(N)
for i in range(K):
    p, q = map(int, input().split())
    p -= 1
    q -= 1
    un.unite(p, q)
G = [[] for i in range(N)]
for i in range(L):
    r, s = map(int, input().split())
    r -= 1
    s -= 1
    G[r].append(s)
    G[s].append(r)
done = [False]*N
D = []
gid = 0
def dfs(i, gid):
    D[gid][un.root(i)] += 1
    done[i] = True
    for nex in G[i]:
        if done[nex]: continue
        dfs(nex, gid)
for i in range(N):
    if not done[i]:
        D.append(defaultdict(int))
        dfs(i, gid)
        gid += 1
ans = [0]*N
done = [False]*N
gid = 0
def dfs2(i, gid):
    done[i] = True
    ans[i] = D[gid][un.root(i)]
    for nex in G[i]:
        if done[nex]: continue
        dfs2(nex, gid)
for i in range(N):
    if not done[i]:
        dfs2(i, gid)
        gid += 1
print(*ans)
### BUGGY CODE ###

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

MOD = 10 ** 9 + 7


def gcd(a, b):
    while a and b:
        a, b = b, a % b
    return a if a > 0 else b


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


_lcm = A[0]
for i in range(1, N):
    _lcm = lcm(_lcm, A[i])

res = 0
for i, a in enumerate(A):
    res = (res + (_lcm * pow(A[i], MOD - 2, MOD))) % MOD

print(res)


### FIXED CODE ###

from fractions import gcd
import sys

input = sys.stdin.readline

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

MOD = 10 ** 9 + 7


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


l = A[0]
for a in A:
    l = lcm(l, a)

res = 0
for a in A:
    res = (res + (l * pow(a, MOD - 2, MOD)) % MOD) % MOD
    # res = (res + l // a) % MOD

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

n, q = map(int, input().split())
text = input()
cnt = 0
for i in range(q):
    l, r = map(int, input().split())
    target = text[l-1:r]
    print(target.count("AC"))

### FIXED CODE ###

N,Q=map(int,input().split())
S=input()
A=[0]*N
for i in range(1,N+1):
	if S[i-1:i+1]=="AC":
		A[i]+=1
for i in range(1,N):
	A[i]=A[i]+A[i-1]
for i in range(Q):
	l,r=map(int,input().split())
	print(A[r-1]-A[l-1])
### BUGGY CODE ###

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

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

### FIXED CODE ###

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

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

main()
### BUGGY CODE ###

import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from collections import Counter
    n = int(input())
    a = list(map(int, readline().split()))

    def factorization(n):
        factors = []

        while n % 2 == 0:
            factors.append(2)
            n //= 2

        for i in range(3, int(n ** 0.5) + 5, 2):
            while n % i == 0:
                factors.append(i)
                n //= i
        if n != 1:
            factors.append(n)

        return Counter(factors)

    a_fac = [0] * n

    for i, num in enumerate(a):
        a_fac[i] = factorization(num)

    lcm = Counter([1])

    for i, fac in enumerate(a_fac):
        add_temp = fac - lcm
        add = Counter({key: value for key, value in add_temp.items() if value > 0})
        lcm += add

    b = [0] * n
    ans = 0

    for i, fac in enumerate(a_fac):
        b_fac = lcm - fac
        temp = 1
        for key, value in b_fac.items():
            temp *= pow(key, value)
            temp %= MOD
        ans += temp
        ans %= MOD

    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from collections import Counter
    n = int(input())
    a = list(map(int, readline().split()))

    def factorization(n):
        factors = []

        while n % 2 == 0:
            factors.append(2)
            n //= 2

        for i in range(3, int(n ** 0.5) + 5, 2):
            while n % i == 0:
                factors.append(i)
                n //= i
        if n != 1:
            factors.append(n)

        return Counter(factors)

    a_fac = [0] * n

    for i, num in enumerate(a):
        a_fac[i] = factorization(num)

    lcm = {1: 1}

    for fac in a_fac:
        for key, value in fac.items():
            lcm[key] = max(lcm.get(key, 0), value)

    ans = 0

    lcmmod = 1

    for key, value in lcm.items():
        lcmmod *= pow(key, value, MOD)
        lcmmod %= MOD

    for ele in a:
        ainv = pow(ele, MOD - 2, MOD)
        ans += ((lcmmod*ainv) % MOD)
        ans %= MOD

    print(ans)


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

import bisect

N, T = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N)]

"""
a_x = 1 and b_x is t_i = 2*(t_i +2) 
n 店舗回るのに 2^nはかかる
30店舗以上は回れない
"""
AB.sort(key=lambda x: (-x[0], x[1]))

a0 = []
nab = []
for a, b in AB:
    if a == 0:
        a0.append(b)
    else:
        nab.append((a, b))
a0.sort()

nab.sort(key=lambda x: ((x[1] + 1) / x[0]))

a0sum = []  # key: n of visit, value : cost
_sum = 0
for b in a0:
    _sum += 1 + b
    a0sum.append(_sum)

dp = [[0] + [float('inf')] * 29 for _ in range(len(nab) + 1)]
for index, (a, b) in enumerate(nab):
    # print(a, b)
    for count in range(1, 29):
        dp[index + 1][count] = min(dp[index][count],
                                   dp[index][count - 1] + 1 + (dp[index][count - 1] + 1) * a + b)

ans = 0
# print(a0sum)
# print(nab)
# print(dp)
for count, t in enumerate(dp[-1]):
    if t > T:
        continue
    v = bisect.bisect_right(a0sum, T - t)
    ans = max(ans, v + count)
print(ans)


### FIXED CODE ###

import bisect

N, T = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N)]

"""
a_x = 1 and b_x is t_i = 2*(t_i +2) 
n 店舗回るのに 2^nはかかる
30店舗以上は回れない
"""

a0 = []
nab = []
for a, b in AB:
    if a == 0:
        a0.append(b)
    else:
        nab.append(((b + 1) / a, a, b))
a0.sort()

nab.sort()

a0sum = []  # key: n of visit, value : cost
_sum = 0
for b in a0:
    _sum += 1 + b
    a0sum.append(_sum)

INF = 1 << 32
dp = [0] + [INF] * 29
for index, (_, a, b) in enumerate(nab):
    # print(a, b)
    ndp = [0] + [INF] * 29
    for count in range(1, 29):
        ndp[count] = min(dp[count],
                         dp[count - 1] + 1 + (dp[count - 1] + 1) * a + b)
    dp = ndp

ans = 0
# print(a0sum)
# print(nab)
# print(dp)
for count, t in enumerate(dp):
    if t > T:
        continue
    v = bisect.bisect_right(a0sum, T - t)
    ans = max(ans, v + count)
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
n,t = map(int,input().split())
f = []
m = 0
for i in range(n):
  p,q = map(int,input().split())
  m = max(m,p)
  f.append((p,q))
  
f.sort()
dp = [[0]*(t+m) for i in range(n+1)]

for i,c in enumerate(f):
  a,b = c
  for j in range(t+m):
    if j < a or j-a >= t:
      dp[i+1][j] = dp[i][j]
    else:
      dp[i+1][j] = max(dp[i][j],dp[i][j-a]+b)
      
print(max(dp[n]))

### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
n,t = map(int,readline().split())
f = []
m = 0
for i in range(n):
  p,q = map(int,readline().split())
  m = max(m,p)
  f.append((p,q))
  
f.sort()
dp = [[0]*(t+m) for i in range(n+1)]

for i,c in enumerate(f):
  a,b = c
  for j in range(t+m):
    if j < a or j-a >= t:
      dp[i+1][j] = dp[i][j]
    else:
      dp[i+1][j] = max(dp[i][j],dp[i][j-a]+b)
      
print(max(dp[n]))
### BUGGY CODE ###

from collections import deque
x = int(input())
que = deque()
count = 0

que.append((count, 0, 0, 0))

while len(que) > 0:
    depth, v1, v2, v3 = que.popleft()
    if any([val == x for val in (v1, v2, v3)]):
        break
    depth += 1
    for v in (v1, v2, v3):
        que.append((depth, v - depth, v, v + depth))

print(depth)


### FIXED CODE ###

x = int(input())

t = 0
s = 0
while s < x:
    t += 1
    s += t
print(t)
### BUGGY CODE ###

import math
X = int(input())
time = X
for i in range(X+1):
    if i > time: continue
    n = - 1 + math.sqrt(1+8*(X-i))
    if n < 2*i and n%2 == 0:
        time = min(time, i)
print(time)

### FIXED CODE ###

import math
X = int(input())
n =  math.ceil((math.sqrt(1+8*X) - 1)/2)
ans = n
print(ans)
### BUGGY CODE ###

def cal():
    x = input()
    i = 0
    while i <= 10**4:
        i += 1
        x = x.replace('ST', '', 10**5)
    print(len(x))

cal()


### FIXED CODE ###

x = input()
ans = []

for i in x:
    if i == 'S':
        ans.append(i)
    else:
        if len(ans) == 0 or ans[-1] == 'T':
            ans.append(i)
        else:
            ans.pop()
print(len(ans))
### BUGGY CODE ###

nn,*a=open(0).read().split()
n=int(nn)
cnt=0
for left in range(n-1):
  for right in range(left+1,n):
    b=[i for i in a[right][:]]
    for leng in range(10):
      flg=True
      if a[left][leng] in b:
        b.remove(a[left][leng])
      else:  
        flg=False
        break
    if flg:
      cnt+=1
print(cnt)      

### FIXED CODE ###

from scipy.misc import comb
n=int(input())
d={}
cnt=0
for i in range(n):
  a=[i for i in input()]
  a.sort()
  b="".join(a)
  d[b]= d[b]+1 if b in d else 1
for k,v in d.items():
  cnt+=comb(v,2,exact=True)
print(cnt)
### BUGGY CODE ###

import collections
# s = [[]]
n, m = map(int,input().split())
s = [list(map(int,input().split())) for i in range(m)]

# n, m = 4, 2
# s = [[1,3], [2,4]]
new = [[] for i in range(m)]
for i in range(m):
    for j in range(s[i][0],s[i][-1]+1):
        new[i].append(j)
tmp = [flatten for inner in new for flatten in inner]
c = collections.Counter(tmp)
count = 0
for i, num in c.most_common():
    if num == m:
        count += 1
    else:
        break
print(count)

### FIXED CODE ###

import collections
# s = [[]]
n, m = map(int,input().split())
s = [list(map(int,input().split())) for i in range(m)]

# n, m = 4, 2
# s = [[1,3], [2,4]]

if m == 1:
    print(s[0][-1] - s[0][0] + 1)
else:
    l = s[0][0]
    r = s[0][1]
    for i in range(1,m):
        l = max(l,s[i][0])
        r = min(r,s[i][1])
    print(max(r-l+1,0))
### BUGGY CODE ###

n, q = map(int, input().split())
gu = [[] for _ in range(n)]
gl = [[] for _ in range(n)]

def upper(a,b):
  if gu[a] == []:
    gl[a].append(b)
  else:
    gl[a].append(b)
    for l in gu[a]:
      upper(l, b)

for i in range(n-1):
  a, b = map(int,input().split())
  a, b = a-1, b-1
  gu[b].append(a)
  upper(a,b)

#print(gu)
#print(gl)

c = [0]*n
for j in range(q):
  x, p = map(int, input().split())
  x = x-1
  c[x] += p
  for k in gl[x]:
    c[k] += p

print(' '.join(map(str, c)))

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

n, q = map(int, input().split())
g = [[] for _ in range(n)]
for i in range(n-1):
  a, b = map(int, input().split())
  a, b = a-1, b-1
  g[a].append(b)
  #g[b].append(a)

ans = [0]*n  
for j in range(q):
  p, x = map(int, input().split())
  ans[p-1] += x
  
from collections import deque
s = deque()
s.append(0)

while s:
  v = s.pop()
  for v_ in g[v]:
    ans[v_] += ans[v]
    s.append(v_)

print(' '.join(map(str, ans)))
### BUGGY CODE ###

import numpy as np
n, W = map(int, input().split())
wv = []
for i in range(n):
    wv.append(list(map(int, input().split())))
dp = np.zeros(W+1, dtype=np.int64)

for w, v in wv:
    for j in range(W, w-1, -1):
        dp[j] = max(dp[j], dp[j-w]+v)
print(dp[-1])

### FIXED CODE ###

def dp():
    n, W = map(int, input().split())
    wv = (map(int, input().split()) for _ in range(n))
    dp = [0] * (W+1)

    for w, v in wv:
        for j in range(W, w-1, -1):
            DP = dp[j-w] + v
            if dp[j] < DP:
                dp[j] = DP
    return max(dp)
print(dp())
### BUGGY CODE ###

import math
k = int(input())
ans = 0
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            ans += math.gcd(c,math.gcd(a, b)) 
print(ans)


### FIXED CODE ###

import math
k = int(input())
ans = 0
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            ans += math.gcd(c,math.gcd(a, b)) 
print(ans)
### BUGGY CODE ###

h,w,d=map(int,input().split())
box=[list(map(int,input().split())) for i in range(h)]
adress={}
for i in range(h):
    for j in range(w):
        adress[box[i][j]]=[i+1,j+1]
q=int(input())
order=[list(map(int,input().split())) for i in range(q)]
for x,y in order:
    point=[]
    ans=0
    if x-y==0:print(0);continue
    try:
        for i in range(x,y+1,d):
            point.append(adress[i])
        for j in range(len(point)-1):
            ans +=abs(point[j+1][0]-point[j][0])+abs(point[j+1][1]-point[j][1])
        print(ans)
    except:print(0)

### FIXED CODE ###

H, W, D = map(int, input().split())
m = [None] * (H * W + 1)
for i in range(H):
    l = map(int, input().split())
    for j, a in enumerate(l):
        m[a] = (i, j)
Q = int(input())
LR = []
for _ in range(Q):
    l, r = map(int, input().split())
    LR.append((l, r))
 
S = [0] * (H * W + 1)
for k in range(D + 1, H * W + 1):
    x, y = m[k]
    i, j = m[k - D]
    S[k] = S[k - D] + abs(x - i) + abs(y - j)
 
for l, r in LR:
    print(S[r] - S[l])
### BUGGY CODE ###

from bisect import bisect_left as bisect

s, t = input(), input()
lens = len(s)


def index(I, CNT, ANS):
    LIST = alp[ord(I) - 97]
    NUM = bisect(LIST, CNT)
    ANS += (NUM == len(LIST)) * lens
    CNT = (LIST[NUM % len(LIST)] + 1) % lens
    return ANS, CNT

if not all(i in s for i in t):
    print(-1)
    exit()

alp = [[] for i in range(26)]
for i, si in enumerate(s):
    alp[ord(si) - 97].append(i)

ans, cnt = 1 - lens, 0
for i in t:
    ans += (cnt == 0) * lens
    ans, cnt = index(i, cnt, ans)
print(ans + (cnt - 1) % lens)


### FIXED CODE ###

from bisect import bisect_left as bisect
from collections import defaultdict


s, t = input(), input()
lens, sets = len(s), set(s)

if not all(i in sets for i in t):
    print(-1)
    exit()

alp = defaultdict(list)
for i, si in enumerate(s):
    alp[si].append(i)

ans, cnt = 1 - lens, 0
for i in t:
    ans += lens * (cnt == 0)
    num = bisect(alp[i], cnt)
    ans += lens * (num == len(alp[i]))
    cnt = (alp[i][num % len(alp[i])] + 1) % lens 
print(ans + (cnt - 1) % lens)
### BUGGY CODE ###

a,b,k=map(int, input().split())
for _ in range(k):
    if a>=1:
        a-=1
    elif b>=1:
        b-=1
    if a==0 and b==0:
        continue
print(a,b)

### FIXED CODE ###

import sys
a,b,k=map(int, input().split())
l=k-a
if l<0:
    print(a-k,b)
    sys.exit()
m=l-b
if m<0:
    print(0,b-l)
    sys.exit()
else:
    print(0,0)
    sys.exit()
### BUGGY CODE ###

x,y,z,q=map(int,input().split())
a=sorted(map(int,input().split()),reverse=True)
b=sorted(map(int,input().split()),reverse=True)
c=sorted(map(int,input().split()),reverse=True)

def bisect(l,r):
  cnt=(l+r)//2
  if cnt==l:
    return l-1+judge(l)
  if judge(cnt):
    return bisect(cnt+1,r)
  else:
    return bisect(l,cnt)
def judge(thr):
  m=0
  for i in a:
    for j in b:
      for k in c:
        if i+j+k<thr:
          break
        m+=1
        if m>=q:
          return True
  return False
def make(thr):
  m=0
  l=[]
  for i in a:
    for j in b:
      for k in c:
        n=i+j+k
        if n<thr+1:
          break
        m+=1
        l+=[n]
  l.sort(reverse=True)
  return l+[thr]*(q-len(l))
thr=bisect(0,a[0]+b[0]+c[0]+1)
ans=make(thr)
for w in ans:
  print(w)

### FIXED CODE ###

x,y,z,q=map(int,input().split())
a=sorted(map(int,input().split()),reverse=True)
b=sorted(map(int,input().split()),reverse=True)
c=sorted(map(int,input().split()),reverse=True)
 
def bisect(l,r):
  cnt=(l+r)//2
  if cnt==l:
    return l-1+judge(l)
  if judge(cnt):
    return bisect(cnt+1,r)
  else:
    return bisect(l,cnt)
def judge(thr):
  m=0
  for i in range(x):
    for j in range(y):
      if i*j>q:
        break
      for k in range(z):
        if i*j*k>q or a[i]+b[j]+c[k]<thr:
          break
        m+=1
        if m>=q:
          return True
  return False
def make(thr):
  m=0
  l=[]
  for i in a:
    for j in b:
      for k in c:
        n=i+j+k
        if n<thr+1:
          break
        m+=1
        l+=[n]
  l.sort(reverse=True)
  return l+[thr]*(q-len(l))
thr=bisect(0,a[0]+b[0]+c[0]+1)
ans=make(thr)
for w in ans:
  print(w)