LogiQuest

465. Custom Sort String

MediumSorting

Rearrange s so its characters follow the order given in order (distinct letters). Characters not in order go at the end, keeping their original relative order.

Input format

Line 1: order Line 2: s

Output format

The rearranged string.

Example 1

Input

cba
abcd

Output

cbad

Example 2

Input

bcafg
abcd

Output

bcad

Constraints

1 ≤ |s| ≤ 200

Read input from standard input and print the answer to standard output. Your code is judged against 4 test cases, most of them hidden.

Loading the MyLoginn IDE…