import java.io.*;
import java.util.*;

/**
 * Created by Ilya Peresadin.
 */
public class distances_ip {
    FastScanner in;
    PrintWriter out;
    public static final String TASK = "distances";
    class Pair implements Comparable {
        public int f, s;
        Pair(int x, int y) {
            f = x;
            s = y;
        }

        @Override
        public int compareTo(Object o) {
            Pair oth = (Pair)o;
            if (f < oth.f || f == oth.f && s < oth.s)
                return -1;
            if (f == oth.f && s == oth.s)
                return 0;
            return 1;
        }

        @Override
        public int hashCode() {
            int p = 1000000000;
            return (int)(1L * (f + p) * p + s + p);
        }

        @Override
        public boolean equals(Object obj) {
            Pair oth = (Pair)obj;
            return f == oth.f && s == oth.s;
        }
    }

    ArrayList <Pair> pts, pif;
    HashSet <Pair> hs = new HashSet<Pair>();
    Pair pr = new Pair(0, 0);
    int fnd(int fx, int fy) {
        pr.f = fx;
        pr.s = fy;
        if (hs.contains(pr))
            return 1;
        return 0;
    }

    public void solve() throws IOException {
        int n;
        long d;
        n = in.nextInt();
        d = in.nextLong();
        pts = new ArrayList<Pair>();
        pif = new ArrayList<Pair>();
        for (int i = 0; i < n; ++i) {
            int x = in.nextInt();
            int y = in.nextInt();
            pts.add(new Pair(x, y));
            hs.add(new Pair(x, y));
        }
        //Collections.sort(pts);
        for (long i = 1; i * i < d; ++i) {
            long j = (long)Math.sqrt(d - i * i);
            if ((j + 1) * (j + 1) + i * i == d) ++j;
            if ((j - 1) * (j - 1) + i * i == d) --j;
            if (i * i + j * j == d)
                pif.add(new Pair((int)i, (int)j));
        }

        int ans = 0;
        int t = (int)Math.sqrt(d);
        if (1L * (t + 1) * (t + 1) == d) ++t;
        if (1L * (t - 1) * (t - 1) == d) --t;
        if (1L * t * t != d) t = -1;

        for (int i = 0; i < n; ++i) {
            int x = pts.get(i).f;
            int y = pts.get(i).s;
            for (int j = 0; j < pif.size(); ++j) {
                int dx = pif.get(j).f;
                int dy = pif.get(j).s;
                int fx = x - dx;
                int fy = y - dy;
                ans += fnd(fx, fy);

                fx = x - dx;
                fy = y + dy;
                ans += fnd(fx, fy);

                fx = x + dx;
                fy = y - dy;
                ans += fnd(fx, fy);

                fx = x + dx;
                fy = y + dy;
                ans += fnd(fx, fy);
            }
            if (t != -1) {
                int fx = x - t;
                int fy = y;
                ans += fnd(fx, fy);

                fx = x + t;
                fy = y;
                ans += fnd(fx, fy);

                fx = x;
                fy = y - t;
                ans += fnd(fx, fy);

                fx = x;
                fy = y + t;
                ans += fnd(fx, fy);
            }
        }
        out.print(ans / 2);
    }

    public void run() {
        try {
            in = new FastScanner(new File(TASK + ".in"));
            out = new PrintWriter(new File(TASK + ".out"));
            long l = System.currentTimeMillis();
            solve();
            long r = System.currentTimeMillis();
            System.err.println((r - l) / 1000.0);
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }

    public static void main(String[] arg) {
        new distances_ip().run();
    }
}
