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

X,Y,Z,K = map(int,input().split())
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)
xy=[]
for a in A[:K]:
    for b in B[:K]:
        xy.append(a+b)
xy=sorted(xy,reverse=True)
xy=xy[:K]
xyz=[]
for x in xy[:K]:
    for c in C:
        xyz.append(x+c)
xyz=sorted(xyz,reverse=True)
for i in range(K):
    print(xyz[i])


### FIXED CODE ###

X,Y,Z,K = map(int,input().split())
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)
xy=[]
for a in A:
    for b in B:
        xy.append(a+b)
xy=sorted(xy,reverse=True)
xy=xy[:K]
xyz=[]
for c in C:
    for x in xy:
        xyz.append(x+c)
xyz=sorted(xyz,reverse=True)
for i in range(K):
    print(xyz[i])
### BUGGY CODE ###

import sys
input = sys.stdin.readline

n, k = map(int,input().split())
h = sorted([int(input()) for _ in range(n)])

hh = [h[i+1] - h[i] for i in range(n-1)]

ans = float("inf")
for i in range(n-k+1):
    ans = min([ans, sum(hh[i:i+k-1])])

print(ans)

### FIXED CODE ###

n,k = map(int, input().split())
h = [int(input()) for i in range(n)]
h.sort()
print(min(h[i+k-1] - h[i] for i in range(n-k+1)))
### BUGGY CODE ###


N=int(input())
A=list(map(int,input().split()))
A.sort()
def main():
    a=0
    s=set()
    t=0
    if A[0]!=1:
        for i in A:
            if i in s:
                if t==i:
                    a-=1
                    t=0
                continue
            for j in range(2,1001):
                if i%j:
                    continue
                if j in s:
                    break
                if i//j in s:
                    break
            else:
                t=i
                a+=1
            s.add(i)
    else:
        if N>1 and A[1]==1:
            a=0
        else:
            a=1
    print(a)
main()

### FIXED CODE ###

from math import sqrt
from time import perf_counter
t0=perf_counter()
N=int(input())
A=list(map(int,input().split()))
A.sort()
def main():
    a=0
    s=set()
    t=0
    if A[0]!=1:
        for i in A:
            if i in s:
                if t==i:
                    a-=1
                    t=0
                continue
            for j in range(2,int(sqrt(i)+1.1)):
                if i%j:
                    continue
                if j in s:
                    break
                if i//j in s:
                    break
            else:
                t=i
                a+=1
            s.add(i)
            if perf_counter()-t0>1.9:
                a=N
                break                
    else:
        if N>1 and A[1]==1:
            a=0
        else:
            a=1
    print(a)
main()
### BUGGY CODE ###

#21:10
h,w = map(int,input().split())
raw = []
for x in range(h):
  raw.append(input())
xx = []
for x in range(h):
  now = []
  tmp = 0
  for y in range(w):
    if raw[x][y] == '.':
      tmp += 1
    else:
      now += [tmp] * tmp
      tmp = 0
      now.append(0)
  now += [tmp] * tmp
  xx.append(now)
yy = []
for y in range(w):
  now = []
  tmp = 0
  for x in range(h):
    if raw[x][y] == '.':
      tmp += 1
    else:
      now += [tmp] * tmp
      tmp = 0
      now.append(0)
  now += [tmp] * tmp
  yy.append(now)
'''
for x in range(h):
  print(xx[x])
for y in range(w):
  print(yy[y])
'''
maxi = 0
for x in range(h):
  for y in range(w):
    maxi = max(maxi,xx[x][y]+yy[y][x]-1)
print(maxi)

### FIXED CODE ###

#21:10
h,w = map(int,input().split())
raw = []
for x in range(h):
  raw.append(input())
xx = []
for x in range(h):
  now = []
  tmp = 0
  for y in range(w):
    if raw[x][y] == '.':
      tmp += 1
    else:
      now += [tmp] * tmp
      tmp = 0
      now.append(0)
  now += [tmp] * tmp
  xx.append(now)
