logo AlgoBeat OnlineJudge
登录 注册

#206216. [NWRRC 2014] Expression

内存限制:512 MiB 时间限制:8000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

In computing, regular expressions is a powerful tool for text search and string matching. In this problem a simplified version of regular expressions is used:

  • An empty string is a regular expression, only the empty string matches it.

  • A single lowercase letter c is a regular expression, a string consisting of a single letter matches it.

  • A dot . is a regular expression, a string consisting of any single letter matches it.

  • Alternation: if and are regular expressions then (α|β) is a regular expression, a string matches it only if matches or matches .

  • Concatenation: if and are regular expressions then (αβ) is a regular expression, a string matches it only if xy, matches and matches .

  • Kleene star: if is regular expression then (α∗) is a regular expression, a string matches it only if is empty or xy, is nonempty and matches and matches In other words, consists of zero or more strings, each of them matches

Parentheses can be omitted, in this problem Kleene star has the highest priority, concatenation has medium priority and alternation has lowest priority. Thus abc*|de means (ab(c*))|(de).

For example, string abcabcab matches a(bc|a)*ab, but string abcbab does not.

Your task is to find the shortest string that matches the given regular expression and contains the given substring .

输入格式

The first line of the input file contains the regular expression . The second line of the input file contains the substring .

String consists of lowercase English letters. Expression consists of lowercase English letters and special characters: dots (.), parentheses (() and ()), pipes (|), and asterisks (*).

输出格式

Output the shortest possible string that both matches and contains as substring. If there are no such strings, output NO.

The string should contain only lowercase English letters.

样例

样例输入 1

a.*b
bab

样例输出 1

abab

样例输入 2

(ab)*
bb

样例输出 2

NO

数据范围与提示

Time limit: 10 s, Memory limit: 256 MB.