#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 79, iter = 100;
struct point {
  long double x, y;
};
point a, b;
vector<point> v(maxn);
long double distance(point p1, point p2) {
  return sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
}
bool distance_from_center(point p, long double len, long double d) {
  point c;
  c.x = (a.x + b.x) / 2. + (a.y - b.y) * len;
  c.y = (a.y + b.y) / 2. + (b.x - a.x) * len;
  return distance(c, p) - d > distance(c, a);
}
long double binary_search(point p, long double d) {
  long double l = -1e12, r = 1e12;
  bool dl = distance_from_center(p, l, d), dr = distance_from_center(p, r, d);
  for (int i = 0; i < iter; i++) {
    long double m = (l + r) / 2.;
    if (distance_from_center(p, m, d) == dl)
      l = m;
    else
      r = m;
  }
  return l;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(30) << fixed;
  cin >> a.x >> a.y >> b.x >> b.y;
  int n;
  cin >> n;
  vector<pair<long double, int> > ev{{0, 0}};
  for (int i = 0; i < n; i++) {
    long double radius;
    cin >> v[i].x >> v[i].y >> radius;
    long double l = binary_search(v[i], radius),
                r = binary_search(v[i], -radius);
    if (l > r) swap(l, r);
    ev.push_back({l, 1});
    ev.push_back({r, -1});
  }
  sort(ev.begin(), ev.end());
  long double ans = 1e18;
  int bad = 0;
  for (int i = 0; i < ev.size(); i++) {
    if (bad == 0) ans = min(ans, abs(ev[i].first));
    bad += ev[i].second;
    if (bad == 0) ans = min(ans, abs(ev[i].first));
  }
  long double ab = distance(a, b);
  long double r = ab * sqrt(ans * ans + 0.25);
  cout << r << "\n";
  return 0;
}
