eolymp
bolt
Try our new interface for solving problems
Problems

Counting-Out

Counting-Out

\textbf{n} children, standing in a circle, are using counting-outs to determine who will leave the circle. It means, they recite counting-out rhymes, pointing each rhyme’s word on next (by circle) child. The child being pointed on at the last word of the rhyme leaves the circle. The process repeats \textbf{k} (\textbf{1} ≤ \textbf{k} ≤ \textbf{n}) times, restarting from the child following the one who just had left the circle. Counting starts from lower numbers to higher, but counting-out rhymes are different. Write a program which reads number of children, number of counting-out rhymes, and numbers of words in used counting-out rhymes, and finds the order in which children will leave the circle. \InputFile The first line contains space separated number of children \textbf{n} (\textbf{1} ≤ \textbf{n} ≤ \textbf{10^18}) and number of used counting-out rhymes \textbf{k} (\textbf{1} ≤ \textbf{k} ≤ min(\textbf{n}, \textbf{10^5})). The second line contains \textbf{k} integers (each in range \textbf{1} ≤ \textbf{a_i} ≤ \textbf{10^18}) - numbers of words in the counting-out rhymes, used the \textbf{1}st, the \textbf{2}nd, …, the \textbf{k}-th time. \OutputFile The only line of the output should contain space-separated sequence of \textbf{k} numbers - the numbers of the children leaving the circle after the corresponding counting-out. Initially, children are numbered from \textbf{1} to \textbf{k}, and the \textbf{1}st is the child who is pointed on when reciting the \textbf{1}st word of the \textbf{1}st counting-out rhyme. Further, each child keeps the same number, irrespectively of how children leave the circle. \includegraphics{https://static.e-olymp.com/content/8d/8d78e19cbfbdade988fe3515d3e9a416702d24d2.jpg}
Time limit 3 seconds
Memory limit 64 MiB
Input example #1
10 5
2 7 1 8 2
Output example #1
2 9 10 1 4
Input example #4
8 3
10 1 2
Output example #4
2 3 5
Source 2014 ACM-ICPC Ukraine, 2nd Round Ukraine, September 13, Problem I