#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > a;
long double val[1001][1001];
long double dp(long double p[], int pos, int last, int n) {
  if (val[pos][last] != -1) {
    return val[pos][last];
  }
  if (pos == n) {
    if (last == 0) {
      val[pos][last] = p[a[pos - 1][3]];
    } else {
      if (a[pos - 1][0] - a[last - 1][0] >=
          sqrt((a[pos - 1][1] - a[last - 1][1]) *
                   (a[pos - 1][1] - a[last - 1][1]) +
               (a[pos - 1][2] - a[last - 1][2]) *
                   (a[pos - 1][2] - a[last - 1][2]))) {
        val[pos][last] = p[a[pos - 1][3]];
      } else {
        val[pos][last] = 0;
      }
    }
  } else if (last == 0) {
    val[pos][last] =
        max(dp(p, pos + 1, last, n), p[a[pos - 1][3]] + dp(p, pos + 1, pos, n));
  } else {
    val[pos][last] = dp(p, pos + 1, last, n);
    if (a[pos - 1][0] - a[last - 1][0] >=
        sqrt((a[pos - 1][1] - a[last - 1][1]) *
                 (a[pos - 1][1] - a[last - 1][1]) +
             (a[pos - 1][2] - a[last - 1][2]) *
                 (a[pos - 1][2] - a[last - 1][2]))) {
      val[pos][last] =
          max(val[pos][last], p[a[pos - 1][3]] + dp(p, pos + 1, pos, n));
    }
  }
  return val[pos][last];
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  vector<int> a2(4);
  long double p[n];
  for (int i = 0; i < n; i++) {
    cin >> a2[1] >> a2[2] >> a2[0] >> p[i];
    a2[3] = i;
    a.push_back(a2);
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < 1001; i++) {
    for (int j = 0; j < 1001; j++) {
      val[i][j] = -1;
    }
  }
  long double ll = dp(p, 1, 0, n);
  cout << setprecision(8) << ll << endl;
  return 0;
}
