public static void main(String[] args) {
        Map<Integer, Integer> p = new HashMap<>();
        TreeMap<Integer, Integer> sorted = new TreeMap<>(new ValueComparator(p));

        for (int a = 1; a < 999; a++) {
            for (int b = 1; b < 999; b++) {
                for (int c = 1; c <= 1000; c++) {
                    if (Math.pow(a, 2) + Math.pow(b, 2) == Math.pow(c, 2)) {
                        if (a + b + c > 1000) {
                            continue;
                        }

                        if (!p.containsKey(a + b + c)) {
                            p.put(a + b + c, 0);
                        }

                        int t = p.get(a + b + c);
                        p.put(a + b + c, ++t);
                    }
                }
            }
        }

        sorted.putAll(p);

        System.out.println(sorted.firstKey());
    }