You're given an array of integers
and a permutation , each of size . Recall that a permutation of length is an array where every element from to occurs exactly once.
The following operation is performed on the array times:
- For each index (), add to simultaneously.
For example, if and , after one operation .
Find the values of modulo , after performing the above operation times.
Input Format
- The first line contains two space separated integers and .
- The second line contains space separated integers , the elements of the array .
- The third line contains space separated integers , the elements of the permutation .
Output Format
Print space separated integers, the elements of the array modulo after performing the above operation times.
Constraints
- It is guaranteed that is a permutation.
Sample Input 1
4 3
2 6 1 7
3 1 4 2
Sample Output 1
32 22 42 32
Explanation
The array evolves as follows
where denotes the array after operations.
Thus, finally the elements of read .
No comments:
Post a Comment