yy = []
for y in range(w):
  now = []
  tmp = 0
  for x in range(h):
    if raw[x][y] == '.':
      tmp += 1
    else:
      now += [tmp] * tmp
      tmp = 0
      now.append(0)
  now += [tmp] * tmp
  yy.append(now)
'''
for x in range(h):
  print(xx[x])
for y in range(w):
  print(yy[y])
'''
maxi = 0
for x in range(h):
  for y in range(w):
    maxi = max(maxi,xx[x][y]+yy[y][x]-1)
print(maxi)
### BUGGY CODE ###

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

aaa = list(map(int, input().strip().split()))
h = sum(aaa)

for i in range(a):
  maxat = max(aaa)
  h -= maxat

if h <= 0:
  h = 0
print(h)

### FIXED CODE ###

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

if n <= a:
  print(0)
else:
  aaa = list(map(int, input().strip().split()))

  aaa = sorted(aaa, reverse=True)
  h = 0
  for i in range(a, n):
    h += aaa[i]

  print(h)
### BUGGY CODE ###

n, k = map(int, input().split())
c = list(map(int, input().split()))
ans = float('Inf')
for i in range(n-k+1):
  temp = c[i:i+k]
  l, r = abs(temp[0]), abs(temp[-1])
  if temp[0] < 0 and temp[-1] > 0:
    ans = min(ans, min(l, r) * 2 + max(l, r))
  else:
    ans = min(ans, max(map(abs, temp)))
print(ans)

### FIXED CODE ###

n, k = map(int, input().split())
c = list(map(int, input().split()))
ans = float('Inf')
for i in range(n-k+1):
  l, r = c[i], c[i+k-1]
  ans = min(abs(l) + abs(r-l), abs(r) + abs(r-l), ans)

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

import math

n, d, a = map(int,input().split())
xh = [[0 for i in range(2)] for j in range(n)]
for i in range(n):
    x,h = map(int,input().split())
    xh[i] = [x,h]

num = 0
xh.sort(key=lambda xh:xh[0])

dam = [0]*n
for i in range(n):
    res = xh[i][1]-dam[i]
    pos = xh[i][0]
    if res > 0:
        nat = math.ceil(res/a)
        num += nat
        for j in range(i+1,n):
            if xh[j][0]-d <= pos + d:
                dam[j] += a*nat
            else:
                break
print(num)


### FIXED CODE ###

import math

n, d, a = map(int,input().split())
xh = [[0 for i in range(2)] for j in range(n)]
left = [i for i in range(n)]
for i in range(n):
    x,h = map(int,input().split())
    xh[i] = [x,h]

num = 0
xh.sort(key=lambda xh:xh[0])

for i in range(n):
    for j in range(left[i-1],i):
        if xh[j][0]+d >= xh[i][0]-d:
            left[i] = j
            break

dam = [0]*n

def dsum(k):
    if k == 0:
        return 0
    elif left[k] == 0:
        return dam[k-1]
    else:
        return dam[k-1]-dam[left[k]-1]

for i in range(n):
    res = xh[i][1]-dsum(i)
    nat = max([math.ceil(res/a),0])
    dam[i] = dam[i-1]+a*nat
    if res > 0:
        num += nat

print(num)
### BUGGY CODE ###

N, K, Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]

import numpy as np
scores = np.array([K]*N)

for a in A:
    scores -= 1
    scores[a-1] += 1
    
print(*["Yes" if x else "No" for x in scores > 0], sep="\n")

### FIXED CODE ###

N, K, Q, *A = map(int, open(0).read().split())

import numpy as np
answered = np.array([0]*N)

for a in A:
    answered[a-1] += 1

for s in answered + K - len(A):
    if s > 0:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

memo = {}


def furoshiki(i, w_limit):
    global memo, treasures

    if not i or not w_limit:
        return (0, 0)

    if (i, w_limit) in memo:
        return memo[(i, w_limit)]

    v, w = treasures[i - 1]
    not_stole = furoshiki(i - 1, w_limit)
    if w_limit < w:
        return not_stole
    stole_v_total, stole_w_total = furoshiki(i - 1, w_limit - w)
    stole_v_total += v
    stole_w_total -= w
    return max(not_stole, (stole_v_total, stole_w_total))


