#include <bits/stdc++.h>
using namespace std;
double dp[2005];
long long n;
long long sqr(long long x) { return x * x; }
struct zero {
  long long x, y, t;
  double p;
} lib[2222];
bool cmp(zero a, zero b) { return a.t < b.t; }
int main() {
  scanf("%lld", &n);
  for (int i = 1; i <= n; i++)
    scanf("%lld%lld%lld%lf", &lib[i].x, &lib[i].y, &lib[i].t, &lib[i].p);
  sort(lib + 1, lib + n + 1, cmp);
  for (int i = 1; i <= n; i++) dp[i] = lib[i].p;
  for (int i = 1; i <= n; i++) {
    for (int r = i + 1; r <= n; r++)
      if (sqr(lib[r].x - lib[i].x) + sqr(lib[r].y - lib[i].y) <=
          sqr(lib[r].t - lib[i].t)) {
        dp[r] = max(dp[r], dp[i] + lib[r].p);
      }
  }
  double res = 0;
  for (int i = 1; i <= n; i++) res = max(res, dp[i]);
  printf("%.10lf", res);
}
