public class Euler126 {
    static int layerSize(int a, int b, int c, int n) {
        return 2 * (a * b + a * c + b * c) + 4 * (n - 1) * (a + b + c) + 4 * (n - 1) * (n - 2);
    }

    public static void main(String[] args) {
        int target = 1000, limit = 50000;
        while (true) {
            int[] count = new int[limit + 1];
            for (int a = 1; layerSize(a, a, a, 1) <= limit; a++)
                for (int b = a; layerSize(a, b, b, 1) <= limit; b++)
                    for (int c = b; layerSize(a, b, c, 1) <= limit; c++)
                        for (int n = 1;; n++) {
                            int cu = layerSize(a, b, c, n);
                            if (cu > limit)
                                break;
                            count[cu]++;
                        }
            for (int i = 1; i <= limit; i++)
                if (count[i] == target) {
                    System.out.println(i);
                    return;
                }
            limit *= 2;
        }
    }
}
