#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
struct Node {
  int x, y, t;
  double p;
  bool operator<(const Node& B) const { return t < B.t; }
  void read() { scanf("%d%d%d%lf", &x, &y, &t, &p); }
} A[N];
long long sqr(long long x) { return x * x; }
double dis(int i, int j) {
  return sqrt(1.0 * sqr(A[i].x - A[j].x) + sqr(A[i].y - A[j].y));
}
double dp[N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) A[i].read();
  sort(A, A + n);
  double ans = 0;
  for (int i = 0; i < n; i++) {
    double mmax = 0;
    for (int j = 0; j < i; j++)
      if (dis(j, i) <= A[i].t - A[j].t) mmax = max(mmax, dp[j]);
    ans = max(ans, dp[i] = A[i].p + mmax);
  }
  printf("%.7f\n", ans);
  return 0;
}
