import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;

public class Euler782 {

    static class Coeff {
        int c00, c11, c22, cab, cac, cbc;

        Coeff(int c00, int c11, int c22, int cab, int cac, int cbc) {
            this.c00 = c00;
            this.c11 = c11;
            this.c22 = c22;
            this.cab = cab;
            this.cac = cac;
            this.cbc = cbc;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o)
                return true;
            if (!(o instanceof Coeff))
                return false;
            Coeff coeff = (Coeff) o;
            return c00 == coeff.c00 && c11 == coeff.c11 && c22 == coeff.c22 &&
                    cab == coeff.cab && cac == coeff.cac && cbc == coeff.cbc;
        }

        @Override
        public int hashCode() {
            int h = Integer.hashCode(c00);
            h = 31 * h + c11;
            h = 31 * h + c22;
            h = 31 * h + cab;
            h = 31 * h + cac;
            h = 31 * h + cbc;
            return h;
        }
    }

    static class Bitset {
        long[] data;

        Bitset(long bits) {
            data = new long[(int) ((bits + 63) / 64)];
        }

        void set(long idx) {
            data[(int) (idx >> 6)] |= (1L << (idx & 63));
        }

        void orWith(Bitset other) {
            for (int i = 0; i < data.length; ++i) {
                data[i] |= other.data[i];
            }
        }

        long count() {
            long total = 0;
            for (long w : data) {
                total += Long.bitCount(w);
            }
            return total;
        }
    }

    static List<Coeff> buildCoeffs() {
        HashSet<Coeff> uniq = new HashSet<>();
        for (int bits = 0; bits < (1 << 9); ++bits) {
            int[][] B = new int[3][3];
            for (int i = 0; i < 3; ++i) {
                for (int j = 0; j < 3; ++j) {
                    B[i][j] = (bits >> (i * 3 + j)) & 1;
                }
            }
            int[] rows = {
                    B[0][0] | (B[0][1] << 1) | (B[0][2] << 2),
                    B[1][0] | (B[1][1] << 1) | (B[1][2] << 2),
                    B[2][0] | (B[2][1] << 1) | (B[2][2] << 2),
            };
            int[] cols = {
                    B[0][0] | (B[1][0] << 1) | (B[2][0] << 2),
                    B[0][1] | (B[1][1] << 1) | (B[2][1] << 2),
                    B[0][2] | (B[1][2] << 1) | (B[2][2] << 2),
            };

            if (!(rows[0] != rows[1] && rows[0] != rows[2] && rows[1] != rows[2]))
                continue;
            if (!(cols[0] != cols[1] && cols[0] != cols[2] && cols[1] != cols[2]))
                continue;

            int[] rsorted = rows.clone();
            int[] csorted = cols.clone();
            Arrays.sort(rsorted);
            Arrays.sort(csorted);
            if (!Arrays.equals(rsorted, csorted))
                continue;

            uniq.add(new Coeff(B[0][0], B[1][1], B[2][2],
                    B[0][1] + B[1][0], B[0][2] + B[2][0], B[1][2] + B[2][1]));
        }
        return new ArrayList<>(uniq);
    }

    static long computeC(int n, List<Coeff> coeffs) {
        long n2 = (long) n * n;
        long bits = n2 + 1;

        Bitset le3 = new Bitset(bits);
        for (int a = 0; a <= n; ++a) {
            for (int b = 0; b <= n; ++b) {
                long k = (long) a * b;
                le3.set(k);
                le3.set(n2 - k);
            }
        }

        long[] sq = new long[n + 1];
        for (int i = 0; i <= n; ++i) {
            sq[i] = (long) i * i;
        }

        // Multithreading in Java
        int numThreads = Runtime.getRuntime().availableProcessors();
        numThreads = Math.min(numThreads, 8);
        Bitset[] locals = new Bitset[numThreads];
        Thread[] threadsArr = new Thread[numThreads];

        for (int t = 0; t < numThreads; t++) {
            final int tId = t;
            final int tCount = numThreads;
            locals[tId] = new Bitset(bits);
            threadsArr[tId] = new Thread(() -> {
                Bitset local = locals[tId];
                for (int a = tId; a <= n; a += tCount) {
                    int bmax = (n - a) / 2;
                    if (bmax < a)
                        continue;
                    long aa = sq[a];
                    for (int b = a; b <= bmax; ++b) {
                        int c = n - a - b;
                        long bb = sq[b];
                        long cc = sq[c];
                        long ab = (long) a * b;
                        long ac = (long) a * c;
                        long bc = (long) b * c;
                        for (Coeff cf : coeffs) {
                            long k = cf.c00 * aa + cf.c11 * bb + cf.c22 * cc
                                    + cf.cab * ab + cf.cac * ac + cf.cbc * bc;
                            local.set(k);
                        }
                    }
                }
            });
            threadsArr[tId].start();
        }

        for (int t = 0; t < numThreads; t++) {
            try {
                threadsArr[t].join();
                le3.orWith(locals[t]);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        Bitset s2 = new Bitset(bits);
        for (int a = 0; a <= n; ++a) {
            int b = n - a;
            long w1 = sq[a];
            long w2 = sq[b];
            long w3 = 2L * a * b;
            long[] vals = { w1, w2, w3, w1 + w2, w1 + w3, w2 + w3, w1 + w2 + w3 };
            for (long k : vals) {
                if (k == 0 || k == n2)
                    continue;
                s2.set(k);
            }
        }

        long countLe3 = le3.count();
        long countS2 = s2.count();
        long total = n2 + 1;
        long n4 = total - countLe3;
        return 3L * total - 4L - countS2 + n4;
    }

    public static String solve() {
        List<Coeff> coeffs = buildCoeffs();
        return Long.toString(computeC(10000, coeffs));
    }

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