#include <bits/stdc++.h>
using namespace std;
struct tgt {
  long long x, y, t;
  double p;
};
bool cmp(tgt a, tgt b) { return a.t < b.t; }
int main() {
  int n;
  cin >> n;
  vector<tgt> v;
  for (int i = 0; i < n; i++) {
    tgt t;
    cin >> t.x >> t.y >> t.t >> t.p;
    v.push_back(t);
  }
  sort(v.begin(), v.end(), cmp);
  double maxexp = 0.0;
  double exp[1000];
  for (int i = 0; i < n; i++) {
    exp[i] = 0.0;
    for (int j = 0; j < i; j++)
      if ((v[i].x - v[j].x) * (v[i].x - v[j].x) +
              (v[i].y - v[j].y) * (v[i].y - v[j].y) <=
          (v[i].t - v[j].t) * (v[i].t - v[j].t))
        exp[i] = max(exp[i], exp[j]);
    exp[i] += v[i].p;
    maxexp = max(maxexp, exp[i]);
  }
  cout.precision(12);
  cout << maxexp << endl;
  return 0;
}
