#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T& x) {
  bool fu = 0;
  char c;
  for (c = getchar(); c <= 32; c = getchar())
    ;
  if (c == '-') fu = 1, c = getchar();
  for (x = 0; c > 32; c = getchar()) x = x * 10 + c - '0';
  if (fu) x = -x;
};
template <class T>
inline void read(T& x, T& y) {
  read(x);
  read(y);
}
template <class T>
inline void read(T& x, T& y, T& z) {
  read(x);
  read(y);
  read(z);
}
inline char getc() {
  char c;
  for (c = getchar(); c <= 32; c = getchar())
    ;
  return c;
}
const long double pi = 2 * acos(0);
const long double eps = 1e-9;
const int N = 200010;
int n, d, i, j, k, l, p, g, low, up;
struct node {
  long double x, y, r;
} a[N];
long double t, d2, D, R, alp, th;
pair<long double, long double> st[N * 20], op;
long double o[N * 40];
int og;
int s[N * 40];
int findo(long double x) { return lower_bound(o + 1, o + 1 + og, x) - o; }
int main() {
  read(n, d);
  for (i = 1; i <= n; i++) read(a[i].x, a[i].y, a[i].r);
  for (i = 1; i <= n; i++) {
    R = a[i].r;
    d2 = t = sqrt(((a[i].x) * (a[i].x)) + ((a[i].y) * (a[i].y)));
    low = int((t - R) / d);
    if (low * d != t - R) low++;
    up = int((t + R) / d);
    th = atan2(a[i].y, a[i].x);
    for (p = low; p <= up; p++) {
      D = p * d;
      alp = acos((d2 * d2 + D * D - R * R) / (2 * d2 * D));
      op = make_pair(th - alp, th + alp);
      if (op.first < -pi)
        st[++g] = make_pair(op.first + 2 * pi, pi - eps), op.first = -pi;
      if (op.second > pi)
        st[++g] = make_pair(-pi + eps, op.second - 2 * pi), op.second = pi;
      st[++g] = op;
    }
  }
  sort(st + 1, st + 1 + g);
  for (i = 1; i <= g; i++) o[++og] = st[i].first, o[++og] = st[i].second;
  sort(o + 1, o + 1 + og);
  j = 1;
  for (i = 2; i <= og; i++)
    if (o[i] != o[i - 1]) o[++j] = o[i];
  og = j;
  for (i = 1; i <= g; i++)
    s[findo(st[i].first)]++, s[findo(st[i].second) + 1]--;
  int ans = 0;
  for (i = 1; i <= og; i++) {
    s[i] += s[i - 1];
    ans = max(ans, s[i]);
  }
  printf("%d\n", ans);
  scanf("\n");
  return 0;
}
