/* Solution to Ball toss by Bob Roos */ import java.io.*; import java.util.*; public class BA { public static int n, k, count; public static String temp; public static int t[] = new int[32]; public static boolean used[] = new boolean[32]; public static int total; public static int tosser, next; public static BufferedReader in; public static int add(int a, int b) { if (a+b < 0) return a+b+n; return (a+b)%n; } public static void toss() { int i,hold; /* pre: tosser is completely processed; next receives the ball */ while (total < n) { count++; if (!used[next]) { total++; used[next] = true; } /* figure out new value of "next" */ if (tosser == add(next,1) && t[next] == -1) { t[next] = -t[next]; tosser = next; next = add(next,-1); } else if (tosser == add(next,-1) && t[next] == 1) { t[next] = -t[next]; tosser = next; next = add(next,1); } else { t[next] = -t[next]; hold = tosser; tosser = next; next = add(hold,-t[next]); } } System.out.println("Classmate " + (tosser+1) + " got the ball last after " + count + " tosses."); } public static void main(String args[]) throws Exception{ int i; StringTokenizer tok; in = new BufferedReader(new InputStreamReader(System.in)); while (true) { String line = in.readLine(); tok = new StringTokenizer(line); n = Integer.parseInt(tok.nextToken().trim()); if (n <= 0) break; k = Integer.parseInt(tok.nextToken().trim()); for (i = 0; i < n; i++) { temp = tok.nextToken(); used[i] = false; total = 0; count = 0; t[i] = 1; if (temp.charAt(0) == 'L') t[i] = -1; } next = k-1; tosser = 0; toss(); } } }