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

//double C(String x,Map<Character,Integer>f){double H=0,g;for(char c:x.toCharArray())f.put(c,f.containsKey(c)?f.get(c)+1:1);for(char c:f.keySet()){g=f.get(c);H+=g*Math.log(g/x.length())/Math.log(2);}return-H;}

class Ideone
{
	public static double C(String x,Map<Character,Integer>f)
	{
		double H=0,g;
		
		for(char c:x.toCharArray())
		{
			f.put(c, f.containsKey(c) ? f.get(c)+1 : 1);
		}
		
		for(char c : f.keySet())
		{
			g = f.get(c);
			H += (g/Math.log(2)) * Math.log(g/x.length());
		}
		
		return-H;
	}
	
	public static void main (String[] args) throws java.lang.Exception
	{
		System.out.println("'This is a test.'=> "+C("This is a test.",new TreeMap<Character,Integer>()));
		System.out.println("'00001111' => "+C("00001111",new TreeMap<Character,Integer>()));
		System.out.println("'cwmfjordbankglyphsvextquiz' => "+C("cwmfjordbankglyphsvextquiz",new TreeMap<Character,Integer>()));
		System.out.println("'               ' => "+C("               ",new TreeMap<Character,Integer>()));
	}
}


