#include <bits/stdc++.h>
using namespace std;
struct aa {
  long double a;
  int b;
  aa() {}
  aa(long double _a, int _b) {
    a = _a;
    b = _b;
  }
} a[810000];
int n, d, i, len, ans, now;
long double x, y, l, r, R;
bool cmp(aa a, aa b) {
  if (abs(a.a - b.a) < 1e-14) return a.b > b.b;
  return a.a < b.a;
}
long double calc(long double x) {
  while (x >= 2 * 3.1415926535897932384626L) x -= 2 * 3.1415926535897932384626L;
  while (x < 0) x += 2 * 3.1415926535897932384626L;
  return x;
}
void add(long double l, long double r) {
  if (calc(r - l) > 3.1415926535897932384626L) swap(l, r);
  if (abs(l - r) < 1e-14 || l < r) {
    a[++len] = aa(l, 1);
    a[++len] = aa(r, -1);
  } else {
    a[++len] = aa(-3.1415926535897932384626L, 1);
    a[++len] = aa(r, -1);
    a[++len] = aa(l, 1);
    a[++len] = aa(3.1415926535897932384626L, -1);
  }
}
void slove(long double x, long double y, long double r, long double l) {
  long double s = (x * x + y * y - r * r + l * l) / 2;
  if (abs(x) < 1e-14) {
    long double Y = s / y;
    add(atan2(Y, sqrt(l * l - Y * Y)), atan2(Y, -sqrt(l * l - Y * Y)));
  } else if (abs(y) < 1e-14) {
    long double X = s / x;
    add(atan2(sqrt(l * l - X * X), X), atan2(-sqrt(l * l - X * X), X));
  } else {
    long double A = y * y + x * x, B = -2 * s * y, C = s * s - x * x * l * l;
    long double delta = B * B - 4 * A * C;
    long double Y1 = (-B + sqrt(delta)) / 2 / A,
                Y2 = (-B - sqrt(delta)) / 2 / A;
    add(atan2(Y1, (s - y * Y1) / x), atan2(Y2, (s - y * Y2) / x));
  }
}
void read(long double &x) {
  double y;
  scanf("%lf", &y);
  x = y;
}
int main() {
  scanf("%d%d", &n, &d);
  for (i = 1; i <= n; i++) {
    read(x);
    read(y);
    read(R);
    l = max(0.0L, sqrt(x * x + y * y) - R);
    r = sqrt(x * x + y * y) + R;
    for (int i = int((l - 1e-14) / d) + 1; i * d <= r; i++)
      slove(x, y, R, i * d);
  }
  sort(a + 1, a + len + 1, cmp);
  for (int i = 1; i <= len; i++) now += a[i].b, ans = max(ans, now);
  printf("%d\n", ans);
}
