// Words sorted on frequency
import java.io.*;
import java.util.*;
public class ISC2010Q3
{   public static void main(String args[])throws IOException
    {   BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter Para ");
        String para=br.readLine();
        StringTokenizer st=new StringTokenizer(para," ,?.");
        String words[]=new String[st.countTokens()];
        int frequency[]=new int[st.countTokens()];
        //put words in an array
        int index=0;
        while(st.hasMoreTokens())
        {   words[index++]=st.nextToken();
        }
        //count frequency of each word
        for(int i=0; i<words.length; i++)
        {   int count=0;
            for(int j=0; j<words.length; j++)
            {   if(words[i].equals(words[j]))
                {   count++;
                }
            }
            frequency[i]=count;
        }
        //sort arrays on frequency
        for(int i=0; i<frequency.length-1; i++)
        {   for(int j=0; j<frequency.length-1-i; j++)
            {   if(frequency[j]>frequency[j+1])
                {   int temp1=frequency[j]; frequency[j]=frequency[j+1];frequency[j+1]=temp1;
                    String temp2=words[j]; words[j]=words[j+1];words[j+1]=temp2;
                }
            }
        }
        //display
        for(int i=0; i<words.length; i+=frequency[i])
        {   System.out.println(words[i]+"\t"+frequency[i]);
        }
    }//main
}//class

