#include <bits/stdc++.h>
using namespace std;
int n;
complex<long double> a[100005], b, c, opkgerk, bcdir;
long double r[100005];
complex<long double> pt(long double x) { return opkgerk + bcdir * x; }
long double det(complex<long double> a, complex<long double> b,
                complex<long double> c) {
  return (conj(b - a) * (c - b)).imag();
}
long double seek_touch(complex<long double> a, long double d) {
  bool flip = det(a, b, c) > 0;
  long double l = -1e12, r = 1e12;
  int steps = 90;
  while (steps--) {
    long double m = (l + r) / 2;
    complex<long double> z = pt(m);
    ((abs(z - b) + d > abs(z - a)) ^ flip ? l : r) = m;
  }
  return l;
}
long double seek_contain(complex<long double> a, long double d) {
  bool flip = det(a, b, c) > 0;
  long double l = -1e12, r = 1e12;
  int steps = 90;
  while (steps--) {
    long double m = (l + r) / 2;
    complex<long double> z = pt(m);
    ((abs(z - b) > d + abs(z - a)) ^ flip ? l : r) = m;
  }
  return l;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cerr.tie(nullptr);
  {
    int p, q, r, s;
    cin >> p >> q >> r >> s;
    b = complex<long double>(p, q);
    c = complex<long double>(r, s);
    opkgerk = (b + c) / complex<long double>(2, 0);
    bcdir = (c - b) * complex<long double>(0, 1);
  }
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    a[i] = complex<long double>(x, y);
    r[i] = z;
  }
  map<long double, int> mp;
  for (int i = 0; i < n; i++) {
    long double u = seek_touch(a[i], r[i]);
    long double v = seek_contain(a[i], r[i]);
    if (u > v) swap(u, v);
    mp[u]++;
    mp[v]--;
  }
  mp[0];
  int z = 0;
  long double d = 1e50;
  for (auto [p, v] : mp) {
    if (z == 0) d = min(d, abs(p));
    z += v;
    if (z == 0) d = min(d, abs(p));
  }
  cout << setprecision(20) << fixed << abs(pt(d) - b) << '\n';
}
