#include <bits/stdc++.h>
using namespace std;
int t;
struct bdy {
  int x, y, t;
  double p;
};
bool cmp(bdy a, bdy b) { return a.t < b.t; }
double dist(bdy a, bdy b) {
  double abx = abs(a.x - b.x), aby = abs(a.y - b.y);
  return sqrt(abx * abx + aby * aby);
}
vector<bdy> a;
map<pair<int, int>, double> dp;
double solve(int idx, int flg, int lidx) {
  if (idx >= t) return 0;
  if (dp.find({idx, lidx}) != dp.end()) return dp[{idx, lidx}];
  double temp = 0;
  if (flg == 1) {
    temp = max(a[idx].p + solve(idx + 1, 0, idx), solve(idx + 1, 1, -1));
  } else {
    if (a[idx].t - (a[lidx].t + dist(a[idx], a[lidx])) >= 0)
      temp = (a[idx].p + solve(idx + 1, 0, idx));
    temp = max(solve(idx + 1, 0, lidx), temp);
  }
  return dp[{idx, lidx}] = temp;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  bdy tar;
  cin >> t;
  for (int i = 0; i < t; i++) {
    cin >> tar.x >> tar.y >> tar.t >> tar.p;
    a.push_back(tar);
  }
  sort(a.begin(), a.end(), cmp);
  cout << setprecision(14) << fixed << solve(0, 1, -1);
}
