#include <bits/stdc++.h>
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, -1, 0, 1};
using namespace std;
class Point {
 public:
  int xi;
  int yi;
  int ti;
  double wi;
} target[1005];
bool cmp(Point a, Point b) { return a.ti < b.ti; }
double dist(int a, int b) {
  return sqrt((double)(target[a].xi - target[b].xi) *
                  (target[a].xi - target[b].xi) +
              (target[a].yi - target[b].yi) * (target[a].yi - target[b].yi));
}
int work() {
  double f[1005];
  int n;
  double ans = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i)
    scanf("%d%d%d%lf", &target[i].xi, &target[i].yi, &target[i].ti,
          &target[i].wi);
  sort(&target[0], &target[n], cmp);
  memset(f, 0, sizeof(f));
  for (int i = 0; i < n; ++i) {
    f[i] = target[i].wi;
    for (int j = 0; j < i; ++j)
      if (dist(i, j) <= (target[i].ti - target[j].ti + 10e-6))
        if (f[j] + target[i].wi > f[i]) f[i] = f[j] + target[i].wi;
    if (f[i] > ans) ans = f[i];
  }
  printf("%lf\n", ans);
  return 0;
}
int main() {
  work();
  return 0;
}
