#include <bits/stdc++.h>
using namespace std;
int N, x, y, t;
double rez, d[1010], p;
struct pct {
  int x, y, t;
  double p;
  pct(int xx, int yy, int tt, double pp) { x = xx, y = yy, t = tt, p = pp; }
  pct() {}
} v[1010];
int cmp(pct v1, pct v2) { return v1.t < v2.t; }
long long dist(int i, int j) {
  return 1LL * (v[i].x - v[j].x) * (v[i].x - v[j].x) +
         1LL * (v[i].y - v[j].y) * (v[i].y - v[j].y);
}
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) {
    scanf("%d%d%d%lf", &x, &y, &t, &p);
    v[i] = pct(x, y, t, p);
  }
  sort(v + 1, v + N + 1, cmp);
  for (int i = 1; i <= N; ++i) {
    for (int j = 0; j < i; ++j) {
      if (j && dist(i, j) > 1LL * (v[i].t - v[j].t) * (v[i].t - v[j].t))
        continue;
      d[i] = max(d[i], d[j] + v[i].p);
    }
    rez = max(d[i], rez);
  }
  printf("%.12lf", rez);
  return 0;
}
