#include <bits/stdc++.h>
using namespace std;
struct node {
  int x, y, t;
  double pp;
} q[1005], p[1005];
double dis(node a, node b) {
  return sqrt(1.0 * (a.x - b.x) * (a.x - b.x) +
              1.0 * (a.y - b.y) * (a.y - b.y));
}
double dp[1005];
bool cmp(node a, node b) {
  if (a.t == b.t && a.x == b.x) return a.y < b.y;
  if (a.t == b.t) return a.x < b.x;
  return a.t < b.t;
}
int main() {
  int i, j, n, k;
  double ans, tmp;
  while (~scanf("%d", &n)) {
    for (i = 0; i < n; i++)
      scanf("%d%d%d%lf", &q[i].x, &q[i].y, &q[i].t, &q[i].pp);
    sort(q, q + n, cmp);
    k = 0;
    p[0] = q[0];
    for (i = 1; i < n; i++) {
      p[++k] = q[i];
    }
    for (i = 0; i < n; i++) dp[i] = 0;
    ans = 0;
    for (i = 0; i <= k; i++) {
      dp[i] = p[i].pp;
      for (j = 0; j < i; j++) {
        tmp = dis(p[i], p[j]);
        if (p[i].t - p[j].t > tmp || fabs(p[i].t - p[j].t - tmp) < 1e-6)
          dp[i] = max(dp[i], dp[j] + p[i].pp);
      }
      ans = max(ans, dp[i]);
    }
    printf("%.10f\n", ans);
  }
}
