import java.util.*;

public class Euler385 {
    static class Point implements Comparable<Point> {
        long x, y;

        Point(long x, long y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public int compareTo(Point o) {
            if (this.x != o.x)
                return Long.compare(this.x, o.x);
            return Long.compare(this.y, o.y);
        }

        @Override
        public boolean equals(Object o) {
            if (!(o instanceof Point))
                return false;
            Point p = (Point) o;
            return this.x == p.x && this.y == p.y;
        }

        @Override
        public int hashCode() {
            int hx = Long.hashCode(x), hy = Long.hashCode(y);
            return hx ^ (hy + 0x9e3779b9 + (hx << 6) + (hx >> 2));
        }
    }

    static class TriangleKey {
        Point[] pts;

        TriangleKey(Point p1, Point p2, Point p3) {
            pts = new Point[] { p1, p2, p3 };
            Arrays.sort(pts);
        }

        @Override
        public boolean equals(Object o) {
            if (!(o instanceof TriangleKey))
                return false;
            TriangleKey tk = (TriangleKey) o;
            return pts[0].equals(tk.pts[0]) && pts[1].equals(tk.pts[1]) && pts[2].equals(tk.pts[2]);
        }

        @Override
        public int hashCode() {
            int h = 0;
            for (Point p : pts) {
                h ^= p.hashCode() + 0x9e3779b9 + (h << 6) + (h >> 2);
            }
            return h;
        }
    }

    static class Pair implements Comparable<Pair> {
        long d, k;

        Pair(long d, long k) {
            this.d = d;
            this.k = k;
        }

        @Override
        public int compareTo(Pair o) {
            if (this.d != o.d)
                return Long.compare(this.d, o.d);
            return Long.compare(this.k, o.k);
        }

        @Override
        public boolean equals(Object o) {
            if (!(o instanceof Pair))
                return false;
            Pair p = (Pair) o;
            return this.d == p.d && this.k == p.k;
        }

        @Override
        public int hashCode() {
            return Long.hashCode(d) ^ Long.hashCode(k);
        }
    }

    static class Direction {
        int q0, u, v, m, pell_n;
        long d_max, k_max;
    }

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

    static List<Pair> generatePellPairs(int pellN, long dMax, long kMax) {
        List<Pair> seeds = new ArrayList<>();
        if (pellN == -39) {
            seeds.add(new Pair(4, 3)); // (d, k) form => k0=3, d0=4
            seeds.add(new Pair(5, 6)); // k0=6, d0=5
        } else if (pellN == -3) {
            seeds.add(new Pair(2, 3)); // k0=3, d0=2
        } else {
            return new ArrayList<>();
        }

        List<Pair> all = new ArrayList<>();
        for (Pair s : seeds) {
            long k = s.k, d = s.d;
            while (d <= dMax && k <= kMax) {
                all.add(new Pair(d, k));
                if (k > (Long.MAX_VALUE - 3 * d) / 2 || d > (Long.MAX_VALUE - k) / 2)
                    break;
                long nK = 2 * k + 3 * d;
                long nD = k + 2 * d;
                k = nK;
                d = nD;
            }
        }

        Set<Pair> set = new HashSet<>(all);
        all = new ArrayList<>(set);
        Collections.sort(all);
        return all;
    }

    static List<Direction> buildDirections(long n) {
        List<Direction> dirs = new ArrayList<>();
        int[] q0s = { 3, 39 };
        for (int q0 : q0s) {
            int pellN = -117 / q0;
            int limit = (int) Math.sqrt(q0) + 2;
            for (int u = -limit; u <= limit; u++) {
                for (int v = -limit; v <= limit; v++) {
                    if (u == 0 && v == 0)
                        continue;
                    if (gcd(u, v) != 1)
                        continue;
                    if (u * u + u * v + v * v != q0)
                        continue;

                    int a = 2 * u + v;
                    int b = u + 2 * v;
                    int m = (int) gcd(a, b);
                    if (m != 3)
                        continue;

                    long xScale = Math.max(Math.max(Math.abs(u), Math.abs(v)), Math.abs(u + v));
                    long yScaleRaw = Math.max(Math.max(Math.abs(a), Math.abs(b)), Math.abs(u - v));
                    if (xScale == 0 || yScaleRaw % m != 0)
                        continue;

                    long yScale = yScaleRaw / m;
                    if (yScale == 0)
                        continue;

                    long dMax = n / xScale;
                    long kMax = n / yScale;

                    if (dMax > 0 && kMax > 0) {
                        Direction d = new Direction();
                        d.q0 = q0;
                        d.u = u;
                        d.v = v;
                        d.m = m;
                        d.pell_n = pellN;
                        d.d_max = dMax;
                        d.k_max = kMax;
                        dirs.add(d);
                    }
                }
            }
        }
        return dirs;
    }

    static class Result {
        TriangleKey tk;
        long area;
    }

    static Result buildTriangleKey(Direction dir, long d, long k, long n) {
        long u = dir.u, v = dir.v, m = dir.m;
        long a = 2 * u + v;
        long b = u + 2 * v;

        if (a % m != 0 || b % m != 0 || (u - v) % m != 0)
            return null;

        long x1 = d * u;
        long x2 = d * v;
        long x3 = -d * (u + v);

        long y1 = (b / m) * k;
        long y2 = -(a / m) * k;
        long y3 = ((u - v) / m) * k;

        if (Math.abs(x1) > n || Math.abs(x2) > n || Math.abs(x3) > n ||
                Math.abs(y1) > n || Math.abs(y2) > n || Math.abs(y3) > n) {
            return null;
        }

        Point p1 = new Point(x1, y1), p2 = new Point(x2, y2), p3 = new Point(x3, y3);
        TriangleKey tk = new TriangleKey(p1, p2, p3);

        if (tk.pts[0].equals(tk.pts[1]) || tk.pts[1].equals(tk.pts[2]))
            return null;

        Result r = new Result();
        r.tk = tk;
        r.area = dir.q0 * Math.abs(d * k);
        return r;
    }

    static String solve() {
        long n = 1000000000L;
        List<Direction> dirs = buildDirections(n);
        if (dirs.isEmpty())
            return "0";

        long maxDN39 = 0, maxKN39 = 0, maxDN3 = 0, maxKN3 = 0;
        for (Direction d : dirs) {
            if (d.pell_n == -39) {
                maxDN39 = Math.max(maxDN39, d.d_max);
                maxKN39 = Math.max(maxKN39, d.k_max);
            } else if (d.pell_n == -3) {
                maxDN3 = Math.max(maxDN3, d.d_max);
                maxKN3 = Math.max(maxKN3, d.k_max);
            }
        }

        List<Pair> pairsN39 = generatePellPairs(-39, maxDN39, maxKN39);
        List<Pair> pairsN3 = generatePellPairs(-3, maxDN3, maxKN3);

        Map<TriangleKey, Long> map = new HashMap<>();

        for (Direction dir : dirs) {
            List<Pair> pairs = (dir.pell_n == -39) ? pairsN39 : pairsN3;
            for (Pair p : pairs) {
                if (p.d > dir.d_max || p.k > dir.k_max)
                    continue;
                for (long sign : new long[] { -1, 1 }) {
                    Result res = buildTriangleKey(dir, p.d, sign * p.k, n);
                    if (res == null)
                        continue;

                    if (map.containsKey(res.tk) && map.get(res.tk) != res.area) {
                        throw new RuntimeException("Inconsistency in triangle area");
                    }
                    map.put(res.tk, res.area);
                }
            }
        }

        long total = 0;
        for (long a : map.values())
            total += a;
        return Long.toString(total);
    }

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