#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 55;
struct node {
  long long x, y, t;
  double p;
  bool operator<(const node& c) const { return t < c.t; }
  void init() { scanf("%lld%lld%lld%lf", &x, &y, &t, &p); }
} a[maxn];
int n;
double f[maxn];
int main(void) {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) a[i].init();
  sort(a + 1, a + 1 + n);
  memset(f, 0, sizeof(f));
  double cur = -1e18;
  for (int i = 1; i <= n; ++i) {
    f[i] = a[i].p;
    for (int j = 1; j < i; ++j) {
      long long t1 = (a[i].x - a[j].x) * (a[i].x - a[j].x) +
                     (a[i].y - a[j].y) * (a[i].y - a[j].y);
      long long t2 = (a[i].t - a[j].t) * (a[i].t - a[j].t);
      if (t2 >= t1) {
        f[i] = max(f[i], f[j] + a[i].p);
      }
    }
    cur = max(f[i], cur);
  }
  printf("%.9lf\n", cur);
  return 0;
}
