#include <bits/stdc++.h>
using namespace std;
double search(double vx, double vy, double mx, double my, double cx, double cy,
              double r, double d, double i) {
  double x = mx + vx * i, y = my + vy * i;
  return r * r + 2 * r * sqrt(i * i + d * d) + (i * i + d * d) -
         ((x - cx) * (x - cx) + (y - cy) * (y - cy));
}
double search(double vx, double vy, double mx, double my, double cx, double cy,
              double R, double d) {
  double r = 1e12, l = -1e12;
  double tr = search(vx, vy, mx, my, cx, cy, R, d, r),
         tl = search(vx, vy, mx, my, cx, cy, R, d, l);
  double err = 1e-6;
  while (r - l > err) {
    double mid = (r + l) / 2;
    double mido = search(vx, vy, mx, my, cx, cy, R, d, mid);
    if (tl < 0 && mido < 0 || tl > 0 && mido > 0)
      l = mid;
    else
      r = mid;
  }
  return (l + r) / 2;
}
int main() {
  ios_base::sync_with_stdio(false);
  double x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  long N;
  cin >> N;
  vector<long long> X, Y, R;
  for (int i = 0; i < N; ++i) {
    long x, y, r;
    cin >> x >> y >> r;
    X.push_back(x);
    Y.push_back(y);
    R.push_back(r);
  }
  double mx = (x1 + x2) / 2;
  double my = (y1 + y2) / 2;
  double d = sqrt((x1 - mx) * (x1 - mx) + (y1 - my) * (y1 - my));
  double vx, vy;
  {
    double dy = y2 - y1;
    double dx = x2 - x1;
    vx = -dy / sqrt(dy * dy + dx * dx);
    vy = dx / sqrt(dy * dy + dx * dx);
  }
  set<pair<double, long> > block = {{0, 0}};
  for (int i = 0; i < N; i++) {
    double i1 = search(vx, vy, mx, my, X[i], Y[i], R[i], d);
    double i2 = search(vx, vy, mx, my, X[i], Y[i], -R[i], d);
    double b1 = min(i1, i2), b2 = max(i1, i2);
    block.insert({b1 - 1e-6, i + 1});
    block.insert({b2 + 1e-6, -(i + 1)});
  };
  double best = 1e13;
  long long stat = 0;
  for (auto b : block) {
    double i = b.first;
    long long oldstat = stat;
    if (b.second > 0)
      stat--;
    else if (b.second < 0)
      stat++;
    if (stat == 0 || oldstat == 0) best = min(best, sqrt(d * d + i * i));
  }
  cout << best << endl;
}
