The new camp by widely-known over the country Spring Programming Camp is going to start soon. Hence, all the team of friendly curators and teachers started composing the camp's schedule. After some continuous discussion, they came up with a schedule s, which can be represented as a binary string, in which the i-th symbol is '1' if students will write the contest in the i-th day and '0' if they will have a day off.

At the last moment Gleb said that the camp will be the most productive if it runs with the schedule t (which can be described in the same format as schedule s). Since the number of days in the current may be different from number of days in schedule t, Gleb required that the camp's schedule must be altered so that the number of occurrences of t in it as a substring is maximum possible. At the same time, the number of contest days and days off shouldn't change, only their order may change.

Could you rearrange the schedule in the best possible way?

Input

The first line contains string s (1 ⩽ |s| ⩽ 500 000), denoting the current project of the camp's schedule.

The second line contains string t (1 ⩽ |t| ⩽ 500 000), denoting the optimal schedule according to Gleb.

Strings s and t contain characters '0' and '1' only.

Output

In the only line print the schedule having the largest number of substrings equal to t. Printed schedule should consist of characters '0' and '1' only and the number of zeros should be equal to the number of zeros in s and the number of ones should be equal to the number of ones in s.

In case there multiple optimal schedules, print any of them.

Examples

Input


101101
110


Output


110110

Input


10010110
100011


Output


01100011


Input


10
11100


Output


01

Note

In the first example there are two occurrences, one starting from first position and one starting from fourth position.

In the second example there is only one occurrence, which starts from third position. Note, that the answer is not unique. For example, if we move the first day (which is a day off) to the last position, the number of occurrences of t wouldn't change.

In the third example it's impossible to make even a single occurrence.

Difficulty: MEDIUM_HARD
Tags: String algorithms

Greedy algorithms
Skill types: Greedy algorithms

Starter code:

Solutions:
def kmp(s):
	p = [0] * len(s)
	idx = 0
	for i in range(1, len(s)):
		while idx > 0 and s[idx] != s[i]:
			idx = p[idx - 1]
		if s[idx] == s[i]:
			idx += 1
		p[i] = idx
	return idx

def solve(s, t, pref):
	f = [0, 0]
	f[0] = s.count('0')
	f[1] = s.count('1')
	i = 0
	ans = ''
	while f[0] or f[1]:
		if f[0] and (not f[1]):
			ans += '0'
			f[0] -= 1
		elif not f[0] and f[1]:
			ans += '1'
			f[1] -= 1
		elif t[i] == '0':
			ans += '0'
			f[0] -= 1
		else:
			ans += '1'
			f[1] -= 1
		i += 1
		if i == len(t):
			i = pref
	return ans
s = input()
t = input()
pref = kmp(t)
print(solve(s, t, pref))


def z_func(s: str):
	z = [0] * len(s)
	(left, right) = (0, 0)
	for i in range(1, len(s)):
		z[i] = max(0, min(z[i - left], right - i))
		while i + z[i] < len(s) and s[z[i]] == s[i + z[i]]:
			z[i] += 1
		if i + z[i] > right:
			(left, right) = (i, i + z[i])
	return z

def get_zeros_ones_count(s: str):
	zeros_count = 0
	ones_count = 0
	for digit in s:
		if digit == '0':
			zeros_count += 1
		else:
			ones_count += 1
	return (zeros_count, ones_count)
