#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-12;
const int N = 100000 + 10;
long double sqr(long double x) { return x * x; }
struct PT {
  long double x, y;
  PT(long double x = 0, long double y = 0) : x(x), y(y) {}
  void in() {
    double xx, yy;
    scanf("%lf%lf", &xx, &yy);
    x = xx, y = yy;
  }
} P[N];
bool operator<(const PT& p1, const PT& p2) {
  if (fabs(p1.x - p2.x) > EPS) return p1.x < p2.x;
  return p1.y + EPS < p2.y;
}
bool operator==(const PT& p1, const PT& p2) {
  return fabs(p1.x - p2.x) < EPS && fabs(p1.y - p2.y) < EPS;
}
PT operator+(PT p1, PT p2) { return PT(p1.x + p2.x, p1.y + p2.y); }
PT operator-(PT p1, PT p2) { return PT(p1.x - p2.x, p1.y - p2.y); }
PT operator*(PT p, long double c) { return PT(p.x * c, p.y * c); }
PT operator/(PT p, long double c) { return PT(p.x / c, p.y / c); }
long double dis(PT p) { return sqrt(sqr(p.x) + sqr(p.y)); }
long double dis2(PT p) { return sqr(p.x) + sqr(p.y); }
long double dis2(PT p1, PT p2) { return sqr(p1.x - p2.x) + sqr(p1.y - p2.y); }
long double dis(PT p1, PT p2) { return sqrt(dis2(p1, p2)); }
long double vect(PT p1, PT p2) { return p1.x * p2.y - p2.x * p1.y; }
long double scal(PT p1, PT p2) { return p1.x * p2.x + p1.y * p2.y; }
long double getAngle(PT p) { return atan2(p.y, p.x); }
long double vect(PT p, PT p1, PT p2) { return vect(p1 - p, p2 - p); }
long double scal(PT p, PT p1, PT p2) { return scal(p1 - p, p2 - p); }
long double getAngle(PT p, PT p1, PT p2) {
  return acos(scal(p, p1, p2) / dis(p, p1) / dis(p, p2));
}
long double disToLineSgn(PT p, PT p1, PT p2) {
  return vect(p, p1, p2) / dis(p1, p2);
}
long double r[N];
PT P1, P2;
vector<pair<long double, long double> > vec[2];
int main() {
  P1.in(), P2.in();
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    P[i].in();
    double rr;
    scanf("%lf", &rr);
    r[i] = rr;
  }
  PT M = (P1 + P2) / 2;
  long double a = dis(P1, P2) / 2;
  int flg = 0;
  for (int i = 0; i < n; i++) {
    long double d = disToLineSgn(P[i], P1, P2);
    long double l2 = dis2(M, P[i]);
    long double p = l2 - sqr(a) - sqr(r[i]);
    long double A = 4 * (sqr(d) - sqr(r[i]));
    long double B = -4 * d * p;
    long double C = sqr(p) - 4 * sqr(a * r[i]);
    long double D = B * B - 4 * A * C;
    if (D < EPS) continue;
    long double x1 = (-B - sqrt(D)) / (2 * A), x2 = (-B + sqrt(D)) / (2 * A);
    if (x2 < EPS)
      vec[0].push_back(pair<long double, long double>(-x2, -x1));
    else if (x1 > -EPS)
      vec[1].push_back(pair<long double, long double>(x1, x2));
    else {
      flg = 1;
      vec[0].push_back(pair<long double, long double>(0, -x1));
      vec[1].push_back(pair<long double, long double>(0, x2));
    }
  }
  if (!flg) return printf("%.10lf\n", (double)a), 0;
  for (int i = 0; i < 2; i++) sort(vec[i].begin(), vec[i].end());
  long double ans = 1e60;
  for (int i = 0; i < 2; i++) {
    long double prv = EPS * 2;
    for (auto it : vec[i]) {
      if (it.first < prv - EPS)
        prv = max(prv, it.second);
      else {
        ans = min(ans, prv);
        break;
      }
    }
    ans = min(ans, prv);
  }
  printf("%.10lf\n", (double)sqrt(sqr(ans) + sqr(a)));
}
