#K14991. Restore Shuffled String

    ID: 24257 Type: Default 1000ms 256MiB

Restore Shuffled String

Restore Shuffled String

You are given a string s and an array of indices. The array indices indicates the final shuffled position of each character in s. Your task is to restore the original shuffled string using these indices.

More formally, let \(s = s_0s_1\cdots s_{n-1}\) be a string of length \(n\) and \(indices = [i_0, i_1, \dots, i_{n-1}]\) be an array of \(n\) integers. The answer string \(t\) is defined such that for each \(0 \le k < n\), the character \(s_k\) will be placed at position \(i_k\) in \(t\). That is, if we denote \(t\) as \(t_0t_1\cdots t_{n-1}\), then for every \(k\), we require that \(t_{i_k} = s_k\).

You can assume that the length of s is equal to the length of indices.

inputFormat

The input is read from stdin and consists of two lines:

  • The first line contains the string s.
  • The second line contains \(n\) space-separated integers representing the array indices, where \(n\) is the length of s.

You can assume that \(s\) contains only printable characters and that the number of indices exactly matches the length of s.

outputFormat

Output to stdout a single line containing the restored string after shuffling.

## sample
abc
2 1 0
cba