#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
const long double eps = 1e-6;
long long n;
long double ans = 1e12;
vector<pair<long double, long long> > vec;
struct Point {
  long double x, y;
  Point(long double x = 0, long double y = 0) : x(x), y(y) {}
  Point operator+(const Point& rhs) const {
    return Point(x + rhs.x, y + rhs.y);
  }
  Point operator-(const Point& rhs) const {
    return Point(x - rhs.x, y - rhs.y);
  }
  Point operator*(const long double& val) const {
    return Point(x * val, y * val);
  }
  Point operator/(const long double& val) const {
    return Point(x / val, y / val);
  }
  long double dist(const Point& rhs) {
    return sqrtl((x - rhs.x) * (x - rhs.x) + (y - rhs.y) * (y - rhs.y));
  }
  long double distpw2(const Point& rhs) {
    return (x - rhs.x) * (x - rhs.x) + (y - rhs.y) * (y - rhs.y);
  }
  Point norm(const long double& val) {
    return Point(x * val / dist(Point()), y * val / dist(Point()));
  }
  long double ccw(const Point& rhs1, const Point& rhs2) {
    return (rhs1.x - x) * (rhs2.y - y) - (rhs2.x - x) * (rhs1.y - y);
  }
  long long signccw(const Point& rhs1, const Point& rhs2) {
    return ccw(rhs1, rhs2) >= 0 ? 1 : -1;
  }
} p1, p2, middle, p3;
struct Circle {
  Point cen;
  long double r;
  Circle(Point cen = Point(), long double r = 0) : cen(cen), r(r) {}
  bool in(const Circle& rhs) { return cen.dist(rhs.cen) + r <= rhs.r; }
  bool out(const Circle& rhs) { return cen.dist(rhs.cen) >= r + rhs.r; }
  bool intersect(Circle rhs) { return !in(rhs) && !out(rhs) && !rhs.in(*this); }
} c[N + 5], minn;
void solve(Circle jud) {
  long double l = -1e12, r = 1e12;
  long long sign = p1.signccw(p2, jud.cen);
  while (r - l > eps) {
    long double mid = (l + r) / 2;
    Circle cmid =
        Circle(middle + p3.norm(mid), sqrt(minn.r * minn.r + mid * mid));
    if (cmid.intersect(jud) || jud.in(cmid)) {
      if (sign == 1)
        r = mid;
      else
        l = mid;
    } else {
      if (sign == -1)
        r = mid;
      else
        l = mid;
    }
  }
  vec.push_back({l, -sign});
  l = -1e12, r = 1e12;
  while (r - l > eps) {
    long double mid = (l + r) / 2;
    Circle cmid =
        Circle(middle + p3.norm(mid), sqrt(minn.r * minn.r + mid * mid));
    if (cmid.out(jud) || cmid.intersect(jud)) {
      if (sign == 1)
        l = mid;
      else
        r = mid;
    } else {
      if (sign == -1)
        l = mid;
      else
        r = mid;
    }
  }
  vec.push_back({l, sign});
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> p1.x >> p1.y >> p2.x >> p2.y;
  middle = p1 + (p2 - p1) / 2;
  p3 = Point(p2.y - p1.y, p1.x - p2.x);
  p3 = p3 * -1;
  cin >> n;
  for (long long i = 1; i <= n; ++i) cin >> c[i].cen.x >> c[i].cen.y >> c[i].r;
  minn = Circle(middle, p1.dist(p2) / 2);
  bool okMinn = 1;
  for (long long i = 1; i <= n; ++i)
    if (minn.intersect(c[i])) {
      okMinn = 0;
      break;
    }
  if (okMinn) {
    cout << minn.r;
    return 0;
  }
  for (long long i = 1; i <= n; ++i) solve(c[i]);
  sort(vec.begin(), vec.end());
  long long cur = 0;
  for (auto i : vec) {
    if (cur >= 0) {
      ans = min(ans, sqrt(i.first * i.first + minn.r * minn.r));
    }
    cur += i.second;
    if (cur >= 0) {
      ans = min(ans, sqrt(i.first * i.first + minn.r * minn.r));
    }
  }
  cout << ans;
  return 0;
}
