// Arup Guha
// 2/14/2017
// Solution to 2016 German Programming Contest Problem H: Celestial Map

import java.util.*;

public class h {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int n = stdin.nextInt();
		double d = stdin.nextDouble();

		// Get both vectors.
		double[] tmp = new double[3];
		for (int i=0; i<3; i++)
			tmp[i] = stdin.nextDouble();
		vect v1 = new vect(tmp);
		for (int i=0; i<3; i++)
			tmp[i] = stdin.nextDouble();
		vect v2 = new vect(tmp);

		// Calculate the normal to the plane.
		vect pNormUnit = v1.cross(v2).unit();

		int res = 0;

		// Process each star.
		for (int i=0; i<n; i++) {

			// Get star line equation.
			for (int j=0; j<3; j++)
				tmp[j] = stdin.nextDouble();
			vect pt = new vect(tmp);
			for (int j=0; j<3; j++)
				tmp[j] = stdin.nextDouble();
			vect dir = new vect(tmp);

			// This is the point where the transmission came from.
			vect ptAtTrans = pt.add(dir.multiply(-d));

			// Point must be on the plane AND at the given distance from the origin.
			if (Math.abs(ptAtTrans.mag()-d) < .1 && Math.abs(pNormUnit.dot(ptAtTrans)) < .1)
				res++;
		}

		// Ta da!
		System.out.println(res);
	}
}

class vect {

	public double x;
	public double y;
	public double z;

	public vect(double[] v) {
		x = v[0];
		y = v[1];
		z = v[2];
	}

	public vect(double myx, double myy, double myz) {
		x = myx;
		y = myy;
		z = myz;
	}

	public double dot(vect other) {
		return x*other.x + y*other.y + z*other.z;
	}

	public vect cross(vect other) {
		return new vect(this.y*other.z-other.y*this.z, this.z*other.x-other.z*this.x, this.x*other.y-other.x*this.y);
	}

	public vect unit() {
		double m = mag();
		return new vect(x/m, y/m, z/m);
	}

	public vect multiply(double f) {
		return new vect(x*f, y*f, z*f);
	}

	public vect add(vect other) {
		return new vect(x+other.x, y+other.y, z+other.z);
	}

	public double mag() {
		return Math.sqrt(x*x+y*y+z*z);
	}

	// Treat as pts.
	public double dist(vect other) {
		return Math.sqrt(Math.pow(x-other.x,2)+Math.pow(y-other.y,2)+Math.pow(z-other.z,2));
	}

	public String toString() {
		return "("+x+","+y+","+z+")";
	}
}