#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1000;
struct Target {
  int x, y, t;
  double p;
  Target() {}
  Target(int _x, int _y, int _t, double _p) : x(_x), y(_y), t(_t), p(_p) {}
  bool operator<(const Target &g) const { return t < g.t; }
  void read() { scanf("%d%d%d%lf", &x, &y, &t, &p); }
  int d2(const Target &g) const {
    int dx = g.x - x, dy = g.y - y;
    return dx * dx + dy * dy;
  }
  long long dt2(const Target &g) const {
    long long dt = g.t - t;
    return dt * dt;
  }
};
Target gs[MAX_N];
double dp[MAX_N];
inline void setmax(double &a, double b) {
  if (a < b) a = b;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) gs[i].read();
  sort(gs, gs + n);
  for (int i = 0; i < n; i++) {
    Target &gi = gs[i];
    dp[i] = gi.p;
    for (int j = i - 1; j >= 0; j--)
      if (gi.d2(gs[j]) <= gi.dt2(gs[j])) setmax(dp[i], dp[j] + gi.p);
  }
  double maxd = 0.0;
  for (int i = 0; i < n; i++) setmax(maxd, dp[i]);
  printf("%.10lf\n", maxd);
  return 0;
}
