#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 100;
const long double pi = acos(-1.0);
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while ((ch < '0') || (ch > '9')) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ((ch >= '0') && (ch <= '9')) {
    x = x * 10 + (ch - '0');
    ch = getchar();
  }
  return x * f;
}
inline long long readll() {
  long long x = 0;
  int f = 1;
  char ch = getchar();
  while ((ch < '0') || (ch > '9')) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ((ch >= '0') && (ch <= '9')) {
    x = x * 10 + (ch - '0');
    ch = getchar();
  }
  return x * f;
}
namespace Geometry {
struct Point {
  double x, y;
  Point(double _x = 0.0, double _y = 0.0) {
    x = _x;
    y = _y;
  }
};
Point operator+(Point a, Point b) { return Point(a.x + b.x, a.y + b.y); }
Point operator-(Point a, Point b) { return Point(a.x - b.x, a.y - b.y); }
Point operator*(Point a, double b) { return Point(a.x * b, a.y * b); }
double Dis2(Point a) { return a.x * a.x + a.y * a.y; }
double Dis(Point a) { return sqrt(Dis2(a)); }
Point rotate(Point a, double ang) {
  return Point(a.x * cos(ang) - a.y * sin(ang),
               a.x * sin(ang) + a.y * cos(ang));
}
Point adjust(Point a, double b) { return a * (b / Dis(a)); }
struct Circle {
  Point p;
  double r;
};
double Intersect(Circle a, Circle b) {
  Point c = b.p - a.p;
  double d2 = Dis2(a.p - b.p), d1 = sqrt(d2);
  double ang = acos((a.r * a.r + d2 - b.r * b.r) / (d1 * a.r * 2));
  return ang;
}
}  // namespace Geometry
using namespace Geometry;
int n, d, tot = 0;
struct node {
  double ang;
  int op;
} p[2002000];
bool cmp(node p, node q) {
  return ((p.ang < q.ang) || ((p.ang == q.ang) && (p.op > q.op)));
}
int main() {
  n = read();
  d = read();
  for (register int i = 1; i <= n; i++) {
    Circle c, c2;
    c.p.x = read();
    c.p.y = read();
    c.r = read();
    double dis = Dis(c.p), R = dis - c.r;
    R = ceil(R / d) * d;
    c2.r = R;
    double Ang = atan2(c.p.y, c.p.x);
    if (Ang < -1e-8) Ang += pi * 2;
    while (1) {
      if (c2.r > dis + c.r) break;
      Point p1, p2;
      double ang = Intersect(c2, c);
      p[++tot] = (node){Ang - ang, 1};
      p[++tot] = (node){Ang + ang, -1};
      c2.r += d;
    }
  }
  sort(p + 1, p + 1 + tot, cmp);
  int ans = 0, sum = 0;
  for (register int i = 1; i <= tot; i++) {
    sum += p[i].op;
    ans = max(ans, sum);
  }
  printf("%d\n", ans);
  return 0;
}
