import java.io.File;
import java.util.Map;
import java.util.TreeMap;
import java.util.HashMap;

interface FileCondition
{
    boolean satisfiesCondition( File f );
}

class ANDFileCondition implements FileCondition
{
    public ANDFileCondition( FileCondition fc1, FileCondition fc2 )
    {
        cnd1 = fc1;
        cnd2 = fc2;
    }

    public boolean satisfiesCondition( File f )
    {
        return cnd1.satisfiesCondition( f ) && cnd2.satisfiesCondition( f );
    }

    private FileCondition cnd1;
    private FileCondition cnd2;
}

class FiveKJavaFiles implements FileCondition
{
    public boolean satisfiesCondition( File f )
    {
        return f.length( ) > 5000 && f.getName( ).endsWith( ".java" );
    }
}

class NameEndsWith implements FileCondition
{
    public NameEndsWith( String s )
    {
        suffix = s;
    }

    public boolean satisfiesCondition( File f )
    {
        return f.getName( ).endsWith( suffix );
    }

    private String suffix;
}

class TrueCondition implements FileCondition
{
    public boolean satisfiesCondition( File f )
    {
        return true;
    }
}

class LargerThan implements FileCondition
{
    public LargerThan( long s )
    {
        size = s;
    }

    public boolean satisfiesCondition( File f )
    {
        return f.length( ) > size;
    }

    private long size;
}

class SmallerThan implements FileCondition
{
    public SmallerThan( long s )
    {
        size = s;
    }

    public boolean satisfiesCondition( File f )
    {
        return f.length( ) < size;
    }

    private long size;
}

class Day20
{

    public static void listAllFiles( File d, FileCondition fc )
    {
        if( fc.satisfiesCondition( d ) )
            System.out.println( d.getAbsolutePath( ) );

        if( d.isDirectory( ) )
        {
            for( File f : d.listFiles( ) )
                listAllFiles( f, fc );
        }
    }

    public static void listAllFiles( File d )
    {
        listAllFiles( d, new TrueCondition( ) );
    }




/*
    public static void main( String [ ] args )
    {
        System.out.println( "ALL FILES" );
        listAllFiles( new File( "." ) );
        
        System.out.println( );
        System.out.println( "ALL .java" );
        listAllFiles( new File( "." ), new NameEndsWith( ".java" ) );

        System.out.println( );
        System.out.println( "ALL big files" );
        listAllFiles( new File( "." ), new LargerThan( 10000 ) );

        System.out.println( );
        System.out.println( "ALL java files > 5K bytes" );
        listAllFiles( new File( "."),
             new ANDFileCondition( new LargerThan( 5000 ), new NameEndsWith( ".java" ) ) );

        System.out.println( );
        System.out.println( "ALL JAVA files > 1 Kbytes < 2 Kbytes" );
        listAllFiles( new File( "."),
                new ANDFileCondition(
             new ANDFileCondition( new LargerThan( 1000 ), new SmallerThan( 2000 ) ),
             new NameEndsWith( ".java" ) ) );
    }
*/

    public static void main( String [ ] args )
    {

        int [ ] arr = { 3, 4, 6, 5, 4, 3, 2, 1, 3, 9, 6, 4, 1, 194532, 4, 3, 2 };

        Map<Integer,Integer> counts = new TreeMap<Integer,Integer>( );

        for( int x : arr )
        {
            Integer numberOfTimes = counts.get( x );

            if( numberOfTimes == null )
                counts.put( x, 1 );
            else
                counts.put( x, numberOfTimes + 1 );
        }

        System.out.println( counts );
    }

}
