/* * And Then There was One * * Parke Godfrey * 2 October 2008 */ import java.util.Scanner; import java.io.PrintStream; class Node { public final int id; public Node before; public Node after; public Node(int key) { id = key; before = this; after = this; } public void insertAfter(Node other) { Node next = this.after; this.after = other; other.after = next; other.before = this; next.before = other; } public void unlink() { this.before.after = this.after; this.after.before = this.before; } } public class WasOne { public static void main(String[] args) { Scanner input = new Scanner(System.in); PrintStream output = System.out; int n = input.nextInt(); int k = input.nextInt(); int m = input.nextInt(); while (n != 0) { int count = n; Node head = new Node(0); for (int i = n-1; i > 0; i--) head.insertAfter(new Node(i)); while (count > 1) { /* output.printf("%d ", head.id); Node current = head.after; while (current != head) { output.printf("%d ", current.id); current = current.after; } output.printf("\n"); output.printf("%d ", head.id); current = head.before; while (current != head) { output.printf("%d ", current.id); current = current.before; } output.printf("\n"); */ count--; int steps = ((k - 1) % count) + 1; if (steps <= count - steps) { head = head.after; head.before.unlink(); for (int i = 1; i < steps; i++) head = head.after; } else { head = head.before; head.after.unlink(); for (int i = 1; i <= count - steps; i++) head = head.before; } } // output.println(head.id); output.println(((head.id + m - 1) % n) + 1); // if (1 == 1) break; n = input.nextInt(); k = input.nextInt(); m = input.nextInt(); } } }