case = 1
while True:
    w = int(input())
    if not w:
        break
    n = int(input())
    treasures = [None] * n
    for i in range(n):
        treasures[i] = tuple(map(int, input().split(',')))

    total_v, total_w = furoshiki(n, w)
    print('Case {}:'.format(case))
    print(total_v)
    print(-total_w)
    memo.clear()
    case += 1

### FIXED CODE ###

case = 1
while True:
    w_limit = int(input())
    if not w_limit:
        break
    n = int(input())
    treasures = [tuple(map(int, input().split(','))) for _ in range(n)]

    furoshiki = [0] * (w_limit + 1)
    for v, w in treasures:
        for j in range(w_limit, w - 1, -1):
            furoshiki[j] = max(furoshiki[j], furoshiki[j - w] + v)

    max_v = max_v_w = 0
    for w in range(w_limit + 1):
        if furoshiki[w] > max_v:
            max_v = furoshiki[w]
            max_v_w = w

    print('Case {}:'.format(case))
    print(max_v)
    print(max_v_w)
    case += 1
### BUGGY CODE ###

def z_array(pattern, text):
    str = pattern + '$' + text
    matchsize = 0
    for i in range(len(str)-1):
        j = 0
        while (i+1+j <= len(str)-1 and str[j] == str[i+1+j]):
            j += 1
        if(matchsize < j): matchsize = j
    return matchsize

def main(size, text):
    length = 0
    for i in range(size-1):
        z = z_array(text[i+1:size], text[:i+1])
        if(length < z):
            length = z
    return length

size = int(input())
text = input()
print(main(size, text))

### FIXED CODE ###

def main(size, text):
    pattern = ""
    matchlen = 0

    for i in range(size):
        pattern += text[i]
        while (len(pattern) > 0 and len(pattern) <= len(text[i+1:])):
            if pattern in text[i+1:]:
                matchlen = max(matchlen, len(pattern))
                break
            else:
                pattern = pattern[1:]
    
    return matchlen

if __name__ == '__main__':
    N = int(input())
    S = input()
    print (main(N, S))
### BUGGY CODE ###

# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

n = int(input())
a = [int(i) for i in readline().split()]
b = [int(i) for i in readline().split()]

from bisect import bisect_left as bl
from itertools import accumulate

def f(a,b,k,cnta,accb): #k桁目のxor
    p1 = 1<<k
    p2 = p1<<1
    p3 = p1+p2
    
    res = 0
    if k > N:
        bisect_left=bl
        b = sorted(i&(p2-1) for i in b)
        for ai in a:
            ai &= (p2-1)
            if p1 > b[0]: j1 = bisect_left(b,p1-ai)
            else: j1 = 0
            j2 = bisect_left(b,p2-ai)
            if p3 - ai > b[-1]: j3 = n
            else: j3 = bisect_left(b,p3-ai)
            res += j2-j1+n-j3
        return (res&1)<<k
    else:
        for ai,num in enumerate(cnta):
            if num == 0: continue
            
            #print(cnta,accb,p1,p2,p3,ai+1)
            j1 = j2 = j3 = 0
            if p1-ai-1 >= 0:
                j1 = accb[p1-ai-1]
            if p2-ai-1 >= 0:
                j2 = accb[p2-ai-1]
            if p3-ai-1 >= 0:
                j3 = accb[p3-ai-1]
            res += num&(j2-j1+n-j3)
            
            #print(res,cnta,accb,p1,j1,j2,j3,n)
        return (res&1)<<k
            






N = 17
cnta = 0
accb = [0]

