#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int N = 2e4 + 9;
struct Point {
  double x, y, r;
} p[N];
struct Node {
  double ang;
  int v;
  bool operator<(const Node& b) const {
    if (fabs(ang - b.ang) < 1e-7) return v > b.v;
    return ang < b.ang;
  }
};
void solve(double R, Point p, vector<Node>& v) {
  double d = sqrt(p.x * p.x + p.y * p.y);
  double deta = acos((d * d - p.r * p.r + R * R) / (2 * d * R));
  double aa = atan2(p.y, p.x);
  if (aa < -1e-7) aa += 2 * pi;
  double r1 = aa - deta, r2 = aa + deta;
  if (r1 < -1e-7) {
    v.push_back((Node){r1 + 2 * pi, 1});
    v.push_back((Node){2 * pi, -1});
    v.push_back((Node){0, 1});
    v.push_back((Node){r2, -1});
    return;
  }
  if (r2 > 2 * pi + 1e-7) {
    v.push_back((Node){r1, 1});
    v.push_back((Node){2 * pi, -1});
    v.push_back((Node){0, 1});
    v.push_back((Node){r2 - 2 * pi, -1});
    return;
  }
  v.push_back((Node){r1, 1});
  v.push_back((Node){r2, -1});
}
int main() {
  int n, d;
  scanf("%d %d", &n, &d);
  for (int i = 1; i <= n; ++i) {
    scanf("%lf %lf %lf", &p[i].x, &p[i].y, &p[i].r);
  }
  int ans = 0;
  vector<Node> vec;
  for (int i = 1; i <= n; ++i) {
    double dis = sqrt(p[i].x * p[i].x + p[i].y * p[i].y);
    double le = dis - p[i].r, ri = dis + p[i].r;
    for (int j = (int)le; j <= (int)(ri + 1); ++j) {
      if (j % d) continue;
      if (j < dis - p[i].r - 1e-7 || j > dis + p[i].r + 1e-7) continue;
      if (fabs(le - j) < 1e-7 || fabs(ri - j) < 1e-7) {
        double ang = atan2(p[i].y, p[i].x);
        if (ang < -1e-7) ang += 2 * pi;
        vec.push_back((Node){ang, 1});
        vec.push_back((Node){ang, -1});
        continue;
      }
      solve(j, p[i], vec);
    }
  }
  sort(vec.begin(), vec.end());
  int cur = 0;
  for (auto it : vec) {
    cur += it.v;
    ans = max(ans, cur);
  }
  printf("%d", ans);
  return 0;
}
