시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
2 초 128 MB 9 3 2 28.571%

문제

Mark is developing new social network Facepalm for inhabitants of Phobos and Deimos. His recent task is to add information about home asteroid of the owner to each account. Of course, each account owner could enter such information, but Mark decided that it would be more convenient if some default value was suggested to the user at logon. He investigated the situation and found out that home asteroid of a user can be found by analyzing his last name.

Last name of each user of Facepalm is a non-empty word consisting of lowercase letters of the English alphabet. Users from Phobos have their last names matching regular expression P while users from Deimos have their last names matching regular expression D.

However, the problem is that some last names can match both expressions. Two expressions are called disjoint if there is no such non-empty string s that matches both expressions. Mark believes that expressions P and D are disjoint. However he needs your help to check it.

You are given two regular expressions P and D. Check whether they are disjoint, and if they are not, find the shortest non-empty string s that matches both of them. If there are several shortest common strings, you can find any one.

입력

The input file contains two lines. The first line contains regular expression P. The second line contains regular expression D. Each expression contains from 1 to 100 characters.

출력

If Mark’s guess is correct and the two expressions are indeed disjoint, print “Correct” at the first line of the output file. If they are not, print “Wrong” at the first line of the output file. In this case the second line must contain any shortest non-empty string that matches both expressions.

예제 입력

a(ab)*b
a(a|b)*ab

예제 출력

Correct

예제 입력 2

a(ab)*a
a(a|b)*ba

예제 출력 2

Wrong
aaba

힌트

Let us define regular expressions and matching strings to them formally.

  • A single lowercase letter c is a regular expression, it matches only a string consisting of a single letter c.
  • Alternation: if P and Q are regular expressions then (P|Q) is a regular expression, a string α matches it if α matches P or α matches Q.
  • Concatenation: if P and Q are regular expressions then (PQ) is a regular expression, a string α matches it if α = βγ, β matches P and γ matches Q.
  • Kleene star: if P is regular expression then (P*) is a regular expression, a string α matches it if α can be represented as a concatenation of zero or more strings α1α2...αk where all αi match P. An empty string always matches Kleene star.