import java.util.*;

public class Euler583 {
    public static String solve() {
        int P = 10000000, L = P / 2;
        List<int[]> tris = genTriples(L);
        List<int[]> rects = genRects(L);
        Map<Integer, List<int[]>> triByA = new HashMap<>();
        Map<Integer, List<Integer>> rectByA = new HashMap<>();
        for (int[] t : tris)
            triByA.computeIfAbsent(t[0], k -> new ArrayList<>()).add(new int[] { t[1], t[2] });
        for (int[] r : rects)
            rectByA.computeIfAbsent(r[0], k -> new ArrayList<>()).add(r[1]);
        long total = 0;
        for (int a = 1; a <= L; a++) {
            if (!triByA.containsKey(a) || !rectByA.containsKey(a))
                continue;
            List<int[]> ts = triByA.get(a);
            ts.sort(Comparator.comparingInt(x -> x[0]));
            List<Integer> rs = rectByA.get(a);
            Collections.sort(rs);
            Set<Integer> tSet = new HashSet<>();
            for (int[] t : ts)
                tSet.add(t[0]);
            for (int h : rs) {
                int limitS = L - a - h;
                if (limitS <= 0)
                    break;
                for (int[] t : ts) {
                    if (t[0] >= h)
                        break;
                    if (t[1] > limitS)
                        break;
                    int u = h + t[0];
                    if (u > L)
                        continue;
                    if (tSet.contains(u))
                        total += 2L * (a + h + t[1]);
                }
            }
        }
        return String.valueOf(total);
    }

    static int gcd(int a, int b) {
        a = Math.abs(a);
        b = Math.abs(b);
        while (b != 0) {
            int t = b;
            b = a % b;
            a = t;
        }
        return a;
    }

    static List<int[]> genTriples(int limit) {
        List<int[]> tris = new ArrayList<>();
        int mmax = (int) Math.sqrt(limit) + 2;
        for (int m = 2; m <= mmax; m++)
            for (int n = 1; n < m; n++) {
                if ((m - n) % 2 == 0 || gcd(m, n) != 1)
                    continue;
                int a0 = m * m - n * n, b0 = 2 * m * n, c0 = m * m + n * n;
                if (c0 > limit)
                    continue;
                for (int k = 1; k * c0 <= limit; k++) {
                    tris.add(new int[] { k * a0, k * b0, k * c0 });
                    tris.add(new int[] { k * b0, k * a0, k * c0 });
                }
            }
        return tris;
    }

    static List<int[]> genRects(int limit) {
        List<int[]> rects = new ArrayList<>();
        int maxLeg = 2 * limit, mmax = (int) Math.sqrt(maxLeg) + 2;
        for (int m = 2; m <= mmax; m++)
            for (int n = 1; n < m; n++) {
                if ((m - n) % 2 == 0 || gcd(m, n) != 1)
                    continue;
                int a0 = m * m - n * n, b0 = 2 * m * n;
                if (Math.max(a0, b0) > maxLeg)
                    continue;
                for (int k = 1; k * Math.max(a0, b0) <= maxLeg; k++) {
                    int x = k * a0, y = k * b0;
                    if (x % 2 == 0) {
                        int a = x / 2;
                        if (a > 0 && a <= limit && y > 0 && y <= limit)
                            rects.add(new int[] { a, y });
                    }
                    if (y % 2 == 0) {
                        int a = y / 2;
                        if (a > 0 && a <= limit && x > 0 && x <= limit)
                            rects.add(new int[] { a, x });
                    }
                }
            }
        return rects;
    }

    public static void main(String[] args) {
        System.out.println(solve());
    }
}
