#include <bits/stdc++.h>
using namespace std;
double dp[1100];
long long sqr(long long a) { return a * a; }
struct Point {
  int x, y;
  double p;
  int t;
  void scan() {
    scanf("%d%d", &x, &y);
    scanf("%d%lf", &t, &p);
  }
  bool operator<(const Point& p) const { return t < p.t; }
  long long distTo(Point p) { return sqr(x - p.x) + sqr(y - p.y); }
} p[1100];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    p[i].scan();
  }
  sort(p, p + n);
  double res = 0;
  for (int i = 0; i < n; i++) {
    dp[i] = p[i].p;
    for (int j = 0; j < i; j++) {
      long long T2 = sqr(p[i].t - p[j].t);
      long long d2 = p[i].distTo(p[j]);
      if (T2 < d2) {
        continue;
      }
      dp[i] = max(dp[i], dp[j] + p[i].p);
    }
    res = max(res, dp[i]);
  }
  printf("%.9lf", res);
  return 0;
}
