C - Dubious Document 2 Editorial /

Time Limit: 2 sec / Memory Limit: 256 MB

配点:300300

問題文

E869120 は、宝物が入ってそうな箱を見つけました。
しかし、これには鍵がかかっており、鍵を開けるためには英小文字からなる文字列 SS が必要です。
彼は文字列 SS' を見つけ、これは文字列 SS00 個以上 S|S| 個以内の文字が ? に置き換わった文字列であることも分かりました。
ただし、文字列 AA に対して、A|A| を「文字列 AA の長さ」とします。

そこで、E869120 はヒントとなる紙を見つけました。

  • 条件1:文字列 SS の中に連続する部分文字列として英小文字から成る文字列 TT が含まれている。
  • 条件2:SS は、条件1を満たす文字列の中で辞書順最小の文字列である。

そのとき、鍵となる文字列 SS を出力しなさい。
ただし、そのような文字列 SS が存在しない場合は代わりに UNRESTORABLE と出力しなさい。

制約

  • 1S,T501 \leq |S'|, |T| \leq 50
  • SS' は英小文字と ? から成る
  • TT は英小文字から成る

入力

入力は以下の形式で標準入力から与えられる。

SS'
TT

出力

鍵となる文字列 SS を出力しなさい。
ただし、そのような文字列 SS が存在しない場合は、代わりに UNRESTORABLE と出力しなさい。


入力例 1Copy

Copy
?tc????
coder

出力例 1Copy

Copy
atcoder

条件1 を満たす文字列は atcoder, btcoder, ctcoder,..., ztcoder2626 個がありますが、その中で最も辞書順で小さいものは atcoder なので、S=S = atcoder と特定できます。


入力例 2Copy

Copy
??p??d??
abc

出力例 2Copy

Copy
UNRESTORABLE

条件1を満たすような文字列 SS が存在しないので、鍵となる文字列 SS は存在しません。

Score : 300300 points

Problem Statement

E869120 found a chest which is likely to contain treasure.
However, the chest is locked. In order to open it, he needs to enter a string SS consisting of lowercase English letters.
He also found a string SS', which turns out to be the string SS with some of its letters (possibly all or none) replaced with ?.

One more thing he found is a sheet of paper with the following facts written on it:

  • Condition 1: The string SS contains a string TT as a contiguous substring.
  • Condition 2: SS is the lexicographically smallest string among the ones that satisfy Condition 1.

Print the string SS.
If such a string does not exist, print UNRESTORABLE.

Constraints

  • 1S,T501 \leq |S'|, |T| \leq 50
  • SS' consists of lowercase English letters and ?.
  • TT consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

SS
TT'

Output

Print the string SS.
If such a string does not exist, print UNRESTORABLE instead.


Sample Input 1Copy

Copy
?tc????
coder

Sample Output 1Copy

Copy
atcoder

There are 2626 strings that satisfy Condition 1: atcoder, btcoder, ctcoder,..., ztcoder. Among them, the lexicographically smallest is atcoder, so we can say S=S = atcoder.


Sample Input 2Copy

Copy
??p??d??
abc

Sample Output 2Copy

Copy
UNRESTORABLE

There is no string that satisfies Condition 1, so the string SS does not exist.



2025-04-24 (Thu)
15:56:47 +00:00