// Collection of code snippets by Arne Vajhøj 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
import java.util.Random;

public class MultiNominal {
    private final static int N = 10000;
    private final static int K = 8;
    private final static Random rng = new Random();
    public static boolean match() {
        int[] val = new int[4];
        for(int i = 0; i < K; i++) {
            val[rng.nextInt(val.length)]++;
        }
        return (val[0] == val[1]) && (val[1] == val[2]) && (val[2] == val[3]);
    }
    public static void main(String[] args) {
        int perfect = 0;
        for(int i = 0; i < N; i++) {
            if(match()) {
                perfect++;
            }
        }
        // expected 8!/16^5 = 0.0384
        System.out.println(perfect * 1.0 / N);
    }
}
