import java.io.*;
import java.util.*;

public class Input
{
   private static String current_token = null;
   private static StringTokenizer reader;
   private static BufferedReader in = null;

   public Input(InputStream input_file)
   {
	   in = new BufferedReader (new InputStreamReader(input_file));
	   current_token= null;
	   reader= null;
   }	   

   //-----------------------------------------------------------------
   //  Gets the next input token assuming it may be on subsequent
   //  input lines.
   //-----------------------------------------------------------------
   private static String getNextToken()
   {
      return getNextToken (true);
   }

   //-----------------------------------------------------------------
   //  Gets the next input token, which may already have been read.
   //-----------------------------------------------------------------
   private static String getNextToken (boolean skip)
   {
      String token;

      if (current_token == null)
         token = getNextInputToken (skip);
      else
      {
         token = current_token;
         current_token = null;
      }

      return token;
   }

   //-----------------------------------------------------------------
   //  Gets the next token from the input, which may come from the
   //  current input line or a subsequent one. The parameter
   //  determines if subsequent lines are used.
   //-----------------------------------------------------------------
   private static String getNextInputToken (boolean skip)
   {
      final String delimiters = " \t\n\r\f";
      String token = null;

      try
      {
         if (reader == null)
            reader = new StringTokenizer
               (in.readLine(), delimiters, true);

         while (token == null ||
                ((delimiters.indexOf (token) >= 0) && skip))
         {
            while (!reader.hasMoreTokens())
               reader = new StringTokenizer
                  (in.readLine(), delimiters,true);

            token = reader.nextToken();
         }
      }
      catch (Exception exception)
      {
         token = null;
      }

      return token;
   }

   //-----------------------------------------------------------------
   //  Returns true if there are no more tokens to read on the
   //  current input line.
   //-----------------------------------------------------------------
   public static boolean endOfLine()
   {
      return !reader.hasMoreTokens();
   }

   //*************  Reading Section  *********************************

   //-----------------------------------------------------------------
   //  Returns a string read from standard input.
   //-----------------------------------------------------------------
   public static String readOneString()
   {
      String str;

      try
      {
         do 
         {
            str = getNextToken(false);
         } while (str.equals(" "));
      }
      catch (Exception exception)
      {
         //error ("Error reading String data, null value returned.");
         str = null;
      }
      return str;
   }
   public static String flush_line()
   {
      String str;

      try
      {
         str = "";
         while (! endOfLine())
         {
            str = str + getNextToken(false);
         }
      }
      catch (Exception exception)
      {
         System.out.println("Error reading to end of line.");
         str = null;
      }
      return str;
   }
}
