#include <bits/stdc++.h>
using namespace std;
struct note {
  long long x, y, t;
  double p;
  bool operator<(const note &other) const { return t < other.t; }
} a[1005];
bool juli(note a, note b) {
  double length = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
  if (length <= (a.t - b.t) * (a.t - b.t)) return true;
  return false;
}
int n;
double dp[1005];
int main() {
  while (~scanf("%d", &n)) {
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i < n; i++) {
      scanf("%lld%lld%lld%lf", &a[i].x, &a[i].y, &a[i].t, &a[i].p);
    }
    double maxx = -1.0;
    sort(a, a + n);
    for (int i = 0; i < n; i++) {
      dp[i] = a[i].p;
      maxx = max(dp[i], maxx);
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < i; j++) {
        if (juli(a[i], a[j])) {
          dp[i] = max(dp[i], dp[j] + a[i].p);
          maxx = max(dp[i], maxx);
        }
      }
    }
    printf("%.9lf\n", maxx);
  }
  return 0;
}
