/* Idea: the question is a bit similar to the deformed Joseph ring, but it feels a little troublesome to use the linked list. So I used arrays to simulate every idea at the beginning. Then I saw a good idea on the Internet, I understood it and typed it myself.Code. In this case, we can understand that there is a pile of playing cards on the table as N, which is placed in order, K cards are removed from the left, M cards are removed from the Right, and m cards are removed from the right. When you count from left to end, you need to start from the leftmost card to the right, and the right number is the same as the left number. When the cards on the table are over. */# Include <stdio. h> int queue [25]; void Init (int n) {for (INT I = 1; I <= N; I ++) queue [I] = I ;} int main () {int N, K, M; while (scanf ("% d", & N, & K, & M) {If (! N &&! K &&! M) break; Init (n); int CNT = 0, front = 0, near = n + 1; while (CNT <n) {int C1 = 0, C2 = 0; while (1) {If (queue [Front]! = 0) C1 ++; If (front> N) Front = 0; If (C1 = k) {printf ("% 3d", queue [Front]); CNT ++; break;} front ++;} while (1) {If (queue [near]! = 0) C2 ++; If (near <1) near = n + 1; if (C2 = m) {If (queue [Front]! = Queue [near]) {printf ("% 3d", queue [near]); CNT ++;} break;} near --;} queue [Front] = 0; queue [near] = 0; If (CNT! = N) printf (",") ;}printf ("\ n") ;}return 0 ;}