ans = 0
for k in range(28,-1,-1):
    if k == N:
        N2 = 1<<(N+1)
        cnta = [0]*N2
        cntb = [0]*N2
        N2 -= 1
        for i in a: cnta[i&N2] += 1
        for i in b: cntb[i&N2] += 1
        accb = list(accumulate(cntb)) + [n]*(N2+1)
        
    if k < N:
        cnta = [i+j for i,j in zip(cnta[:(1<<(k+1))],cnta[(1<<(k+1)):])]
        cntb = [i+j for i,j in zip(cntb[:(1<<(k+1))],cntb[(1<<(k+1)):])]
        accb = list(accumulate(cntb)) + [n]*(1<<(k+1))
        
    #print(cnta)
    ans |= f(a,b,k,cnta,accb)

print(ans)    









### FIXED CODE ###

# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

n = int(input())
a = [int(i) for i in readline().split()]
b = [int(i) for i in readline().split()]

from bisect import bisect_left


ans = 0

for k in range(29):
    a0 = []
    a1 = []
    a0a = a0.append
    a1a = a1.append
    
    b0 = []
    b1 = []
    b0a = b0.append
    b1a = b1.append
    for i in a: #基数ソート
        if i&(1<<k): a1a(i)
        else: a0a(i)
    for i in b: #基数ソート
        if i&(1<<k): b1a(i)
        else: b0a(i)
    
    a = a0+a1
    b = b0+b1
    mask = (1<<(k+1))-1
    
    aa = [i&mask for i in a]
    bb = [i&mask for i in b]
    
    res = 0
    p1 = 1<<k
    p2 = mask+1
    p3 = p1+p2

    j1=j2=j3=0    
    for ai in reversed(aa):
        while j1 < n and ai+bb[j1] < p1:
            j1 += 1
        while j2 < n and ai+bb[j2] < p2:
            j2 += 1
        while j3 < n and ai+bb[j3] < p3:
            j3 += 1
        res += j2-j1+n-j3
        #if k < 3: print(ai,p2,res,bb,j1,j2,j3,n)
        #print(bb,p2,ai,j1,j2,j3,n,"R",res)    
    ans |= (res&1)<<k
    



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

n = int(input())

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

b = []

for i in range(n-1,0,-2):
    print(a[i],end="")
    a.pop(i)
    print(" ",end="")
print(" ".join(map(str,a)))

    



### FIXED CODE ###

n = int(input())

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

b = []

for i in range(n-1,0,-2):
    print(a[i],end="")
    a.pop(i)
    print(" ",end="")
print(" ".join(map(str,a)))
### BUGGY CODE ###

N = int(input())
S = input()

count = 0