cur_timetable = input()
ideal_timetable = input()
(cur_zeros_count, cur_ones_count) = get_zeros_ones_count(cur_timetable)
ideal_z_values = z_func(ideal_timetable)
ideal_length = len(ideal_z_values)
max_pref_len = 0
for i in range(ideal_length - 1, ideal_length // 2 - 1, -1):
	if ideal_z_values[i] + i == ideal_length:
		if ideal_z_values[i] > max_pref_len:
			max_pref_len = ideal_z_values[i]
period = ideal_timetable[:ideal_length - max_pref_len] if max_pref_len != 0 else ideal_timetable
suffix = ideal_timetable[:max_pref_len] if max_pref_len != 0 else ''
(period_zeros, period_ones) = get_zeros_ones_count(period)
(suffix_zeros, suffix_ones) = get_zeros_ones_count(suffix)
res = []
while True:
	if period_ones > cur_ones_count or period_zeros > cur_zeros_count:
		break
	res.append(period)
	cur_ones_count -= period_ones
	cur_zeros_count -= period_zeros
if cur_zeros_count >= suffix_zeros and cur_ones_count >= suffix_ones:
	res.append(suffix)
	cur_ones_count -= suffix_ones
	cur_zeros_count -= suffix_zeros
if cur_ones_count != 0:
	res += ['1'] * cur_ones_count
if cur_zeros_count != 0:
	res += ['0'] * cur_zeros_count
print(''.join(res))


from collections import Counter

def zfun(s):
	if len(s) == 0:
		raise Exception('FU')
	if len(s) == 1:
		return 0
	pref___zfun = [0]
	for x in s[1:]:
		curr_zfun = pref___zfun[-1]
		while True:
			if s[curr_zfun] == x:
				pref___zfun.append(curr_zfun + 1)
				break
			elif curr_zfun == 0:
				pref___zfun.append(0)
				break
			else:
				curr_zfun = pref___zfun[curr_zfun - 1]
	return pref___zfun[-1]
origin = input()
t = input()
counts_total = Counter(origin)
counts_template = Counter(t)
ans = []
for s in counts_template:
	if counts_total[s] < counts_template[s]:
		print(origin)
		quit()
zf = zfun(t)
suff = list(t[zf:])
counts_suff = Counter(suff)
ans += list(t)
for s in counts_template:
	counts_total[s] -= counts_template[s]
go_on = True
for s in counts_suff:
	if counts_total[s] < counts_suff[s]:
		go_on = False
while go_on:
	for s in counts_suff:
		counts_total[s] -= counts_suff[s]
		if counts_total[s] < counts_suff[s]:
			go_on = False
	ans += suff
for s in counts_total:
	ans += [s] * counts_total[s]
print(''.join(ans))


s = input()
t = input()
overlap = t
tt = ''
for i in range(len(t) - 1):
	tt = tt + t[i]
	if t.endswith(tt):
		overlap = t[i + 1:]
zro = s.count('0')
mek = s.count('1')
zro_tum = t.count('0')
mek_tum = t.count('1')
zro_toxum = overlap.count('0')
mek_toxum = overlap.count('1')
if zro >= zro_tum and mek >= mek_tum:
	print(t, end='')
	zro -= zro_tum
	mek -= mek_tum
if zro_toxum:
	k = zro // zro_toxum
else:
	k = 10000000000
if mek_toxum:
	n = mek // mek_toxum
else:
	n = 10000000000
ans = min(n, k)
print(overlap * ans, end='')
zro -= zro_toxum * ans
mek -= mek_toxum * ans
print('0' * zro + '1' * mek)


def findNeedSubstring(s):
	n = len(s)
	rst = ''
	tmp = 0
	for i in range(1, n - 1, 1):
		if s[0:i] == s[n - i:n]:
			rst = s[0:i]
			tmp = i
	return s[tmp:n]

def polyHash(s):
	rst = [0] * (len(s) + 1)
	hashValue = 0
	for i in range(len(s)):
		hashValue = hashValue * alpha % TABLE_SIZE + (ord(s[i]) - ord('a'))
		rst[i + 1] = hashValue % TABLE_SIZE
	return rst

def findNeedSubstringEnhance(f, t):
	n = len(t)
	i = n - 2
	while i >= 0:
		if f[i] == (f[n] - f[n - i] * power[i] % TABLE_SIZE + TABLE_SIZE) % TABLE_SIZE:
			return t[i:n]
		i = i - 1
	return t

def powArray():
	rst = [1] * int(500000.0 + 7)
	for i in range(1, int(500000.0 + 2), 1):
		rst[i] = rst[i - 1] * alpha % TABLE_SIZE
	return rst
s = str(input())
t = str(input())
(s0, s1) = (0, 0)
(t0, t1) = (0, 0)
(ls, lt) = (len(s), len(t))
if lt > ls:
	print(s)
else:
	for c in s:
		if c == '0':
			s0 += 1
		else:
			s1 += 1
	for c in t:
		if c == '0':
			t0 += 1
		else:
			t1 += 1
	if (s0 and s1 and t0 and t1) == 0 or len(s) == len(t):
		if s0 == t0 and s1 == t1:
			print(t)
		else:
			print(s)
	else:
		alpha = 257
		TABLE_SIZE = int(1000000000.0 + 7)
		power = powArray()
		f = polyHash(t)
		flag = findNeedSubstringEnhance(f, t)
		if len(flag) != len(t):
			tmp = t
			(f0, f1) = (0, 0)
			for c in flag:
				if c == '0':
					f0 += 1
				else:
					f1 += 1
			k = min((s0 - t0) // f0, (s1 - t1) // f1)
			for i in range(k):
				tmp += flag
			for i in range(s0 - t0 - k * f0):
				tmp += '0'
			for i in range(s1 - t1 - k * f1):
				tmp += '1'
			print(tmp)
		else:
			k = min(s0 // t0, s1 // t1)
			tmp = ''
			for i in range(k):
				tmp += t
			for i in range(s0 - k * t0):
				tmp += '0'
			for i in range(s1 - k * t1):
				tmp += '1'
			print(tmp)


import sys
input = sys.stdin.readline

def MP(s):
	a = [0] * (len(s) + 1)
	a[0] = -1
	j = -1
	for i in range(len(s)):
		while j >= 0 and s[i] != s[j]:
			j = a[j]
		j += 1
		a[i + 1] = j
	return a
s = input()[:-1]
t = input()[:-1]
cnt = [0, 0]
for char in s:
	cnt[int(char)] += 1
tbl = MP(t)
lap = len(t) - tbl[len(t)]
t = t[0:lap]
ans = []
while True:
	for char in t:
		if cnt[int(char)] > 0:
			ans.append(char)
			cnt[int(char)] -= 1
		else:
			break
	else:
		continue
	break
for i in range(cnt[0]):
	ans.append('0')
for i in range(cnt[1]):
	ans.append('1')
print(''.join(ans))


s = input()
t_ = input()
tt = ''
t = t_
ans = ''
for i in range(len(t_) - 1):
	tt += t_[i]
	if t_.endswith(tt):
		t = t_[i + 1:]
s0 = s.count('0')
s1 = s.count('1')
t_0 = t_.count('0')
t_1 = t_.count('1')
t0 = t.count('0')
t1 = t.count('1')
if s0 >= t_0 and s1 >= t_1:
	ans += t_
	s0 -= t_0
	s1 -= t_1
else:
	print(s)
	exit(0)
if t0 > 0:
	n1 = s0 // t0
else:
	n1 = 1000000000
if t1 > 0:
	n2 = s1 // t1
else:
	n2 = 1000000000
val = min(n1, n2)
ans += val * t
s0 -= val * t0
s1 -= val * t1
ans += s0 * '0' + s1 * '1'
print(ans)


from collections import defaultdict as dd
import math

def nn():
	return int(input())

def li():
	return list(input())

def mi():
	return map(int, input().split())

def lm():
	return list(map(int, input().split()))
s = input()
t = input()
answer = []
s0 = 0
s1 = 0
t0 = 0
t1 = 0

def longestPrefixSuffix(s):
	n = len(s)
	lps = [0] * n
	l = 0
	i = 1
	while i < n:
		if s[i] == s[l]:
			l = l + 1
			lps[i] = l
			i = i + 1
		elif l != 0:
			l = lps[l - 1]
		else:
			lps[i] = 0
			i = i + 1
	res = lps[n - 1]
	return res
twindow = longestPrefixSuffix(t)
for i in range(len(s)):
	if s[i] == '0':
		s0 += 1
	else:
		s1 += 1
for i in range(len(t)):
	if t[i] == '0':
		t0 += 1
	else:
		t1 += 1
bad = 0
while s0 > 0 and s1 > 0:
	for i in range(len(t) - twindow):
		if t[i] == '0' and s0 == 0:
			bad = 1
			break
		if t[i] == '1' and s1 == 0:
			bad = 1
			break
		answer.append(t[i])
		if t[i] == '0':
			s0 -= 1
		if t[i] == '1':
			s1 -= 1
	if bad == 1:
		break
if s0 > 0:
	for k in range(s0):
		answer.append('0')
if s1 > 0:
	for k in range(s1):
		answer.append('1')
print(''.join(answer))


(s, t) = (input(), input())
(lenS, lenT) = (len(s), len(t))
tPrefix = [0] * (lenT + 1)
tPrefix[0] = -1
(i, j) = (0, -1)
while i < lenT:
	if j == -1 or t[i] == t[j]:
		i += 1
		j += 1
		tPrefix[i] = j
	else:
		j = tPrefix[j]
prefixLen = tPrefix[lenT]
sumS1 = sum(map(int, list(s)))
sumS0 = lenS - sumS1
r = []
it = 0
for i in range(lenS):
	if t[it] == '0':
		if sumS0 > 0:
			sumS0 -= 1
		else:
			break
	elif sumS1 > 0:
		sumS1 -= 1
	else:
		break
	r.append(t[it])
	it += 1
	if it == lenT:
		it = prefixLen
r.extend(['0'] * sumS0)
r.extend(['1'] * sumS1)
print(''.join(r))


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify, _heapify_max, _heappop_max, nsmallest, nlargest

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	tc = 1
	for _ in range(tc):
		s = rs()
		t = rs()
		ls = len(s)
		lt = len(t)
		ds = Counter(s)
		dt = Counter(t)
		lps = [0] * lt
		if dt['1'] > ds['1'] or dt['0'] > ds['0']:
			print(s)
		else:
			l = 0
			i = 1
			while i < lt:
				if t[i] == t[l]:
					l += 1
					lps[i] = l
					i += 1
				elif l != 0:
					l = lps[l - 1]
				else:
					lps[i] = 0
					i += 1
			zz = lt - lps[-1]
			t = t[:zz]
			c = 0
			ans = ''
			for i in range(ls):
				if ds[t[i % zz]] > 0:
					ans += t[i % zz]
					ds[t[i % zz]] -= 1
				else:
					ans += '1' * ds['1'] + '0' * ds['0']
					break
			ws(ans)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


def prefix(s):
	v = [0] * len(s)
	for i in range(1, len(s)):
		k = v[i - 1]
		while k > 0 and s[k] != s[i]:
			k = v[k - 1]
		if s[k] == s[i]:
			k = k + 1
		v[i] = k
	return v[-1]

def tl():
	ans = input()
	pattern = input()
	ansA1 = ansA0 = ansC1 = ansC0 = ansP0 = ansP1 = 0
	for x in ans:
		if x == '0':
			ansA0 += 1
		else:
			ansA1 += 1
	counter = prefix(pattern)
	patternC = pattern[:len(pattern) - counter]
	patternP = pattern[len(pattern) - counter:]
	for x in patternC:
		if x == '0':
			ansC0 += 1
		else:
			ansC1 += 1
	for x in patternP:
		if x == '0':
			ansP0 += 1
		else:
			ansP1 += 1
	if ansA0 >= ansP0 and ansA1 >= ansP1:
		checkC = 1
	else:
		checkC = 0
	if checkC:
		ansA0 -= ansP0
		ansA1 -= ansP1
		if ansC1 and ansC0:
			check = min(ansA1 // ansC1, ansA0 // ansC0)
			if check:
				ans = patternC * check + patternP + '1' * (ansA1 - check * ansC1) + '0' * (ansA0 - check * ansC0)
		elif ansC1:
			check = ansA1 // ansC1
			if check:
				ans = patternC * check + patternP + '1' * (ansA1 - check * ansC1) + '0' * ansA0
		else:
			check = ansA0 // ansC0
			if check:
				ans = patternC * check + patternP + '1' * ansA1 + '0' * (ansA0 - check * ansC0)
	print(ans)
tl()


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
from collections import defaultdict
from itertools import permutations
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
s = input()
t = input()
s_count = 0
t_count = 0
s_count_0 = 0
t_count_0 = 0
for i in s:
	if i is '1':
		s_count += 1
for i in t:
	if i is '1':
		t_count += 1
s_count_0 = len(s) - s_count
t_count_0 = len(t) - t_count
match = [0]
j = 0
i = 1
while i < len(t):
	while t[j] is not t[i]:
		j -= 1
		if j < 0:
			break
		j = match[j]
	if j < 0:
		j = 0
		match.append(0)
	else:
		match.append(j + 1)
		j += 1
	i += 1
remaining_1 = s_count - t_count
remaining_0 = s_count_0 - t_count_0
if remaining_0 < 0 or remaining_1 < 0:
	print(s)
	exit(0)
for a in t[:match[-1]]:
	if a is '1':
		t_count -= 1
	else:
		t_count_0 -= 1
result = [t]
if t_count is not 0 and t_count_0 is not 0:
	val = int(min(remaining_1 / t_count, remaining_0 / t_count_0))
elif t_count is 0:
	val = int(remaining_0 / t_count_0)
else:
	val = int(remaining_1 / t_count)
for _ in range(val):
	result.append(t[match[-1]:])
for _ in range(remaining_0 - val * t_count_0):
	result.append('0')
for _ in range(remaining_1 - val * t_count):
	result.append('1')
print(''.join(result))


def say_hello(s, t):
	nt = len(t)
	ns = len(s)
	s0 = len([i for i in s if i == '0'])
	s1 = ns - s0
	t0 = len([i for i in t if i == '0'])
	t1 = nt - t0
	if s0 < t0 or s1 < t1:
		return s
	s0 -= t0
	s1 -= t1
	suffix = t
	if nt > 1:
		i = 1
		j = 0
		memory = [-1] * nt
		while i < nt:
			if t[j] == t[i]:
				memory[i] = j
				j += 1
				i += 1
			elif j == 0:
				i += 1
			else:
				j = memory[j - 1] + 1
		suffix = t[memory[-1] + 1:]
	suffix0 = len([i for i in suffix if i == '0'])
	suffix1 = len(suffix) - suffix0
	if suffix0 == 0:
		suffx_rep = s1 // suffix1
	elif suffix1 == 0:
		suffx_rep = s0 // suffix0
	else:
		suffx_rep = min(s0 // suffix0, s1 // suffix1)
	s0 -= suffx_rep * suffix0
	s1 -= suffx_rep * suffix1
	return t + suffix * suffx_rep + '0' * s0 + '1' * s1
s = input()
t = input()
print(say_hello(s, t))


def longestPrefixSuffix(s, n):
	lps = [0 for i in range(n)]
	l = 0
	i = 1
	while i < n:
		if s[i] == s[l]:
			l += 1
			lps[i] = l
			i += 1
		elif l != 0:
			l = lps[l - 1]
		else:
			lps[i] = 0
			i += 1
	res = lps[n - 1]
	return res
s1 = input()
s2 = input()
n1 = len(s1)
n2 = len(s2)
lcsp = longestPrefixSuffix(s2, n2)
no_1 = s1.count('1')
no_0 = n1 - no_1
re_1 = s2.count('1')
re_0 = n2 - re_1
if re_1 > no_1 or re_0 > no_0:
	print(s1)
else:
	ans = s2
	no_1 = no_1 - re_1
	no_0 = no_0 - re_0
	re_1 = re_1 - s2[:lcsp].count('1')
	re_0 = re_0 - s2[:lcsp].count('0')
	if re_1 != 0:
		_1 = no_1 // re_1
	else:
		_1 = float('inf')
	if re_0 != 0:
		_0 = no_0 // re_0
	else:
		_0 = float('inf')
	_min = min(_1, _0)
	ans = ans + s2[lcsp:] * _min
	no_1 = no_1 - _min * re_1
	no_0 = no_0 - _min * re_0
	ans = ans + '1' * no_1 + '0' * no_0
	print(ans)


from collections import defaultdict

def Prefix_Array(t):
	m = len(t)
	arr = [-1] * m
	k = -1
	for i in range(1, m):
		while k > -1 and t[k + 1] != t[i]:
			k = arr[k]
		if t[k + 1] == t[i]:
			k += 1
		arr[i] = k
	return arr[-1]

def fun(ds, dt):
	check = Prefix_Array(t)
	if check == -1:
		if ds['1'] < dt['1'] or ds['0'] < dt['0']:
			return s
		if dt['1'] == 0 and ds['0'] != 0:
			n = ds['0'] // dt['0']
			temp = t * n
			ds['0'] -= n * dt['0']
			while ds['1'] > 0:
				temp += '1'
				ds['1'] -= 1
			while ds['0'] > 0:
				temp += '0'
				ds['0'] -= 1
			return temp
		if dt['0'] == 0 and ds['1'] != 0:
			n = ds['1'] // dt['1']
			temp = t * n
			ds['1'] -= n * dt['1']
			while ds['1'] > 0:
				temp += '1'
				ds['1'] -= 1
			while ds['0'] > 0:
				temp += '0'
				ds['0'] -= 1
			return temp
		m1 = ds['1'] // dt['1']
		m2 = ds['0'] // dt['0']
		n = min(m1, m2)
		temp = t * n
		ds['1'] -= n * dt['1']
		ds['0'] -= n * dt['0']
		while ds['1'] > 0:
			temp += '1'
			ds['1'] -= 1
		while ds['0'] > 0:
			temp += '0'
			ds['0'] -= 1
		return temp
	else:
		if ds['1'] < dt['1'] or ds['0'] < dt['0']:
			return s
		r = t[check + 1:]
		dr = defaultdict(int)
		for v in r:
			dr[v] += 1
		temp = t
		ds['1'] -= dt['1']
		ds['0'] -= dt['0']
		if ds['1'] < dr['1'] or ds['0'] < dr['0']:
			while ds['1'] > 0:
				temp += '1'
				ds['1'] -= 1
			while ds['0'] > 0:
				temp += '0'
				ds['0'] -= 1
			return temp
		if dr['1'] == 0 and ds['0'] != 0:
			n = ds['0'] // dr['0']
			temp += r * n
			ds['0'] -= n * dr['0']
			while ds['1'] > 0:
				temp += '1'
				ds['1'] -= 1
			while ds['0'] > 0:
				temp += '0'
				ds['0'] -= 1
			return temp
		if dr['0'] == 0 and ds['1'] != 0:
			n = ds['1'] // dr['1']
			temp += r * n
			ds['1'] -= n * dr['1']
			while ds['1'] > 0:
				temp += '1'
				ds['1'] -= 1
			while ds['0'] > 0:
				temp += '0'
				ds['0'] -= 1
			return temp
		m1 = ds['1'] // dr['1']
		m2 = ds['0'] // dr['0']
		n = min(m1, m2)
		temp += r * n
		ds['1'] -= n * dr['1']
		ds['0'] -= n * dr['0']
		while ds['1'] > 0:
			temp += '1'
			ds['1'] -= 1
		while ds['0'] > 0:
			temp += '0'
			ds['0'] -= 1
		return temp
s = input()
t = input()
ds = defaultdict(int)
dt = defaultdict(int)
for c in s:
	ds[c] += 1
for c in t:
	dt[c] += 1
print(fun(ds, dt))


def computeLPS(pat):
	l = 0
	M = len(pat)
	i = 1
	while i < M:
		if pat[i] == pat[l]:
			l += 1
			lps[i] = l
			i += 1
		elif l != 0:
			l = lps[l - 1]
		else:
			lps[i] = 0
			i += 1
s = input()
t = input()
ds = {}
dt = {}
lps = [0] * len(t)
ds['0'] = 0
ds['1'] = 0
dt['0'] = 0
dt['1'] = 0
for i in s:
	ds[i] += 1
for i in t:
	dt[i] += 1
if len(s) < len(t) or ds['0'] < dt['0'] or ds['1'] < dt['1']:
	print(s)
else:
	computeLPS(t)
	x = lps[-1]
	sub = t[x:]
	dsub = {}
	dsub['0'] = 0
	dsub['1'] = 0
	for i in sub:
		dsub[i] += 1
	ans = t
	ds['0'] -= dt['0']
	ds['1'] -= dt['1']
	c = min(ds['0'] // dsub['0'] if dsub['0'] > 0 else 10 ** 7, ds['1'] // dsub['1'] if dsub['1'] > 0 else 10 ** 7)
	ans += sub * c + '0' * (ds['0'] - dsub['0'] * c) + '1' * (ds['1'] - dsub['1'] * c)
	print(ans)


string = input()
sub_string = input()
if len(string) < len(sub_string):
	print(string)
else:
	nof1_st = string.count('1')
	nof0_st = string.count('0')
	nof1_su = sub_string.count('1')
	nof0_su = sub_string.count('0')
	if nof1_su == 0:
		print(nof0_st // nof0_su * sub_string + '0' * (nof0_st - nof0_st // nof0_su * nof0_su) + '1' * nof1_st)
	elif nof0_su == 0:
		print(nof1_st // nof1_su * sub_string + '1' * (nof1_st - nof1_st // nof1_su * nof1_su) + '0' * nof0_st)
	else:
		l = 0
		i = 1
		length = len(sub_string)
		lps = [0 for i in range(length)]
		while i < length:
			if sub_string[i] == sub_string[l]:
				l += 1
				lps[i] = l
				i += 1
			elif l != 0:
				l = lps[l - 1]
			else:
				lps[i] = 0
				i += 1
		le = lps[length - 1]
		answer = ''
		if nof0_st >= nof0_su and nof1_st >= nof1_su:
			nof1_st -= nof1_su
			nof0_st -= nof0_su
			answer += sub_string
			nof0_su -= sub_string[:le].count('0')
			nof1_su -= sub_string[:le].count('1')
		tot = min(nof0_st // nof0_su, nof1_st // nof1_su)
		print(answer + tot * sub_string[le:] + '0' * (nof0_st - tot * nof0_su) + '1' * (nof1_st - tot * nof1_su))


def get_len(t, z):
	ori_len = len(t)
	length = 0
	i = 1
	while i < ori_len:
		if t[i] == t[length]:
			length += 1
			z[i] = length
			i += 1
		elif length != 0:
			length = z[length - 1]
		else:
			z[i] = 0
			i += 1
	return z[ori_len - 1]

def problem_1137b():
	maxn = int(1000000.0)
	s = input()
	t = input()
	(zs, os, zt, ot) = (0, 0, 0, 0)
	for i in range(len(s)):
		if s[i] == '0':
			zs += 1
		else:
			os += 1
	for i in range(len(t)):
		if t[i] == '0':
			zt += 1
		else:
			ot += 1
	if zt > zs or ot > os:
		print(s)
		return
	z = [0 for _ in range(maxn)]
	len_t = get_len(t, z)
	answer = t
	add = t[len_t:len(t)]
	(nz, no) = (0, 0)
	(currz, curro) = (zt, ot)
	for i in range(len(add)):
		if add[i] == '0':
			nz += 1
		else:
			no += 1
	while currz + nz <= zs and curro + no <= os:
		answer += add
		currz += nz
		curro += no
	for i in range(zs - currz):
		answer += '0'
	for i in range(os - curro):
		answer += '1'
	print(answer)
	return
problem_1137b()


import sys
import io, os
input = sys.stdin.readline

def z_algorithm(s):
	n = len(s)
	Z = [0] * n
	Z[0] = n
	i = 1
	j = 0
	while i < n:
		while i + j < n and s[j] == s[i + j]:
			j += 1
		Z[i] = j
		if j == 0:
			i += 1
			continue
		k = 1
		while i + k < n and k + Z[k] < j:
			Z[i + k] = Z[k]
			k += 1
		i += k
		j -= k
	return Z
from collections import Counter

def main():
	s = input().rstrip()
	t = input().rstrip()
	n = len(s)
	m = len(t)
	if m == 1:
		print(s)
		exit()
	Z = z_algorithm(t)
	for i in range(1, m):
		if Z[i] == m - i:
			t = t[0:i]
			break
	m = len(t)
	C = Counter(s)
	res = []
	while len(res) < n:
		flag = True
		for i in range(m):
			c = t[i]
			if C[c]:
				C[c] -= 1
				res.append(c)
			else:
				flag = False
				break
		if not flag:
			break
	for (c, v) in C.items():
		res += [c] * v
	print(''.join(res))
main()


s = input()
t = input()
b = 1
count = [0, 0]
count[0] += s.count('0')
count[1] += s.count('1')
kmpArr = [0 for x in range(len(t))]

def kmp():
	j = 0
	for i in range(1, len(t)):
		if t[j] == t[i]:
			kmpArr[i] = j + 1
			j += 1
		else:
			while j:
				j = kmpArr[j - 1]
				if t[j] == t[i]:
					kmpArr[i] = j + 1
					j += 1
					break
kmp()
text = ''
idex = 0
while 1:
	next = int(t[idex])
	if count[next] > 0:
		count[next] -= 1
		text += t[idex]
		idex += 1
		if idex > len(t) - 1:
			idex = kmpArr[-1]
	else:
		for i in range(count[0]):
			text += '0'
		for i in range(count[1]):
			text += '1'
		break
print(text)


from sys import stdin, stdout
from collections import Counter

def prefixsuffixmatch(s):
	pi_table = [0 for i in range(len(s))]
	for i in range(1, len(s)):
		y = pi_table[i - 1]
		while s[i] != s[y] and y != 0:
			y = pi_table[y - 1]
		if s[i] == s[y]:
			y += 1
		pi_table[i] = y
	return pi_table

def canprint(a, b):
	if a['0'] >= b['0'] and a['1'] >= b['1']:
		return True
	return False

def flushit(s):
	if '0' in s:
		stdout.write('0' * s['0'])
	if '1' in s:
		stdout.write('1' * s['1'])

def fillit(x):
	if '0' not in x:
		x['0'] = 0
	if '1' not in x:
		x['1'] = 0
	return x
s = stdin.readline().strip()
counter_s = fillit(Counter(s))
t = stdin.readline().strip()
counter_t = fillit(Counter(t))
t_pi_table = prefixsuffixmatch(t)
longest_match = t_pi_table[-1]
repeating_part = t[longest_match:]
counter_repeating_part = fillit(Counter(repeating_part))
if len(counter_s) == 2 and len(counter_t) == 2:
	if counter_s['0'] >= counter_t['0'] and counter_s['1'] >= counter_t['1']:
		stdout.write(t)
		counter_s['0'] -= counter_t['0']
		counter_s['1'] -= counter_t['1']
	if '0' in counter_repeating_part and '1' in counter_repeating_part:
		if counter_repeating_part['0'] > 0 and counter_repeating_part['1'] > 0:
			r = min(counter_s['0'] // counter_repeating_part['0'], counter_s['1'] // counter_repeating_part['1'])
			stdout.write(repeating_part * r)
			counter_s['0'] -= r * counter_repeating_part['0']
			counter_s['1'] -= r * counter_repeating_part['1']
	flushit(counter_s)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import sys

def longestPrefixSuffix(s):
	n = len(s)
	lps = [0] * n
	l = 0
	i = 1
	while i < n:
		if s[i] == s[l]:
			l = l + 1
			lps[i] = l
			i = i + 1
		elif l != 0:
			l = lps[l - 1]
		else:
			lps[i] = 0
			i = i + 1
	res = lps[n - 1]
	if res > n / 2:
		return n // 2
	else:
		return res
s = input()
t = input()
sr = t + '#' + t[1:]
l = longestPrefixSuffix(sr)
one = s.count('1')
zero = len(s) - one
ans = ''
ans += t
one -= t.count('1')
zero -= t.count('0')
if one < 0 or zero < 0:
	print(s)
	sys.exit()
t = t[l:]
t1 = t.count('1')
t0 = t.count('0')
if t1 == 0:
	y = zero // t0
elif t0 == 0:
	y = one // t1
else:
	y = one // t1
	y = min(y, zero // t0)
for i in range(y):
	ans += t
one = s.count('1') - ans.count('1')
zero = s.count('0') - ans.count('0')
ans += '1' * one + '0' * zero
print(ans)


from sys import stdin
s = stdin.readline().strip()
s1 = stdin.readline().strip()

def lps_array(pat):
	leng = 0
	i = 1
	M = len(pat)
	lps = [0] * M
	j = 0
	while i < M:
		if pat[i] == pat[leng]:
			leng += 1
			lps[i] = leng
			i += 1
		elif leng != 0:
			leng = lps[leng - 1]
		else:
			lps[i] = 0
			i += 1
	return lps[-1]
u = 0
z = 0
for i in range(len(s)):
	if s[i] == '1':
		u += 1
	else:
		z += 1
x = 0
t = True
ans = ''
y = lps_array(s1)
for i in range(len(s)):
	if s1[x] == '1' and u > 0:
		ans += '1'
		u -= 1
	elif s1[x] == '0' and z > 0:
		ans += '0'
		z -= 1
	elif u > 0:
		t = False
		ans += '1'
		u -= 1
	else:
		t = False
		ans += '0'
		z -= 1
	if t:
		x += 1
	if x == len(s1):
		x = y
print(ans)


flip = {'0': '1', '1': '0'}
(s, t) = (input(), input())
(n, m) = (len(s), len(t))
p = [0] * m
for i in range(1, m):
	g = p[i - 1]
	while g and t[i] != t[g]:
		g = p[g - 1]
	p[i] = g + int(t[i] == t[g])
s_cnt = {'0': s.count('0'), '1': s.count('1')}
t = t[:m - p[-1]]
res = [''] * n
for i in range(n):
	char = t[i % len(t)]
	char = char if s_cnt[char] > 0 else flip[char]
	s_cnt[char] -= 1
	res[i] = char
print(''.join(res))


import sys

def count_bits(s):
	return [s.count('0'), s.count('1')]

def compare_bits_count(a, b):
	if a[0] >= b[0] and a[1] >= b[1]:
		return 1
	else:
		return 0

def subtract_bits_count(a, b):
	return [a[0] - b[0], a[1] - b[1]]

def z_function(s):
	n = len(s)
	l = 0
	r = 0
	z = [0 for x in range(n)]
	for i in range(1, n):
		z[i] = max(0, min(r - i, z[i - l]))
		while i + z[i] < n and s[z[i]] == s[i + z[i]]:
			z[i] += 1
		if i + z[i] > r:
			l = i
			r = i + z[i]
	return z
s = input()
t = input()
s_bits_count = count_bits(s)
t_bits_count = count_bits(t)
if compare_bits_count(s_bits_count, t_bits_count) == 0:
	print(s)
	sys.exit()
result = t
s_bits_count = subtract_bits_count(s_bits_count, t_bits_count)
r = ''
z = z_function(t)
for i in range(len(t) // 2, len(t)):
	if z[i] == len(t) - i:
		r = t[len(t) - i:]
		r_bits_count = count_bits(r)
		break
if len(r) == 0:
	r = t
	r_bits_count = t_bits_count
while s_bits_count[0] > 0 or s_bits_count[1] > 0:
	if compare_bits_count(s_bits_count, r_bits_count) == 1:
		result += r
		s_bits_count = subtract_bits_count(s_bits_count, r_bits_count)
	else:
		result += '0' * s_bits_count[0]
		result += '1' * s_bits_count[1]
		break
print(result)


import sys
s = sys.stdin.readline()[:-1]
t = sys.stdin.readline()[:-1]
(count0, count1) = (0, 0)
(n, m) = (len(s), len(t))
for i in range(n):
	if s[i] == '0':
		count0 += 1
		continue
	count1 += 1
lps = [0 for _ in range(m)]
(i, j) = (1, 0)
while i < m:
	if t[i] == t[j]:
		j += 1
		lps[i] = j
		i += 1
	elif j != 0:
		j = lps[j - 1]
	else:
		lps[i] = 0
		i += 1
x = lps[-1]
z = True
(i, j) = (0, 0)
ans = [0 for _ in range(n)]
while z:
	if t[i] == '1':
		if count1 > 0:
			ans[j] = '1'
			count1 -= 1
			i += 1
			j += 1
			if i == m:
				i = x
		else:
			z = False
	elif count0 > 0:
		ans[j] = '0'
		count0 -= 1
		i += 1
		j += 1
		if i == m:
			i = x
	else:
		z = False
while count0 > 0:
	ans[j] = '0'
	j += 1
	count0 -= 1
while count1 > 0:
	ans[j] = '1'
	j += 1
	count1 -= 1
print(''.join((x for x in ans)))


import random

def helper(s):
	size = len(s)
	(c_l, c_r) = ([0, 0], [0, 0])
	candidate_overlaps = []
	for i in range(size):
		if s[i] == '0':
			c_l[0] += 1
		else:
			c_l[1] += 1
		if s[size - 1 - i] == '0':
			c_r[0] += 1
		else:
			c_r[1] += 1
		if c_l == c_r:
			candidate_overlaps.append(i + 1)
	candidate_overlaps.pop()
	result = 0
	for overlap in reversed(candidate_overlaps):
		delta = size - overlap
		found = True
		for start in range(overlap):
			if s[start] != s[start + delta]:
				found = False
				break
		if found:
			result = overlap
			break
	return result

def counter(s):
	(a, b) = (0, 0)
	for ele in s:
		if ele == '0':
			a += 1
		else:
			b += 1
	return (a, b)

def test_helper():
	i = [''.join(('1' if random.random() > 0.05 else '0' for i in range(500000)))]
	i = ['1'] * 500000
	i[-2] = '0'
	i = [''.join(i)]
	i = ['101', '110']
	print('haha')
	for ele in i:
		print(helper(ele))

def solve(s, t):
	(s_0, s_1) = counter(s)
	m = helper(t)
	t_repeat = t[:m]
	t_remain = t[m:]
	(t_repeat_0, t_repeat_1) = counter(t_repeat)
	(t_remain_0, t_remain_1) = counter(t_remain)
	if t_repeat_0 > s_0 or t_repeat_1 > s_1:
		return s
	result = []
	s_0 -= t_repeat_0
	s_1 -= t_repeat_1
	result.append(t_repeat)
	if t_remain_0 == 0:
		n = s_1 // t_remain_1
	elif t_remain_1 == 0:
		n = s_0 // t_remain_0
	else:
		n = min(s_0 // t_remain_0, s_1 // t_remain_1)
	s_0 -= n * t_remain_0
	s_1 -= n * t_remain_1
	result.append(t_remain * n)
	result.append('0' * s_0)
	result.append('1' * s_1)
	return ''.join(result)

def main():
	s = input()
	t = input()
	result = solve(s, t)
	print(result)

def test():
	pass
main()


s = input()
t = input()

def kmp(text, pattern):
	pattern = list(pattern)
	shifts = [1] * (len(pattern) + 1)
	shift = 1
	for pos in range(len(pattern)):
		while shift <= pos and pattern[pos] != pattern[pos - shift]:
			shift += shifts[pos - shift]
		shifts[pos + 1] = shift
	return shifts
pf = kmp('', t)
sl = pf[-1]
tt = t[:sl]
ltt = len(tt)
s0 = sum([1 for v in s if v == '0'])
s1 = sum([1 for v in s if v == '1'])
cs = len(s)
ct = len(t)
ans = ''
i = 0
while len(ans) < len(s):
	v = tt[i]
	i += 1
	i %= ltt
	if v == '1':
		if s1 == 0:
			break
		s1 -= 1
		ans += '1'
	else:
		if s0 == 0:
			break
		s0 -= 1
		ans += '0'
ans += '0' * s0 + '1' * s1
print(ans)


mod = 2333
H = [0]
lmod = [1]
modd = 2 ** 64 - 1

def getv(l, r):
	return (H[r] - H[l - 1] * lmod[r - l + 1] % modd) % modd

def init(t):
	pos = 0
	for i in t:
		H.append((H[pos] * mod + int(i)) % modd)
		lmod.append(lmod[pos] * mod % modd)
		pos += 1
s = input()
s1 = s.count('1')
s0 = len(s) - s1
t = input()
if len(s) > 100:
	if s[:100] == '0' * 100 or s[:100] == '1' * 100:
		print(s)
	else:
		t1 = t.count('1')
		n = len(t)
		t0 = n - t1
		init(t)
		ts = ''
		for i in range(1, len(t) + 1):
			if getv(i + 1, n) == getv(1, n - i):
				break
		ts = t[n - i:]
		ts0 = ts.count('0')
		ts1 = len(ts) - ts0
		if s1 < t1 or s0 < t0:
			print(s)
		else:
			ans = ''
			ans += t
			s1 -= t1
			s0 -= t0
			while s1 >= ts1 and s0 >= ts0:
				ans += ts
				s1 -= ts1
				s0 -= ts0
			ans += '1' * s1 + '0' * s0
			print(ans)
else:
	t1 = t.count('1')
	n = len(t)
	t0 = n - t1
	init(t)
	ts = ''
	for i in range(1, len(t) + 1):
		if getv(i + 1, n) == getv(1, n - i):
			break
	ts = t[n - i:]
	ts0 = ts.count('0')
	ts1 = len(ts) - ts0
	if s1 < t1 or s0 < t0:
		print(s)
	else:
		ans = ''
		ans += t
		s1 -= t1
		s0 -= t0
		while s1 >= ts1 and s0 >= ts0:
			ans += ts
			s1 -= ts1
			s0 -= ts0
		ans += '1' * s1 + '0' * s0
		print(ans)


s = input()
t = input()
if len(t) > len(s):
	print(s)
	exit(0)
MOD = 998244353
d = ''
q = t
hashpref = []
hashsuf = []
ans = 0
pow2 = 1
for sq in t[:len(t) // 2 + 1 - len(t) % 2]:
	ans *= 2
	ans %= MOD
	if sq == '1':
		ans += 1
	hashpref.append(ans)
ans = 0
for szq in t[len(t) // 2 + len(t) % 2:][::-1]:
	if szq == '1':
		ans += pow2
		ans %= MOD
	hashsuf.append(ans)
	pow2 *= 2
	pow2 %= MOD
for i in range(len(hashsuf)):
	if hashpref[i] == hashsuf[i]:
		d = t[:i + 1]
		q = t[i + 1:-i - 1]
(sz, dz, qz) = (0, 0, 0)
for i in range(len(s)):
	if s[i] == '0':
		sz += 1
	if i < len(d) and d[i] == '0':
		dz += 1
	if i < len(q) and q[i] == '0':
		qz += 1
so = len(s) - sz
do = len(d) - dz
qo = len(q) - qz
if dz + qz != 0:
	A1 = sz // (dz + qz)
else:
	A1 = float('inf')
if do + qo != 0:
	A2 = so // (do + qo)
else:
	A2 = float('inf')
sz -= min(A1, A2) * (dz + qz)
so -= min(A1, A2) * (do + qo)
hah = d + q
for i in range(min(A1, A2)):
	print(hah, end='')
if sz >= dz and so >= do:
	print(d, end='')
	sz -= dz
	so -= do
for _ in range(sz):
	print('0', end='')
for oo in range(so):
	print('1', end='')


from collections import defaultdict, deque, Counter
from sys import stdin, stdout
from heapq import heappush, heappop
import math
import io
import os
import math
import bisect

def isPrime(x):
	for i in range(2, x):
		if i * i > x:
			break
		if x % i == 0:
			return False
	return True

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def digits(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def ceil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def mapin():
	return map(int, input().split())

def solve(pat):
	M = len(pat)
	le = 0
	lps = [0] * M
	i = 1
	while i < M:
		if pat[i] == pat[le]:
			le += 1
			lps[i] = le
			i += 1
		elif le != 0:
			le = lps[le - 1]
		else:
			lps[i] = 0
			i += 1
	return lps[-1]
s = list(input())
t = list(input())
ss = [s.count('0'), s.count('1')]
tt = [t.count('0'), t.count('1')]
if 0 in tt:
	print('0' * ss[0], end='')
	print('1' * ss[1])
else:
	sss = solve(t)
	sde = sss
	sss = t[0:sss]
	ttt = [sss.count('0'), sss.count('1')]
	tt = [tt[0] - ttt[0], tt[1] - ttt[1]]
	if ss[0] >= ttt[0] and ss[1] >= ttt[1]:
		ss[0] -= ttt[0]
		ss[1] -= ttt[1]
		print(''.join(sss), end='')
		t = t[sde:]
		a = min(ss[0] // tt[0], ss[1] // tt[1])
		for i in range(a):
			print(''.join(t), end='')
			ss[0] -= tt[0]
			ss[1] -= tt[1]
	print('0' * ss[0], end='')
	print('1' * ss[1])


def longestPrefixSuffix(s):
	n = len(s)
	lps = [0] * n
	l = 0
	i = 1
	while i < n:
		if s[i] == s[l]:
			l = l + 1
			lps[i] = l
			i = i + 1
		elif l != 0:
			l = lps[l - 1]
		else:
			lps[i] = 0
			i = i + 1
	res = lps[n - 1]
	if res > n / 2:
		if n % (n - lps[n - 1]) == 0 and n // (n - lps[n - 1]) % 2 == 1:
			res = 2 * lps[n - 1] - n
		return res
	else:
		return res
s = input()
q = input()
if len(q) > len(s):
	print(s)
else:
	a = 0
	b = 0
	for i in s:
		if i == '0':
			a += 1
		else:
			b += 1
	c = 0
	d = 0
	for i in q:
		if i == '0':
			c += 1
		else:
			d += 1
	z = ''
	if a >= c and b >= d:
		z += q
		a -= c
		b -= d
		y = longestPrefixSuffix(q)
		x = ''
		for i in range(y, len(q)):
			x += q[i]
		c = 0
		d = 0
		for i in x:
			if i == '0':
				c += 1
			else:
				d += 1
		while a >= c and b >= d:
			z += x
			a -= c
			b -= d
		z += '0' * a + '1' * b
		print(z)
	else:
		print(s)


import sys

def count_bits(s):
	return [s.count('0'), s.count('1')]

def compare_bits_count(a, b):
	if a[0] >= b[0] and a[1] >= b[1]:
		return 1
	else:
		return 0

def subtract_bits_count(a, b):
	return [a[0] - b[0], a[1] - b[1]]

def hash_values(s):
	hs = [0 for x in range(len(s))]
	if s[0] == '1':
		hs[0] = 1
	for i in range(1, len(s)):
		if s[i] == '1':
			hs[i] = hs[i - 1] + 1
		else:
			hs[i] = hs[i - 1]
	return hs
s = input()
t = input()
s_bits_count = count_bits(s)
t_bits_count = count_bits(t)
if compare_bits_count(s_bits_count, t_bits_count) == 0:
	print(s)
	sys.exit()
result = t
s_bits_count = subtract_bits_count(s_bits_count, t_bits_count)
r = ''
hs = hash_values(t)
for i in range(len(t) - 1):
	if hs[len(t) - 1] - hs[i] == hs[len(t) - i - 2] and t[i + 1:] == t[:len(t) - i - 1]:
		r = t[len(t) - i - 1:]
		r_bits_count = count_bits(r)
		break
if len(r) == 0:
	r = t
	r_bits_count = t_bits_count
while s_bits_count[0] > 0 or s_bits_count[1] > 0:
	if compare_bits_count(s_bits_count, r_bits_count) == 1:
		result += r
		s_bits_count = subtract_bits_count(s_bits_count, r_bits_count)
	else:
		result += '0' * s_bits_count[0]
		result += '1' * s_bits_count[1]
		break
print(result)


s = input()
t = input()
(lens, lent) = (len(s), len(t))
from sys import exit
if lens < lent:
	print(s)
	exit()
else:
	(onet, zerot) = (0, 0)
	for (i, x) in enumerate(t):
		if x == '0':
			zerot += 1
		else:
			onet += 1
	(ones, zeros) = (0, 0)
	for (i, x) in enumerate(s):
		if x == '0':
			zeros += 1
		else:
			ones += 1
	res = ''
	if onet <= ones and zerot <= zeros:
		(res, ones, zeros) = (t, ones - onet, zeros - zerot)
		if ones == 0 and zeros == 0:
			print(res)
			exit()
	else:
		print(s)
		exit()
	(item, k, ot, zt, ont, zet) = ('', lent, 0, 0, 0, 0)
	for i in range(lent - 1):
		if t[i] == '1':
			ot += 1
		else:
			zt += 1
		item += t[i]
		if t[lent - i - 1:] == item:
			(k, ont, zet) = (i, ot, zt)
	(ont, zet) = (onet - ont, zerot - zet)
	if k < lent:
		plus = t[k + 1:]
	else:
		plus = t
	while ont <= ones and zet <= zeros:
		res += plus
		ones -= ont
		zeros -= zet
	res += '1' * ones + '0' * zeros
	print(res)


s = input()
t = input()
s_count = 0
t_count = 0
s_count_0 = 0
t_count_0 = 0
for i in s:
	if i is '1':
		s_count += 1
for i in t:
	if i is '1':
		t_count += 1
s_count_0 = len(s) - s_count
t_count_0 = len(t) - t_count
match = [0]
j = 0
i = 1
while i < len(t):
	while t[j] is not t[i]:
		j -= 1
		if j < 0:
			break
		j = match[j]
	if j < 0:
		j = 0
		match.append(0)
	else:
		match.append(j + 1)
		j += 1
	i += 1
remaining_1 = s_count - t_count
remaining_0 = s_count_0 - t_count_0
if remaining_0 < 0 or remaining_1 < 0:
	print(s)
	exit(0)
for a in t[:match[-1]]:
	if a is '1':
		t_count -= 1
	else:
		t_count_0 -= 1
result = [t]
if t_count is not 0 and t_count_0 is not 0:
	val = int(min(remaining_1 / t_count, remaining_0 / t_count_0))
elif t_count is 0:
	val = int(remaining_0 / t_count_0)
else:
	val = int(remaining_1 / t_count)
for _ in range(val):
	result.append(t[match[-1]:])
for _ in range(remaining_0 - val * t_count_0):
	result.append('0')
for _ in range(remaining_1 - val * t_count):
	result.append('1')
print(''.join(result))