Alphabet

Program time limit: 1 second

Program memory limit: 512 MB

You have just landed in Quokka kingdom and Queen Quokka has given you a task - to sort a string in alphabetical order.

However, you can't sort the string in our alphabetical order, you have to sort it in their alphabetical order. You are given the order of their alphabet as input.

Input

  • The first line contains a string representing the alphabet order used in Quokka kingdom,
  • The second line contains a string $S$ that you need to sort according to the given alphabet order.

Constraints

For all test cases:

  • The alphabet string contains exactly 26 lowercase English letters, each appearing exactly once
  • $1 \le |S| \le 1000000$ where $|S|$ is the length of string $S$
  • String $S$ contains only lowercase English letters

Output

  • Output the string $S$ sorted according to the given alphabet order.

Templates

You should read from standard input and write to standard output.

In Python, you could use the following code.

# Taking inputs, already done! :D
alphabet = input().strip()
S = input().strip()

result = ""
# Write your code here


# Printing output
print(result)

In C or C++, you could use the following code.

// Taking inputs, already done! :D
char alphabet[27]; scanf("%s", alphabet);
char S[1000001]; scanf("%s", S);

string result;
// Write your code here


// Printing output
printf("%s\n", result.c_str());

Sample Input 1

zyxwvutsrqponmlkjihgfedcba
hello

Sample Output 1

ollhe

Explanation 1

The alphabet order is reversed (z comes first, a comes last). So when we sort "hello" according to this order, 'o' comes first (position 11), followed by 'l' (position 14), 'l' (position 14), 'h' (position 18), and 'e' (position 21). The sorted result is "ollhe".

Sample Input 2

abcdefghijklmnopqrstuvwxyz
world

Sample Output 2

dlorw

Explanation 2

The alphabet order is the standard English alphabet (a comes first, z comes last). When we sort "world" according to this order, 'd' comes first, followed by 'l', 'o', 'r', and 'w'. The sorted result is "dlorw".

Sample Input 3

qwertyuiopasdfghjklzxcvbnm
programming

Sample Output 3

rriopaggnmm

Explanation 3

The alphabet order is based on the QWERTY keyboard layout. When we sort "programming" according to this order, the letters are arranged as: r, r, i, o, p, a, g, g, n, m, m. The sorted result is "rriopaggnmm".

Scoring

Your program will be run on both sample cases and 20 secret cases one after another, and if it produces the correct output for all test cases, it solves this task. Recall that your final score on the task is the score of your highest scoring submission.


Submit

Log in to submit!