#include <bits/stdc++.h>
using namespace std;
const double pi = 2 * acos(0.0);
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  int n, d;
  cin >> n >> d;
  vector<int> x(n), y(n), r(n);
  for (int i = 0; i < n; i++) cin >> x[i] >> y[i] >> r[i];
  vector<pair<double, pair<int, int> > > event;
  vector<int> active;
  int k = 0;
  for (int j = 0; j < n; j++) {
    double d1 = sqrt(x[j] * x[j] + y[j] * y[j]) - r[j],
           d2 = sqrt(x[j] * x[j] + y[j] * y[j]) + r[j];
    for (double i = (int)d1 / d * d; i <= d2; i += d) {
      if (i < d1) continue;
      double a = r[j];
      double b = i;
      double c = sqrt(x[j] * x[j] + y[j] * y[j]);
      double phi = atan2(y[j], x[j]);
      double phi1 = phi - acos((b * b + c * c - a * a) / (2 * b * c));
      double phi2 = phi + acos((b * b + c * c - a * a) / (2 * b * c)) + 1e-8;
      while (phi1 < 0) phi1 += 2 * pi;
      while (phi1 >= 2 * pi) phi1 -= 2 * pi;
      while (phi2 < 0) phi2 += 2 * pi;
      while (phi2 >= 2 * pi) phi2 -= 2 * pi;
      event.push_back({phi1, {k, +1}});
      event.push_back({phi2, {k, -1}});
      k++;
    }
  }
  sort(event.begin(), event.end());
  active.resize(k);
  int cursum = 0;
  for (int i = 0; i < event.size(); i++) {
    if (event[i].second.second == +1) {
      active[event[i].second.first] = 1;
      cursum++;
    } else {
      if (active[event[i].second.first] == 1) {
        active[event[i].second.first] = 0;
        cursum--;
      }
    }
  }
  int res = cursum;
  for (int i = 0; i < event.size(); i++) {
    if (event[i].second.second == +1)
      cursum++;
    else
      cursum--;
    res = max(res, cursum);
  }
  cout << res << '\n';
  return 0;
}
