#include <bits/stdc++.h>
using namespace std;
struct po {
  double t, p, x, y;
};
int cmp(po p1, po p2) {
  if (p1.t != p2.t) return p1.t < p2.t;
  return p1.p < p2.p;
}
po p[1000];
int n;
double maxp;
double sqr(double a) { return a * a; }
double len(po p1, po p2) { return sqrt(sqr(p1.x - p2.x) + sqr(p1.y - p2.y)); }
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%lf%lf%lf%lf", &p[i].x, &p[i].y, &p[i].t, &p[i].p);
  sort(p, p + n, cmp);
  maxp = 0;
  double res[1000];
  for (int i = 0; i < n; i++) {
    res[i] = p[i].p;
    for (int j = 0; j < i; j++)
      if ((len(p[i], p[j]) - 1e-5 <= p[i].t - p[j].t) &&
          res[i] < res[j] + p[i].p)
        res[i] = res[j] + p[i].p;
    if (res[i] > maxp) maxp = res[i];
  }
  printf("%lf\n", maxp);
}
