#include <iostream>
#include <climits>
using namespace std;
int main() {
int rec[3][26] = {0};
int dup[26] = {0};
string a, b, c;
cin >> a >> b >> c;
for (auto &n: a) {
rec[0][n - 'a']++;
}
for (auto &n: b) {
rec[1][n - 'a']++;
}
for (auto &n: c) {
rec[2][n - 'a']++;
}
int l = 0, r = 0;
int ans = 0;
bool flag = true;
for (int i = 0; flag; ++i) {
int cur = INT_MAX;
for (int j = 0; j < 26; ++j) {
if (rec[2][j] != 0) {
cur = min(cur, rec[0][j] / rec[2][j]);
}
}
if (cur + i > ans) {
ans = cur + i;
l = i, r = cur;
for (int j = 0; j < 26; ++j) {
dup[j] = rec[0][j];
dup[j] -= cur * rec[2][j];
}
}
// cout << "for: " << cur << ", " << i << endl;
for (int j = 0; j < 26; ++j) {
rec[0][j] -= rec[1][j];
if (rec[0][j] < 0) {
flag = false;
break;
// goto L1;
}
}
}
L1:
for (int i = 0; i < l; ++i) {
// cout << b;
printf("%s", b.c_str());
}
for (int i = 0; i < r; ++i) {
// cout << c;
printf("%s", c.c_str());
}
if (l + r == 0) {
printf("%s", a.c_str());
} else {
for (int i = 0; i < 26; ++i) {
for (int j = 0; j < dup[i]; ++j) {
printf("%c", i + 'a');
// cout << (char)(i + 'a');
}
}
}
}
1516B - AGAGA XOOORRR | 1515A - Phoenix and Gold |
1515B - Phoenix and Puzzle | 155A - I_love_username |
49A - Sleuth | 1541A - Pretty Permutations |
1632C - Strange Test | 673A - Bear and Game |
276A - Lunch Rush | 1205A - Almost Equal |
1020B - Badge | 1353A - Most Unstable Array |
770A - New Password | 1646B - Quality vs Quantity |
80A - Panoramix's Prediction | 1354B - Ternary String |
122B - Lucky Substring | 266B - Queue at the School |
1490A - Dense Array | 1650B - DIV + MOD |
1549B - Gregor and the Pawn Game | 553A - Kyoya and Colored Balls |
1364A - XXXXX | 1499B - Binary Removals |
1569C - Jury Meeting | 108A - Palindromic Times |
46A - Ball Game | 114A - Cifera |
776A - A Serial Killer | 25B - Phone numbers |