Counting-out Rhyme
time limit per test 1 second memory limit per test 256 megabytes
n children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to n. In the beginning, the first child is considered the leader. The game is played in k steps. In the i-th step the leader counts out ai people in clockwise order, starting from the next person. The last one to be pointed at by the leader is eliminated, and the next player after him becomes the new leader.

For example, if there are children with numbers [8,10,13,14,16] currently in the circle, the leader is child 13 and ai = 12, then counting-out rhyme ends on child 16, who is eliminated. Child 8 becomes the leader.

You have to write a program which prints the number of the child to be eliminated on every step.

传送门:CF792B

Input

The first line contains two integer numbers n and k (2≤n≤100, 1≤k≤n-1). The next line contains k integer numbers a1,a2,...,ak (1≤ai≤1e9).

Output

Print k numbers, the i-th one corresponds to the number of child to be eliminated at the i-th step.

Sample Input

1
2
7 5
10 4 11 4 1

Sample Output

1
4 2 5 6 1

题解

出圈问题 我用队列做的,比较简单,要注意的地方就是每次移动10^9太大了会超时 先把它模上当前剩下的人数,这样操作就很小了
## AC code:(不包含输入类)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import java.io.*;  
import java.util.*;
import java.util.concurrent.LinkedBlockingQueue;
public class Main {

public static void main(String[] args) {
FastScanner sc=new FastScanner();
PrintWriter pw=new PrintWriter(System.out);
while(sc.hasNext()){
int n=sc.nextInt();
int k=sc.nextInt();
int[]jl=new int[k];
for(int i=0;i<k;i++){
jl[i]=sc.nextInt();
}
LinkedBlockingQueue<Integer>queue=new LinkedBlockingQueue<Integer>();
for(int i=1;i<=n;i++){
queue.add(i);
}
for(int i=1;i<=k;i++){
int t=jl[i-1]%queue.size();
int count=0;
while(count<=t){
int temp=queue.poll();
count++;
if(count==t+1){
pw.print(temp+" ");
pw.flush();
}
else{
queue.add(temp);
}
}
}
pw.flush();
}

}

}
class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner() {
try {
br = new BufferedReader(new InputStreamReader(System.in));
st = new StringTokenizer("");
} catch (Exception e){e.printStackTrace();}
}
public boolean hasNext() {
while (!st.hasMoreTokens()) {
String line = nextLine();
if (line == null) {
return false;
}
st= new StringTokenizer(line);
}
return true;
}
public String next() {
if (st.hasMoreTokens()) return st.nextToken();
try {st = new StringTokenizer(br.readLine());}
catch (Exception e) {e.printStackTrace();}
return st.nextToken();
}

public int nextInt() {return Integer.parseInt(next());}

public long nextLong() {return Long.parseLong(next());}

public double nextDouble() {return Double.parseDouble(next());}

public String nextLine() {
String line = "";
try {line = br.readLine();}
catch (Exception e) {e.printStackTrace();}
return line;
}
}