a = list([ord(x)-ord("a") for x in list(eval(input()))])

n = len(a)

m = 26



b = [1]*(n+1)

prev = [n]*m

G = [[] for i in range(n+1)]

for i in reversed(list(range(n))):

    ai = a[i]

    tmp = min(b[j] for j in prev)

    for j in prev:

        G[i].append(j)

    b[i] = tmp+1

    prev[ai] = i



cnt = min(b[j] for j in prev)

edge = prev

ans = []

for _ in range(cnt):

    for i, to in enumerate(edge):

        if b[to] == cnt-_:

            ans.append(chr(ord("a")+i))

            edge = G[to]

            break

print(("".join(ans)))
a = list([ord(x)-ord("a") for x in list(eval(input()))])

n = len(a)

m = 26



b = [0]*n

pos = [[] for i in range(m)]

s = set()

cnt = 0

for i in reversed(list(range(n))):

    b[i] = cnt

    if a[i] not in s:

        s.add(a[i])

    pos[a[i]].append(i)

    if len(s) == m:

        cnt += 1

        s = set()



for i in range(m):

    pos[i].sort()



k = cnt+1



from bisect import bisect_right



ans = []

cur = -1

for i in range(k):

    for j in range(m):

        pj = bisect_right(pos[j], cur)

        if pj == len(pos[j]):

            ans.append(j)

            break

        to = pos[j][pj]

        if b[to] != k-i-1:

            cur = to

            ans.append(j)

            break



ans = "".join(chr(ord("a")+i) for i in ans)

print(ans)

a = list([ord(x) - ord("a") for x in list(eval(input()))])
n = len(a)
m = 26
b = [1] * (n + 1)
prev = [n] * m
G = [[] for i in range(n + 1)]
for i in reversed(list(range(n))):
    ai = a[i]
    tmp = min(b[j] for j in prev)
    for j in prev:
        G[i].append(j)
    b[i] = tmp + 1
    prev[ai] = i
cnt = min(b[j] for j in prev)
edge = prev
ans = []
for _ in range(cnt):
    for i, to in enumerate(edge):
        if b[to] == cnt - _:
            ans.append(chr(ord("a") + i))
            edge = G[to]
            break
print(("".join(ans)))

a = list([ord(x) - ord("a") for x in list(eval(input()))])
n = len(a)
m = 26
b = [0] * n
pos = [[] for i in range(m)]
s = set()
cnt = 0
for i in reversed(list(range(n))):
    b[i] = cnt
    if a[i] not in s:
        s.add(a[i])
    pos[a[i]].append(i)
    if len(s) == m:
        cnt += 1
        s = set()
for i in range(m):
    pos[i].sort()
k = cnt + 1
from bisect import bisect_right

ans = []
cur = -1
for i in range(k):
    for j in range(m):
        pj = bisect_right(pos[j], cur)
        if pj == len(pos[j]):
            ans.append(j)
            break
        to = pos[j][pj]
        if b[to] != k - i - 1:
            cur = to
            ans.append(j)
            break
ans = "".join(chr(ord("a") + i) for i in ans)
print(ans)

-b = [1] * (n + 1) -prev = [n] * m -G = [[] for i in range(n + 1)] +b = [0] * n +pos = [[] for i in range(m)] +s = set() +cnt = 0 -    ai = a[i] -    tmp = min(b[j] for j in prev) -    for j in prev: -        G[i].append(j) -    b[i] = tmp + 1 -    prev[ai] = i -cnt = min(b[j] for j in prev) -edge = prev +    b[i] = cnt +    if a[i] not in s: +        s.add(a[i]) +    pos[a[i]].append(i) +    if len(s) == m: +        cnt += 1 +        s = set() +for i in range(m): +    pos[i].sort() +k = cnt + 1 +from bisect import bisect_right + -for _ in range(cnt): -    for i, to in enumerate(edge): -        if b[to] == cnt - _: -            ans.append(chr(ord("a") + i)) -            edge = G[to] +cur = -1 +for i in range(k): +    for j in range(m): +        pj = bisect_right(pos[j], cur) +        if pj == len(pos[j]): +            ans.append(j) -print(("".join(ans))) +        to = pos[j][pj] +        if b[to] != k - i - 1: +            cur = to +            ans.append(j) +            break +ans = "".join(chr(ord("a") + i) for i in ans) +print(ans)