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 \leqslant |s| \leqslant 500\,000$), denoting the current project of the camp's schedule.

The second line contains string $t$ ($1 \leqslant |t| \leqslant 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:
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)


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)


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)


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))


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))


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))


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()
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)


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)))


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 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)


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 = 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)


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)


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))


import sys
input = sys.stdin.readline

def z_algorithm(s):
	res = [0] * len(s)
	res[0] = len(s)
	(i, j) = (1, 0)
	while i < len(s):
		while i + j < len(s) and s[j] == s[i + j]:
			j += 1
		res[i] = j
		if j == 0:
			i += 1
			continue
		k = 1
		while i + k < len(s) and k + res[k] < j:
			res[i + k] = res[k]
			k += 1
		(i, j) = (i + k, j - k)
	return res
s = input().rstrip()
t = input().rstrip()
cnt = [0] * 2
for i in range(len(s)):
	cnt[int(s[i])] += 1
tbl = z_algorithm(t)
for lap in range(1, len(t) + 1):
	i = 0
	while i < len(t):
		if tbl[i] != len(t) - i:
			break
		i += lap
	else:
		break
t = t[0:lap]
ans = []
while True:
	for c in t:
		if cnt[int(c)] > 0:
			cnt[int(c)] -= 1
			ans.append(c)
		else:
			break
	else:
		continue
	break
ans.extend(['0'] * cnt[0] + ['1'] * cnt[1])
print(''.join(ans))


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)


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 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()


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)