import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Main
{
	//==========================================================================
	// Interface	
	//==========================================================================

	public interface FrequencyVocabulary
	{
	   public class Statistic
	   {
	      public int count;
	      public double frequency;
	      public Statistic()
	      {
	         count = 0;
	         frequency = 0;
	      }
	   }
	   
	   public TreeMap<String,Statistic> getMap();
	   public String selectMaxFreqToken( Set<String> tokens );	   
	}

	//==========================================================================
	// 	Implementation
	//==========================================================================
	
	public class FrequencyVocabularyImpl implements FrequencyVocabulary
   {
      TreeMap<String, Statistic> map;

   public FrequencyVocabularyImpl(String text, String delimiters)
   {
      map = new TreeMap<String, Statistic>();
      int totalCount = 0;
      
      // first we parse text to tokens (words) and fill the map where keys are words and values - statistic for given word
      StringTokenizer st = new StringTokenizer(text, delimiters);
      while (st.hasMoreTokens())
      {
         String key = st.nextToken();
         if ( containsDigits(key) )
         {
         	continue;
         }
         Statistic value = map.get(key);
         if (null != value)
         {
            value.count++;
            map.replace(key, value);
         }
         else
         {
            value = new Statistic();
            value.count = 1;
            map.put( key, value );
         }
         totalCount += value.count;
      }

      // now we can calculate and set frequency field for all the entries
      for (Map.Entry<String, Statistic> entry : map.entrySet())
      {
         if ( entry.getValue().count != 0 )
         {
            entry.getValue().frequency = ((double)entry.getValue().count) / totalCount;
         }
      }
   }

   public TreeMap<String, Statistic> getMap()
   {
      return map;
   }

   // select token with max frequency from the given set of tokens
   public String selectMaxFreqToken( Set<String> tokens )
   {
      String maxFreqToken = null;
      Statistic maxFreqStat = null;
      for( String token : tokens )
      {
         Statistic stat = map.get(token);
         if ( stat != null )
         {
            if ( maxFreqToken == null )
            {
               maxFreqToken = token;
               maxFreqStat = stat;
            }
            else
            {
               if ( stat.count > maxFreqStat.count )
               {
                  maxFreqToken = token;
                  maxFreqStat = stat;
               }
            }
         }
      }
      
      return maxFreqToken;
   }
   
   public boolean containsDigits( String token )
   {
   	if (  token.indexOf('0') >= 0 || 
   			token.indexOf('1') >= 0 ||
   			token.indexOf('2') >= 0 ||
   			token.indexOf('3') >= 0 ||
   			token.indexOf('4') >= 0 ||
   			token.indexOf('5') >= 0 ||
   			token.indexOf('6') >= 0 ||
   			token.indexOf('7') >= 0 ||
   			token.indexOf('8') >= 0 ||
   			token.indexOf('9') >= 0
   			)
      {
	      return true;
      }
   	return false;
   }
}
	
	//==========================================================================
	// Testing
	//==========================================================================

	public static void main(String[] args)
   {   
      String text = "";
      
      Scanner in = new Scanner(System.in);
      
      for(;;)
      {
        if ( ! in.hasNextLine() ) break;
        String inputLine = in.nextLine();
        if ( inputLine == null || inputLine.equals("%EOF%") ) break;
        text = text + inputLine + "\n";
      }
      in.close();
      
      if ( text.isEmpty() )
      {
         System.out.println("*** Empty text ****");
         return;
      }
      
      //System.out.println("*** DBG:input text is: <"+text+">");
              
      Main obj = new Main();
      
      FrequencyVocabulary fv = obj.new FrequencyVocabularyImpl( text, " ?.,;:-+\n\t{}[]=()<>*&%$#@\"\'`~!" );
      
      TreeMap<String,FrequencyVocabulary.Statistic> statMap = fv.getMap();
      System.out.println("Word frequency statistics:\n");
      for (Map.Entry<String, FrequencyVocabulary.Statistic> statEntry : statMap.entrySet())
      {
         System.out.printf("%s\t,\t%d,\t%f\n",
               statEntry.getKey(),
               statEntry.getValue().count,
               statEntry.getValue().frequency
               );
      }
      System.out.println("--------------------------------------\n");
      
      HashSet<String> tokens = new HashSet<String>();
      tokens.add("for");
      tokens.add("do");
      tokens.add("to");
      tokens.add("else");
      tokens.add("while");
      tokens.add("if");
      String caption = "Select max frequent token from: ";
      for( String s : tokens )
      {
         caption += " " + s;
      }
      System.out.println(caption);
      String s = fv.selectMaxFreqToken(tokens);
      if ( s == null ) s = "<null>";
      System.out.println("=> selected is: " + s );  
   }
}