#include <bits/stdc++.h>
using namespace std;
const int N = 1007;
struct Animal {
  int x, y, t;
  double p;
} ani[N];
int n;
double dp[N], ans;
bool cmp(Animal x, Animal y) { return x.t < y.t; }
bool OK(int i, int j) {
  long long D = (long long)(ani[i].x - ani[j].x) * (ani[i].x - ani[j].x) +
                (long long)(ani[i].y - ani[j].y) * (ani[i].y - ani[j].y);
  long long T = (long long)(ani[i].t - ani[j].t) * (ani[i].t - ani[j].t);
  if (D <= T) return true;
  return false;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d %d %d %lf", &ani[i].x, &ani[i].y, &ani[i].t, &ani[i].p);
  sort(ani + 1, ani + n + 1, cmp);
  for (int i = 1; i <= n; i++) {
    dp[i] = ani[i].p;
    for (int j = 1; j < i; j++)
      if (OK(i, j)) dp[i] = max(dp[i], dp[j] + ani[i].p);
    ans = max(ans, dp[i]);
  }
  printf("%.12f\n", ans);
  return 0;
}
