#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 2;
pair<double, pair<double, pair<double, double> > > M[N];
double dp[N];
int n;
double f(int pos) {
  if (pos == n) return 0.0;
  double &ret = dp[pos];
  if (ret != -1.0) return ret;
  double t1 = M[pos].first;
  double p = M[pos].second.first;
  double x1 = M[pos].second.second.first;
  double y1 = M[pos].second.second.second;
  ret = p;
  for (int i = pos + 1; i < n; ++i) {
    double t2 = M[i].first;
    double x2 = M[i].second.second.first;
    double y2 = M[i].second.second.second;
    double d = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
    if (t1 != t2 and d <= t2 - t1) ret = max(ret, p + f(i));
  }
  return ret;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    double x, y, t, p;
    scanf("%lf %lf %lf %lf", &x, &y, &t, &p);
    M[i] = make_pair(t, make_pair(p, make_pair(x, y)));
  }
  sort(M, M + n);
  for (int i = 0; i <= n; ++i) {
    dp[i] = -1.0;
  }
  double ans = 0.0;
  for (int i = 0; i < n; ++i) {
    ans = max(ans, f(i));
  }
  printf("%.10lf\n", ans);
  return 0;
}
