#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
const double EPS = 1e-6;
int _w;
int read() {
  int x;
  _w = scanf("%d", &x);
  return x;
}
int dcmp(double x) {
  if (fabs(x) < EPS) return 0;
  return x > 0 ? 1 : -1;
}
struct Point {
  double x, y;
  Point() {}
  Point(double x, double y) : x(x), y(y) {}
  Point operator+(Point P) const { return Point(x + P.x, y + P.y); }
  Point operator-(Point P) const { return Point(x - P.x, y - P.y); }
  Point operator*(double k) const { return Point(x * k, y * k); }
  Point operator/(double k) const { return Point(x / k, y / k); }
  bool operator<(Point P) const {
    if (dcmp(x - P.x) == 0) return y < P.y;
    return x < P.x;
  }
};
double Length(Point v) { return sqrt(v.x * v.x + v.y * v.y); }
Point Unit(Point v) {
  double len = Length(v);
  return v / len;
}
Point Normal(Point v) {
  v = Unit(v);
  return Point(-v.y, v.x);
}
double Cross(Point v, Point w) { return v.x * w.y - v.y * w.x; }
int n, r[MAXN];
Point P, Q, C[MAXN];
vector<Point> evt;
double solve3(Point M, Point P) { return Length(M - P) - Length(M - Q); }
double solve2(Point M, Point v, Point C, double d) {
  int t = dcmp(Cross(P - Q, v) * Cross(P - Q, C - P)) > 0;
  double low = 0, high = 1e12;
  for (int tm = 0; tm < 88; ++tm) {
    double mid = (low + high) / 2;
    if (dcmp(solve3(M + v * mid, C) - d < 0)) {
      t > 0 ? high = mid : low = mid;
    } else {
      t > 0 ? low = mid : high = mid;
    }
  }
  return dcmp(solve3(M + v * low, C) - d) ? (dcmp(low) ? 1e12 : -1) : low;
}
void solve1(Point M, Point v, Point C, double r) {
  double low = solve2(M, v, C, r);
  double high = solve2(M, v, C, -r);
  if (low > high) swap(low, high);
  evt.push_back(Point(low, -1));
  evt.push_back(Point(high, 1));
}
double solve(Point M, Point v) {
  evt.clear();
  for (int i = 0; i < n; ++i) solve1(M, v, C[i], r[i]);
  evt.push_back(Point(0, 0));
  sort(evt.begin(), evt.end());
  int intsec = 0;
  double ans;
  for (int i = 0; i < (int)evt.size(); ++i) {
    Point e = evt[i];
    intsec += int(e.y);
    if (dcmp(e.x) >= 0 && !intsec) {
      ans = e.x;
      break;
    }
  }
  return Length(M + v * ans - P);
}
int main() {
  P.x = read(), P.y = read();
  Q.x = read(), Q.y = read();
  n = read();
  for (int i = 0; i < n; ++i) {
    C[i].x = read();
    C[i].y = read();
    r[i] = read();
  }
  Point v = Normal(P - Q);
  Point M = (P + Q) / 2;
  double ans = solve(M, v);
  v = Normal(v), v = Normal(v);
  ans = min(ans, solve(M, v));
  printf("%.6lf\n", ans);
  return 0;
}
