#include <bits/stdc++.h>
using namespace std;
struct target {
  long double x;
  long double y;
  long long t;
  long double p;
  bool operator<(const target &b) const;
};
bool target::operator<(const target &b) const { return t < b.t; }
int main() {
  cout.precision(30);
  vector<target> v;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    target t;
    cin >> t.x >> t.y >> t.t >> t.p;
    v.push_back(t);
  }
  sort(v.begin(), v.end());
  long double score[1010];
  for (long long i = n - 1; i >= 0; i--) {
    long double baseScore = v[i].p;
    score[i] = v[i].p;
    for (long long i2 = i + 1; i2 < n; i2++) {
      long double dist = sqrt((v[i].x - v[i2].x) * (v[i].x - v[i2].x) +
                              (v[i].y - v[i2].y) * (v[i].y - v[i2].y));
      if (dist <= v[i2].t - v[i].t) {
        if (baseScore + score[i2] > score[i]) {
          score[i] = baseScore + score[i2];
        }
      }
    }
  }
  long double maxScore = score[0];
  for (int i = 1; i < n; i++) {
    if (score[i] > maxScore) {
      maxScore = score[i];
    }
  }
  cout << maxScore << endl;
}
