public static int medianOfMedians(List<Integer> list) {
        int groupCount = list.size() / 5;
        List<Integer> medians = new ArrayList<Integer>();
                
        for (int i = 0; i <= groupCount; i++) {
            List<Integer> group = new ArrayList<Integer>();
            int startIndex = i * 5;
            int endIndex = i * 5 + 5;
            boolean five = true;
            if (endIndex > list.size()) {
                endIndex = list.size();
                five = false;
            }
            group.addAll(list.subList(startIndex, endIndex));
            if (!group.isEmpty()) {
                int median;
                if (five) {
                    median = median5(group);
                } else {
                    median = median(group);
                }
                medians.add(median);
            }
        }
        
        if (medians.size() > 1) {
            return medianOfMedians(medians);
        } else {
            return medians.get(0);
        }

    }