/*     This is a program to perform "pancake sorting" (or
 *  sorting by prefix reversal).  The idea is that you have
 *  a stack of pancakes of varying (but integer) diameter.
 *  You want to "sort" the pancakes, i.e. arrange them in
 *  a stack from smallest to largest, with largest on 
 *  the bottom of the stack.  
 *
 *  The only operation that you're permitted to do is
 *  to pick up and flip an entire stack of pancakes.  
 *
 *  Input will be read from standard input, and can consist
 *  of one of more lines of input.  Each line of input represents
 *  a separate stack of pancakes.  It is assumed that the stack
 *  is entered from top-to-bottom order, i.e., the first one
 *  in the list is the one on top of the stack.  Also, we
 *  refer to the pancake on top of the stack as pancake #1,
 *  and the one on the bottom as pancake #n (where n=number
 *  in the stack).   
 *
 *  Output should first consist of echoing the stack of pancakes,
 *  and then should consist of a sequence of numbers, where
 *  an integer i means that the stack including  pancake i 
 *  (so pancakes i, i-1, i-2, ..., 1) are flipped over.  
 *  A "0" indicates that no more flips are necessary.    
 *
 *  Input should be in the following format:
 *    n_1 n_2 .....  n_k
 *    n_1 n_2 .....  n_j
 *    ....
 *    ....
 *
 *  Each list consists of k integers (k can vary from stack to stacki, 
 *  but we're going to assume always that k <=300).
 *  
 *  Note:  Integers in each list need *not* be distinct, and this is
 *  something that you should keep in mind.
 *
 *  It's easiest if you redirect input from a file (ask me if you
 *  don't know how to do this).  For example you can try this command:
 *     % java Pancakes <inputfile
 *
 *  RAM   8 February 2009
*/
import java.io.*;
import java.util.*;

class Pancakes
{
    public static void main (String args[])  // entry point from OS
    {
        Scanner s, ls;
        int pancakes[] = new int[300];
        int k;

        s = new Scanner(System.in);  // create new input Scanner

        while(s.hasNextLine())    /*  While there's more data to process...  */
           {
              /*  Read the integers  */
              ls = new Scanner(s.nextLine());
              k = 0;
              while (ls.hasNextInt())
                  pancakes[k++] = ls.nextInt();
 
              processStack(pancakes, k);
           }

   }  /*  end of "main" procedure  */


         public static void processStack(int pancakes[], int L)
         { 
             /*  Print out the stack again  */
             for (int j = 0; j < L; j++)
                 System.out.print(pancakes[j] + "  ");
             System.out.println();
             System.out.print("Flip sequence: ");
 
             /*  Here's where you want to insert your code  */

             System.out.println();  /*  Print a blank line between output */

             return;   

         }  /*  end of "processStack" procedure  */


}  /*  end of "Pancakes" program  */