/* ID: jennife2 LANG: JAVA TASK: beads */ import java.io.*; class beads{ public static void main(String[] args) throws IOException{ BufferedReader console = new BufferedReader(new FileReader("beads.in")); PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("beads.out"))); int counter = 0; int places = Integer.parseInt(console.readLine()); int[] necklace = new int[places+1]; char[] coloring = new char[places+1]; coloring[0] = (char) console.read(); System.out.println(places); System.out.print(coloring[0]); necklace[0] = 1; while(console.ready()){ char cur = (char) console.read(); System.out.print(cur); if (cur != coloring[counter]){ counter++; coloring[counter] = cur; } necklace[counter]++; } // -------- End Input if(counter>0&&coloring[counter]==coloring[0]){ necklace[0] += necklace[counter]; counter--; } boolean flag = true; while(flag){ flag = false; if(counter>1){ for(int i=0;i0&&coloring[counter-1]==coloring[0]){ necklace[0] += necklace[counter-1]; counter--; } // -------- End Modify Input // -------- Time to Solve! int lg = necklace[0]; if (counter>1){ for(int i=0; ilg)lg=cur; } }} System.out.println(); for(int i =0;i