시간 제한메모리 제한제출정답맞힌 사람정답 비율
1.6 초 1024 MB74480.000%

문제

Due to his paranoia about security, Sam decided to pick a long password for his e-mail account that contains only small letters of the English alphabet. However, he realized that he had a high risk of forgetting his password, so he decided to encode it into 2 strings, also containing only small letters of the English alphabet. He wrote these strings on a piece of paper and hid the paper under his bed. Sam chose the strings A and B such that the password S is the anagram of B that appears as a subsequence of A and is lexicographically minimal.

We say that a string B = b1b2...b|B| is a subsequence of A = a1a2...a|A| if and only if there exists a sequence of strictly increasing indices n1, n2, ..., n|B| such that ani=bi for i = 1, 2, ..., |B|.

We say that A is lexicographically smaller than B if and only if there exists an index n < |A| such that ai=bi for i = 1, 2, ..., n and an+1 < bn+1.

We say that S is an anagram of B if S and B contain the same letters and in the same quantities, but possibly in different orders.

As expected, Sam forgot his password one week later and now he is struggling to get it back, so he asks for your help. Write a program that can find his password for him.

Given the two strings A and B, print out Sam's password based on the restrictions above.

입력

The input has exactly one line containing the 2 strings A and B separated by one whitespace.

출력

The output should contain one line representing Sam's password. In case there is no solution, you should print out the word “impossible” (without the quotation marks).

서브태스크

번호배점제한
130

|A| ≤ 1,000; |B| ≤ 100

230

|A| ≤ 1,000,000; |B| ≤ 100,000

340

|A| ≤ 30,000,000; |B| ≤ 3,000,000

예제 입력 1

abacaba bab

예제 출력 1

abb

예제 입력 2

abacaba cbc

예제 출력 2

impossible

예제 입력 3

abacaba caab

예제 출력 3

aacb

채점 및 기타 정보

  • 예제는 채점하지 않는다.