#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-8, pi = acos(-1);
const int N = int(1e6) + 50;
vector<long double> axis;
struct BIT {
  int C[N], nm;
  void add(int x, int v) {
    for (; x <= nm; x += x & -x) C[x] += v;
  }
  int query(int v) {
    int r = 0;
    for (; v; v -= v & -v) r += C[v];
    return r;
  }
} C;
int n;
long double d;
long double X[N], Y[N], R[N];
vector<pair<long double, long double> > ranges;
inline int sgn(long double a) { return fabs(a) < eps ? 0 : a > 0 ? 1 : -1; }
inline long double format(long double a) {
  while (sgn(a) < 0) a += pi * 2;
  while (sgn(a - pi * 2) > 0) a -= pi * 2;
  return a;
}
int solve() {
  int t;
  scanf("%d%d", &n, &t);
  d = t;
  for (int i = 1; i <= n; ++i) {
    int x, y, r;
    scanf("%d%d%d", &x, &y, &r);
    X[i] = x;
    Y[i] = y;
    R[i] = r;
    long double dis = sqrt(X[i] * X[i] + Y[i] * Y[i]);
    long double pos = floor(dis / d) * d, lo = dis - r, hi = dis + r;
    if (sgn(dis - lo) < 0) continue;
    long double balf = atan2(Y[i], X[i]);
    for (int t = -22; t <= 22; ++t) {
      long double a = dis, b = pos + t * d, c = R[i];
      if (sgn(b - lo) < 0 || sgn(b - hi) > 0) continue;
      long double alp = (a * a + b * b - c * c) / (2 * a * b);
      if (alp < -1) alp = -1;
      if (alp > 1) alp = 1;
      alp = acos(alp);
      long double alo = balf - alp, ahi = balf + alp;
      alo = format(alo);
      ahi = format(ahi);
      if (alo > ahi)
        ranges.push_back(pair<long double, long double>(alo, pi * 2)),
            ranges.push_back(pair<long double, long double>(0, ahi));
      else
        ranges.push_back(pair<long double, long double>(alo, ahi));
    }
  }
  for (auto it : ranges) axis.push_back(it.first), axis.push_back(it.second);
  auto func = [](long double a, long double b) { return sgn(a - b) == -1; };
  sort(axis.begin(), axis.end(), func);
  axis.resize(
      unique(axis.begin(), axis.end(),
             [](long double a, long double b) { return sgn(a - b) == 0; }) -
      axis.begin());
  C.nm = axis.size() + 5;
  for (auto it : ranges) {
    int a = lower_bound(axis.begin(), axis.end(), it.first, func) -
            axis.begin() + 1,
        b = lower_bound(axis.begin(), axis.end(), it.second, func) -
            axis.begin() + 1;
    C.add(a, 1);
    C.add(b + 1, -1);
  }
  int res = 0;
  for (int i = 1; i <= C.nm; ++i) res = max(res, C.query(i));
  cout << res << endl;
  return 0;
}
int main() { return solve(); }
