#include <bits/stdc++.h>
using namespace std;
struct node {
  long x, y, t;
  double p;
} d[2000] = {0};
double f[2000] = {0};
bool cmp(node a, node b) { return a.t < b.t; }
long wym(long x) { return x > 0 ? x : -x; }
double sqr(double x) { return x * x; }
double dis(node a, node b) { return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y)); }
int main() {
  int n;
  double ans = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> d[i].x >> d[i].y >> d[i].t >> d[i].p;
  sort(d, d + n, cmp);
  for (int i = 0; i < n; ++i) {
    double best = 0;
    for (int j = 0; j < i; ++j)
      if (best < f[j] && (d[i].t - d[j].t) >= dis(d[i], d[j])) best = f[j];
    f[i] = best + d[i].p;
    ans = max(f[i], ans);
  }
  printf("%.10lf\n", ans);
  return 0;
}
