#include <bits/stdc++.h>
enum { FR, TO };
const long double EPS = 1e-9;
const long double PI = acosl(-1.0);
const long double TWO_PI = 2 * PI;
inline int cmp(const long double& a, const long double& b = 0) {
  return (a + EPS < b) ? (-1) : ((b + EPS < a) ? (1) : (0));
}
inline long double sq(const long double& x) { return x * x; }
inline long double cross(const std::complex<long double>& a,
                         const std::complex<long double>& b) {
  return std::imag(a * std::conj(b));
}
inline bool is_left(const std::complex<long double>& q,
                    const std::complex<long double>& a,
                    const std::complex<long double>& b) {
  return cmp(cross(q - a, b - a)) < 0;
}
inline long double ang(const std::complex<long double>& x) {
  long double answer;
  answer = std::arg(x);
  if (cmp(answer, PI) == 0) {
    return -PI;
  }
  return answer;
}
struct event {
  long double time;
  int type;
  event(const long double& i, const long double& y) : time(i), type(y) {}
  bool operator<(const event& o) const {
    if (cmp(time, o.time) == 0) {
      return type < o.type;
    }
    return cmp(time, o.time) < 0;
  }
};
std::vector<std::complex<long double> > cl_int(const long double& r,
                                               const long double& a,
                                               const long double& b,
                                               const long double& c) {
  std::complex<long double> p0;
  long double d, m, n;
  std::vector<std::complex<long double> > inter;
  n = sq(a) + sq(b);
  p0 = std::complex<long double>(-a * c / n, -b * c / n);
  if (cmp(sq(c), sq(r) * n) == 0) {
    inter.push_back(p0);
  } else if (cmp(sq(c), sq(r) * n) < 0) {
    d = sq(r) - sq(c) / n;
    m = sqrtl(d / n);
    inter.push_back(std::complex<long double>(std::real(p0) + b * m,
                                              std::imag(p0) - a * m));
    inter.push_back(std::complex<long double>(std::real(p0) - b * m,
                                              std::imag(p0) + a * m));
  }
  return inter;
}
std::vector<std::complex<long double> > cc_int(
    const long double& r1, const long double& r2,
    const std::complex<long double>& c2) {
  long double a, b, c;
  a = -2 * std::real(c2);
  b = -2 * std::imag(c2);
  c = sq(std::real(c2)) + sq(std::imag(c2)) + sq(r1) - sq(r2);
  return cl_int(r1, a, b, c);
}
int main(void) {
  int count, best, n, i, j;
  long double lo, hi, a0, a1, ac, x, y, r, d;
  std::complex<long double> c;
  std::vector<std::complex<long double> > inter;
  std::vector<event> sweep;
  std::cin >> n >> d;
  for (i = 0; i < n; ++i) {
    std::cin >> x >> y >> r;
    c = std::complex<long double>(x, y);
    lo = d * std::ceil((std::abs(c) - r) / d);
    hi = d * std::floor((std::abs(c) + r) / d);
    for (j = lo; j <= hi; j += d) {
      inter = cc_int(j, r, c);
      if (inter.size() == 1) {
        sweep.push_back(event(std::arg(inter[0]), FR));
        sweep.push_back(event(std::arg(inter[0]), TO));
      } else if (inter.size() == 2) {
        a0 = ang(inter[0]);
        a1 = ang(inter[1]);
        if (cmp(a0, a1) > 0) {
          std::swap(a0, a1);
        }
        if (cmp(a1 - a0, PI) > 0) {
          sweep.push_back(event(a1 - TWO_PI, FR));
          sweep.push_back(event(a0, TO));
          sweep.push_back(event(a1, FR));
          sweep.push_back(event(a0 + TWO_PI, TO));
        } else {
          sweep.push_back(event(a0, FR));
          sweep.push_back(event(a1, TO));
        }
      }
    }
  }
  std::sort(sweep.begin(), sweep.end());
  best = 0;
  count = 0;
  for (i = 0; i < sweep.size(); ++i) {
    if (sweep[i].type == FR) {
      best = std::max(best, ++count);
    } else {
      --count;
    }
  }
  std::cout << best << std::endl;
  return 0;
}
