You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. 

Suitability of string s is calculated by following metric:

Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulting strings s, you choose the one with the largest number of non-intersecting occurrences of string t. Suitability is this number of occurrences.

You should replace all '?' characters with small Latin letters in such a way that the suitability of string s is maximal.


-----Input-----

The first line contains string s (1 ≤ |s| ≤ 10^6).

The second line contains string t (1 ≤ |t| ≤ 10^6).


-----Output-----

Print string s with '?' replaced with small Latin letters in such a way that suitability of that string is maximal.

If there are multiple strings with maximal suitability then print any of them.


-----Examples-----
Input
?aa?
ab

Output
baab

Input
??b?
za

Output
azbz

Input
abcd
abacaba

Output
abcd



-----Note-----

In the first example string "baab" can be transformed to "abab" with swaps, this one has suitability of 2. That means that string "baab" also has suitability of 2.

In the second example maximal suitability you can achieve is 1 and there are several dozens of such strings, "azbz" is just one of them.

In the third example there are no '?' characters and the suitability of the string is 0.

Source: codeforces | Difficulty: MEDIUM
Tags: Sorting

Implementation

Greedy algorithms


Solutions:
import sys
from collections import Counter
s = list(sys.stdin.buffer.readline().decode('utf-8').rstrip())
s_cnt = Counter(s)
t_cnt = Counter(sys.stdin.buffer.readline().decode('utf-8').rstrip())
(ok, ng) = (0, 10 ** 6 + 1)
hatena = s_cnt['?']
while abs(ok - ng) > 1:
	mid = ok + ng >> 1
	req = 0
	for (k, v) in t_cnt.items():
		req += max(0, v * mid - s_cnt[k])
	if req <= hatena:
		ok = mid
	else:
		ng = mid
keys = list(t_cnt.keys())
for i in range(len(s)):
	if s[i] != '?':
		continue
	while keys and t_cnt[keys[-1]] * ok <= s_cnt[keys[-1]]:
		keys.pop()
	if keys:
		s[i] = keys[-1]
		s_cnt[keys[-1]] += 1
	else:
		s[i] = 'a'
sys.stdout.buffer.write(''.join(s).encode('utf-8'))


s = list(input())
t = input()
L = [0] * 27
for i in range(len(s)):
	if s[i] != '?':
		L[ord(s[i]) - ord('a')] += 1
count = 0
i = 0
while i < len(s):
	if s[i] == '?':
		count += 1
		if L[ord(t[count % len(t)]) - ord('a')] > 0:
			L[ord(t[count % len(t)]) - ord('a')] -= 1
			i -= 1
		else:
			s[i] = t[count % len(t)]
	i = i + 1
print(''.join(s))


import os
import sys
from io import BytesIO, IOBase
import math
from queue import Queue
import collections
import itertools
import bisect
import heapq
import random

def main():
	pass
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')

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return 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(i)
			n = n / i
	if n > 2:
		l.append(int(n))
	return l

def primeFactorsCount(n):
	cnt = 0
	while n % 2 == 0:
		cnt += 1
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			cnt += 1
			n = n // i
	if n > 2:
		cnt += 1
	return cnt

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def maxPrimeFactors(n):
	maxPrime = -1
	while n % 2 == 0:
		maxPrime = 2
		n >>= 1
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			maxPrime = i
			n = n / i
	if n > 2:
		maxPrime = n
	return int(maxPrime)

def countcon(s, i):
	c = 0
	ch = s[i]
	for i in range(i, len(s)):
		if s[i] == ch:
			c += 1
		else:
			break
	return c

def lis(arr):
	n = len(arr)
	lis = [1] * n
	for i in range(1, n):
		for j in range(0, i):
			if arr[i] > arr[j] and lis[i] < lis[j] + 1:
				lis[i] = lis[j] + 1
	maximum = 0
	for i in range(n):
		maximum = max(maximum, lis[i])
	return maximum

def isSubSequence(str1, str2):
	m = len(str1)
	n = len(str2)
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m

def maxfac(n):
	root = int(n ** 0.5)
	for i in range(2, root + 1):
		if n % i == 0:
			return n // i
	return n

def p2(n):
	c = 0
	while n % 2 == 0:
		n //= 2
		c += 1
	return c