for i in range(0, N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            if i -j == j - k:
                continue
            if S[i] != S[j] and S[k] != S[j] and S[i] != S[k]:
                count += 1
print(count)

### FIXED CODE ###

N = int(input())
S = input()

count = 0

R_count = [0] * (N+1)
R = 0
G_count = [0] * (N+1)
G = 0
B_count = [0] * (N+1)
B = 0

for i, s in enumerate(reversed(list(S))):
    if s == 'R':
        R += 1
    if s == 'G':
        G += 1
    if s == 'B':
        B += 1

    R_count[N - i - 1] = R
    G_count[N-i-1] = G
    B_count[N-i-1] = B
# print(R_count)
# print(G_count)
# print(B_count)

for i in range(0, N-2):
    for j in range(i+1, N-1):
        if S[i] == S[j]:
            continue
        if (S[i] == 'R' and S[j] == 'G') or (S[i] == 'G' and S[j] == 'R'):
            count += B_count[j+1]
            if j + (j-i) < N and S[j + (j-i)] == 'B':
                count -= 1
        elif (S[i] == 'R' and S[j] == 'B') or (S[i] == 'B' and S[j] == 'R'):
            count += G_count[j+1]
            if j + (j-i) < N and S[j + (j-i)] == 'G':
                count -= 1
        if (S[i] == 'B' and S[j] == 'G') or (S[i] == 'G' and S[j] == 'B'):
            count += R_count[j+1]
            if j + (j-i) < N and S[j + (j-i)] == 'R':
                count -= 1
print(count)
### BUGGY CODE ###

from collections import deque

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

for i in range(N):
  d=deque(X)
  d.remove(X[i])
  d=list(d)
  d.sort()
  print(d[N//2-1])

### FIXED CODE ###

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

x=[]
for i in range(N):
  x.append(X[i])
x.sort()

for i in range(N):
  if X[i]<x[N//2]:
    print(x[N//2])
  else:
    print(x[N//2-1])
### BUGGY CODE ###

import sys
from itertools import accumulate
def input(): return sys.stdin.readline().strip()


def get_sieve_of_eratosthenes(n):
    """
    エラトステネスの篩。√N以下の数に対して2から順にその数の倍数を消していく。
    計算量は「調和級数」になるのがミソ。具体的には
        N/2 + N/3 + N/5 + ... + N/(√N) = N * (1/2 + 1/3 + 1/5 + ... + 1/√N)
                                       = N * loglog(√N) (素数の逆数和の発散スピードがこれ)
                                       = N(loglogN - log2)
    """
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        return []
    prime = [2]
    limit = int(n**0.5)
    data = [i + 1 for i in range(2, n, 2)]
    while True:
        p = data[0]
        if limit < p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]


def main():
    primes = get_sieve_of_eratosthenes(100000)
    like = [0] * 10**5
    for i in range(3, 10**5):
        if i in primes and (i + 1) // 2 in primes:
            like[i] = 1
    like = list(accumulate(like))

    q = int(input())
    for _ in range(q):
        l, r = map(int, input().split())
        if l < 3: l = 3
        if r < 3:
            print(0)
            continue
        print(like[r] - like[l - 1])



if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
from itertools import accumulate
def input(): return sys.stdin.readline().strip()


def get_sieve_of_eratosthenes(n):
    """
    エラトステネスの篩。√N以下の数に対して2から順にその数の倍数を消していく。
    計算量は「調和級数」になるのがミソ。具体的には
        N/2 + N/3 + N/5 + ... + N/(√N) = N * (1/2 + 1/3 + 1/5 + ... + 1/√N)
                                       = N * loglog(√N) (素数の逆数和の発散スピードがこれ)
                                       = N(loglogN - log2)
    """
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        return []
    prime = [2]
    limit = int(n**0.5)
    data = [i + 1 for i in range(2, n, 2)]
    while True:
        p = data[0]
        if limit < p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]


def main():
    primes = get_sieve_of_eratosthenes(100000)
    like = [0] * 10**5
    for i in range(3, 10**5):
        if i in primes and (i + 1) // 2 in primes:
            like[i] = 1
    like = list(accumulate(like))

    q = int(input())
    for _ in range(q):
        l, r = map(int, input().split())
        if l < 3: l = 3
        if r < 3:
            print(0)
            continue
        print(like[r] - like[l - 1])



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

def next_max(lst,mi,v):
    l, r = 0, mi-1
    while l <= r:
        mid = int((l+r)/2)
        if lst[mid] == v: return mid -1
        if lst[mid] > v:
            r = mid - 1
        else:
            l = mid + 1
    return r


N,Q = list(map(int,input().split()))
C = list(map(int,input().split()))
C.sort()
for i in range(Q):
    t = int(input())
    idx = N-1
    m = C[-1]% t
    idx = next_max(C,idx,C[idx]-m)
    while idx >= 0:
        amr = C[idx]%t
        m = max(m,amr) 
        idx = next_max(C,idx,C[idx]-amr)
    print(m)

### FIXED CODE ###

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

M = max(C)+1
t1 = [0]*(M)
for v in C:
    t1[v] = 1

t2 = [0]*(M)
v = 0
for i in range(M):
    if t1[i]:
        v = i
    t2[i] = v

for i in range(Q):
    t = int(input())
    n_v = M-1
    m = 0
    while n_v != 0:
        amr = n_v % t
        m = max(m, amr) 
        tmp = n_v-m-1
        if tmp <= 0: break
        n_v = t2[tmp]

    print(m)
### BUGGY CODE ###

from collections import deque
n , m = map(int, input().split())
keys = deque()
def trans(k):
    res = [0 for i in range(n)]
    for i in k:
        res[-i] = 1
    res = int("".join(map(str, res)), 2)
    return res

for i in range(m):
    a, b = list(map(int, input().split()))
    c = deque(list(map(int, input().split())))
    c.appendleft(a)
    keys.append(c)
inf = 10 ** 8
dp = [inf for i in range(2**n)]
dp[0] = 0
for i in range(m):
    key_value = keys[i].popleft()
    can_open = keys[i]
    for j in range(2**n):
        next = j | trans(can_open)
        dp[next] = min(dp[next], dp[j] + key_value)
#print(dp)
if dp[-1] >= inf:
    print(-1)
else:
    print(dp[-1])

### FIXED CODE ###

from collections import deque
n , m = map(int, input().split())
keys = deque()
def trans(k):
    res = [0 for i in range(n)]
    for i in k:
        res[-i] = 1
    res = int("".join(map(str, res)), 2)
    return res

for i in range(m):
    a, b = list(map(int, input().split()))
    c = deque(list(map(int, input().split())))
    c.appendleft(a)
    keys.append(c)
inf = 10 ** 8
dp = [inf for i in range(2**n)]
dp[0] = 0
for i in range(m):
    key_value = keys[i].popleft()
    can_open = keys[i]
    p = trans(can_open)
    for j in range(2**n):
        next = j | p
        dp[next] = min(dp[next], dp[j] + key_value)
#print(dp)
if dp[-1] >= inf:
    print(-1)
else:
    print(dp[-1])
### BUGGY CODE ###

N = int(input())
S = str(input())

white = 0
black = 0
ans = None

for i in range(N):
  white = S[0:i].count("#")
  black = S[i+1:N+1].count(".")
  if ans == None:
    ans = white+black
  else:
    ans = min(ans,white+black)

print(ans)


### FIXED CODE ###

N = int(input())
S = str(input())

white = S.count(".")
black = 0
ans = S.count(".")

for i in range(N):
  if S[i] == ".":
    white -=1
  else:
    black +=1
  ans = min(ans,white+black)

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

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *
		
s = input()
t = input()

dp = [[0]*(len(t)+1) for _ in range(len(s)+1)]



for i in range(len(s)):
	for j in range(len(t)):
		if s[i] == t[j]:
			dp[i+1][j+1] = dp[i][j] + 1
		else:
			dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j])


y = len(s)
x = len(t)
ans = ""
while 1:
	#print(y, x, ans)
	if x*y == 0:
		break
	elif s[y-1] == t[x-1]:
		ans += s[y-1]
		x -= 1
		y -= 1
	else:
		if dp[y][x] == dp[y-1][x]:
			y -= 1
		elif dp[y][x] == dp[y][x-1]:
			x -= 1

lcs  = dp[len(s)][len(t)]

q = deque([(len(s), len(t))])
common = [set() for _ in range(lcs)]

while q:
	#print(q)
	y, x =q.popleft()
	if x*y != 0 :
		if s[y-1] == t[x-1]:
			common[dp[y][x]-1].add(t[x-1])
			y -= 1
			x -= 1
			q.append((y, x))
		else:
			if dp[y][x] == dp[y-1][x]:
				q.append((y-1, x))

			if dp[y][x] == dp[y][x-1]:
				q.append((y, x-1))

print(*[list(common[i])[0] for i in range(lcs)], sep="")



### FIXED CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *
		
s = input()
t = input()
 
dp = [[0]*(len(t)+1) for _ in range(len(s)+1)]

for i in range(len(s)):
	for j in range(len(t)):
		if s[i] == t[j]:
			dp[i+1][j+1] = dp[i][j] + 1
		else:
			dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j])
            
y = len(s)
x = len(t)
ans = ""
while 1:
	#print(y, x, ans)
	if x*y == 0:
		break
	elif s[y-1] == t[x-1]:
		ans += s[y-1]
		x -= 1
		y -= 1
	else:
		if dp[y][x] == dp[y-1][x]:
			y -= 1
		elif dp[y][x] == dp[y][x-1]:
			x -= 1
            
print(ans[::-1])