#include <bits/stdc++.h>
using namespace std;
int x[1010], y[1010], t[1010];
double res[1010];
double p[1010];
int main() {
  int i, j, n, k;
  long long dt, dx, dy;
  set<pair<int, int> > q;
  while (scanf("%d", &n) == 1) {
    for (i = 0; i < n; i++) {
      cin >> x[i] >> y[i] >> t[i] >> p[i];
      q.insert(make_pair(t[i], i));
    }
    double mx = 0;
    while (!q.empty()) {
      int k = q.begin()->second;
      res[k] = p[k];
      q.erase(*q.begin());
      for (i = 0; i < n; i++)
        if (t[i] < t[k]) {
          dx = x[i] - x[k];
          dy = y[i] - y[k];
          dt = t[i] - t[k];
          if ((dx * dx + dy * dy) > (dt * dt)) continue;
          res[k] = max(res[k], p[k] + res[i]);
        }
      mx = max(mx, res[k]);
    }
    printf("%.12lf\n", mx);
  }
  return 0;
}
