#include <bits/stdc++.h>
using namespace std;
int n;
const int N = 1003;
struct Node {
  int x, y, t;
  double p;
  bool operator<(const Node &p) const { return t < p.t; }
} p[N];
double dp[N];
bool ok(int j, int i) {
  return (p[i].x - p[j].x) * (p[i].x - p[j].x) +
             (p[i].y - p[j].y) * (p[i].y - p[j].y) <=
         (long long)(p[i].t - p[j].t) * (p[i].t - p[j].t);
}
int main() {
  int i, j;
  scanf("%d", &n);
  for (i = 1; i <= n; i++)
    scanf("%d%d%d%lf", &p[i].x, &p[i].y, &p[i].t, &p[i].p);
  sort(p + 1, p + n + 1);
  for (i = 1; i <= n; i++) dp[i] = p[i].p;
  for (i = 2; i <= n; i++)
    for (j = 1; j < i; j++)
      if (ok(j, i)) dp[i] = max(dp[i], dp[j] + p[i].p);
  double ans = 0;
  for (i = 1; i <= n; i++) ans = max(ans, dp[i]);
  printf("%.10f\n", ans);
  return 0;
}