def seive(n):
	primes = [True] * (n + 1)
	primes[1] = primes[0] = False
	i = 2
	while i * i <= n:
		if primes[i] == True:
			for j in range(i * i, n + 1, i):
				primes[j] = False
		i += 1
	pr = []
	for i in range(0, n + 1):
		if primes[i]:
			pr.append(i)
	return pr

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 denofactinverse(n, m):
	fac = 1
	for i in range(1, n + 1):
		fac = fac * i % m
	return pow(fac, m - 2, m)

def numofact(n, m):
	fac = 1
	for i in range(1, n + 1):
		fac = fac * i % m
	return fac

def sod(n):
	s = 0
	while n > 0:
		s += n % 10
		n //= 10
	return s

def getChar():
	for i in range(0, 26):
		if rt[i] > 0:
			rt[i] -= 1
			return chr(i + 97)
	return ''

def getVal(mid):
	req = 0
	for i in range(0, 26):
		req += max(0, mid * ct[i] - cs[i])
	return req
s = list(input())
t = list(input())
(cs, ct) = ([0] * 26, [0] * 26)
cq = 0
for i in s:
	if i != '?':
		cs[ord(i) - 97] += 1
	else:
		cq += 1
for i in t:
	ct[ord(i) - 97] += 1
(l, r) = (0, (len(s) + len(t) - 1) // len(t))
while l <= r:
	mid = (l + r) // 2
	if getVal(mid) <= cq:
		l = mid + 1
	else:
		r = mid - 1
rt = [0] * 26
for i in range(0, 26):
	if r * ct[i] - cs[i] > 0:
		rt[i] = r * ct[i] - cs[i]
n = len(s)
for i in range(0, n):
	if s[i] == '?':
		temp = getChar()
		if temp:
			s[i] = temp
		else:
			break
anss = ''.join(s)
anss = anss.replace('?', 'a')
print(anss)


def check(mid, ha, has, c):
	need = 0
	for i in range(26):
		need += max(0, ha[i] * mid - has[i])
	return c >= need
ss = 'abcdefghijklmnopqrstuvwxyz'
s = list(input())
t = list(input())
ha = [0] * 26
has = [0] * 26
m = 10000000000
c = 0
for i in t:
	ha[ord(i) - ord('a')] += 1
for i in s:
	if i == '?':
		c += 1
	else:
		has[ord(i) - ord('a')] += 1
l = 0
r = 10000000000
while l <= r:
	mid = l + (r - l) // 2
	if check(mid, ha, has, c):
		l = mid + 1
	else:
		r = mid - 1
j = 0
ll = len(s)
for i in range(26):
	req = max(0, ha[i] * r - has[i])
	while j < ll and req != 0:
		if s[j] == '?':
			s[j] = ss[i]
			req -= 1
		j += 1
for i in range(ll):
	if s[i] == '?':
		s[i] = 'a'
print(''.join(s))


f = lambda q: ord(q) - 97
(s, t) = (list(input()), input())
(n, k) = (len(t), [0] * 26)
for q in s:
	if q != '?':
		k[f(q)] += 1
i = j = 0
while i < len(s):
	if s[i] == '?':
		while k[f(t[j % n])]:
			k[f(t[j % n])] -= 1
			j += 1
		s[i] = t[j % n]
		j += 1
	i += 1
print(''.join(s))


s = input()
t = input()
count_q = s.count('?')
set_t = set(t)
c_s = {i: s.count(i) for i in set_t}
c_s['?'] = s.count('?')
c_t = {i: t.count(i) for i in set_t}
max_n = sum(c_s.values()) // sum(c_t.values())
for i in set_t:
	c_s[i] -= c_t[i] * max_n
while True:
	ss = c_s['?']
	for i in c_s.values():
		if i < 0:
			ss += i
	if ss >= 0:
		break
	elif ss < 0:
		for i in set_t:
			c_s[i] += c_t[i]
for i in set_t:
	if c_s[i] < 0:
		s = s.replace('?', i, -c_s[i])
s = s.replace('?', 'a')
print(s)


from itertools import cycle
from collections import defaultdict
s = defaultdict(int)
init = input()
for digit in init:
	s[digit] += 1
t = input()
token_gen = cycle(t)
questions = []
while True:
	next_token = next(token_gen)
	if s.get(next_token, -1) > 0:
		s[next_token] -= 1
	elif s.get('?', -1) > 0:
		questions.append(next_token)
		s['?'] -= 1
	else:
		break
question_iter = iter(questions)
print(''.join((c if c != '?' else next(question_iter) for c in init)))


(a, b) = (input(), input())
i = 0
j = len(a) // len(b)
e = a.count('?')
from collections import Counter
(ca, cb) = (Counter(a), Counter(b))
while i <= j:
	m = (i + j) // 2
	if sum((cb[x] * m - min(cb[x] * m, ca[x]) for x in set(b))) <= e:
		i = m + 1
	else:
		j = m - 1
r = []
for i in set(b):
	r.extend([*i * max(0, cb[i] * j - ca[i])])
ans = [*a]
for i in range(len(a)):
	if ans[i] == '?':
		if len(r):
			ans[i] = r[-1]
			del r[-1]
		else:
			ans[i] = 'a'
print(''.join(ans))


s = list(input())
t = input()
abc = 'abcdefghijklmnopqrstuvwxyz'
dabc = {}
for i in range(26):
	dabc[abc[i]] = i
lt = {}
ls = {}
dd = {}
ls['?'] = 0
for i in abc:
	lt[i] = 0
	ls[i] = 0
	dd[i] = 0
for letter in t:
	lt[letter] += 1
for letter in s:
	ls[letter] += 1
X = ls['?']

def check(ans):
	global ls, lt, abc, X
	return -sum((min(0, ls[l] - lt[l] * ans) for l in abc)) <= X
(start, end) = [0, 2000000]
i = 0
while start < end:
	st = start + end
	ans = (st + st % 2) // 2
	if check(ans):
		start = ans
	else:
		end = ans - 1
ans = start
for letter in abc:
	dd[letter] = max(0, lt[letter] * ans - ls[letter])
	X -= max(0, lt[letter] * ans - ls[letter])
j = 0
for i in range(len(s)):
	if s[i] == '?':
		try:
			while dd[abc[j]] == 0:
				j += 1
			s[i] = abc[j]
			dd[abc[j]] -= 1
		except:
			s[i] = 'z'
print(''.join(s))


from collections import Counter
(s, t) = (input(), input())
(cs, ct) = (Counter(s), Counter(t))
remain = Counter()
while True:
	for x in ct:
		if cs[x] < ct[x]:
			plus = ct[x] - cs[x]
			if cs['?'] < plus:
				cl = []
				for c in remain:
					cl.extend([c] * remain[c])
				ans = []
				for c in s:
					if c == '?':
						if not cl:
							ans.extend(list(s[len(ans):].replace('?', 'a')))
							break
						else:
							ans.append(cl.pop())
					else:
						ans.append(c)
				print(''.join(ans))
				exit(0)
			else:
				cs['?'] -= plus
				cs[x] += plus
				remain[x] += plus
	cs = cs - ct


import string
source = {i: 0 for i in string.ascii_lowercase}
q = 0
stra = input()
for i in stra:
	if i == '?':
		q += 1
	else:
		source[i] += 1
pack = {i: 0 for i in string.ascii_lowercase}
strb = input()
for i in strb:
	pack[i] += 1

def check(source, pack, q, pkcount):
	for i in pack:
		if source[i] - pack[i] * pkcount < 0:
			q -= pack[i] * pkcount - source[i]
	return q >= 0
(l, r) = (0, 1000001)
while l + 1 != r:
	m = (l + r) // 2
	if check(source, pack, q, m):
		l = m
	else:
		r = m
st = ''
for i in pack:
	if source[i] - pack[i] * l < 0:
		q -= pack[i] * l - source[i]
		st = st + i * (pack[i] * l - source[i])
st = st + 'a' * q
res = ''
p = 0
for i in stra:
	if i == '?':
		res = res + st[p]
		p += 1
	else:
		res = res + i
print(res)


from collections import Counter
A = input()
AC = Counter(A)
B = input()
BC = Counter(B)
letters = [chr(ord('a') + i) for i in range(ord('z') - ord('a') + 1)]
result = 0
(a, b, c) = (0, len(A) + 1, 0)
while a < b:
	c = (a + b) // 2
	needed = 0
	for x in letters:
		needed += max([0, c * BC[x] - AC[x]])
	if needed <= AC['?']:
		a = c + 1
	else:
		b = c
result = a - 1
C = list(A)
i = 0
for x in letters:
	cneed = max([0, result * BC[x] - AC[x]])
	while cneed > 0:
		if C[i] == '?':
			C[i] = x
			cneed -= 1
		i += 1
while i < len(A):
	if C[i] == '?':
		C[i] = 'z'
	i += 1
print(''.join(C))


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
BUFSIZE = 8192
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')

def main():
	s = str(input())
	t = str(input())
	cnt = [0] * 26
	for i in range(len(t)):
		cnt[ord(t[i]) - ord('a')] += 1
	q = s.count('?')
	if q == 0:
		print(s)
		return
	cnt1 = [0] * 26
	for i in range(len(s)):
		if s[i] != '?':
			cnt1[ord(s[i]) - ord('a')] += 1
	res = [0] * 26
	while q > 0:
		for i in range(26):
			if cnt1[i] >= cnt[i]:
				cnt1[i] -= cnt[i]
			elif q >= cnt[i] - cnt1[i]:
				q -= cnt[i] - cnt1[i]
				res[i] += cnt[i] - cnt1[i]
				cnt1[i] = 0
			else:
				res[i] += q
				q = 0
				break
	ans = list(s)
	for i in range(len(ans)):
		if ans[i] == '?':
			j = 0
			while j < 26:
				if res[j] > 0:
					ans[i] = chr(ord('a') + j)
					res[j] -= 1
					break
				j += 1
	print(''.join(ans))
main()


import sys, math, queue, bisect
MOD = 10 ** 9 + 7
sys.setrecursionlimit(1000000)

def can(x):
	rem = ops
	for k in need:
		rem -= max(0, x * need[k] - have[k])
	return rem >= 0
s = list(input())
t = input()
(need, have) = ({}, {})
for ti in t:
	if ti in need:
		need[ti] += 1
	else:
		have[ti] = 0
		need[ti] = 1
ops = 0
for si in s:
	if si in have:
		have[si] += 1
	elif si == '?':
		ops += 1
(low, high) = (0, len(s) // len(t))
while low <= high:
	mid = (low + high) // 2
	if can(mid):
		ans = mid
		low = mid + 1
	else:
		high = mid - 1
x = []
for k in need:
	for i in range(max(0, ans * need[k] - have[k])):
		x.append(k)
j = 0
for i in range(len(s)):
	if s[i] != '?':
		continue
	if j == len(x):
		s[i] = 'z'
	else:
		s[i] = x[j]
		j += 1
print(''.join(s))


def main():
	s = input()
	t = input()
	nd = {}
	hv = {}
	for x in t:
		if x not in nd:
			nd[x] = 1
		else:
			nd[x] += 1
	for x in s:
		if x not in hv:
			hv[x] = 1
		else:
			hv[x] += 1

	def f(n):
		hp = 0
		if '?' in hv:
			hp += hv['?']
		for x in nd:
			if x not in hv:
				hp -= nd[x] * n
			elif hv[x] - nd[x] * n >= 0:
				hp += 0
			else:
				hp += hv[x] - nd[x] * n
		if hp < 0:
			return False
		else:
			return True
	l = 0
	r = len(s) + 100
	while r - 1 != l:
		mid = (l + r) // 2
		if f(mid):
			l = mid
		else:
			r = mid
	tmp = ''
	for x in nd:
		now = hv[x] if x in hv else 0
		if now < nd[x] * l:
			q = nd[x] * l - now
			tmp += x * q
	s = list(s)
	p = 0
	for x in range(len(s)):
		if s[x] == '?':
			if p == len(tmp):
				s[x] = 'a'
			else:
				s[x] = tmp[p]
				p += 1
	print(''.join(s))
main()


from collections import Counter
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')
from collections import Counter
s = input()
t = input()
d = Counter(s)
e = Counter(t)
rem = s.count('?')

def can(x):
	var = rem
	for i in e:
		var -= max(0, e[i] * x - d[i])
	return var >= 0
low = 0
high = len(s) // len(t)
while low <= high:
	mid = (low + high) // 2
	if can(mid):
		ans = mid
		low = mid + 1
	else:
		high = mid - 1
x = ''
for i in e:
	if e[i] * ans > d[i]:
		x += i * (e[i] * ans - d[i])
j = 0
s = list(s)
for i in range(len(s)):
	if s[i] != '?':
		continue
	if j >= len(x):
		s[i] = 'z'
	else:
		s[i] = x[j]
		j += 1
print(''.join(s))


def solve():
	s = list(get(str))
	t = get(str)
	smap = collections.Counter(s)
	tmap = collections.Counter(t)
	alphabet = set(tmap)
	suit = min((smap[a] // tmap[a] for a in alphabet if tmap[a] > 0))
	for a in alphabet:
		smap[a] -= suit * tmap[a]

	def getchar():
		while True:
			for a in alphabet:
				while tmap[a] > smap[a]:
					yield a
					smap[a] += 1
				smap[a] -= tmap[a]
	gen = getchar()
	for (i, a) in enumerate(s):
		if a == '?':
			s[i] = gen.__next__()
	return ''.join(s)
_testcases = '\n?aa?\nab\n\nbaab\n\n??b?\nza\n\nazbz\n\nabcd\nabacaba\n\nabcd\n\n\n'.strip()
import re
import sys
import math
import heapq
from heapq import heapify, heappop, heappush
import bisect
import string
from bisect import bisect_left, bisect_right
import operator
from operator import itemgetter, attrgetter
import itertools
import collections
inf = float('inf')
sys.setrecursionlimit(10000)

def tree():
	return collections.defaultdict(tree)

def cache(func):
	cache_dict = {}

	def _cached_func(*args, _get_cache=False):
		if _get_cache:
			return cache_dict
		if args in cache_dict:
			return cache_dict[args]
		cache_dict[args] = func(*args)
		return cache_dict[args]
	return _cached_func

def equal(x, y, epsilon=1e-06):
	if -epsilon <= x - y <= epsilon:
		return True
	if -epsilon <= x <= epsilon or -epsilon <= y <= epsilon:
		return False
	return -epsilon <= (x - y) / x <= epsilon or -epsilon <= (x - y) / y <= epsilon

def get(_type):
	if type(_type) == list:
		if len(_type) == 1:
			_type = _type[0]
			return list(map(_type, input().strip().split()))
		else:
			return [_type[i](inp) for (i, inp) in enumerate(input().strip().split())]
	else:
		return _type(input().strip())
print(solve())


def solve(mid):
	tmp = 0
	for i in cnt_t:
		if cnt_t[i] * mid <= cnt_s[i]:
			pass
		else:
			tmp += cnt_t[i] * mid - cnt_s[i]
	return tmp <= cnt_s['?']

def solve2(mid):
	tmp = deque([])
	for i in cnt_t:
		if cnt_t[i] * mid <= cnt_s[i]:
			pass
		else:
			for _ in range(cnt_t[i] * mid - cnt_s[i]):
				tmp.append(i)
	return tmp
from collections import deque
import sys
input = sys.stdin.readline
s = input()[:-1]
t = input()[:-1]
cnt_s = {'?': 0}
cnt_t = {}
for (i, char) in enumerate(t):
	if char not in cnt_t:
		cnt_t[char] = 1
		cnt_s[char] = 0
	else:
		cnt_t[char] += 1
for (i, char) in enumerate(s):
	if char not in cnt_s:
		cnt_s[char] = 1
	else:
		cnt_s[char] += 1
ok = -1
ng = 10 ** 9
while abs(ok - ng) > 1:
	mid = (ok + ng) // 2
	if solve(mid):
		ok = mid
	else:
		ng = mid
s = list(s)
q = solve2(ok)
for i in range(len(s)):
	if s[i] == '?':
		if q:
			s[i] = q.pop()
		else:
			s[i] = 'a'
print(''.join(s))


from collections import Counter
import sys
input = sys.stdin.readline
s = list(input().rstrip())
t = input().rstrip()
cnt1 = Counter(s)
cnt2 = Counter(t)
if cnt1['?'] == 0:
	print(*s, sep='')
	exit()
(ok, ng) = (0, 10 ** 9)
while abs(ok - ng) > 1:
	mid = (ok + ng) // 2
	hatena = cnt1['?']
	for (k, v) in cnt2.items():
		hatena -= max(0, v * mid - cnt1[k])
	if hatena >= 0:
		ok = mid
	else:
		ng = mid
keys = list(cnt2.keys())
for i in range(len(s)):
	if s[i] == '?':
		while keys and cnt2[keys[-1]] * ok <= cnt1[keys[-1]]:
			keys.pop()
		if keys:
			s[i] = keys[-1]
			cnt1[keys[-1]] += 1
		else:
			s[i] = 'z'
print(*s, sep='')


(s, t) = (list(input()), list(input()))
os = [0 for i in range(26)]
for i in s:
	if i != '?':
		os[ord(i) - ord('a')] += 1
i = j = 0
while i < len(s):
	if s[i] == '?':
		j = (j + 1) % len(t)
		if os[ord(t[j]) - ord('a')] > 0:
			os[ord(t[j]) - ord('a')] -= 1
			i -= 1
		else:
			s[i] = t[j]
	i += 1
print(''.join(s))


import sys
input = sys.stdin.readline

def solve():
	s = input().strip()
	t = input().strip()
	t_dict = {}
	s_dict = {}
	for c in t:
		if c in t_dict:
			t_dict[c] += 1
		else:
			t_dict[c] = 1
			s_dict[c] = 0
	for c in s:
		if c in s_dict:
			s_dict[c] += 1
		elif c != '?':
			s_dict[c] = 1

	def good(x):
		return sum([max(0, x * t_dict[c] - s_dict[c]) for c in t_dict]) <= s.count('?')
	l = 0
	r = len(s) + 1
	while r - l > 1:
		m = (l + r) // 2
		if good(m):
			l = m
		else:
			r = m
	s = list(s)
	chars = [c for c in t_dict]
	i = 0
	for j in range(len(s)):
		while i < len(chars) and s_dict[chars[i]] >= l * t_dict[chars[i]]:
			i += 1
		if i == len(chars) and s[j] == '?':
			s[j] = 'x'
		elif s[j] == '?':
			s[j] = chars[i]
			s_dict[chars[i]] += 1
	return ''.join(s)
print(solve())


from sys import stdin, stdout
EPS = 10 ** (-20)
INF = float('inf')
sze = 26
first = list(stdin.readline().strip())
second = list(stdin.readline().strip())
symbols1 = [0 for i in range(sze)]
for f in second:
	symbols1[ord(f) - 97] += 1
symbols2 = [0 for i in range(sze + 1)]
for f in first:
	if f == '?':
		symbols2[-1] += 1
	else:
		symbols2[ord(f) - 97] += 1
l = 0
r = max(len(first), len(second)) + 1
while r - l > 1:
	m = (r + l) // 2
	cnt = symbols2[-1]
	for i in range(sze):
		cnt -= max(0, symbols1[i] * m - symbols2[i])
	if cnt >= 0:
		l = m
	else:
		r = m
for i in range(len(first)):
	if first[i] == '?':
		for j in range(sze):
			if symbols2[j] < symbols1[j] * l:
				symbols2[j] += 1
				first[i] = chr(97 + j)
				break
first = ''.join(first).replace('?', 'x')
stdout.write(''.join(first))


import sys
from bisect import bisect_left as lb
from collections import deque
from queue import PriorityQueue as pq
from math import *
input_ = lambda : sys.stdin.readline().strip('\r\n')
ii = lambda : int(input_())
il = lambda : list(map(int, input_().split()))
ilf = lambda : list(map(float, input_().split()))
ip = lambda : input_()
fi = lambda : float(input_())
ap = lambda ab, bc, cd: ab[bc].append(cd)
li = lambda : list(input_())
pr = lambda x: print(x)
prinT = lambda x: print(x)
f = lambda : sys.stdout.flush()
inv = lambda x: pow(x, mod - 2, mod)
mod = 10 ** 9 + 7
s = list(ip())
t = ip()
l = [0 for i in range(26)]
for i in s:
	if i != '?':
		l[ord(i) - 97] += 1
i = 0
c = 0
while i < len(s):
	if s[i] == '?':
		c += 1
		if l[ord(t[c % len(t)]) - 97] > 0:
			l[ord(t[c % len(t)]) - 97] -= 1
			i -= 1
		else:
			s[i] = t[c % len(t)]
	i += 1
print(''.join(s))