#include <bits/stdc++.h>
const double EPS = 0.00000001;
const long long mod = 1000000000 + 7;
using namespace std;
int n;
map<int, vector<pair<pair<int, int>, double>>> mp;
int t[2000], x[2000], y[2000];
double p[2000];
double dp[2000];
int vis[2000];
double f(int i) {
  if (vis[i]) return dp[i];
  double ans = 0;
  for (int j = i + 1; j < n; j++) {
    double time =
        sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
    if (t[j] >= t[i] + time) ans = max(ans, f(j));
  }
  vis[i] = 1;
  return dp[i] = ans + p[i];
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    int xi, yi, ti;
    double pi;
    cin >> xi >> yi >> ti >> pi;
    mp[ti].push_back(make_pair(make_pair(xi, yi), pi));
  }
  int i = 0;
  for (auto entry : mp) {
    for (int j = 0; j < entry.second.size(); j++) {
      t[i] = entry.first;
      x[i] = entry.second[j].first.first;
      y[i] = entry.second[j].first.second;
      p[i++] = entry.second[j].second;
    }
  }
  memset(dp, -1, sizeof(dp));
  double ans = 0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, f(i));
  }
  cout.precision(18);
  cout << fixed << ans << endl;
  return 0;
}
