#include <bits/stdc++.h>
using namespace std;
struct node {
  int x, y, t;
  double p;
};
bool comp(node a, node b) { return a.t < b.t; }
int n;
double ans;
node ar[1000];
double dp[1000];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d%d%d%lf", &ar[i].x, &ar[i].y, &ar[i].t, &ar[i].p);
  sort(ar, ar + n, comp);
  for (int i = 0; i < n; i++) {
    dp[i] = ar[i].p;
    for (int j = 0; j < i; j++)
      if (pow(ar[i].t - ar[j].t, 2) >=
          pow(ar[i].x - ar[j].x, 2) + pow(ar[i].y - ar[j].y, 2))
        dp[i] = max(dp[i], dp[j] + ar[i].p);
    ans = max(ans, dp[i]);
  }
  printf("%.10lf\n", ans);
  return 0;
}
