Professor GukiZ doesn't accept string as they are. He likes to swap some letters in string to obtain a new one.

GukiZ has strings *a*, *b*, and *c*. He wants to obtain string *k* by swapping some letters in *a*, so that *k* should contain as many non-overlapping substrings equal either to *b* or *c* as possible. Substring of string *x* is a string formed by consecutive segment of characters from *x*. Two substrings of string *x* overlap if there is position *i* in string *x* occupied by both of them.

GukiZ was disappointed because none of his students managed to solve the problem. Can you help them and find one of possible strings *k*?
The first line contains string *a*, the second line contains string *b*, and the third line contains string *c* (1 ≤ |*a*|, |*b*|, |*c*| ≤ 10<sup class="upper-index">5</sup>, where |*s*| denotes the length of string *s*).

All three strings consist only of lowercase English letters. 

It is possible that *b* and *c* coincide.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

def func(x, y):
    xy = {}
    for i in x:
        if i in y:
            if i in xy:
                xy[i] += 1
            else:
                xy[i]  = 1
    for i in y:
        if i not in xy.keys():
            xy[i] = 0
    return xy

def max_str(x, y):

    buf = {}
    for i in x.keys():
        buf[i] = divmod(x[i], y[i])[0]
    if buf != {}:
        m = min(buf.values())
    else:
        m = 0
    return m

def constr(x, y):
    f1 = func(x, y)
    f2 = func(y, y)
    return (f1, f2, max_str(f1, f2))

def newmax(ax, ay, xx, yy, maxy):
    new_ax = copy.deepcopy(ax)

    for i in ay.keys():
        if i in ax.keys():
            new_ax[i] = max(new_ax[i] - yy[i]*maxy, 0)

    return (max_str(new_ax, xx))

import time
import copy

a   = input()
b   = input()
c   = input()

start = time.time()

(ab, bb, maxb) = constr(a, b)
(ac, cc, maxc) = constr(a, c)

maxb_new = newmax(ab, ac, bb, cc, maxc)
maxc_new = newmax(ac, ab, cc, bb, maxb)

if maxb+maxc_new > maxc+maxb_new:
    ans = b*maxb+c*maxc_new

else:
    ans = b*maxb_new+c*maxc


a = list(a)

for i in range(len(ans)):
    if ans[i] in a:
        a.remove(ans[i])

for i in range(len(a)):
    ans += a[i]

print(ans)
finish = time.time()
#print(finish - start)
