#include <bits/stdc++.h>
using namespace std;
struct Point {
  int x, y, t;
  double v;
};
const int maxN = 1005;
Point p[maxN];
double dp[maxN];
int n;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p[i].x >> p[i].y >> p[i].t >> p[i].v;
  }
  sort(p, p + n, [](const Point& l, const Point& r) { return l.t < r.t; });
  for (int i = 1; i <= n; i++) {
    dp[i] = p[i - 1].v;
  }
  for (int i = 2; i <= n; i++) {
    for (int j = i - 1; j >= 1; j--) {
      double dist =
          (double)(p[i - 1].x - p[j - 1].x) * (p[i - 1].x - p[j - 1].x) +
          (double)(p[i - 1].y - p[j - 1].y) * (p[i - 1].y - p[j - 1].y);
      double diff = p[i - 1].t - p[j - 1].t;
      diff *= diff;
      if (dist <= diff) {
        dp[i] = max(dp[i], dp[j] + p[i - 1].v);
      }
    }
  }
  double ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = max(ans, dp[i]);
  }
  cout << setprecision(15) << ans << '\n';
}
