#include <bits/stdc++.h>
using namespace std;
template <class C>
constexpr int sz(const C &c) {
  return int(c.size());
}
using ll = long long;
using ld = long double;
constexpr const char nl = '\n', sp = ' ';
using T = long double;
constexpr const T EPS = 1e-9;
bool lt(T a, T b) { return a + EPS < b; }
bool le(T a, T b) { return !lt(b, a); }
bool gt(T a, T b) { return lt(b, a); }
bool ge(T a, T b) { return !lt(a, b); }
bool eq(T a, T b) { return !lt(a, b) && !lt(b, a); }
bool ne(T a, T b) { return lt(a, b) || lt(b, a); }
int sgn(T a) { return lt(a, 0) ? -1 : lt(0, a) ? 1 : 0; }
template <class F>
struct Functor {
  F f;
  Functor(F f) : f(f) {}
  template <class U>
  bool operator()(const U &a, const U &b) const {
    return f(a, b);
  }
};
template <class F>
Functor<F> makeFunctor(F f) {
  return Functor<F>(f);
}
using pt = complex<T>;
istream &operator>>(istream &stream, pt &p) {
  T X, Y;
  stream >> X >> Y;
  p = pt(X, Y);
  return stream;
}
ostream &operator<<(ostream &stream, const pt &p) {
  return stream << p.real() << ' ' << p.imag();
}
bool operator<(const pt &a, const pt &b) {
  return eq(a.real(), b.real()) ? lt(a.imag(), b.imag())
                                : lt(a.real(), b.real());
}
bool operator<=(const pt &a, const pt &b) { return !(b < a); }
bool operator>(const pt &a, const pt &b) { return b < a; }
bool operator>=(const pt &a, const pt &b) { return !(a < b); }
bool operator==(const pt &a, const pt &b) { return !(a < b) && !(b < a); }
bool operator!=(const pt &a, const pt &b) { return a < b || b < a; }
struct pt_lt {
  bool operator()(const pt &a, const pt &b) const { return a < b; }
};
struct pt_le {
  bool operator()(const pt &a, const pt &b) const { return a <= b; }
};
struct pt_gt {
  bool operator()(const pt &a, const pt &b) const { return a > b; }
};
struct pt_ge {
  bool operator()(const pt &a, const pt &b) const { return a >= b; }
};
struct pt_eq {
  bool operator()(const pt &a, const pt &b) const { return a == b; }
};
struct pt_ne {
  bool operator()(const pt &a, const pt &b) const { return a != b; }
};
T dot(const pt &a, const pt &b) {
  return a.real() * b.real() + a.imag() * b.imag();
}
T cross(const pt &a, const pt &b) {
  return a.real() * b.imag() - a.imag() * b.real();
}
T norm(const pt &a) { return dot(a, a); }
T distSq(const pt &a, const pt &b) { return norm(b - a); }
T dist(const pt &a, const pt &b) { return abs(b - a); }
T ang(const pt &a, const pt &b) { return arg(b - a); }
T ang(const pt &a, const pt &b, const pt &c) {
  return remainder(ang(b, a) - ang(b, c), 2 * acos(T(-1)));
}
T area2(const pt &a, const pt &b, const pt &c) { return cross(b - a, c - a); }
int ccw(const pt &a, const pt &b, const pt &c) { return sgn(area2(a, b, c)); }
pt rot(const pt &a, const pt &p, const T &theta) {
  return (a - p) * pt(polar(T(1), theta)) + p;
}
pt perp(const pt &a) { return pt(-a.imag(), a.real()); }
template <class It>
It sortByAng(It st, It en, const pt &pivot) {
  en = partition(st, en, [&](const pt &p) { return p != pivot; });
  It mid = partition(st, en, [&](const pt &p) {
    return eq(p.imag(), pivot.imag()) ? lt(p.real(), pivot.real())
                                      : lt(p.imag(), pivot.imag());
  });
  auto cmp = [&](const pt &p, const pt &q) { return 0 < ccw(pivot, p, q); };
  sort(st, mid, cmp);
  sort(mid, en, cmp);
  return en;
}
struct Circle {
  pt o;
  T r;
  Circle(T r = 0) : o(0, 0), r(r) {}
  Circle(const pt &o, T r) : o(o), r(r) {}
  int inCircle(const pt &p) { return sgn(distSq(o, p) - r * r); }
};
int circleCircleIntersection(const Circle &c1, const Circle &c2,
                             vector<pt> &res) {
  pt d = c2.o - c1.o;
  T d2 = norm(d);
  if (eq(d2, 0)) return eq(c1.r, c2.r) ? 2 : 0;
  T pd = (d2 + c1.r * c1.r - c2.r * c2.r) / 2;
  T h2 = c1.r * c1.r - pd * pd / d2;
  if (!lt(h2, 0)) {
    pt p = c1.o + d * pd / d2, h = perp(d) * sqrt(h2 / d2);
    res.push_back(p - h);
    res.push_back(p + h);
  }
  sort(res.begin(), res.end(), pt_lt());
  res.erase(unique(res.begin(), res.end(), pt_eq()), res.end());
  return !res.empty();
}
const T PI = acos(T(-1));
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int N;
  T D;
  cin >> N >> D;
  vector<T> R(N);
  vector<pt> P(N);
  pt O(0, 0);
  vector<pair<T, int>> A;
  for (int i = 0; i < N; i++) {
    cin >> P[i] >> R[i];
    T d1 = dist(O, P[i]) - R[i], d2 = dist(O, P[i]) + R[i];
    int st = max(int(floor(d1 / D)) - 1, 1), en = max(int(ceil(d2 / D)) + 1, 1);
    for (int k = st; k <= en; k++) {
      vector<pt> Q;
      circleCircleIntersection(Circle(O, k * D), Circle(P[i], R[i]), Q);
      if (sz(Q) == 1) Q.push_back(Q[0]);
      if (sz(Q) == 2) {
        if (ccw(O, Q[0], Q[1]) == -1) swap(Q[0], Q[1]);
        T ang0 = arg(Q[0]), ang1 = arg(Q[1]);
        if (gt(ang0, ang1)) ang1 += 2 * PI;
        for (int j = 0; j <= 2; j++) {
          A.emplace_back(ang0, -1);
          A.emplace_back(ang1, 1);
          ang0 += 2 * PI;
          ang1 += 2 * PI;
        }
      }
    }
  }
  sort(A.begin(), A.end());
  int sm = 0, mx = 0;
  for (auto &&a : A) {
    sm -= a.second;
    mx = max(mx, sm);
  }
  cout << mx << nl;
  return 0;
}
