/** * Solution to "Once Around the Lock" */ import java.util.*; class Move { public String dir; // "C" or "CC" public int dist; public Move(String d, int ds) { dir = d; dist = ds; } } public class Lock { public static Scanner in = new Scanner(System.in); public static int n, // number of positions on dial x,y,z; // combination public static ArrayList move; public static int caseNum; public static void main(String[] args) { caseNum = 0; while ((n = in.nextInt()) != 0) { caseNum++; x = in.nextInt(); y = in.nextInt(); z = in.nextInt(); move = new ArrayList(); String dir = in.next(); while (!dir.equals("?")) { int dist = in.nextInt(); move.add(new Move(dir,dist)); dir = in.next(); } //display(); boolean open = true; // First, look for clockwise rotations adding up to // 2n-x or 3n-x or ...: int i = 0; int sum = 0; while (i < move.size()) { Move m = move.get(i); if (m.dir.equals("C")) sum += m.dist; else break; i++; } if (sum < n || sum%n != n-x) { open = false; } else { // Next, look for counterclockwise rotations adding up to // exactly (n+y-x)%n + n sum = 0; while (i < move.size()) { Move m = move.get(i); if (m.dir.equals("CC")) sum += m.dist; else break; i++; } if (sum != n + (n+y-x)%n) { open = false; } else { // Finally, look for z: sum = 0; while (i < move.size()) { Move m = move.get(i); if (m.dir.equals("C")) sum += m.dist; else break; i++; } if (sum != (n+y-z)%n) { open = false; } else { // make sure we don't move the dial anymore sum = 0; while (i < move.size()) { Move m = move.get(i); sum += m.dist; i++; } if (sum != 0) { open = false; } } } } if (open) System.out.println("Open"); else System.out.println("Closed"); } } public static void display() { System.out.printf("Case %d: %d %d %d %d\n",caseNum,n,x,y,z); for (Move m: move) { System.out.printf("%s %d ",m.dir,m.dist); } System.out.println(); } }